<template>
  <div class="card content-box">
    <div class="table-inner">
      <ProTable :config="config" ref="caseLRef" :api="getCreditPage">
        <!-- <ProTable :config="config" ref="caseLRef" :data="data"> -->
        <!-- <template #table_top>
          <div class="topgrp">
            <div class="topbox">
              <div class="topinner">
                <p>统计值</p>
                <p>111</p>
              </div>
            </div>
          </div>
        </template> -->
      </ProTable>
    </div>
    <caseModal ref="caseModalRef" />
  </div>
</template>

<script setup name="case-manage" lang="jsx">
  import caseModal from './components/caseModal.vue';
  import { useRouter } from 'vue-router';
  import { reactive, ref } from 'vue';
  import { getCreditPage } from '@/api/property';
  const caseModalRef = ref();
  const caseLRef = ref();
  import { onMounted } from 'vue';

  const router = useRouter();
  const options = ref([]);
  const onCellClick = ({ row, rowIndex }) => {
    router.push({
      path: '/property/case-detail',
      query: { id: row.id }, //这里不能直接写成 query: JSON.stringify(item)
    });
  };
  const config = reactive({
    columns: [
      { field: 'id', title: '案件ID', search: { el: 'input' }, width: 80 },
      {
        field: 'code',
        title: '借款机构',
        width: 100,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'code',
        title: '资管公司',
        width: 100,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: '借款人姓名',
        width: 120,
        search: {
          el: 'input',
          props: { clearable: true },
          slots: {
            default: ({ row }) => {
              return <>{row?.borrower?.name}</>;
            },
          },
        },
      },
      {
        field: 'role',
        title: '身份证',
        width: 140,
        search: {
          el: 'input',
          props: { clearable: true },
          slots: {
            default: ({ row }) => {
              return <>{row?.borrower?.idCard}</>;
            },
          },
        },
      },
      {
        field: 'role',
        title: '手机号',
        width: 140,
        search: {
          el: 'input',
          props: { clearable: true },
          slots: {
            default: ({ row }) => {
              return <>{row?.borrower?.phone}</>;
            },
          },
        },
      },
      {
        field: 'loanAmount',
        title: '委案金额',
        width: 80,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: '累计还款金额',
        width: 110,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: '累计减免金额',
        width: 110,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: '剩余待还金额',
        width: 110,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: 'CPE',
        width: 80,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: '分配CPE日期',
        width: 110,
        search: { el: 'date-picker', props: { type: 'date', valueFormat: 'YYYY-MM-DD' } },
      },
      {
        field: 'principalBalance',
        title: '本金余额',
        width: 80,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'debitInterest',
        title: '欠息额',
        width: 80,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'commission',
        title: '手续费',
        width: 80,
        search: { el: 'input', props: { clearable: true } },
      },
      {
        field: 'role',
        title: '跟进结果',
        width: 80,
        enum: options,
        search: { el: 'select', props: { filterable: true }, span: 1 },
        fieldNames: { label: 'genderLabel', value: 'genderValue' },
      },
      {
        field: 'role',
        title: '跟进状态',
        width: 80,
        enum: options,
        search: { el: 'select', props: { filterable: true }, span: 1 },
        fieldNames: { label: 'genderLabel', value: 'genderValue' },
      },
      {
        field: 'creditStatus',
        title: '案件状态',
        width: 80,
        enum: options,
        search: { el: 'select', props: { filterable: true }, span: 1 },
        fieldNames: { label: 'genderLabel', value: 'genderValue' },
      },
    ],
    onCellClick: onCellClick,
  });

  const allocation = (row) => {
    if (
      !caseLRef.value.element.getCheckboxRecords() ||
      caseLRef.value.element.getCheckboxRecords().length === 0
    )
      return;
    console.log('111', caseLRef.value.element.getCheckboxRecords());
    caseModalRef.value.openModal(JSON.parse(JSON.stringify(row)));
  };
  const query = () => caseLRef.value?.search();

  onMounted(() => {
    query();
  });
</script>
<style lang="scss" scoped>
  .table-inner {
    width: 100%;
    :deep(.topgrp) {
      display: flex;
      margin-bottom: 8px;
      .topbox {
        margin-right: 10px;
        background: rgba(0, 0, 0, 0.02);
        border-radius: 16px;
        width: 146px;
        height: 97px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 24px;
        p:nth-child(1) {
          font-size: 14px;
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }
  }
</style>
