import {OrderButton, OrderPayStatus} from "$utils/control/order/const/order";

import popup, {PopupExportComponent} from "$utils/tool/popup";

export default <LibMixins>{

    inject:['updateOrderStatus'],

    methods:{

        triggerPayButton(button:Record<string, any>){

            return this.orderTrigger[button.status] && this[this.orderTrigger[button.status]](button);

        },

        // 点击接单触发
        triggerReceivedStatus(){

            return popup.$confirm({
               title:'是否确认接单?',
               confirm:()=>{
                   return new Promise((resolve, reject)=>{
                       this.$request({
                           url:'player/take_player_order',
                           data:{
                               oid: this.item.oid
                           },
                           token:true,
                           message:true,
                           failMessage:true,
                           loading:'接单中'
                       }).then((data)=>{
                           resolve(false);
                           if (data.isSuccess) {
                               // 设置订单已完成
                               return this.updateOrderStatus(this.item,OrderPayStatus.have);
                           }
                       }).catch(reject);
                   });

               }
            });

        },

        // 联系顾客
        triggerContactCustomer(){
            return popup.$open(PopupExportComponent.chat,{
                user:{
                    uid:this.item.uid,
                    nick_name:this.item.user_nick_name,
                    head_pic:this.item.user_head_pic
                }
            });
        }

    },

    created(){
        this.orderTrigger = {
            [OrderButton.received]:'triggerReceivedStatus',
            [OrderButton.contactCustomer]:'triggerContactCustomer'
        }
    }

}
