<template>
  <div class="main-content market search-result">
    <!-- <CommonTitle label="查询结果" /> -->
    <DetailHead result="查询结果" style="border-top:0;border-left:0;border-right:0" />
    <el-table
      v-loading="loading"
      style="margin-top:20px"
      :data="tableData"
      :row-class-name="tableRowClassName"
      :header-cell-style="{background:'#8cc3fb',color:'#fff'}"
      @row-click="rowClick"
    >
      <el-table-column label="序号" prop="index" min-width="50" />
      <el-table-column label="统一社会信用代码/注册号" min-width="100" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.uniscid && scope.row.uniscid.length > 0 ? scope.row.uniscid: scope.row.regno }}
        </template>
      </el-table-column>
      <el-table-column label="主体名称" prop="entname" min-width="120" show-overflow-tooltip />
      <el-table-column label="法定代表人/负责人" prop="name" show-overflow-tooltip />
      <el-table-column label="经营地址" prop="dom" show-overflow-tooltip />
      <el-table-column label="企业类型" prop="enttypeCn" show-overflow-tooltip />
      <el-table-column label="经营期限" prop="opto" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.opto ? scope.row.opto: '长期' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="信用等级" /> -->
      <el-table-column label="风险等级" prop="level" min-width="60" show-overflow-tooltip />
    </el-table>
    <div class="page-box">
      <el-row>
        <el-col :span="24" style="text-align:right">
          <el-pagination
            :disabled="loading"
            :page-size="pageParam.pageSize"
            :total="pageParam.total"
            :page-sizes="[10, 20, 30, 40,50,100,200]"
            layout="slot,total, sizes, prev, pager, next, jumper"
            @size-change="pageSizeChange"
            @current-change="pageIndexChange"
          >
            <!-- <batchFunction :options="options" style="float:left" /> -->
            <span>
              第 {{ pageParam.curPage }} 页 /
              共 {{ (pageParam.total !== 0 ? parseInt((pageParam.total + pageParam.pageSize - 1)/pageParam.pageSize) : 1) }} 页
            </span>
          </el-pagination>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import DetailHead from '@/components/DetailHead'
import { complexEntInfoPage } from '@/api/entBase'
export default {
  components: {
    DetailHead
  },
  data() {
    return {
      tableData: [],
      pageParam: {
        curPage: 1,
        pageSize: 10,
        total: 0,
        paramMap: {

        }
      },
      loading: false
    }
  },
  mounted() {
    this.pageParam.paramMap = {
      ...this.$route.query
    }
    this.loadPage()
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      }
    },
    rowClick(row, column, event) {
      const { href } = this.$router.resolve({ path: '/market/search/result/detail', query: { pripid: row.pripid }})
      window.open(href)
    },
    // 当前分页改变
    pageIndexChange(curPage) {
      this.pageParam.curPage = curPage
      this.loadPage()
    },
    // 分页大小改变
    pageSizeChange(pageSize) {
      this.pageParam.pageSize = pageSize
      this.loadPage()
    },
    // 加载分页
    loadPage() {
      if (this.loading) return
      this.loading = true
      complexEntInfoPage(this.pageParam).then(res => {
        this.loading = false
        if (res.code === 0) {
          const data = res.data
          const list = []
          let index = (this.pageParam.curPage - 1) * this.pageParam.pageSize
          data.records.forEach(each => {
            each.index = ++index
            list.push(each)
          })
          this.tableData = list
          this.pageParam.total = data.total
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.main-content{
  padding: 20px;
  background: #fff;
  /deep/.el-table .warning-row {
    background: #eaf4fe!important;
  }
}
</style>
<style lang="scss">
.market.search-result{
  .el-table__row{
    cursor: pointer;
  }
}
</style>
