<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="员工姓名" 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="工号" prop="workNum" v-model="form.workNum" placeholder="请输入工号"/>
                            <Field label="所属公司" prop="companyIds" v-model="form.companyIds" placeholder="请输入所属公司"/>
                            <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="staffType" v-model="form.staffType" type="select" :enumData="dict.staffType" placeholder="请选择员工类型"/>
                            <Field label="员工状态" prop="staffStatus" v-model="form.staffStatus" type="select" :enumData="dict.staffStatus" placeholder="请选择员工状态"/>
                            <Field label="员工来源" prop="source" v-model="form.source" type="select" :enumData="dict.source" placeholder="请选择员工来源"/>
                            <Field label="入职登记表" prop="registerPath" v-model="form.registerPath" type="textarea" placeholder="请输入入职登记表"/>
                            <Field label="入职时间" prop="entryDate" v-model="form.entryDate" type="date" />
                            <Field label="转正时间" prop="regularDate" v-model="form.regularDate" type="date" />
                            <Field label="离职时间" prop="leaveDate" v-model="form.leaveDate" type="date" />
                            <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="请输入当日查看次数"/>
                            <Field label="发送名片次数" prop="sendBusinessCardTimes" v-model="form.sendBusinessCardTimes" 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: "StaffDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("staff")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "员工基本信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "gender",
                    "staffType",
                    "staffStatus",
                    "source",
                ],
                toDate:[
                    "birthday",
                    "entryDate",
                    "regularDate",
                    "leaveDate",
                ],
                // 表单校验
                rules: {
                    name: [
                        {required: true,message: "请输入员工姓名", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="staff/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改员工基本信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "staff/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增员工基本信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="staff/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 = {
                    name : "",
                    gender : 1,
                    birthday : null,
                    photoPath : "",
                    Email : "",
                    phoneNumber : "",
                    idCard : "",
                    workNum : "",
                    companyIds : "",
                    companyName : "",
                    positionId : null,
                    positionName : "",
                    staffType : 1,
                    staffStatus : 1,
                    source : 1,
                    registerPath : "",
                    entryDate : null,
                    regularDate : null,
                    leaveDate : null,
                    remark : "",
                    sumViews : 0,
                    viewsByDay : 0,
                    sendBusinessCardTimes : 0,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
