<template>
  <el-dialog
    title="选择学习附件"
    :visible.sync="isShow"
    class="g-dialog-select-safe-check"
    :close-on-click-modal="false"
    width="55%"
    top="10vh"
    append-to-body
  >
    <div class="el-dialog-div">
      <g-search-table
        ref="st"
        url="/core/materials/fileList"
        method="post"
        :search-data="search"
        :manual="true"
        :pageable="true"
        :select="true"
        :select-default="selectList"
        :drag="false"
        @select="onSelect"
      >
        <!-- 搜索 -->
        <template slot="searchs">
          <el-form-item prop="title" label="资料标题">
            <el-input v-model="search.title"></el-input>
          </el-form-item>
          <el-form-item prop="fileName" label="附件名称">
            <el-input v-model="search.fileName"></el-input>
          </el-form-item>
        </template>

        <!-- 表格 -->
        <template slot="columns">
          <el-table-column
            prop="orgName"
            label="资料上传机构"
           min-width="40%"
          ></el-table-column>
          <el-table-column label="资料标题" prop="title" min-width="40%"> </el-table-column>
          <el-table-column
            label="资料附件"
            min-width="20%"
          >
          <template slot-scope="scope">
            <template v-if="scope.row.fileList">
              <el-tag size="mini" type="success" v-for="(item, index) in scope.row.fileList"
                      :key="index">
                {{ JSON.parse(item).name }}
              </el-tag>
            </template>
          </template>
        </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>
  </el-dialog>
</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,
      selectList: [],
      // ruleList: [],
      search: this.emptySearch(),
    };
  },
  computed: {},
  watch: {
    orgId(newval) {
      console.log("orgId",newval);
      this.search.orgId=newval;
    },
  },
  props: {
    defaultSelect:{
      type:Array
    },
    orgId:{

    },
  },
  methods: {
    show() {
      this.search= this.emptySearch();
      console.log("this.search",this.search)
      this.isShow = true;
      this.selectList =this.defaultSelect;
      // TODO: 处理第一次进入弹窗时，表格数据不加载
    },
    onHide() {
      this.isShow = false;
      this.search=this.emptySearch();
    },
    onSelect(item) {
      this.selectList = item;
    },
    onSubmit() {
      let s=this.selectList
      this.$emit("select", this.selectList);
      this.onHide();
    },
    emptySearch() {
      return {
        title: null,
        fileName: null,
        orgId:this.$store.getters.orgId,
        t:new Date(),
      };
    },
  },
  mounted() {

  },
};
</script>
<style lang="scss" scoped>
.el-dialog-div {
  overflow: auto;
}
</style>
