const _Http = getApp().globalData.http;
let sys_enterpriseid = null;
Page({
    data: {
        form: [{
            label: "联系人",
            error: false,
            errMsg: "",
            type: "text",
            value: "",
            placeholder: "请填写",
            valueName: "name",
            required: true,
            checking: "base"
        }, {
            label: "手机号",
            error: false,
            errMsg: "",
            type: "number",
            value: "",
            placeholder: "联系人手机号码",
            valueName: "phonenumber",
            required: true,
            checking: "phone"
        }, {
            label: "省市县",
            error: false,
            errMsg: "",
            type: "region",
            value: [],
            placeholder: "省,市,县",
            valueName: "region",
            required: true
        }, {
            label: "详细地址",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "例: 科创园11栋1103室",
            valueName: "address",
            required: true,
            checking: "base"
        }, {
            label: "备注",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "地址说明",
            valueName: "remarks",
            required: false,
            checking: "base"
        }],
        disabled: true
    },
    onLoad(options) {
        sys_enterpriseid = options.id
    },
    submit() {
        let content = Object.assign({
            "contactsid": 0,
            sys_enterpriseid,
            sex: "男",
            "name": "",
            "depname": "",
            "position": "",
            "isleader": 1,
            "birthday": "",
            "phonenumber": "",
            "email": "",
            "address": "",
            "remarks": "",
            "workaddress": 1,
            "isdefault": 0
        }, this.selectComponent("#Form").submit());
        content.province = content.region[0] || "";
        content.city = content.region[1] || "";
        content.county = content.region[2] || "";
        delete(content.region);
        _Http.basic({
            id: 20221009155703,
            content
        }).then(res => {
            console.log("新建地址", res)
            wx.showToast({
                title: res.msg != '成功' ? res.msg : "添加成功",
                icon: "none",
                mask: true
            });
            if (res.msg == '成功') setTimeout(() => {
                wx.navigateBack();
                let page = getCurrentPages().find(v => v.route == 'pages/address/index');
                if (page) {
                    let content = JSON.parse(JSON.stringify(page.data.content));
                    content.pageNumber = 1;
                    content.pageSize = (page.data.content.pageNumber - 1) * (page.data.content.pageSize || 20);
                    _Http.basic({
                        "id": "20221009155803",
                        content
                    }).then(res => {
                        if (res.msg == '成功') page.setData({
                            list: res.data
                        })
                    })
                }
            }, 500)



        })
    },
    /* 表单是否填写完成 */
    onConfirm({
        detail
    }) {
        this.setData({
            disabled: detail
        })
    },
})