const _Http = getApp().globalData.http;

Page({
    data: {
        form: [{
            label: "银行名称",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "银行名称",
            valueName: "bank",
            required: true,
            checking: "base"
        }, {
            label: "卡号",
            error: false,
            errMsg: "",
            type: "number",
            value: "",
            placeholder: "卡号",
            valueName: "bankcardno",
            required: true,
            checking: "base"
        }, {
            label: "开户人",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "开户人",
            valueName: "name",
            required: true
        }, {
            label: "手机号码",
            error: false,
            errMsg: "",
            type: "phone",
            value: "",
            placeholder: "手机号码",
            valueName: "phonenumber",
            required: false,
            checking: "phone"
        }],
        disabled: true,
        "content": {
            "sys_enterprise_bankid": 0
        },
    },
    onLoad(options) {
        this.data.content.sys_enterpriseid = options.sys_enterpriseid || 0;
        console.log(options)
        if (options.data) {
            let data = JSON.parse(options.data);
            this.setData({
                disabled: false,
                content: {
                    sys_enterpriseid: data.sys_enterpriseid,
                    sys_enterprise_bankid: data.sys_enterprise_bankid,
                },
                form: this.data.form.map(v => {
                    v.value = data[v.valueName] || "";
                    return v
                })
            })
        }
    },
    submit() {
        let content = Object.assign(this.data.content, this.selectComponent("#Form").submit());
        wx.showModal({
            title: '提示',
            content: '是否确定添加银行卡',
            complete: ({
                confirm
            }) => {
                if (confirm) _Http.basic({
                    "id": 20221022165703,
                    content
                }).then(res => {
                    console.log("创建银行卡信息", res)
                    wx.showToast({
                        title: res.msg != '成功' ? '添加成功' : res.msg,
                        icon: "none",
                        mask: true
                    });
                    if (res.msg == '成功') setTimeout(() => {
                        let pages = getCurrentPages()[getCurrentPages().length - 2];
                        pages.selectComponent("#Bankcard").getList(content.sys_enterpriseid, true);
                        wx.navigateBack()
                    }, 500)
                })
            }
        })
    },
    /* 表单是否填写完成 */
    onConfirm({
        detail
    }) {
        this.setData({
            disabled: detail
        })
    },
})