<template>
  <a-modal class="add-custom custom-detail"
           title="融资明细"
           centered
           v-model:visible="visible"
           :maskClosable="false"
           @cancel="cancel"
           width="890px">
    <template #footer>
      <a-button key="submit"
                type="primary"
                :loading="loading"
                @click="cancel">关闭</a-button>
    </template>
    <a-form class="inlineForm">
      <fieldset class="formFieldSet">
        <legend>融资信息</legend>
        <Des :list="desList" />
      </fieldset>
      <fieldset class="formFieldSet">
        <legend>还款信息</legend>
        <div class="tableDatas tableContextCenter">
          <a-table class="dialogTable"
                   :columns="columns"
                   :data-source="tableList"
                   :pagination="false">
          </a-table>
        </div>
      </fieldset>
    </a-form>
  </a-modal>
</template>

<script lang="ts">
import { defineComponent, PropType, ref, watchEffect } from 'vue';
import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
import { formatValue } from '@/common/methods';
import { Des, handleDesList } from '@/common/components/commonDes';
import { closeModal } from '@/common/setup/modal';
import { queryTableList } from '@/common/export/table';
import { QhjContract, QueryContractLogReq } from '@/services/go/ermcp/qhj/interface';
import { queryContractLog } from '@/services/go/ermcp/qhj';
import Long from 'long';
import {getFinancingStatus} from "@/common/constants/enumsName";

export default defineComponent({
    name: 'platinum_financing_information_detail',
    components: { Des },
    props: {
        selectedRow: {
            type: Object as PropType<QhjContract>,
            default: {},
        },
    },
    setup(props: { selectedRow: QhjContract }) {
        const { visible, cancel } = closeModal('platinum_financing_information_detail');
        const { desList, getDesList } = handleDesList();
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList();
        const columns = [
            {
                title: '追加/还款时间',
                dataIndex: 'updatetime',
                key: 'updatetime',
            },
            {
                title: '金额',
                dataIndex: 'amount',
                key: 'amount',
            },
            {
                title: '剩余款',
                dataIndex: 'remainamount',
                key: 'remainamount',
            },
        ];
        function getStatus(type: number): string {
            let result = '--';
            switch (type) {
                case 1:
                    result = '待确认';
                    break;
                case 2:
                    result = '已确认';
                    break;
                case 3:
                    result = '确认拒绝';
                    break;
                case 4:
                    result = '已支付保证金';
                    break;
                case 5:
                    result = '已激活';
                    break;
                case 6:
                    result = '已违约';
                    break;
                case 7:
                    result = '到期结束';
                    break;
                case 8:
                    result = '延期结束';
                    break;
                case 9:
                    result = '违约结束';
                    break;
                case 10:
                    result = '已注销';
                    break;
                case 11:
                    result = '已关闭';
                    break;
                case 99:
                    result = '未提交';
                    break;
            }
            return result;
        }
        watchEffect(() => {
            if (visible.value) {
                const data = props.selectedRow;

                const addinfo = data.currisklevel === 2 ? " 需追加" + data.reckonrecovermargin + "元" : ""
                // 个人
                const person = [
                    { label: '账号', value: formatValue(data.logincode) },
                    { label: '名称', value: formatValue(data.username) },
                    { label: '账户类型', value: formatValue(data.userinfotype === 1 ? '个人' : '企业') },
                    { label: '商品', value: formatValue(data.goodsname) },
                    { label: '价格', value: formatValue(data.tradeprice) },
                    { label: '数 量', value: formatValue(data.wrqty) },
                    { label: '金额', value: formatValue(data.lenderamount) },
                    { label: '已付款', value: formatValue(data.payamount) },
                    { label: '融资额', value: formatValue(data.remainamount) },
                    { label: '融资时间', value: formatValue(data.contractconfirmtime) },
                    { label: '状 态', value: getFinancingStatus(data.currisklevel, data.reckonrecovermargin.toString()) + addinfo},
                ];

                getDesList(person);
                const param: QueryContractLogReq = {
                    scfcontractid: data.scfcontractid,
                };
                queryTable(queryContractLog, param);
            }
        });
        return {
            desList,
            cancel,
            visible,
            loading,
            tableList,
            columns,
            getFinancingStatus,
        };
    },
});
</script>

<style lang="less">
.custom-detail {
    .ant-form.inlineForm {
        margin-top: 20px;
    }
    .upload {
        .look {
            margin-left: 0;
        }
    }
    .red {
        color: @m-red1;
    }
}
</style>;
