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

Page({
    data: {
        loading: false,
        showAll: false,
        repetitionShow: false,
        repetitionList: [],
        content: {
            sa_doctorid: 0
        },
        disabled: true,
    },
    onLoad(options) {
        let form = [{
            label: "是否科室负责人",
            error: false,
            errMsg: "",
            hint: "",
            type: "radio",
            value: "0",
            radioList: [{
                id: '1',
                name: '是'
            }, {
                id: '0',
                name: '否'
            }],
            valueName: "isleader", //绑定的字段名称
            required: true, //必填
            direction: "horizontal",
            interrupt: true
        }, {
            label: "医生名称",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "医生名称",
            valueName: "doctorname",
            checking: "base",
            required: true
        }, {
            label: "联系方式",
            error: false,
            errMsg: "",
            type: "number",
            value: "",
            placeholder: "联系方式",
            valueName: "phonenumber",
            required: true,
            checking: "phone"
        }, {
            label: "职称",
            error: false,
            errMsg: "",
            type: "option",
            optionNmae: "careertitle",
            optionType: "radio", //复选   radio 单选
            value: "",
            placeholder: "职称",
            valueName: "professional",
            checking: "base",
            required: true
        }, {
            label: "所属科室",
            error: false,
            errMsg: "",
            type: "route",
            url: "/prsx/select/department/index",
            value: "",
            placeholder: "所属科室",
            valueName: "sa_hospitaldepid",
            checking: "base",
            required: true,
            params: {
                "content": {
                    "pageNumber": 1,
                    "pageSize": 20,
                    "where": {
                        "condition": ""
                    }
                },
                "id": 2025102208540702,
            },
            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);
            data.isleader = data.isleader + '';
            data.sa_hospitaldepid = [data.hospitaldepname, [data.sa_hospitaldepid]]
            form = form.map(v => {
                v.value = data[v.valueName] || "";
                return v
            })
            this.setData({
                disabled: false,
                content: {
                    sa_doctorid: data.sa_doctorid,
                },
                form
            })
        }
        if (options.department) {
            let department = JSON.parse(options.department);
            let item = form.find(v => v.valueName == 'sa_hospitaldepid')
            item.value = department;
            item.disabled = true;
        }
        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_hospitaldepid = data.sa_hospitaldepid.length ? data.sa_hospitaldepid[1][0] : 0
        _Http.basic({
            "id": 2025102116461002,
            "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/doctors/detail') v.getDetail()
            })
            setTimeout(() => {
                if (content.sa_doctorid == 0) {
                    wx.redirectTo({
                        url: '/prsx/doctors/detail?id=' + res.data.sa_doctorid,
                    })
                } else {
                    wx.navigateBack()
                }
            }, 300)
        })
    },
})