import Vue from 'vue'
const orderMixins = {
    data() {
        return {
            btnClubUserId: 0,
            handleShopOrderId: 0, //点击按钮传入的的订单ID
            handleModelEven: 0,
            modal: false,
            contentModalText: '订单查询失败,请稍候重试~', //操作文字提示语句
            modalButton: [
            	{
            		text: '取消',
            		type: 'gray',
            		plain: true //是否空心
            	},
            	{
            		text: '确定',
            		customStyle: {
            			color: '#fff',
            			bgColor: '#F3B574'
            		},
            		plain: false
            	}
            ]
        }
    },
    filters: {
        NumFormat(value) {
            //处理金额
            return Number(value).toFixed(2)
        },
        statusFilters(value) {
            //处理订单状态显示
            const map = {
                0: '待确认',
                2: '交易完成',
                4: '已关闭',
                5: '交易全退',
                6: '交易全退',
                11: '待付款待发货',
                12: '待付款部分发货',
                13: '待付款已发货',
                21: '部分付款待发货',
                22: '部分付款部分发货',
                23: '部分付款已发货',
                31: '已付款待发货',
                32: '已付款部分发货',
                33: '已付款已发货'
            }
            return map[value]
        }
    },
    computed: {
       
    },
    methods: {
        //确认操作
        handleClick(e) {
            if (e.index == 1) {
                switch (this.handleModelEven) {
                case 1: //取消订单
                    this.cancelOrder(this.handleShopOrderId)
                    break
                case 2: //删除订单
                    this.deleteOrder(this.handleShopOrderId)
                    break
                case 3: //确认订单
                    this.affirmOrder(this.handleShopOrderId)
                    break
                }
            }
            this.modal = false
        },
        //取消订单
        async cancelOrder(shopOrderId) {
        	try {
        		const res = await this.OrderService.CancelOrder({ shopOrderId: shopOrderId, userIdentity: 1 })
        		this.$util.msg(res.msg, 2000, true, 'success')
        		setTimeout(() => {
        			this.getOrderDatainit(this.currentTab)
        		}, 2000)
        	} catch (error) {
        		this.$util.msg(error.msg, 2000)
        	}
        },
        //删除订单
        async deleteOrder(shopOrderId) {
        	try {
        		const res = await this.OrderService.DeleteOrder({ shopOrderId: shopOrderId })
        		this.$util.msg(res.msg, 2000, true, 'success')
        		setTimeout(() => {
        			this.getOrderDatainit(this.currentTab)
        		}, 2000)
        	} catch (error) {
        		this.$util.msg(error.msg, 2000)
        	}
        },
        //确认订单
        async affirmOrder(shopOrderId) {
        	try {
        		const res = await this.OrderService.AffirmOrder({ shopOrderId: shopOrderId })
        		this.$util.msg(res.msg, 2000, true, 'success')
        		setTimeout(() => {
        			this.getOrderDatainit(this.currentTab)
        		}, 2000)
        	} catch (error) {
        		this.$util.msg(error.msg, 2000)
        	}
        },
        // 再来一单
        async handOrderAgain(shopOrderId) {
        	try {
        		const res = await this.SellerService.SellerCreateOrderAgain({
        			confirmFlag: 0,
        			shopOrderId: shopOrderId,
        			serviceProviderId: this.listQuery.serviceProviderId
        		})
        		const data = res.data
        		this.$api.setStorage('orderUserInfo', {
        			clubId: data.clubId,
        			againBuyProductIds: data.productIds,
        			userId: data.userId
        		})
        		this.$api.navigateTo('/pages/seller/cart/cart')
        	} catch (error) {
        		if (error.code == -3) {
        			this.showAgan = true
        			this.promptitle = error.msg
        			this.failList = error.data
        		} else if (error.code == -2) {
        			this.$util.modal('', error.msg, '确定', '', false, () => {})
        		} else {
        			this.$util.msg(error.msg, 2000)
        		}
        	}
        },
        // 再来一单弹窗
        async handleAddAgian() {
        	try {
        		await this.SellerService.SellerCreateOrderAgain({
        			confirmFlag: 1,
        			shopOrderId: this.handleShopOrderId,
        			serviceProviderId: this.listQuery.serviceProviderId
        		})
        		this.$api.navigateTo('/pages/seller/cart/cart')
        		this.showAgan = false
        	} catch (error) {
        		this.$util.msg(error.msg, 2000)
        	}
        }
    },
    onShareAppMessage(res) {
	    //分享转发
	    this.isShareModal = false
	    if (res.from === 'button') {
	        // 来自页面内转发按钮
	    }
	    return {
	        title: '您有新的分享订单，快来查看吧~',
	        path: `/pages/user/order/order-sharelogin?shopOrderId=${this.handleShopOrderId}&userId=${
	            this.btnClubUserId
	        }&serviceProviderId=${this.listQuery.serviceProviderId}`,
	        imageUrl: 'https://static.caimei365.com/app/mini-mcare/icon/icon_shareOrder@2x.png'
	    }
    }
}

export default orderMixins
