<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                            <Field :span="20" label="所属关联员工" prop="staffId" v-model="form.staffId" type="select" :enumData="dict.staffId" placeholder="请输入名片所属关联员工ID"/>

                            <Field :span="20" label="名片姓名" prop="name" v-model="form.name" placeholder="请输入名片姓名"/>
                            <Field :span="20" label="性别" prop="gender" v-model="form.gender" type="select" :enumData="dict.gender" placeholder="请选择性别"/>
                            <Field :span="20" label="出生日期" prop="birthday" v-model="form.birthday" type="date" />
                             <Field :span="20" label="照片" prop="photoPath"  placeholder="请输入照片"><imageUpload v-model="form.photoPath" prePath="/file/preview"/> </Field>


              <Field :span="20" label="邮件地址" prop="email" v-model="form.email" placeholder="请输入邮件地址"/>
                            <Field :span="20" label="联系电话" prop="phoneNumber" v-model="form.phoneNumber" placeholder="请输入联系电话"/>
                            <Field :span="20" label="身份证号码" prop="idCard" v-model="form.idCard" placeholder="请输入身份证号码"/>
                            <Field :span="20" label="所在公司" prop="companyId" v-model="form.companyId"  type="select" :enumData="dict.companyId" placeholder="请输入记录名片持有者所在公司或组织的名称ID"/>
                            <Field :span="20" label="职位" prop="positionId" v-model="form.positionId"  type="select" :enumData="dict.positionId"  placeholder="请输入职位ID"/>

                            <Field :span="20" label="简介" prop="bio" v-model="form.bio" type="textarea" placeholder="请输入简介"/>
                            <Field :span="20" label="社交媒体链接" prop="socialMedia" v-model="form.socialMedia" type="textarea" placeholder="请输入社交媒体链接, 可以是一个包含社交媒体账号的JSON对象或单独的字段"/>

              <Field :span="20" label="二维码图片" prop="qRCode"  placeholder="请输入二维码图片"><imageUpload v-model="form.qRCode" prePath="/file/preview"/> </Field>


              <Field :span="20" label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>

            </el-row>

            <form-buttons @submit='submitForm' v-if="pageInfo.type!='view'" noCancelBtn />
        </el-form>

    </el-drawer>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    export default {
        name: "BussinesscardDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("bussinesscard")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "名片基本信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "gender",
                    "staffId",
                    "companyId",
                    "positionId",
                ],
                toDate:[
                    "birthday",
                ],
                // 表单校验
                rules: {
                  staffId: [
                    {required: true,message: "请选择员工", trigger: "blur" },
                  ],
                    name: [
                        {required: true,message: "请输入名片姓名", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                  companyId: [
                    {required: true,message: "请选择所在公司", trigger: "blur" },
                  ],

                  positionId: [
                    {required: true,message: "请选择职位", trigger: "blur" },
                  ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="bussinesscard/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改名片基本信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "bussinesscard/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增名片基本信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="bussinesscard/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "名片基本信息详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    staffId : null,
                    staffName : "",
                    name : "",
                    gender : 1,
                    birthday : null,
                    photoPath : "",
                    email : "",
                    phoneNumber : "",
                    idCard : "",
                    companyId : "",
                    companyName : "",
                    positionId : null,
                    positionName : "",
                    bio : "",
                    socialMedia : "",
                    qRCode : "",
                    remark : "",
                    sumViews : 0,
                    viewsByDay : 0,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
