<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                <Field label="部门名称" prop="deptName" v-model="form.deptName" type="textarea" placeholder="请输入部门名称" :maxLength="15"/>
                <Field label="上级部门" prop="parentId" v-model="form.parentId" type="select" :enumData="dict.deptName" placeholder="请选择上级部门"/>
                <Field label="负责人" prop="workId" v-model="form.workId" type="select" :enumData="dict.workName" placeholder="请选择员工"/>

            </el-row>
            <form-buttons @submit='submitForm' noCancelBtn />
        </el-form>

    </el-drawer>
</template>

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

        },
        created() {
            this.changePath("dept")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "部门信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "deptStatus",
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    deptName: [
                        {required: true,message: "请输入部门名称", trigger: "blur" },
                        {max: 15,message: "最多只能录入15个字符",trigger: "blur",},
                    ],
                    parentId: [
                        {required: true,message: "请输入部门", trigger: "change" },
                    ]
                }
            };
        },

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

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

            // 表单重置
            reset() {
                this.form = {
                    parentId : null,
                    ancestors : "",
                    deptName : "",
                    deptStatus : 1,
                    orderNum : 0,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
