<template>
  <section class="AppLoanSta">
    <ai-list>
      <ai-title slot="title" title="贷款情况汇总" isShowBottomBorder isShowArea v-model="search.areaId"
                @change="page.current=1,getTableData()" :instance="instance"/>
      <template #content>
        <ai-search-bar>
          <template #left>
            <ai-select v-model="search.organizationType" placeholder="机构类型" clearable
                       :selectList="dict.getDict('financialOrganizationType')" @change="page.current=1,getTableData()"/>
            <ai-search label="申请时间">
              <el-date-picker size="small" placeholder="请选择" type="daterange"
                              start-placeholder="开始日期"
                              end-placeholder="结束日期" v-model="search.applyTime"
                              :default-time="['00:00:00','23:59:59']" value-format="yyyy-MM-dd"
                              @change="handleSearchTime"/>
            </ai-search>
          </template>
          <template #right>
            <el-input size="small" placeholder="搜索产品名称、身份证、企业、贷款机构" v-model="search.enterpriseName" clearable
                      @change="page.current=1,getTableData()"/>
            <ai-download :instance="instance" url="/app/appfinancialloanapply/export" :params="search"
                         fileName="交易记录">
              <el-button icon="iconfont iconExported">导出</el-button>
            </ai-download>
          </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"/>
      </template>
    </ai-list>
  </section>
</template>

<script>
import {mapState} from "vuex";
import {ID} from "dvcp-ui/lib/js/utils";

export default {
  name: "AppLoanSta",
  label: "贷款情况汇总",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      search: {status: ''},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      colConfigs: [
        {label: "产品名称", width: '200', prop: "productName"},
        {label: "联系人", width: '100', prop: "name"},
        {label: "联系方式", width: '140', prop: "phone"},
        {label: "身份证号", render: (h, {row}) => h('p', ID.hideId(row.idNumber)), width: 160},
        {label: "企业主体", width: '200', prop: "enterpriseName"},
        {label: "贷款金额(万)", width: '120', prop: "loanAmount"},
        {label: "申请时间", prop: "createTime", width: 160},
        {label: "贷款机构", prop: "organizationName"},
        {label: "机构类型", prop: "organizationType", dict: "financialOrganizationType"},
        {label: "状态", prop: "status", dict: "financialLoanApplyStatus"},
      ],
    }
  },
  methods: {
    getTableData() {
      let status = this.search.status || 999
      this.instance.post("/app/appfinancialloanapply/list", null, {
        params: {...this.page, ...this.search, status}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    handleSearchTime(v) {
      this.page.current = 1
      this.search.applyStartDate = v?.[0].substring(0, 10)
      this.search.applyEndDate = v?.[1].substring(0, 10)
      this.getTableData()
    }
  },
  created() {
    this.search.areaId = this.user.info.areaId
    this.dict.load('financialLoanApplyStatus', 'financialOrganizationType', 'financialOrganizationType')
    this.getTableData()
  }
}
</script>

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