<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 label="名片所属关联员工ID" prop="staffId" v-model="form.staffId" placeholder="请输入名片所属关联员工ID"/>
                            <Field label="名片所属关联员工姓名" prop="staffName" v-model="form.staffName" placeholder="请输入名片所属关联员工姓名"/>
                            <Field label="名片姓名" prop="name" v-model="form.name" placeholder="请输入名片姓名"/>
                            <Field label="性别" prop="gender" v-model="form.gender" type="select" :enumData="dict.gender" placeholder="请选择性别"/>
                            <Field label="出生日期" prop="birthday" v-model="form.birthday" type="date" />
                            <Field label="照片" prop="photoPath" v-model="form.photoPath" type="textarea" placeholder="请输入照片"/>
                            <Field label="邮件地址" prop="email" v-model="form.email" placeholder="请输入邮件地址"/>
                            <Field label="联系电话" prop="phoneNumber" v-model="form.phoneNumber" placeholder="请输入联系电话"/>
                            <Field label="身份证号码" prop="idCard" v-model="form.idCard" placeholder="请输入身份证号码"/>
                            <Field label="记录名片持有者所在公司或组织的名称ID" prop="companyId" v-model="form.companyId" placeholder="请输入记录名片持有者所在公司或组织的名称ID"/>
                            <Field label="记录名片持有者所在公司或组织的名称" prop="companyName" v-model="form.companyName" placeholder="请输入记录名片持有者所在公司或组织的名称"/>
                            <Field label="职位ID" prop="positionId" v-model="form.positionId" placeholder="请输入职位ID"/>
                            <Field label="职位名称" prop="positionName" v-model="form.positionName" placeholder="请输入职位名称"/>
                            <Field label="简介" prop="bio" v-model="form.bio" type="textarea" placeholder="请输入简介"/>
                            <Field label="社交媒体链接, 可以是一个包含社交媒体账号的JSON对象或单独的字段" prop="socialMedia" v-model="form.socialMedia" type="textarea" placeholder="请输入社交媒体链接, 可以是一个包含社交媒体账号的JSON对象或单独的字段"/>
                            <Field label="二维码图片, 可以是一个图片链接或存储路径" prop="qRCode" v-model="form.qRCode" type="textarea" placeholder="请输入二维码图片, 可以是一个图片链接或存储路径"/>
                            <Field label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>
                            <Field label="累计查看次数" prop="sumViews" v-model="form.sumViews" placeholder="请输入累计查看次数"/>
                            <Field label="当日查看次数" prop="viewsByDay" v-model="form.viewsByDay" 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",
                ],
                toDate:[
                    "birthday",
                ],
                // 表单校验
                rules: {
                    name: [
                        {required: true,message: "请输入名片姓名", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",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>
