const _Http = getApp().globalData.http,
    getTime = require("../../utils/getTime");

Page({
    data: {
        showAll: false,
        form: [{
                label: "项目名称",
                error: false,
                errMsg: "",
                type: "textarea",
                value: "",
                placeholder: "项目名称",
                valueName: "projectname",
                checking: "base",
                required: true
            }, {
                label: "项目类型",
                error: false,
                errMsg: "",
                type: "option",
                optionNmae: "projecttype",
                optionType: "radio", //复选   radio 单选
                value: "",
                placeholder: "选择类型",
                valueName: "projecttype",
                checking: "base",
                required: true
            }, {
                label: "项目等级",
                error: false,
                errMsg: "",
                type: "option",
                optionNmae: "projectgrade",
                optionType: "radio", //复选   radio 单选
                value: "",
                placeholder: "选择项目等级",
                valueName: "grade",
                checking: "base",
                required: false
            }, {
                label: "省市县",
                error: false,
                errMsg: "",
                type: "region",
                value: [],
                placeholder: "省/市/县",
                valueName: "region",
                required: true
            }, {
                label: "详细地址",
                error: false,
                errMsg: "",
                type: "textarea",
                value: "",
                placeholder: "详细地址",
                valueName: "address",
                checking: "base",
                required: false
            }, {
                label: "项目规模",
                error: false,
                errMsg: "",
                type: "textarea",
                value: "",
                placeholder: "请填写建筑面积(㎡)/吨位(t)",
                valueName: "scale",
                checking: "base",
                required: false
            }, {
                label: "项目预算(万元)",
                error: false,
                errMsg: "",
                type: "digit",
                value: "",
                placeholder: "请填写金额",
                valueName: "budgetary",
                checking: "base",
                required: false
            }, {
                label: "总投资额(万元)",
                error: false,
                errMsg: "",
                type: "digit",
                value: "",
                placeholder: "请填写金额",
                valueName: "totalinvestment",
                checking: "base",
                required: false
            }, {
                label: "造价(万元)",
                error: false,
                errMsg: "",
                type: "digit",
                value: "",
                placeholder: "请填写金额",
                valueName: "costofconstruction",
                checking: "base",
                required: false
            }, {
                label: "预计开工时间",
                error: false,
                errMsg: "",
                type: "date",
                fields: "month",
                value: "",
                placeholder: "预计开工时间",
                valueName: "begdate_due",
                checking: "base",
                required: false
            }, {
                label: "预计完工时间",
                error: false,
                errMsg: "",
                type: "date",
                fields: "month",
                value: "",
                placeholder: "预计完工时间",
                valueName: "enddate_due",
                checking: "base",
                required: false
            },
            {
                label: "预计签约时间",
                error: false,
                errMsg: "",
                type: "date",
                fields: "month",
                value: "",
                placeholder: "预计签约时间",
                valueName: "signdate_due",
                checking: "base",
                required: false
            }
        ],
        "content": {
            "sat_orderclueid": ""
        },
        disabled: true
    },
    onLoad(options) {
        let data = JSON.parse(options.rowData);
        this.setData({
            form: this.data.form.map(v => {
                if (v.valueName != 'region') {
                    if (v.valueName == 'campaign_name') {
                        v.value = [data[v.valueName],
                            [data.sat_campaignid]
                        ]
                    } else {
                        v.value = data[v.valueName];
                    }
                } else {
                    v.value = data.province ? [data.province, data.city, data.county] : []
                }
                return v
            }),
            'content.sat_orderclueid': data.sat_orderclueid,
            'content.sat_campaignid': data.sat_campaignid
        });
    },
    submit() {
        let content = {
            ...this.data.content,
            ...this.selectComponent("#Form").submit()
        };
        _Http.basic({
            "id": "20221124154902",
            content
        }).then(res => {
            console.log("转化", res)
            wx.showToast({
                title: res.msg != '成功' ? res.msg : '转化成功',
                icon: "none"
            })
            if (res.msg != '成功') return;
            setTimeout(() => {
                wx.navigateBack()
                getCurrentPages().forEach(item => {
                    console.log(item);
                    if (item.__route__ == 'packageA/saleClue/detail') {
                        item.getDetail()
                    }
                })
                wx.navigateTo({
                    url: `/packageA/project/detail?sa_projectid=${res.data.sa_projectid}`,
                })
            }, 300)
        })
    },
    // 是否显示全部
    onChange({
        detail
    }) {
        this.setData({
            showAll: detail
        })
    },
    /* 表单必填项是否完成 */
    onConfirm({
        detail
    }) {
        this.setData({
            disabled: detail
        })
    }
})