<template>
    <div class="p-3">
        <div class="bg-fff flex1 ov-hd d-flex flex-cln">
            <div class="pd-16 border-bottom">
                <div class="f-s-20 c-333 f-w-7 mb-10">上报价格审核</div>
                <div class="d-flex j-ed">
                    <div class="d-flex pl-20">
                        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="auto">
                            <el-form-item label="上报时间" prop="dateRange">
                                <div class="d-flex" style="width: 220px">
                                    <DateRange v-model="queryParams.dateRange" v-model:start-date="queryParams.startDate" v-model:end-date="queryParams.endDate" @change="handleQuery"></DateRange>
                                </div>
                            </el-form-item>
                            <el-form-item label="品种名称" prop="varietyName">
                                <el-input style="width: 180px;" v-model="queryParams.varietyName" placeholder="搜品种名称" clearable />
                            </el-form-item>
                            <el-form-item label="企业名称" prop="cpyName">
                                <el-input style="width: 180px;" v-model="queryParams.cpyName" placeholder="搜企业名称" clearable />
                            </el-form-item>
                            <el-form-item label="审核状态" prop="auditStatus">
                                <el-select style="width: 160px;" v-model="queryParams.auditStatus" @change="handleQuery" placeholder="请选择审核状态" clearable>
                                    <el-option v-for="item in check_status" :key="item.value" :label="item.label" :value="item.value" />
                                </el-select>
                            </el-form-item>
                            <el-form-item>
                                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                                <el-button @click="exportList">导出</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </div>
            <div class="flex1 ov-hd pd-16 d-flex flex-cln">
                <div class="flex1 ov-hd">
                    <vxe-table ref="tableRef" :loading="loading" border :data="list" min-height="0" max-height="auto" :column-config="{ resizable: true }" :row-config="{ keyField: 'id', isCurrent: true, isHover: true }" :checkbox-config="{ highlight: true, range: true, trigger: 'row', reserve: true }">
                        <!-- 多选 -->
                        <vxe-column type="checkbox" width="60" align="center" />
                        <!-- 序号 -->
                        <vxe-column type="seq" width="60" title="序号" align="center" />
                        <vxe-column title="上报品种" field="varietyName" min-width="100" :formatter="colNoData" />
                        <vxe-column title="上报企业" field="cpyName" min-width="100" :formatter="colNoData" />
                        <vxe-column title="所在区域" field="originName" min-width="100" :formatter="colNoData" />
                        <vxe-column title="联系方式" field="tel" width="110" :formatter="colNoData" />
                        <vxe-column title="上报说明" field="remark" min-width="100" :formatter="colNoData" />
                        <vxe-column title="上报人" field="createByName" width="90" :formatter="colNoData" />
                        <vxe-column title="上报时间" field="createTime" width="160" :formatter="colNoData" />
                        <vxe-column title="规格数" field="specCount" width="80" :formatter="colNoData" />
                        <vxe-column title="待审核数" field="waitCount" width="80" />
                        <vxe-column title="已通过/不通过" width="120">
                            <template #default="{ row }">
                                <el-tag class="mr-10" type="primary">{{ row?.agreeCount }}</el-tag>
                                <el-tag type="danger">{{ row?.refuseCount }}</el-tag>
                            </template>
                        </vxe-column>
                        <vxe-column title="操作" align="center" fixed="right" width="100">
                            <template #default="{ row }">
                                <el-button @click="router.push({ path: 'report-detail', query: { id: row?.id, cpyid: row?.cpyid } })" type="primary" text>详情</el-button>
                            </template>
                        </vxe-column>
                    </vxe-table>
                </div>
            </div>
            <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
            <div class="pd-5"></div>
        </div>
    </div>
</template>
<script setup name="price-report" lang="ts">
import { colNoData } from '@/utils/noData';
import NP from 'number-precision';
import { originPriceList, priceReportExport } from '@/api/price/report';
import { DateRange } from '@/views/models';
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { check_status } = toRefs<any>(proxy?.useDict('check_status'));
const queryParams = ref<any>({
    pageNum: 1,
    pageSize: 10,
    auditStatus: '',
    startDate: '',
    endDate: '',
    dateRange: []
});
const loading = ref(false);
const total = ref(0);
const list = ref<any>([]);
const getList = async () => {
    loading.value = true;
    const res = await originPriceList(queryParams.value);
    if (!res || res.code !== 200) return;
    list.value = res.rows;
    total.value = res.total;
    loading.value = false;
};
const handleQuery = () => {
    queryParams.value.pageNum = 1;
    getList();
};
const queryFormRef = ref<any>();
const resetQuery = () => {
    queryFormRef.value?.resetFields();
    queryParams.value.startDate = '';
    queryParams.value.endDate = '';
    handleQuery();
};

const tableRef = ref<any>();
const exportList = async () => {
    // 获取表格选中信息
    const selected = tableRef.value?.getCheckboxReserveRecords(true).concat(tableRef.value?.getCheckboxRecords());
    console.log(selected);
    const ids = selected.map((item: any) => item.id);
    const res = await priceReportExport({ ids })
    if (!res || res.code !== 200) return;
};
onMounted(() => {
    handleQuery();
});
</script>
