const _Http = getApp().globalData.http;
let sa_quotedpriceid = null;
Page({
    data: {
        form: [{
            label: "类型",
            error: false,
            errMsg: "",
            type: "option",
            optionNmae: "quotedpriceitemtype",
            optionType: "radio", //复选   radio 单选
            value: "",
            placeholder: "请选择",
            valueName: "itemtype",
            required: false
        }, {
            label: "费用明细",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "费用明细",
            valueName: "itemname",
            required: false, //必填
        }, {
            label: "单位",
            error: false,
            errMsg: "",
            type: "selector",
            range: [{
                    "unitid": 2,
                    "rowindex": "1",
                    "unitname": "个"
                },
                {
                    "unitid": 3,
                    "rowindex": "2",
                    "unitname": "米"
                },
                {
                    "unitid": 4,
                    "rowindex": "3",
                    "unitname": "千克"
                },
                {
                    "unitid": 5,
                    "rowindex": "4",
                    "unitname": "克"
                }
            ],
            rangeKey: "unitname",
            rangeIndex: "",
            value: "",
            placeholder: "计量单位",
            valueName: "unitname",
            required: false, //必填
        }, {
            label: "单价(元)",
            error: false,
            errMsg: "",
            type: "digit",
            value: "",
            placeholder: "单价(元)",
            valueName: "price",
            required: false, //必填
        }, {
            label: "数量",
            error: false,
            errMsg: "",
            type: "digit",
            value: "",
            placeholder: "数量",
            valueName: "qty",
            required: false, //必填
        }],
    },
    onLoad(options) {
        sa_quotedpriceid = options.id;
    },
    submit() {
        let content = this.selectComponent("#Form").submit();
        for (const key in content) {
            if (content[key]) {
                content.sa_quotedprice_specialitemsid = 0;
                wx.showModal({
                    title: '提示',
                    content: '是否确认添加本条费用明细',
                    complete: (res) => {
                        if (res.confirm) _Http.basic({
                            "id": 20230211155503,
                            "version": 1,
                            "content": {
                                "sa_quotedpriceid": sa_quotedpriceid,
                                "items": [content]
                            }
                        }).then(res => {
                            wx.showToast({
                                title: res.msg == '成功' ? '添加成功' : res.msg,
                                icon: "none",
                                mask: true
                            });
                            if (res.msg == '成功') setTimeout(() => {
                                getApp().globalData.saveFun(sa_quotedpriceid, true);
                                getApp().globalData.saveFun = null;
                                wx.navigateBack();
                            }, 500);
                        })
                    }
                })
                break;
            }
        }
    },
})