<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 :span="20" label="所属房间" prop="roomId" v-model="form.roomId" :enumData="dict.roomId" type="select" placeholder="请输入所属房间"/>

                            <Field :span="20" label="所属部门" prop="deptName" v-model="form.deptName" placeholder="请输入所属部门"/>
                            <Field :span="20" label="姓名" prop="name" v-model="form.name" placeholder="请输入姓名"/>
                            <Field :span="20" label="性别" prop="sex" v-model="form.sex" type="select" :enumData="dict.sex" placeholder="请选择性别"/>
                            <Field :span="20" label="职务" prop="userPost" v-model="form.userPost" placeholder="请输入职务"/>
                            <Field :span="20" label="电话" prop="phone" v-model="form.phone" placeholder="请输入电话"/>
                            <Field :span="20" label="手机" prop="mobile" v-model="form.mobile" placeholder="请输入手机"/>
                            <Field :span="20" label="简介" prop="summary" v-model="form.summary" type="textarea" placeholder="请输入简介"/>
              <Field :span="20" label="状态" prop="workStatus" v-model="form.workStatus" :enumData="dict.workStatus" type="select" placeholder="请选择工作状态"/>

              <Field :span="20" label="照片"
              ><ImageUpload
                  v-model="form.photoPath"
                  prePath="/file/preview"
                  :fileName="form.photoPath"
              /></Field>


            </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: "WorkmanDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("workman")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "工作人员",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "sex",
                    "roomId",
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    workStatus: [
                        {required: true,message: "请输入工作状态，来源基础设置", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="workman/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改工作人员";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "workman/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增工作人员";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="workman/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "工作人员详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
          beforeSubmit(data) {
            data.roomName=this.dict.roomId[data.roomId]
            return data
          },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

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

            // 表单重置
            reset() {
                this.form = {
                    roomId : null,
                    roomName : "",
                    deptName : "",
                    name : "",
                    sex : 0,
                    userPost : "",
                    phone : "",
                    mobile : "",
                    summary : "",
                    photoPath : "",
                    workStatus : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
