<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.oldCreditPeriod }}</text>
                        </view>
                        <view class="label">
                            <text>新账期:</text>
                            <text>{{ row.creditPeriod }}</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>
    <AccountPeriodReview ref="AccountPeriodReviewRef" @refresh="handleQuery"/>
</template>

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

// 账期审核

defineOptions({
    name: 'AccountPeriod'
})

const width = ref(document.documentElement.clientWidth || document.body.clientWidth)
const id = ref('')
const queryParams = ref({})
const drawerContainerRef = ref()
const AccountPeriodReviewRef = ref()

const tableData = ref([])
const total = ref()
const paging = ref({
    pageNum: 1,
    pageSize: 100,
})

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: 0
    }
    await handleQuery()
}

defineExpose({openDrawer})

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

const handleReview = (data) => {
    AccountPeriodReviewRef.value.openDrawer(data)
}

</script>