var app = new Vue({
	el :"#wrapper",
	data:{
		hostName : "http://ypx.shenmikj.com/am_shop/Wechat/Store/",
		tabState:0,
		layOrder:[],
		deliOrder:[],
		finishOrder:[],
		cancelOrder:[],
		refuseOrder:[],
		refuseState: false,
		cancelState: false,
		refuseId:null,
		refuseIndex:null,
		cancelIndex:null,
		cancelReason:"",
		reason:"",
	},
	methods:{
		changeTab: function(e){
			if (e) {
				this.tabState = 1
			}else {
				this.tabState = 0
			}
		},
		countLimite: function() {
			if (this.reason.length >=100) {
				alert("最多输入五十字")
				return false
			}
		},
		limited: function(){
			if (this.cancelReason.length >=100) {
				alert("最多输入五十字")
				return false
			}
		},
		check: function(id,sn,state){
			window.location.href = "http://ypx.shenmikj.com/am_shop/Wechat/Store/orderDetail?goodsId="+id+"&order_sn="+sn+"&state="+state
		},
		getOrder: function(goodsId) {
			var goodsId = 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)
				}
			})
		},
		refuse: function(id,index){
			this.refuseState = true
			this.refuseId = id
			this.refuseIndex = index
		},
		cancel: function(id,index){
			this.cancelState = true
			this.cancelId = id
			this.cancelIndex = index
		},
		cancelOrderFn: function(){
			var id = this.cancelId,
			reason = this.cancelReason
			$.ajax({
				method:"get",
				url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/handleStoreOrder",
				data:{
					id:id,
					status: -1,
					reason: reason
				},
				async: false,
				dataType:"json",
				success: function(res){
					console.log("success",res)
				},
				error: function(res){
					console.log("error",res)
				}
			})
			this.deliOrder.splice(this.cancelIndex,1)
			this.cancelId = null
			this.cancelIndex = null
			this.cancelState = false
		},
		close: function(){
			this.refuseState = false
			this.cancelState = false
		},
		update: function(){
			var id = this.refuseId,
			reason = this.reason
			$.ajax({
				method:"get",
				url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/handleStoreOrder",
				data:{
					id:id,
					status: -2,
					reason: reason
				},
				async: false,
				dataType:"json",
				success: function(res){
					console.log("success",res)
				},
				error: function(res){
					console.log("error",res)
				}
			})
			this.layOrder.splice(this.refuseIndex,1)
			this.refuseId = null
			this.refuseIndex = null
			this.refuseState = false
		},
		arrive: function(id,index){
			var that = this
			$.ajax({
				method:"get",
				url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/handleStoreOrder",
				data:{
					id:id,
					status: 3
				},
				async: false,
				dataType:"json",
				success: function(res){
					console.log("success",res)
					that.deliOrder.splice(index,1)
				},
				error: function(res){
					console.log("error",res)
				}
			})
		}
	},
	created(){
		var order = []
		$.ajax({
			method:"get",
			url:"http://ypx.shenmikj.com/am_shop/Wechat/Api/getStoreOrderAll",
			async: false,
			dataType:"json",
			success: function(res){
				order = res
			},
			error: function(res){
				console.log(res)
			}
		})
		var len = order.length
		for (var i = 0; i < len; i++) {
			switch(Number(order[i].status)){
				case 1:
					this.layOrder.push(order[i])
					break;
				case 2:
					this.deliOrder.push(order[i])
					break;
				case 3:
					this.finishOrder.push(order[i])
					break;
				case -1:
					this.cancelOrder.push(order[i])
					break;
				case -2:
					this.refuseOrder.push(order[i])
					break;
				default:
					console.log(order[i])
			}
		}
	}
})