<!-- 搜索表单 -->
<template>
  <el-form
    label-width="100px"
    class="ele-form-search"
    @keyup.enter.native="search"
    @submit.native.prevent
  >
    <el-row :gutter="15">
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="工单单号:">
          <el-input clearable v-model="where.code" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="巡点检人员:">
          <el-input
            clearable
            v-model="where.executeUserName"
            placeholder="请输入"
          />
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="计划单号:">
          <el-input clearable v-model="where.planId" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="状态:">
          <el-select
            style="width: 100%"
            clearable
            filterable
            v-model="where.orderStatus"
          >
            <el-option label="待接收" :value="0"></el-option>
            <el-option label="已接收" :value="1"></el-option>
            <el-option label="执行中" :value="2"></el-option>
            <el-option label="已完成" :value="3"></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="巡点检名称:">
          <el-input clearable v-model="where.planName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="规则名称:">
          <!-- <el-input clearable v-model="where.ruleName" placeholder="请输入" /> -->
          <el-select
            v-model="where.ruleId"
            size="small"
            clearable
            style="width: 100%"
            filterable
          >
            <el-option
              v-for="item in ruleNameList"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="设备分类:">
          <equipmentSelect v-model="where.categoryLevelId" />
        </el-form-item> -->
      </el-col>
      <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
        <el-form-item label="巡点检部门:">
          <deptSelect v-model="where.groupId" @changeGroup="changeGroup" />
        </el-form-item>
        <!-- <el-form-item label="规则名称:">
          <el-input clearable v-model="where.name" placeholder="请输入" />
        </el-form-item> -->
        <!-- <el-form-item label="组织机构:">
          <auth-selection v-model="where.deptIds" style="width: 100%"></auth-selection>
        </el-form-item> -->
      </el-col>
    </el-row>
    <el-row :gutter="15">
      <el-col class="ele-form-actions">
        <el-button
          type="primary"
          icon="el-icon-search"
          class="ele-btn-icon"
          @click="search"
          size="small"
        >
          查询
        </el-button>
        <el-button
          @click="reset"
          icon="el-icon-refresh-left"
          size="small"
          type="primary"
        >重置</el-button
        >
      </el-col>
    </el-row>
  </el-form>
</template>

<script>
  import { getRule } from '@/api/ruleManagement/plan';
  import equipmentSelect from '@/components/CommomSelect/equipment-select.vue';
  import deptSelect from '@/components/CommomSelect/dept-select.vue';
  import personSelect from '@/components/CommomSelect/person-select.vue';
  export default {
    components: { equipmentSelect, deptSelect, personSelect },
    data() {
      // 默认表单数据
      const defaultWhere = {
        name: '',
        executeUserName: '',
        planCode: '',
        code: '',
        orderStatus: '',
        groupId: '',
        categoryLevelId: '',
        planName: ''
      };
      return {
        // 表单数据
        where: { ...defaultWhere },
        treeData: [],
        ruleNameList: []
      };
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    created() {
      this.getRuleNameList();
    },
    methods: {
      /* 部门选择 */
      changeGroup(id, data) {
        if (id) {
          this.where.groupId = id;
          this.where.executeGroupName = data.name;
        } else {
          this.where.groupId = '';
          this.where.executeGroupName = '';
        }
      },
      /* 搜索 */
      search() {
        console.log(this.where);
        this.$emit('search', this.where);
      },
      /*  重置 */
      reset() {
        this.where = { ...this.defaultWhere };
        this.search();
      },
      // 获取规则名列表(设备保养)
      async getRuleNameList() {
        const res = await getRule({
          status: 1,
          type: 1,
          pageNum: 1,
          size: -1
        });
        if (res.list) {
          this.ruleNameList = res.list || [];
        }
      }
    }
  };
</script>
<style lang="scss" scoped>
  .ele-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
</style>
