<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    size="50%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px" style="padding: 20px;">
      <el-row>
        <Field
          type="select"
          label="负责人姓名"
          prop="name"
          filterable
          v-model="form.name"
          :enumData="userList"
          placeholder="请输入负责人姓名"
        />
        <Field
          label="联系电话"
          prop="phone"
          v-model="form.phone"
          placeholder="请输入联系电话"
        />
        <!-- <Field
          label="大厅"
          prop="deptId"
          type="select"
          v-model="form.deptId"
          placeholder="请选择大厅"
        /> -->
        <el-col :span="12">
          <el-form-item label="大厅/部门" prop="deptId">
            <el-cascader
              v-model="form.deptId"
              style="width:100%"
              @change="cascaderChange"
              :options="dict.deptId"
              clearable
              :props="{ label: 'label', value: 'id' }"
            >
            </el-cascader>
          </el-form-item>
        </el-col>

        <!-- <Field
          label="部门"
          prop="deptId"
          type="select"
          v-model="form.deptId"
          placeholder="请选择部门"
        /> -->
        <!-- <Field
          label="工号"
          prop="number"
          v-model="form.number"
          placeholder="请输入工号"
        /> -->

        <!-- <Field
          label="负责窗口数量"
          prop="windowCount"
          v-model="form.windowCount"
          placeholder="请输入负责窗口数量"
        /> -->
        <!-- <Field
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        /> -->
      </el-row>
      <div style="background-color: rgba(242, 246, 252, 1);padding: 20px;">
        <div style="display: flex;align-items: center;margin-bottom: 20px;">
          <div style="flex: 1;">请选择窗口</div>
          <div>
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
              <el-form-item >
                <el-input v-model="formInline.user" placeholder="请输入窗口名称或编号"></el-input>
              </el-form-item>
              <el-form-item >
                <el-select v-model="formInline.region" placeholder="请选择大厅">
                  <el-option label="区域一" value="shanghai"></el-option>
                  <el-option label="区域二" value="beijing"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitSearch">查询</el-button>
              </el-form-item>
            </el-form>

          </div>
        </div>
        <el-table
          :data="tableData"
          border
          style="width: 100%">
          <el-table-column
            prop="date"
            label="序号">
          </el-table-column>
          <el-table-column
            prop="date"
            label="窗口名称">
          </el-table-column>
          <el-table-column
            prop="name"
            label="编号">
          </el-table-column>
          <el-table-column
            prop="address"
            label="所属楼栋">
          </el-table-column>
          <el-table-column
            prop="address"
            label="所属楼层">
          </el-table-column>
          <el-table-column
            prop="address"
            label="操作">
          </el-table-column>
        </el-table>
      </div>
      <div style="padding: 20px;">
        <el-button type="primary" @click="submitForm" >提交</el-button>
      </div>
    </el-form>
  </el-drawer>
</template>

<script>
import form from "@/assets/mixins/formdialog";
export default {
  name: "WindowOwnerDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("window/owner");
    this.getUser()
  },
  data() {
    return {
      //搜索表单
      formInline:{

      },
      // 大厅
      options:[],
      //窗口
      tableData:[],
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "窗口负责人",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      toString: [],
      toDate: [],
      // 表单校验
      rules: {
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          { max: 20, message: "最多只能录入20个字符", trigger: "blur" },
        ]
      },
      userList:{},

    };
  },

  methods: {
    cascaderChange(val) {
      if (this.deptList.length > 0) {
        this.form.deptId = this.deptList[this.deptList.length - 1];
      } else {
        this.form.deptId = "";
      }
      console.log(this.form.deptId, "当前选择");
    },
    // 查询人员
    getUser(){
      this.$post("/staff/list",{page:1,size:-1}).then(res=>{
        console.log(res)
        const {code,data} = res
        if(code == 1){
          const userList = data.data
          const arr = {}
          data.data.forEach(element => {
            arr[element.id] = element.name
            // arr.push({label:element.name,value:element.id})
          });
          this.userList = arr
          console.log(arr,"@@@")
        }
      })
    },
    onSubmitSearch(){

    },
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "window/owner/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "修改窗口负责人";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "window/owner/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增窗口负责人";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "window/owner/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 = {
        deptId: 0,
        deptName: "",
        name: "",
        number: "",
        phone: "",
        windowCount: null,
        remark: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
