<template>
    <view class="container">
        <MBCard>
            <uni-forms ref="baseForm" :modelValue="queryParams">
                <uni-forms-item label="合同编号">
                    <uni-easyinput
                        v-model="queryParams.contractCode"
                        errorMessage
                        focus
                        placeholder="请输入合同编号"
                        trim="all"
                        @input="handleQuery"
                    />
                </uni-forms-item>
                <uni-forms-item label="地域">
                    <Area v-model="queryParams.areaId" @change="handleQuery"/>
                </uni-forms-item>
                <uni-forms-item label="商业公司">
                    <BusinessCompany v-model="queryParams.params.userId" :areaId="queryParams.areaId"
                                     @change="handleQuery"/>
                </uni-forms-item>
                <uni-forms-item label="货主">
                    <ProductionUnit v-model="queryParams.companyId" @change="handleQuery"/>
                </uni-forms-item>
            </uni-forms>
        </MBCard>


        <MBLoading v-if="loading"/>
        <view v-else>
            <ListItem v-if="tableData.length > 0" :items="tableData"/>
            <MBPagination
                v-if="total > 0"
                v-model:limit="paging.pageSize"
                v-model:page="paging.pageNum"
                :total="total"
                @pagination="handleQuery"
            />
        </view>
    </view>
</template>

<script setup>
import MBCard from "../../../components/MB/MBCard.vue";
import ProductionUnit from "../../../components/ProductionUnit/ProductionUnit.vue";
import UniForms from "../../../uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
import UniFormsItem from "../../../uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue";
import {onMounted, ref} from 'vue'
import BusinessCompany from "../../../components/BusinessCompany.vue";
import Area from "../../../components/Area.vue";
import MBLoading from "../../../components/MB/MBLoading.vue";
import MBPagination from "../../../components/MB/MBPagination.vue";
import ListItem from "./ListItem.vue";
import {getReportOrderQuery} from "../../../api/order";

const queryParams = ref({
    params: {}
})

const loading = ref(true)
const total = ref(0)
const paging = ref({
    pageNum: 1,
    pageSize: 20,
    isAsc: 'descending',
    orderByColumn: 'adddate'
})
const tableData = ref([])

const handleQuery = async () => {
    loading.value = true
    const data = await getReportOrderQuery(queryParams.value, paging.value)
    total.value = data.total
    tableData.value = data.rows
    loading.value = false
}

onMounted(async () => {
    await handleQuery()
})

</script>
