<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="deviceName" v-model="form.deviceName" placeholder="请输入设备名称"/>
                            <Field label="设备编码" prop="deviceCode" v-model="form.deviceCode" placeholder="请输入设备编码"/>
                            <Field label="Ip地址" prop="ip" v-model="form.ip" placeholder="请输入Ip地址"/>
                            <Field label="端口" prop="port" v-model="form.port" placeholder="请输入端口"/>
                            <Field label="用户名" prop="username" v-model="form.username" placeholder="请输入用户名"/>
                            <Field label="密码" prop="password" v-model="form.password" placeholder="请输入密码"/>
              <Field
                  label="所属部门"
                  prop="deptId"
                  v-model="form.deptId"
                  type="select"
                  placeholder="请选择所属部门"
                  :enumData="dict.deptId"
                  :disabled="pageInfo.type == 'view'"
              />
            </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: "DoorDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("door")
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "门禁设备",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                }
            };
        },

        methods: {
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="door/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改门禁设备";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "door/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增门禁设备";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="door/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 = {
                    deviceName : "",
                    deviceCode : "",
                    ip : "",
                    port : null,
                    username : "",
                    password : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
