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

    </view>
</template>

<script>
export default {
    data() {
        return {
            sys_enterprise_hrid: 0,
            form: []
        }
    },
    async onLoad() {
        uni.setNavigationBarTitle({
            title: '新增人员'
        });
        let form = [{
            key: "name",
            type: "text",
            label: "姓名",
            isMust: true,//是否必填
            value: "",
        }, {
            key: "phonenumber",
            type: "text",
            label: "手机号",
            isMust: true,//是否必填
            value: "",
            placeholder: "请输入收货人手机号",
            inputmode: 'number',
            verify: [this.getReg("phonenumber")]
        }, {
            key: "sex",
            type: "sex",
            label: "性别",
            value: "男",
        }, {
            key: "birthday",
            type: "date",
            label: "生日",
            value: "",
            placeholder: "请选择出生日期",
        }, {
            key: "email",
            type: "text",
            label: "邮箱",
            isMust: false,//是否必填
            value: "",
            verify: [this.getReg("email")]
        }, {
            key: "position",
            type: "text",
            label: "店内职位",
            isMust: false,//是否必填
            value: "",
        }, {
            key: "sa_storeids",
            type: "route",
            path: "/select/store/store",
            isRadio: false,
            label: "所属门店",
            isMust: false,//是否必填
            value: [],
            showValue: [],
        }];
        this.form = form;
    },
    methods: {
        isUncomplete(uncomplete) {
            this.uncomplete = uncomplete;
        },
        submit() {
            this.loading = true;
            let that = this;
            this.$refs.form.submit().then(data => {
                this.$Http.basic({
                    "id": 20240410164102,
                    "content": {
                        "sys_enterprise_hrid": this.sys_enterprise_hrid,
                        ...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',
                                    })
                                }
                            });
                        })
                    }
                })
            })
        },
    },
}
</script>

<style></style>