<template>
  <DialogCom
    title="选择履职内容"
    :visible.sync="isShow"
    class="g-dialog-select-safe-check"
    width="55%"
    top="10vh"
    append-to-body
    @close="closed"
  >
    <div class="el-dialog-div">
      <g-search-table
        ref="st"
        url="/core/resumption/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="key" label="关键字">
            <el-input
              v-model="search.key"
              maxlength="50"
              placeholder="请输入履职项或履职内容"
            ></el-input>
          </el-form-item>
          <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>
        </template>

        <!-- 表格 -->
        <template slot="columns">
          <el-table-column
            header-align="center"
            prop="itemName"
            label="履职项"
            min-width="40%"
          ></el-table-column>
          <el-table-column
            header-align="center"
            label="履职内容"
            prop="pointName"
            min-width="40%"
          >
            <template slot-scope="scope">
              <div style="white-space: pre-wrap">{{ scope.row.pointName }}</div>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="areaName"
            label="履职区域"
            min-width="20%"
          ></el-table-column>
          <el-table-column
            header-align="center"
            prop="checkName"
            label="履职点位"
            min-width="20%"
          ></el-table-column>
          <!--         <el-table-column  header-align="center"   prop="nfcName"
                           label="采集点"
                           width="120"></el-table-column>-->
        </template>
      </g-search-table>
    </div>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="onSubmit">确定</el-button>
      <el-button @click="onHide">关闭</el-button>
    </div>
  </DialogCom>
</template>
<script>
import GSearchTable from "@/components/table/gx.search.table.vue";
import { ruleListForOrg } from "@/api/resumption/rule.js";
export default {
  components: { GSearchTable },
  data() {
    return {
      isShow: false,
      prevOrgType: null,
      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) {
      if (this.orgType == null) {
        this.prevOrgType = this.orgType;
        this.$modal.alert("请选择机构类型");
        return;
      }
      this.isShow = true;
      if (defaultSelect && defaultSelect.map) {
        this.selectList = defaultSelect.map((s) => ({ id: s }));
      }
      if (this.prevOrgType == this.orgType) {
        this.search.itemName = null;
        if (this.search.ruleId) {
          this.$refs.st.search();
        }
      } else {
        this.search = this.emptySearch();
        ruleListForOrg({ orgType: this.orgType }).then((r) => {
          this.ruleList = r.data;
          this.prevOrgType = this.orgType;
          if (r.data && r.data.length > 0) {
            this.search.ruleId = r.data[0].id;
          }
        });
      }
    },
    onHide() {
      this.isShow = false;
    },
    closed() {
      this.$refs.st.dataList = [];
    },
    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>
.DialogCom-div {
  overflow: auto;
}
.dialog-footer {
  margin-top: 20px;
}
</style>
