<template>
  <DialogCom
    title="选择检查要点"
    :visible.sync="isShow"
    class="g-dialog-select-safe-check"
    :close-on-click-modal="false"
    destroy-on-close
    width="55%"
    top="10vh"
    append-to-body
  >
    <div class="el-dialog-div">
      <g-search-table
        ref="st"
        url="/core/safetycheck/ruleItem/pointSelectionPage"
        method="get"
        :search-data="search"
        :manual="true"
        :pageable="true"
        :select="true"
        :select-default="selectList"
        :drag="false"
        @select="onSelect"
      >
        <!-- 搜索 -->
        <template slot="searchs">
          <el-form-item prop="ruleId" label="检查内容库">
            <el-select v-model="search.ruleId">
              <el-option
                v-for="item in ruleList"
                :value="item.id"
                :key="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="key" label="关键字">
            <el-input v-model="search.key" maxlength="50" placeholder="请输入检查项或检查内容"></el-input>
          </el-form-item>
        </template>

        <!-- 表格 -->
        <template slot="columns">
          <el-table-column
            prop="itemName"
            label="检查项"
           min-width="40%"
          ></el-table-column>
          <el-table-column label="检查内容" prop="pointName" min-width="40%"> </el-table-column>
          <el-table-column
            prop="areaName"
            label="检查区域"
            min-width="20%"
          ></el-table-column>
          <!--          <el-table-column prop="nfcName"
                           label="采集点"
                           width="120"></el-table-column>-->
        </template>
      </g-search-table>
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button @click="onHide">关闭</el-button>
      <el-button type="primary" @click="onSubmit">确定</el-button>
    </div>
  </DialogCom>
</template>
<script>
import GSearchTable from "@/components/table/gx.search.table.vue";
import { ruleListForOrg } from "@/api/safetycheck/rule.js";
export default {
  components: { GSearchTable },
  data() {
    return {
      isShow: false,
      selectList: [],
      ruleList: [],
      search: this.emptySearch(),
    };
  },
  computed: {},
  watch: {
    search:{
      deep:true,
      handler(v){
        if(v.ruleId){
          this.$refs.st.search();    
        }    
      }
    }
  },
  props: {
    // defaultSelect:{
    //   type:Array
    // },
    orgType:{
      type:String
    }
  },
  methods: {
    show(defaultSelect) {
      this.search = this.emptySearch();
      this.isShow = true;
      if (defaultSelect && defaultSelect.map) {
        this.selectList = defaultSelect.map((s) => ({ id: s }));
      }
      
      ruleListForOrg({ orgType: this.orgType }).then((r) => {
        this.ruleList = r.data;
        
        if (r.data && r.data.length > 0) {
          this.search.ruleId = r.data[0].id;
        }
      });
    },
    onHide() {
      this.isShow = false;
    },
    onSelect(item) {      
      this.selectList = item;
    },
    onSubmit() {
      let s=this.selectList
      this.$emit("select", this.selectList);
      this.onHide();
    },
    emptySearch() {
      return {
        ruleId: null,
        itemName: null,
      };
    },
  },
  mounted() {},
};
</script>
<style lang="scss" scoped>
.el-dialog-div {
  overflow: auto;
}
</style>
