<template>
    <!-- 弹出框表单 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
        <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="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="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="入职登记表"><fileUpload v-model="form.filePath"  prePath="/file/fileupload"/></Field>
                            <Field label="政治面貌 " prop="politicalstatus" v-model="form.politicalstatus" type="select" :enumData="dict.politicalstatus" placeholder="请选择政治面貌 "/>
                            <Field label="所属部门" prop="deptId" v-model="form.deptId" placeholder="请输入所属部门"/>
                            <Field label="所属部门名称" prop="deptName" v-model="form.deptName" placeholder="请输入所属部门名称"/>
                            <Field label="职位ID" prop="jobId" v-model="form.jobId" placeholder="请输入职位ID"/>
                            <Field label="职位名称" prop="jobName" v-model="form.jobName" placeholder="请输入职位名称"/>
                            <Field label="员工类型" prop="staffType" v-model="form.staffType" type="select" :enumData="dict.staffType" placeholder="请选择员工类型"/>
                            <Field label="员工状态" prop="onBoardStatus" v-model="form.onBoardStatus" type="select" :enumData="dict.onBoardStatus" placeholder="请选择员工状态"/>
                            <Field label="入职时间" prop="entryDate" v-model="form.entryDate" type="date" />

            </el-row>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" v-if="pageInfo.type !== 'view'" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    import dialogShow from "./dialogshow";
    import FileUpload from '@/components/FileUpload';
    export default {
        mixins: [form],
        components: {
            dialogShow ,
            FileUpload,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "员工入职信息",
                // 是否显示弹出层
                open: false,
                toString:[
                    "gender",
                    "politicalstatus",
                    "staffType",
                    "onBoardStatus",
                ],
                // 表单校验
                rules: {
                    staffName: [
                        {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/onboard/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改员工入职信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "staff/onboard/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增员工入职信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="staff/onboard/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 : "",
                    gender : 1,
                    birthday : null,
                    photoPath : "",
                    phoneNumber : "",
                    idCard : "",
                    workNum : "",
                    filePath : "",
                    politicalstatus : 1,
                    deptId : null,
                    deptName : "",
                    jobId : null,
                    jobName : "",
                    staffType : 1,
                    onBoardStatus : 1,
                    entryDate : null,
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
