var app = new Vue({
	el:"#wrapper",
	data:{		
		hostName : "http://ypx.shenmikj.com/am_shop/Wechat/Store/",
		refuseState: false,
		reason:"",
		state: null,
		goodsId: null,
		orderSn: null
	},
	methods:{
		getOrder: function() {
			var goodsId = this.goodsId,
			that = this
			$.ajax({
				method:"get",
				url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/handleStoreOrder",
				data:{
					id:goodsId,
					status: 2,
				},
				async: false,
				dataType:"json",
				success: function(res){
					let url = that.hostName+"storeOrder"
					// console.log(url)
					window.location.href = url
				},
				error: function(res){
					console.log("error",res)
				}
			})
		},
		refuseOrder: function(){
			this.refuseState = true
		},
		countLimite: function() {
			if (this.reason.length >=100) {
				alert("最多输入五十字")
				return false
			}
		},
		close: function(){
			this.refuseState = false
		},
		update: function(){
			var that = this
			var id = this.goodsId,
			reason = this.reason
			state = null
			(this.state==1)?state = -1:state = -2
			// return
			$.ajax({
				method:"get",
				url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/handleStoreOrder",
				data:{
					id:id,
					status: state,
					reason: reason
				},
				async: false,
				dataType:"json",
				success: function(res){
					console.log("success",res)
					that.refuseId = null
					that.refuseState = false
					window.location.href = that.hostName + 'storeOrder'
				},
				error: function(res){
					console.log("error",res)
				}
			})
		},
		arrive: function(){
			var that = this
			console.log(this.goodsId)
			$.ajax({
				method:"get",
				url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/handleStoreOrder",
				data:{
					id:this.goodsId,
					status: 3,
				},
				async: false,
				dataType:"json",
				success: function(res){
					console.log("success",res)
					window.location.href = that.hostName + 'storeOrder'
				},
				error: function(res){
					console.log("error",res)
				}
			})
		},
		getQueryString: function(name){
		    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		    var r = window.location.search.substr(1).match(reg);
		    if(r!=null)return  unescape(r[2]); return null;
		}
	},
	created(){
		var order = [],
		address = null,
		moblie = null,
		userName = null,
		goodsList = [],
		time = "",
		that = this
		this.state = this.getQueryString("state"),
		this.goodsId = this.getQueryString("goodsId"),
		this.orderSn = this.getQueryString("order_sn")
		console.log(this.goodsId,this.orderSn,this.state)
		// return
		$.ajax({
			method:"get",
			url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/getStoreOrderDetail",
			data:{
				id: that.goodsId,
				orderSn: that.orderSn
			},
			async: false,
			dataType:"json",
			success: function(res){
				that.order = res.order
				that.goods = res.goods
				that.userName = res.order[0].name
				that.mobile = res.order[0].mobile
				that.address = res.order[0].address
				that.time = res.order[0].create_time
				that.totalFee = res.order[0].total_fee
				that.storeName = res.storename
				console.log("success",res)
			},
			error: function(res){
				console.log("error",res)
			}
		})
	}
})