<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="照片"><imageUpload v-model="form.photoPath" prePath="/file/preview"/></Field>
                            <Field label="邮件地址" prop="email" v-model="form.email" placeholder="请输入邮件地址"/>
                            <Field label="联系电话" prop="phoneNumber" v-model="form.phoneNumber" placeholder="请输入联系电话"/>
                            <Field label="所属公司" prop="companyIds" v-model="form.companyIds" type="select" :enumData="dict.companyIds" placeholder="请选择所属公司"/>
                            <Field label="所属公司名称" prop="companyName" v-model="form.companyName" placeholder="请输入所属公司名称"/>
                            <Field label="职位名称" prop="positionName" v-model="form.positionName" placeholder="请输入职位名称"/>
                            <Field label="员工状态" prop="staffStatus" v-model="form.staffStatus" type="select" :enumData="dict.staffStatus" placeholder="请选择员工状态"/>
                            <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="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: "StaffLeaveDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("staff/leave")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "员工离职信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "staffStatus",
                ],
                toDate:[
                    "leaveDate",
                ],
                // 表单校验
                rules: {
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="staff/leave/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改员工离职信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "staff/leave/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增员工离职信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="staff/leave/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 : "",
                    photoPath : "",
                    email : "",
                    phoneNumber : "",
                    companyIds : "",
                    companyName : "",
                    positionName : "",
                    staffStatus : 3,
                    leaveDate : null,
                    remark : "",
                    sumViews : 0,
                    viewsByDay : 0,
                    sendBusinessCardTimes : 0,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
