<template>
    <uni-drawer ref="drawerContainerRef" :width="width" mode="right">

        <uni-nav-bar
            :border="false"
            :fixed="true"
            left-icon="left"
            status-bar
            title="额度审核"
            @clickLeft="hideDrawer"
        />

        <uni-collapse ref="collapse">
            <uni-collapse-item
                v-for="row in tableData"
                :key="row.creditHistId"
                :title="row.shortName"
                open
            >
                <view class="padding">
                    <view class="context">
                        <view class="label">
                            <text>货主:</text>
                            <text>{{ row.companyName }}</text>
                        </view>
                        <view class="label">
                            <text>状态:</text>
                            <text>{{ row.state }}</text>
                        </view>
                        <view class="label">
                            <text>老额度(万元) :</text>
                            <text>{{ row.oldCreditLine }}</text>
                        </view>
                        <view class="label">
                            <text>新额度(万元):</text>
                            <text>{{ row.creditLine }}</text>
                        </view>
                        <view class="label">
                            <text>申请日期:</text>
                            <text>{{ row.addDate }}</text>
                        </view>
                        <view class="label">
                            <text></text>
                            <button class="mini-btn" size="mini" type="primary" @click="handleReview(row)">查看</button>
                        </view>
                    </view>
                </view>
            </uni-collapse-item>
        </uni-collapse>
    </uni-drawer>
    <CreditLimitReview ref="CreditLimitReviewRef" @refresh="handleQuery"/>
</template>

<script setup>
import {defineExpose, defineOptions, ref} from 'vue'
import {getLastPaymentAndQuotaList} from "../../../../api/AccountPricePreliminaryRreview.js";
import CreditLimitReview from "./components/CreditLimitReview.vue";

// 额度审核


defineOptions({
    name: "CreditLimit"
})

const width = ref(document.documentElement.clientWidth || document.body.clientWidth)
const queryParams = ref({})
const tableData = ref([])
const total = ref()
const paging = ref({
    pageNum: 1,
    pageSize: 100,
})

const drawerContainerRef = ref()
const CreditLimitReviewRef = ref()

const handleQuery = async () => {
    uni.showLoading({
        title: '加载中'
    });
    const {rows, total: count} = await getLastPaymentAndQuotaList(queryParams.value, paging.value)
    tableData.value = rows
    total.value = count
    uni.hideLoading()
}

const openDrawer = async (item) => {
    drawerContainerRef.value.open()
    queryParams.value = {
        userId: item.userId,
        type: 1
    }
    await handleQuery()
}

defineExpose({openDrawer})

const hideDrawer = () => {
    drawerContainerRef.value.close()
}

const handleReview = (data) => {
    CreditLimitReviewRef.value.openDrawer(data)
}
</script>