<!-- 搜索表单 -->
<template>
  <el-form
    label-width="90px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <el-col :span="6">
        <el-form-item label="工单编码:">
          <el-input clearable v-model="where.repairCode" placeholder="请输入" />
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="仓库名称:">
          <el-input
            clearable
            v-model="where.warehouseName"
            placeholder="请输入"
          />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="设备名称:">
          <el-input clearable v-model="where.deviceName" placeholder="请输入" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="物品名称:">
          <el-input
            clearable
            v-model="where.categoryName"
            placeholder="请输入"
          />
        </el-form-item>
      </el-col>

      <!-- <el-col :span="6">
        <el-form-item label="组织机构:">
          <auth-selection
            v-model="where.deptIds"
            style="width: 100%"
          ></auth-selection>
        </el-form-item>
      </el-col> -->
      <el-col :span="6">
        <el-form-item label="领用部门:">
          <deptSelect
            v-model="where.useDeptId"
            @changeGroup="searchDeptNodeClick"
          />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="领用人:">
          <el-select
            v-model="where.userId"
            size="small"
            style="width: 100%"
            filterable
          >
            <el-option
              v-for="item in executorList"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>

      <el-col
        style="display: flex; justify-content: flex-end"
        v-bind="styleResponsive ? { lg: 24, md: 24 } : { span: 24 }"
      >
        <el-form-item label-width="0px">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="ele-btn-icon"
            @click="search"
          >
            查询
          </el-button>
          <el-button @click="reset" icon="el-icon-refresh-left" type="primary"
            >重置</el-button
          >
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  import { getUserPage } from '@/api/system/organization';
  import deptSelect from '@/components/CommomSelect/dept-select.vue';

  export default {
    components: {
      deptSelect
    },
    props: [],
    data() {
      // 默认表单数据
      const defaultWhere = {
        repairCode: '',
        warehouseName: '',
        deviceName: '',
        categoryName: '',
        deptIds: '',
        useDeptId: '',
        userId: ''
      };
      return {
        // 表单数据
        where: { ...defaultWhere },
        executorList: []
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    watch: {},
    created() {},
    methods: {
      /* 搜索 */
      search() {
        this.$emit('search', this.where);
      },
      /*  重置 */
      reset() {
        this.where = { ...this.defaultWhere };
        this.search();
      },
      //选择部门(搜索)
      searchDeptNodeClick(info) {
        if (info) {
          const params = { groupId: info };
          this.getUserList(params);
          this.where.userId = '';
        }
      },
      // 获取审核人列表、巡点检人员
      async getUserList(params) {
        try {
          let data = { pageNum: 1, size: -1 };
          // 如果传了参数就是获取巡点检人员数据
          if (params) {
            data = Object.assign(data, params);
          }
          const res = await getUserPage(data);
          this.executorList = res.list;
        } catch (error) {}
      }
    }
  };
</script>
<style lang="scss" scoped></style>
