<template>
  <section class="needsList">
    <ai-list>
      <ai-title slot="title" title="融资需求" isShowBottomBorder/>
      <template #content>
        <ai-search-bar>
          <template #left>
            <ai-select placeholder="融资主体类型" v-model="search.applyType" @change="page.current=1,getTableData()"
                       :selectList="dict.getDict('financingDemandApplyType')"/>
          </template>
          <template #right>
            <el-input size="small" placeholder="搜索联系人、企业名称" v-model="search.name" 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">
            <template slot-scope="{row}">
              <el-button type="text" @click="showDetail(row.id)">详情</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: "needsList",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      search: {name: ""},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      colConfigs: [
        {label: "联系人", prop: "name"},
        {label: "联系方式", prop: "phone"},
        {label: "企业名称", prop: "enterpriseName"},
        {label: "所在地区", prop: "areaName"},
        {label: "意向金额(万)", prop: "loanAmount"},
        {label: "申请时间", prop: "createTime"},
        {label: "备注", prop: "remark"},
        {slot: "options"}
      ]
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/appfinancingdemand/list", null, {
        params: {...this.page, ...this.search, status: 0}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    showDetail(id) {
      this.$router.push({query: {id}})
    },
  },
  created() {
    this.getTableData()
  }
}
</script>

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