import payData from './data/payData';
import Status from "$mixins/status/const/status";
import popup from "$utils/tool/popup";

import mixins from './mixins';

export default <LibMixins>{

    data(){
        return {
            payData,
            payCheck:0,
            triggerPayName:'payOrderInfo',
            payStatus: Status.none,
            payOrder:['weChat','alipay','balance'],
        }
    },

    computed:{
        payFormat(){

            return {
                balanceIntroduce: this.$store.state.pay && this.$store.state.pay.payRatio ? '('+this.$store.state.pay.payRatio + '巧鱼币=1.00元)' : ''
            }
        },
        payTotal(){
            if (this.payOrder[this.payCheck] === 'balance' && this.$store.state.pay && this.$store.state.pay.payRatio) {
                return  this.total * this.$store.state.pay.payRatio;
            } else {
                return this.total;
            }
        },
        payTotalFormat(){
            if (this.payOrder[this.payCheck] === 'balance' && this.$store.state.pay && this.$store.state.pay.payRatio) {
                return  this.payTotal + '巧鱼币';
            } else {
                return '¥'+this.payTotal;
            }
        }
    },

    methods:{

        triggerPayType(index:number){
            if (this.payCheck !== index) {
                this.payCheck = index;
            }
        },

        triggerPayOrder(callback){

            if (this.payStatus === Status.loading) return;

            let item = this.payData[this.payOrder[this.payCheck]];
            if (!item || item.check && !item.check(this,this.payTotal)) return ;

            if (callback && typeof callback === 'function') {
                return callback({
                    password:'123456',
                    type: item.type
                });
            } else {
                return this[this.triggerPayName] && this[this.triggerPayName]({
                    password:'123456',
                    type: item.type
                });
            }

        },


        // 支付等待过程
        triggerPayEnd(data){

            this.storagePayReuslt = data;
            this.nowPayStatus = false;
            let type = this.payOrder[this.payCheck];
            if (type === 'alipay') {
                return this.triggerPayAlipay(data);
            } else if(type === 'weChat') {
                return this.triggerPayWeChat(data);
            }

        },

        // 打开弹窗
        openPayInfoConfirm(confirm = undefined,cancel=undefined){
            popup.$confirm({
                title:'是否支付完成?',
                confirmText:'支付完成',
                cancelText:'未完成',
                confirm,
                cancel
            });
        },

    },

    mixins

}