<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.warehouseName }}</text>
                        </view>
                        <view class="label">
                            <text>新考核价(元,含税):</text>
                            <text>{{ row.checkPrice }}</text>
                        </view>
                        <view class="label">
                            <text>新开票价(元,含税):</text>
                            <text>{{ row.invoicePrice }}</text>
                        </view>
                        <view class="label">
                            <text>原考核价(元,无税):</text>
                            <text>{{ row.oldCheckPrice }}</text>
                        </view>
                        <view class="label">
                            <text>原开票价(元,无税):</text>
                            <text>{{ row.oldInvoicePrice }}</text>
                        </view>


                        <view class="label">
                            <text>状态:</text>
                            <text>{{ row.state }}</text>
                        </view>
                        <view class="label">
                            <text>更新日期:</text>
                            <text>{{ row.updateTime }}</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>
    <PriceReview ref="PriceReviewRef" @refresh="handleQuery"/>
</template>

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

// 价格审核

defineOptions({
    name: "Price"
})

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 PriceReviewRef = ref()

const handleQuery = async () => {
    uni.showLoading({
        title: '加载中'
    });
    const {rows, total: count} = await getPriceChangeReviewList(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) => {
    PriceReviewRef.value.openDrawer(data)
}
</script>