

export default {
	methods: {
		// 酒店支付订单
		payOrder(id, orderId, replacePay){
			console.log(id, orderId);
			let self = this
			this.$api(replacePay ? 'replacePay' : 'orderPay', {
				id : replacePay ? orderId : id,
			}, res => {
				if (res.code == 200) {
					uni.requestPayment({
						provider: 'wxpay', // 服务提提供商
						timeStamp: res.result.timeStamp, // 时间戳
						nonceStr: res.result.nonceStr, // 随机字符串
						package: res.result.packageValue,
						signType: res.result.signType, // 签名算法
						paySign: res.result.paySign, // 签名
						success: function(res) {
							self.getData()
						},
						fail: function(err) {
							console.log('支付失败', err);
							// self.$refs.confirmationPopup.close()
							uni.showToast({
								icon: 'none',
								title: "支付失败"
							})
						}
					});
				}else{
					setTimeout(self.getData, 500)
				}
			})
		},
		// 酒店取消订单
		orderCancel(item){
			let self = this
			uni.showModal({
				title: '您确认取消吗？',
				success(res) {
					if (res.confirm) {
						self.$api('orderCancel', {
							id: item.id
						}, res => {
							if (res.code == 200) {
								self.getData()
							}
						})
					}
				}
			})
		},
		// 确认收货
		confirmReceiveGoods(item) {
			let self = this
			
			uni.showModal({
				title: '您收到货了吗？',
				success(res) {
					if (res.confirm) {
						self.$api('orderConfirm', {
							id: item.id
						}, res => {
							if (res.code == 200) {
								self.getData()
							}
						})
					}
				}
			})
		},
		// 水洗店确认接单
		orderConfirmAccept(item){
			let self = this
			this.$api('orderConfirmAccept', {
				id: item.id
			}, res => {
				if (res.code == 200) {
					uni.showToast({
						title: '接单成功',
						icon: 'none'
					})
					self.getData()
				}
			})
		},
		// 水洗店确认破损 0确认接单 1确认正常 2破损上报
		orderConfirmedDamage(item, flag, args = {}, fn){
			let self = this
			this.$api('orderConfirmAccept', {
				id: item.id,
				flag,
				...args
			}, res => {
				if (res.code == 200) {
					uni.showToast({
						title: '上报成功',
						icon: 'none'
					})
					fn && fn()
					self.getData()
				}
			})
		},
		// 水洗店完成水洗
		orderFinishedWashing(item){
			let self = this
			self.$api('orderConfirm', {
				id: item.id
			}, res => {
				if (res.code == 200) {
					self.getData()
				}
			})
		},
	}
}