const _Http = getApp().globalData.http;

Page({
    data: {
        showAll: false,
        form: [{
            label: "企业名称",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "企业全称",
            valueName: "enterprisename",
            checking: "base",
            required: true
        }, {
            label: "企业简称",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "企业",
            valueName: "abbreviation",
            checking: "base",
            required: false
        }, {
            label: "统一社会信用代码",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "企业税号/注册号/营业执照号码",
            valueName: "taxno",
            checking: "base",
            required: true
        }, {
            label: "法定代表人",
            error: false,
            errMsg: "",
            type: "text",
            value: "",
            placeholder: "企业法人",
            valueName: "contact",
            checking: "base",
            required: false
        }, {
            label: "法人电话号码",
            error: false,
            errMsg: "",
            type: "number",
            value: "",
            placeholder: "法人联系手机号",
            valueName: "phonenumber",
            checking: "phone",
            required: false
        }, {
            label: "所属行业",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "企业所属行业",
            valueName: "industry",
            checking: "base",
            required: false
        }, {
            label: "地区",
            error: false,
            errMsg: "",
            type: "region",
            value: [],
            placeholder: "所属地区 省/市/区",
            valueName: "region",
            required: false
        }, {
            label: "注册地址",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "企业注册地址",
            valueName: "address",
            checking: "base",
            required: false
        }, {
            label: "客户类型",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "客户类型",
            valueName: "type",
            checking: "base",
            required: false
        }, {
            label: "客户级别",
            error: false,
            errMsg: "",
            type: "number",
            value: "",
            placeholder: "客户数字级别",
            valueName: "grade",
            checking: "base",
            required: false
        }],
        disabled: true
    },
    onLoad(options) {

    },
    /* 表单必填项是否完成 */
    onConfirm({
        detail
    }) {
        this.setData({
            disabled: detail
        })
    },
    // 是否显示全部
    onChange({
        detail
    }) {
        this.setData({
            showAll: detail
        })
    },
    submit() {
        let data = this.selectComponent("#Form").submit();
        if (data.region.length != 0) {
            data.province = data.region[0]
            data.city = data.region[1]
            data.county = data.region[2]
        };
        delete(data.region);
        _Http.basic({
            "id": 20221012163902,
            "content": {
                "sa_customersid": 0, //新增是传0
                "parentid": 0, //上级客户ID,默认或没有上级的时候传0
                "sys_enterpriseid": 0, //合作企业档案ID，新增是传0，更新
                "sa_customerpoolid": 0, //客户池（公海池）ID,默认或没有的时候传0
                ...data,
                source: "", //客户来源
            }
        }).then(res => {
            console.log("新建客户", res)
            if (res.msg != '成功') return wx.showToast({
                title: res.data,
                icon: "none"
            })
            wx.showToast({
                title: '保存成功',
                icon: "none"
            })
            const pages = getCurrentPages();

            setTimeout(() => {
                console.log(pages)
                const page = pages[pages.length - 2];
                console.log(page)
                if (page.__route__ == 'packageA/setclient/index') {
                    page.getList(true);
                    wx.navigateBack();
                    setTimeout(() => {
                        wx.navigateTo({
                            url: '/packageA/setclient/detail?id=' + res.data.sa_customersid,
                        })
                    }, 200)
                }
            }, 300)

        })


    },
})