<template>
  <div>
    <div class="filter-container">
      <div class="filter-row mb-10">
        <div class="filter-group ">
          <div class="filter-lable">
            关键字：
          </div>
          <div class="filter-width">
            <el-input v-model="KEYWORDS" placeholder="搜索" />
          </div>
        </div>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-left:10px" @click="getQuery">
          搜索
        </el-button>
        <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
          重置
        </el-button>
      </div>
    </div>
    <el-table v-loading="listLoading" ref="multipleTable" :data="varList" :row-key="getRowKey" :header-cell-style="{'font-weight': 'bold','color': '#000'}" tooltip-effect="dark" border fit highlight-current-row>
      <el-table-column :reserve-selection="true" type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="CORP_NAME" label="企业名称" />
      <el-table-column prop="CREATTIME" label="创建时间" />
      <el-table-column prop="COMPANY_AREA" label="所属区域" />
      <el-table-column prop="ADDRESS" label="注册地址" />
    </el-table>
    <div class="page-btn-group">
      <div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageSizes" @pagination="getList" />
    </div>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      config: config,
      listLoading: true,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 8
      },
      pageSizes: [6, 8, 10, 20, 50],
      total: 0,
      KEYWORDS: '',
      varList: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getRowKey(row) {
      return row.CORPINFO_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.listQuery = {
        page: 1,
        limit: 8
      }
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.getQuery()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/corpinfo/resList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
        this.hasButton()
      }).catch((e) => {
        this.listLoading = false
      })
    },
    confirm() {
      const _selectData = this.$refs.multipleTable.selection
      if (_selectData == null || _selectData.length == 0) {
        this.$message({
          message: '请选中要选入的项...',
          type: 'error'
        })
        return false
      }
      const ids = _selectData.map((item, index) => {
        return item.CORPINFO_ID
      }).join(',')

      this.$confirm('是否添加该企业到资源库?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/resourcecorp/add',
          {
            DATA_IDS: ids
          }
        ).then(() => {
          this.$emit('onClose')
          this.$message({
            message: '添加成功',
            type: 'success'
          })
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped>

</style>
