import paymentService from './PaymentConstant'
import PaymentConstant from "./PaymentConstant";

/**
 * 线上支付动作
 * payment
 */
export default {
    execute(context, param) {
        console.log('s1 payment')
        if (context.selects.length === 0) {
            context.dom.$Message.info(paymentService.paymentNotSelectMessage);
            return;
        }
        if (context.selects.length !== 1) {
            context.dom.$Message.info(paymentService.paymentSelectSingletonWarnMessage);
            return;
        }
        try {
            if (paymentService.checkSingletonSelectData(context.selects[0]) !== paymentService.CHECK_FLAG_SUCCESS) {
            }
        } catch (e) {
            context.dom.$Message.info(e.message);
            return;
        }
        context.dom.$Modal.confirm({
            title: '信息提示',
            content: paymentService.paymentConfirmMessage,
            onOk: () => {
                let param = {
                    "payIds": [],
                    "tableName": PaymentConstant.tableName
                }
                context.selects.forEach(e => {
                    param.payIds.push(e.id)
                })
                paymentService.postPaymentOnlineRequest(param, (data) => {
                    debugger
                    if (data.code === 200 && data.data.extErrorFlag) {
                        setTimeout(() => {
                            context.dom.$Modal.error({
                                title: "错误",
                                content: data.data.errorMessage
                            });
                        }, 400)
                    } else {
                        let allDataLength = param.payIds.length;
                        let failureLength = data.data.failureItems.length;
                        let info = '提交待支付数据完成，本次共提交' + allDataLength + '条记录。\n失败：' + failureLength + '条。\n'
                        if (failureLength > 0) {
                            let msg = ''
                            data.data.failureItems.forEach(e => {
                                msg += e.message + '\n'
                            })
                            info = info + '详细信息：\n' + msg
                        }
                        setTimeout(() => {
                            context.dom.$Modal.info({
                                title: "支付结果",
                                content: info.replace(/\n/g, '<br/>'),
                                onOk: () => {
                                    GMS.vbus.$emit('custom-query-refresh');
                                    GMS.vbus.$emit('tab-count-refresh');
                                }
                            })
                        }, 400)
                    }
                }, (resp) => {
                })
            },
            onCancel() {
            }
        });
    },
}


