<template>
    <view>
        <my_form ref="form" :form="form" @isUncomplete="isUncomplete" requiredFieldOnly @interrupt="interrupt" />
    </view>
</template>

<script>
export default {
    data() {
        return {
            sa_storeid: 0,
            form: []
        }
    },
    async onLoad() {
        uni.setNavigationBarTitle({
            title: '新增人员'
        });
        this.form = [{
            key: "storename",
            type: "text",
            label: "门店名称",
            isMust: true,//是否必填
            value: "",
        }, {
            key: "area",
            type: "text",
            label: "面积(m²)",
            isMust: true,//是否必填
            value: "",
            inputmode: 'digit',
        }, {
            key: "leader_hrid",
            type: "route",
            path: "/team/userCenter/selectUser?title=选择负责人",
            isRadio: true,
            label: "负责人姓名",
            isMust: true,//是否必填
            value: [],
            showValue: [],
            interrupt: true
        }, {
            key: "phonenumber",
            type: "text",
            label: "负责人电话",
            isMust: true,//是否必填
            value: "",
            inputmode: 'number',
            disabled: true,
            verify: [this.getReg("phonenumber")]
        }, {
            key: "sale_phonenmber",
            type: "text",
            label: "门店售前电话",
            isMust: false,//是否必填
            value: "",
            inputmode: 'number',
            verify: [this.getReg("phonenumber")]
        }, {
            key: "service_phonenmber",
            type: "text",
            label: "门店售后电话",
            isMust: false,//是否必填
            value: "",
            inputmode: 'number',
            verify: [this.getReg("phonenumber")]
        }, {
            key: "storetype",
            type: "radio",
            label: "门店类型",
            value: "直营",
            options: [{
                label: "直营",
                name: "直营",
                marginRight: 60
            }, {
                label: "分销",
                name: "分销",
            }]
        }, {
            key: "markettype",
            type: "customClass",
            label: "门店卖场类型",
            isMust: false,//是否必填
            isMultipleChoice: false,//是否多选
            value: '',// 多选[] 单选 ""
            list: await this.getCustomClass('storetype')
        }, {
            key: "selectMap",
            type: "route",
            path: "/select/place/index",
            label: "门店地址",
            isMust: true,//是否必填
            value: {},
        }];
    },
    methods: {
        isUncomplete(uncomplete) {
            this.uncomplete = uncomplete;
        },
        interrupt(item, selected, index) {
            console.log(item)
            console.log(selected)
            console.log(index)
            switch (item.key) {
                case "leader_hrid":
                    item.showValue = [selected.name];
                    item.value = [selected.sys_enterprise_hrid];
                    this.$refs.form.setItem(index, item)
                    this.$refs.form.setValue(index + 1, selected.phonenumber, true)
                    break;
            }

        },
        submit() {
            this.loading = true;
            let that = this;
            this.$refs.form.submit().then(data => {
                this.$Http.basic({
                    "id": 20240410095302,
                    "content": {
                        "sa_storeid": this.sa_storeid,
                        ...data
                    }
                }).then(res => {
                    this.loading = false;
                    console.log("加入团队", res)
                    if (this.cutoff(res.msg)) return;
                    this.loading = true;
                    if (this.attachmentids.length) {
                        this.uploadCallback(this.attachmentids, "sys_users", this.userid).then(s => {
                            if (s) getUserMsg()
                        });
                        if (this.headportraits.length) this.$Http.basic({
                            "classname": "system.attachment.Attachment",
                            "method": "deleteFileLink",
                            "content": {
                                linksids: this.headportraits.map(v => v.linksid)
                            }
                        })

                    } else {
                        getUserMsg()
                    }
                    function getUserMsg() {
                        that.$Http.wechatLogin().then(token => {
                            that.loading = false;
                            uni.showModal({
                                title: '提示',
                                content: '成功加入团队',
                                showCancel: false,
                                confirmText: '确定',
                                confirmColor: '#C40C24',
                                success: ({ confirm }) => {
                                    if (confirm) uni.redirectTo({
                                        url: '/pages/index/index',
                                    })
                                }
                            });
                        })
                    }
                })
            })
        },
    },
    onShow() {
        /*    let a11 = {
               address: "浙江省嘉兴市南湖区望湖路585号",
               city: "嘉兴市",
               county: "南湖区",
               district: "南湖区",
               latitude: 30.74803,
               longitude: 120.786539,
               name: "翡翠花园",
               province: "浙江省"
           }
           if (location) {
               location.county = location.district;
               this.location = location;
               this.$refs.form.setValue(this.form.findIndex(v => v.label == '门店地址'), location.name || this.getCity(location))
           } */
    }
}
</script>

<style></style>