<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 :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="order" v-model="form.order" 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 {
              fileType:['png', 'jpg', 'jpeg'],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "工作人员",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "sex",
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    name: [
                        {required: true,message: "请输入姓名", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    photoPath: [
                        {required: true,message: "请输入照片", trigger: "blur" },
                        {max: 255,message: "最多只能录入255个字符",trigger: "blur",},
                    ],
                }
            };
        },

        methods: {
          getFileName(fileName) {
            this.form.fileName = fileName;
          },
            /** 编辑 */
            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;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

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

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