<template>
  <section class="loanList">
    <ai-list>
      <ai-title slot="title" title="贷款审核" isShowBottomBorder/>
      <template #content>
        <ai-search-bar>
          <template #left>
            <ai-select v-model="search.status" :selectList="dict.getDict('financialLoanApplyStatus')" placeholder="审批状态"
                       @change="page.current=1,getTableData()"/>
            <ai-search label="申请时间">
              <el-date-picker size="small" v-model="search.applyTime" type="daterange" @change="handleFilterApplyTime"
                              :default-time="['00:00:00','23:59:59']" value-format="yyyy-MM-dd HH:mm:ss"/>
            </ai-search>
          </template>
          <template #right>
            <el-input size="small" placeholder="搜索产品名称、企业主体、贷款银行" v-model="search.enterpriseName" 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: "loanList",
  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: "productName"},
        {label: "企业主体", prop: "enterpriseName"},
        {label: "贷款金额(万)", prop: "loanAmount"},
        {label: "申请时间", prop: "createTime"},
        {label: "联系人", prop: "name"},
        {label: "联系方式", prop: "phone"},
        {label: "贷款银行", prop: "organizationName"},
        {label: "状态", prop: "status", align: "center", dict: "financialLoanApplyStatus"},
        {slot: "options"}
      ]
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/appfinancialloanapply/list", null, {
        params: {...this.page, ...this.search}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    showDetail(id) {
      this.$router.push({query: {id}})
    },
    handleFilterApplyTime() {
      this.page.current = 1
      this.search.applyStartDate = this.search.applyTime?.[0].substring(0,10)
      this.search.applyEndDate = this.search.applyTime?.[1].substring(0,10)
      this.getTableData()
    }
  },
  created() {
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.loanList {
}
</style>
