<template>
  <section class="list">
    <ai-list>
      <ai-title slot="title" title="信息报告申请" isShowBottomBorder/>
      <template #content>
        <ai-search-bar>
          <template #right>
            <el-input size="small" placeholder="搜索信用主体/证件号码/信用代码" v-model="search.objName" clearable @change="page.current=1,getTableData()"/>
          </template>
        </ai-search-bar>
        <ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" :size.sync="page.size"
                  @getList="getTableData" :col-configs="colConfigs" :dict="dict">
          <el-table-column slot="options" label="操作" fixed="right" align="center" width="300">
            <template slot-scope="{row}">
              <el-button type="text" @click="handleAdd(row.id)">详情</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

<script>
export default {
  name: "list",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  data() {
    return {
      search: {objName: ""},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      colConfigs: [
        {prop: "createUserPhone", label: "联系方式"},
        {prop: "createUserName", label: "申请人"},
        {prop: "idNumber", label: "证件号码"},
        {prop: "objName", label: "信用主体"},
        {prop: "type", label: "申请类型", dict: "creditReportType"},
        {prop: "createTime", label: "申请时间"}],
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/app/appcreditreport/applyList", null, {
        params: {...this.page, ...this.search}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data.records
          this.page.total = res.data.total
        }
      })
    },
    handleAdd(id) {
      this.$router.push({hash: "#add", query: {id}})
    },
  },
  created() {
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.list {
  height: 100%;
}
</style>
