<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    size="60%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="180px">
      <el-row>
        <Field :span="20" label="电子门牌信息">
          <el-checkbox true-label="1" false-label="0" v-model="form.showPhoto"
            >照片</el-checkbox
          >

          <el-checkbox true-label="1" false-label="0" v-model="form.showName"
            >姓名</el-checkbox
          >

          <el-checkbox true-label="1" false-label="0" v-model="form.showPost"
            >职位</el-checkbox
          >

          <el-checkbox true-label="1" false-label="0" v-model="form.showWork"
            >在岗状态</el-checkbox
          >

          <el-checkbox true-label="1" false-label="0" v-model="form.showPhone"
            >电话</el-checkbox
          >
        </Field>
        <Field
          :span="20"
          label="电子门牌底部信息设置"
          prop="showElect"
          v-model="form.showElect"
          type="radio"
          :enumData="dict.showElect"
          placeholder="请选择显示电子门牌信息"
        />
        <Field
          :span="20"
          label="自定义内容"
          v-if="form.showElect == 1"
          prop="showElectDesc"
          type="textarea"
          v-model="form.showElectDesc"
          placeholder="请输入显示电子门牌信息自定义内容"
        />
        <Field
          :span="20"
          label="会议室门牌底部信息设置"
          prop="showMeet"
          v-model="form.showMeet"
          type="radio"
          :enumData="dict.showMeet"
          placeholder="请选择显示会议室门牌信息"
        />
        <Field
          :span="20"
          label="自定义内容"
          v-if="form.showMeet == 1"
          type="textarea"
          prop="showMeetDesc"
          v-model="form.showMeetDesc"
          placeholder="请输入显示会议室门牌信息自定义内容"
        />

        <Field  :span="20" label="会议开始前几分钟切换" prop="preMeetStart" v-model="form.preMeetStart"  placeholder="请选择会议开始前几分钟切换"/>
        <Field  :span="20" label="会议开始后几分钟切换" prop="postMeetStart" v-model="form.postMeetStart"  placeholder="请选择会议开始后几分钟切换"/>
        <Field  :span="20" label="会议结束切换" prop="meetEnd" v-model="form.meetEnd"  placeholder="请选择会议结束切换">
          <el-checkbox
              true-label="1"
              false-label="0"
              v-model="form.meetEnd"
          ></el-checkbox>
        </Field>


        <Field
          :span="20"
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        />
      </el-row>

      <el-divider content-position="center">状态设置信息</el-divider>
      <br />
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAddBasicStatus"
            >添加</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            @click="handleDeleteBasicStatus"
            >删除</el-button
          >
        </el-col>
      </el-row>

      <el-table
        :data="basicStatusList"
        :row-class-name="rowBasicStatusIndex"
        @selection-change="handleBasicStatusSelectionChange"
        ref="basicStatus"
        height="520"

      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="序号" align="center" prop="index" width="50" />
        <el-table-column label="状态名称" prop="statusName">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.statusName"
              placeholder="请输入状态名称"
            />
          </template>
        </el-table-column>
        <el-table-column label="状态颜色值" prop="statusColor">
          <template slot-scope="scope">
            <el-color-picker
              v-model="scope.row.statusColor"
              placeholder="请输入状态颜色值"
            ></el-color-picker>
          </template>
        </el-table-column>
      </el-table>

      <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: "BasicSetDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("basic/set");
  },
  data() {
    return {
      // 子表选中数据
      checkedBasicStatus: [],
      // 状态设置表格数据
      basicStatusList: [],
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "基础设置",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: [
        "showPhoto",
        "showName",
        "showPost",
        "showWork",
        "showPhone",
        "showElect",
        "showMeet",
      ],
      toDate: [],
      // 表单校验
      rules: {
        preMeetStart: [{ required: true, message: "请输入" },{ pattern: /^-?\d+\.?\d*$/, message: '请输入正确数据', trigger: 'blur' }],
        postMeetStart: [{ required: true, message: "请输入" },{ pattern: /^-?\d+\.?\d*$/, message: '请输入正确数据', trigger: 'blur' }],
        createTime: [{ required: true, message: "请选择创建时间" }],
      },
    };
  },

  methods: {
    /** 状态设置序号 */
    rowBasicStatusIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 状态设置添加按钮操作 */
    handleAddBasicStatus() {
      let obj = {};
      obj.statusName = "";
      obj.statusColor = "";
      obj.remark = "";
      obj.createUserId = "";
      obj.createTime = "";
      obj.updateUserId = "";
      obj.updateTime = "";
      this.basicStatusList.push(obj);
    },
    /** 状态设置删除按钮操作 */
    handleDeleteBasicStatus() {
      if (this.checkedBasicStatus.length == 0) {
        this.$alert("请先选择要删除的状态设置数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.basicStatusList.splice(this.checkedBasicStatus[0].index - 1, 1);
      }
    },
    /** 单选框选中数据 */
    handleBasicStatusSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.basicStatus.clearSelection();
        this.$refs.basicStatus.toggleRowSelection(selection.pop());
      } else {
        this.checkedBasicStatus = selection;
      }
    },
    // 渲染前置处理
    beforeRender(data) {
      if (data.entity.basicStatusList) {
        this.basicStatusList = data.entity.basicStatusList;
      }
      data.entity.meetEnd=data.entity.meetEnd+""

      return data;
    },
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "basic/set/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "修改基础设置";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "basic/set/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增基础设置";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "basic/set/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 = {
        showPhoto: 0,
        showName: 0,
        showPost: 0,
        showWork: 0,
        showPhone: 0,
        showElect: 0,
        showElectDesc: "",
        showMeet: 0,
        showMeetDesc: "",
        remark: "",
        preMeetStart : 0,
        postMeetStart : 0,
        meetEnd : 0,
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
