export class PaymentConstant {
    static paymentNotSelectMessage = "请勾选条目后在进行支付";
    static paymentConfirmMessage = "请确认是否进行支付";
    static paymentBatchConfirmMessage = "请确认是否进行批量支付";
    static paymentOfflineConfirmMessage = "请确认是否进行线下支付";
    static paymentSelectSingletonWarnMessage = "请勾选单条数据，如需批量支付，请点击批量支付按钮";
    static PAYMENT_DATA_CHECK_FAIL_COMMON = "数据校验异常 暂时无法支付";
    static PAYMENT_DATA_CHECK_FAIL_MONEY = "存在支付金额异常的人员已被选择，请勾掉之后再进行支付!";
    static PAYMENT_DATA_CHECK_FAIL_KHYH = "所选条目中存在收款银行账号为空的条目,请核对后再进行支付!"
    static CHECK_FLAG_SUCCESS = 0;
    static MULTI_CHECK_FLAG_SUCCESS = 10
    static MULTI_CHECK_FLAG_FAILURE = 11
    static CHECK_FLAG_FAIL_A = 1;
    static CHECK_FLAG_FAIL_B = 2;
    static JE = "je";
    static KHYH = "yhmc";
    static YHZH = "yhzh";
    static SKR = "skr";
    static SKDW = "skdw";
    static postPaymentOnlineApi = "/rbc/payment/batchPayOnline";
    static postPaymentOfflineApi = "/rbc/payment/batchPayOffline";
    static tableName = "AA1"

    static checkSingletonSelectData(data) {
        if (this.isObject(data)) {
            if (this.JE in data && data[this.JE] > 0) {
            } else {
                throw new Error(this.PAYMENT_DATA_CHECK_FAIL_MONEY);
            }
            if (this.KHYH in data && data[this.KHYH] && data[this.KHYH].length > 0 && this.YHZH in data && data[this.YHZH] && data[this.YHZH].length > 0) {
            } else {
                throw new Error(this.PAYMENT_DATA_CHECK_FAIL_KHYH);
            }
        } else {
            throw new Error(this.PAYMENT_DATA_CHECK_FAIL_COMMON);
        }
        return this.CHECK_FLAG_SUCCESS;
    }

    /**
     * 批量支付校验重复数据
     * @param array
     * @returns {number}
     */
    static checkMultiSelectData(array) {
        debugger
        if (this.isArray(array)) {
            if (array.length <= 1) {
                return this.CHECK_FLAG_SUCCESS;
            }
            let flag = false
            let num = ''
            let ii;
            for (let i = 0; i < array.length - 1; i++) {
                let a = this.getMultiCheckStringInfo(array[i])
                for (let j = i + 1; j < array.length; j++) {
                    let b = this.getMultiCheckStringInfo(array[j]);
                    if (a === b) {
                        flag = true
                        ii = i;
                        num = (i + 1) + ',' + (j + 1)
                        break;
                    }
                }
                if (flag) {
                    break;
                }
            }
            if (flag) {
                throw new Error('第' + num + '行：' + this.getMultiCheckStringInfo(array[ii]) + '，数据相同，是否仍然进行支付？');
            }
        } else {
            throw new Error(this.PAYMENT_DATA_CHECK_FAIL_COMMON);
        }
        return this.CHECK_FLAG_SUCCESS;
    }

    static isObject(data) {
        return !!(typeof data === 'object' && data && data instanceof Object);
    }

    static isArray(data) {
        return !!(typeof data === 'object' && data && data instanceof Array);
    }

    /**
     * 提取收款人 收款单位 银行账号 支付金额
     * @param data
     */
    static getMultiCheckStringInfo(data) {
        return '收款人：' + data[this.SKR] + '，收款单位：' + data[this.SKDW] + '，银行账号：' + data[this.YHZH] + ',支付金额：' + data[this.JE]
    }

    /**
     * 线上批量支付接口
     * @param param
     * @param callBack
     * @param errorCallBack
     */
    static postPaymentOnlineRequest(param, callBack, errorCallBack) {
        GMS.$http.post(this.postPaymentOnlineApi, param).then(data => {
            callBack(data.data);
        }).catch((resp) => {
            errorCallBack(resp);
        });
    }

    /**
     * 线下批量支付接口
     * @param param
     * @param callBack
     * @param errorCallBack
     */
    static postPaymentOfflineRequest(param, callBack, errorCallBack) {
        GMS.$http.post(this.postPaymentOfflineApi, param).then(data => {
            callBack(data.data);
        }).catch((resp) => {
            errorCallBack(resp);
        });
    }

    static getTableFromParam(data) {
        return ''
    }
}

export default PaymentConstant;
