let _Http = getApp().globalData.http,
    count = null;

Page({
    data: {
        loading: false,
        showAll: false,
        repetitionShow: false,
        repetitionList: [],
        content: {
            sa_hospitaldepid: 0
        },
        disabled: true,
    },
    onLoad(options) {
        let form = [{
            label: "科室名称",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "科室名称",
            valueName: "hospitaldepname",
            checking: "base",
            slot: "info",
            required: true
        }, {
            label: "科室类型",
            error: false,
            errMsg: "",
            type: "option",
            optionNmae: "depttype",
            optionType: "radio", //复选   radio 单选
            value: "",
            placeholder: "科室类型",
            valueName: "type",
            checking: "base",
            required: true
        }, {
            label: "所属医院",
            error: false,
            errMsg: "",
            type: "route",
            url: "/prsx/select/hospital/index",
            value: "",
            placeholder: "所属医院",
            valueName: "sa_customersid",
            checking: "base",
            required: true,
            params: {
                "content": {
                    "pageNumber": 1,
                    "pageSize": 20,
                    "where": {
                        "condition": ""
                    }
                },
                "id": 2025101409411402,
            },
            query: "&radio=true",
            required: true
        }, {
            label: "备注",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "备注",
            valueName: "remarks",
            checking: "base",
            required: false
        }]
        if (options.data) {
            let data = JSON.parse(options.data);
            form = form.map(v => {
                v.value = data[v.valueName] || "";
                return v
            })
            this.setData({
                disabled: false,
                content: {
                    sa_hospitaldepid: data.sa_hospitaldepid,
                },
                form
            })
        }
        this.setData({
            form
        })
        getApp().globalData.Language.getLanguagePackage(this, options.data ? '编辑科室' : '新建科室');

    },
    /* 表单必填项是否完成 */
    onConfirm({
        detail
    }) {
        this.setData({
            disabled: detail
        })
    },
    // 是否显示全部
    onChange({
        detail
    }) {
        this.setData({
            showAll: detail
        })
    },
    async submit() {
        this.setData({
            loading: true
        })
        let data = this.selectComponent("#Form").submit(),
            content = this.data.content
        data.sa_customersid = data.sa_customersid.length ? data.sa_customersid[1][0] : 0
        _Http.basic({
            "id": 2025101409385002,
            "content": {
                ...content,
                ...data,
            }
        }).then(res => {
            this.setData({
                loading: false
            })
            wx.showToast({
                title: res.code != '1' ? res.msg : '保存成功',
                icon: "none",
                mask: res.code == '1'
            })
            if (res.code != '1') return;
            getCurrentPages().forEach(v => {
                if (v.route == 'prsx/department/detail') v.getDetail()
            })
            setTimeout(() => {
                if (content.sa_hospitaldepid == 0) {
                    wx.redirectTo({
                        url: '/prsx/department/detail?id=' + res.data.sa_hospitaldepid,
                    })
                } else {
                    wx.navigateBack()
                }
            }, 300)
        })
    },
})