<template>
  <section class="AppNeedSta">
    <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.status" placeholder="状态" :selectList="dict.getDict('financingDemandStatus')"
                       @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.name" clearable
                      @change="getTableData()"/>
            <ai-download :instance="instance" url="appfinancingdemand/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">
          <el-table-column slot="options" label="状态" fixed="right" width="100" align="center">
            <template slot-scope="{row}">
              <span :class="`status${row.status}`">{{ dict.getLabel('financingDemandStatus', row.status) }}</span>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

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

export default {
  name: "AppNeedSta",
  label: "融资情况汇总",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      search: {status: "1"},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      colConfigs: [
        // {label: "产品名称", width: '200', prop: "enterpriseName"},
        {label: "联系人", width: '150', prop: "name"},
        {label: "联系方式", width: '150', prop: "phone"},
        // {label: "身份证号", width: '180', prop: "idNumber"},
        {label: "企业主体", width: '200', prop: "enterpriseName"},
        {label: "意向金额(万)", width: '150', prop: "loanAmount"},
        {label: "申请时间", width: '180', prop: "createTime"},
        {label: "客户经理", width: '200', prop: "auditUserName"},
        {label: "贷款银行", width: '200', prop: "organizationName"},
        {label: "放款金额(万)", width: '200', prop: "auditAmount"},
        // {label: "机构类型", width: '200', prop: "organizationType", dict:'financialOrganizationType'},
      ],
    }
  },
  methods: {
    getTableData() {
      let status = this.search.status || 999
      this.instance.post("/appfinancingdemand/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.createTimeStart = v?.[0].substring(0, 10)
      this.search.createTimeEnd = v?.[1].substring(0, 10)
      this.getTableData()
    }
  },
  created() {
    this.dict.load('financingDemandStatus')
    this.search.areaId = this.user.info.areaId
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.AppNeedSta {
  height: 100%;

  .status0 {
    color: #f82;
  }

  .status1 {
    color: #2EA222;
  }

  .status2 {
    color: #f46;
  }
}
</style>
