DetectionReportPage.vue 14.4 KB
<template>
    <a-card class="tabs-card" :bordered="false">

        <!--查询栏-->
        <m-pagination-query-render :fields="pagination.filterFields" :form="pagination.queryForm"
            @onSearch="handlePageReload" @onReset="handleReset" :simpleFieldNum="4">
            <template #keyword="{ record }">
                <a-popover>
                    <template #content>
                        <p>搜索报告编号、工单号、车源号、VIN码、车牌</p>
                    </template>
                    <a-input v-model:value="pagination.queryForm.keyword" placeholder="搜索报告编号、工单号、车源号、VIN码、车牌" autocomplete="off" />
                </a-popover>
            </template>
        </m-pagination-query-render>

        <!--查询栏end-->

        <!--库存车辆列表start-->
        <div class="table-operations" style="margin-bottom: 16px;width: 100%;float: left;">
            <div class="flex justify-end" style="float: left;">
                已选 {{ selectedItems.length }} 项
                <a-button @click="handleBatchBind(1)">批量绑定</a-button>
                <a-button @click="handleBatchBind(2)">批量解绑</a-button>
            </div>
            <div class="flex justify-end" style="float: right;">
                <a-button type="primary" @click="modalVisible = true, excelValue = '1'" :disabled="exporting">
                    导出
                </a-button>
            </div>
        </div>

        <a-table :columns="columns" :data-source="pagination.content" :loading="loading" :bordered="false"
            @change="pageRefresh" @resizeColumn="this.$filters.tableResizeColumn" size="small" :pagination="pageState"
            :row-key="record => record.id" :scroll="{ y: 'calc(100vh - 350px)' }"
            :row-selection="{ selectedRowKeys: selectIds, onChange: onSelectChange, type: 'checkbox', preserveSelectedRowKeys: true, }">

            <template #bodyCell="{ column, record }">
                <template v-if="column.key === 'vehicleState'">
                    <vehicle-state-tag :vehicle-state="record.vehicle.vehicleState"></vehicle-state-tag>
                </template>

                <template v-if="column.key === 'carTypeName'">
                    <div class="carTypeNameBox">
                        <div class="carTypeNameBox_image">
                            <a-image v-if="record.vehicle?.cover?.url" :width="60" style="border-radius: 4px;"
                                :src="record.vehicle?.cover?.url" />
                        </div>
                        <div class="carTypeNameBox_text">
                            <div class="carTypeNameBox_name"
                                :title="record.vehicle?.baseInfo?.carSeriesName + record.vehicle?.baseInfo?.carTypeName || '-'">
                                {{ record.vehicle?.baseInfo?.carSeriesName }} {{ record.vehicle?.baseInfo?.carTypeName
                                    ||
                                    '-' }}
                            </div>
                            <div class="carTypeNameBox_vin" :title="record.vehicle?.baseInfo?.vin || '-'">VIN码:{{
                                record.vehicle?.baseInfo?.vin || '-' }}</div>
                        </div>
                    </div>
                </template>


                <template v-if="column.key === 'bindStatus'">
                    <a-tag v-if="record.bindStatus == 1" color="#E8F8F2" :style="{ color: '#00AD74' }"
                        :bordered="false">已绑定</a-tag>
                    <a-tag v-if="record.bindStatus == 2" color="#F0F2F5" :style="{ color: '#777C85' }"
                        :bordered="false">未绑定</a-tag>
                </template>

                <template v-if="column.key === 'scoreLevel'">
                    <div>
                        <span>{{ (record.inspectionRecord?.overallScore ?? '') === '' ? '-' : `${record.inspectionRecord?.overallScore} 分`}}</span>
                    </div>
                </template>

                <template v-if="column.key === 'woId'">
                    <router-link
                        :to="{ path: '/detection/order/view', query: { id: record.id, page: 'report', action: 'VIEW' } }">
                        <a-button type="link" size="small">{{ record.woId }}</a-button>
                    </router-link>
                </template>

                <template v-if="column.key === 'action'">
                    <router-link
                        :to="{ path: '/detection/order/view', query: { id: record.id, page: 'report', action: 'VIEW' } }">
                        <a-button type="link" size="small">预览</a-button>
                    </router-link>
                    <a-button type="link" @click="handleBind(record, 2)" v-if="record.bindStatus == 1"
                        size="small">解绑</a-button>
                    <a-button type="link" @click="handleBind(record, 1)" v-if="record.bindStatus == 2"
                        size="small">绑定</a-button>
                </template>
            </template>
        </a-table>
        <bind-dialog ref="bindDialogRef" @emitOk="handlePageReload" />

        <a-modal :visible="modalVisible" @ok="handleVisibleOk" @cancel="modalVisible = false" title="导出范围"
            width="420px">
            <div>
                <div class="visible-title">请选择导出范围 <span class="validate">*</span> </div>
                <a-select v-model:value="excelValue" style="width: 100%" placeholder="请选择导出范围">
                    <a-select-option value="1">导出全部</a-select-option>
                    <a-select-option value="2">导出当前勾选的结果</a-select-option>
                </a-select>
            </div>
        </a-modal>

    </a-card>
</template>
<script lang="ts">
import { Component } from 'vue-facing-decorator';
import { message, TableColumnsType } from "ant-design-vue";
import { Operator, Order } from "lib/src/core/page/Pagination";
import VehicleStateTag from "@/views/vehicle/inventory/VehicleStateTag.vue";
import { PaginationComponent } from "@/components/PaginationComponent";
import { Vehicle } from "lib/src/entity/vehicle/entity/Vehicle";
import { ExportUtil } from "@/common/ExportUtil";

import { DetectionController } from "@/api/DetectionController";
import bindDialog from "@/views/detection/report/components/bindDialog.vue";


@Component({
    components: { VehicleStateTag, bindDialog }
})


export default class DetectionReportPage extends PaginationComponent<Vehicle> {

    exporting = false;

    selectIds: number[] = [];
    selectedItems = [];

    bindStatusList = [
        { label: '已绑定', value: 1 },
        { label: '未绑定', value: 2 },
    ];

    modalVisible = false;
    excelValue = '1';

    vehicleStateList = [
        { label: '待入库', value: 'INVENTORY' },
        { label: '场地待维护', value: 'VENUE' },
        { label: '待定价', value: 'TO_BE_PRICED' },
        { label: '待关联拍场', value: 'PRICED' },
        { label: '待上拍', value: 'PENDING_AUCTION' },
        { label: '待拍卖', value: 'WAIT_AUCTION' },
        { label: '预展中', value: 'PREVIEW' },
        { label: '拍卖中', value: 'AUCTIONING' },
        { label: '待签署合同', value: 'CONTRACT_UNSIGNED' },
        { label: '待付车款', value: 'UNPAID' },
        { label: '待提车', value: 'WAIT_PICKUP' },
        { label: '待过户', value: 'TRANSFERRING' },
        { label: '已完成', value: 'COMPLETED' },
        { label: '已取消', value: 'CANCELED' },
    ];

    /**
     * 表格列配置
     */
    columns: TableColumnsType = [
        {
            title: '序号', key: 'index', width: 70, align: 'center', fixed: 'left', sorter: false,
            customRender: ({ index }) => {
                return (this.getPagination().pageIndex - 1) * this.getPagination().pageSize + index + 1;
            },
        },
        { title: '报告编号', dataIndex: 'reportNo', key: 'reportNo', align: 'center', fixed: 'left', width: 150, resizable: true, ellipsis: true },
        { title: '生成时间', dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: true },
        { title: '工单单号', dataIndex: "woId", key: 'woId', align: 'center', width: 150, resizable: true, ellipsis: true },
        { title: '车源号', dataIndex: ['vehicle', 'baseInfo', "sourceNo"], key: 'sourceNo', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '车型名称', dataIndex: ['vehicle', 'baseInfo', "carTypeName"], key: 'carTypeName', align: 'left', width: 240, resizable: true, ellipsis: true },
        { title: '车牌号', dataIndex: ['vehicle', 'baseInfo', "licensePlate"], key: 'licensePlate', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '车辆状态', dataIndex: ['vehicle', "vehicleState"], key: 'vehicleState', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '评分', dataIndex: 'scoreLevel', key: 'scoreLevel', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: true },
        { title: '绑定状态', dataIndex: 'bindStatus', key: 'bindStatus', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '更新时间', dataIndex: 'updateTime', key: 'updateTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: true },
        { title: '操作', key: 'action', width: 170, align: 'center', fixed: 'right' },
    ];

    getPagination() {
        return this.pagination;
    }

    /**
     * 初始化配置
     */
    created(): void {
        this.init(this.axios, DetectionController.PAGE_INSPECTOR_REPORT);

        this.buildQueryForm({
            keyword: [null, {
                name: 'keyword', label: '关键字', field: 'keyword', type: 'slot', placeholder: '搜索报告编号、工单号、车源号、VIN码、车牌', operator: Operator.eq
            }],
            bindStatus: [null, {
                label: '绑定状态', field: 'bindStatus', type: 'select', allowClear: true, optionItems: this.bindStatusList, operator: Operator.eq
            }],
            vehicleState: [null, { label: '车辆状态', type: 'select', optionItems: this.vehicleStateList, allowClear: true, field: 'vehicleState', operator: Operator.eq }],
            createTime: [null, { label: '生成时间', field: 'createTime', operator: Operator.dateBetween, type: 'date-range' }],
        });
        this.pagination.setDefaultSort('createTime', Order.desc);
        this.pageLoad();
    }

    //查询
    handlePageReload() {
        this.selectIds = [];
        this.selectedItems = [];
        this.pageReload();
    }

    //重置查询条件
    handleReset() {
        this.selectIds = [];
        this.selectedItems = [];
        this.pageReset();
    }

    //选择数据
    onSelectChange(selectedRowKeys: number[], selectedRows: []): void {
        this.selectIds = selectedRowKeys;
        this.selectedItems = selectedRows;
    }

    //批量绑定/解绑
    handleBatchBind(bindStatus: number) {
        if (this.selectedItems.length === 0) {
            message.warning(bindStatus == 1 ? '请选择需要绑定的数据' : '请选择需要解绑的数据');
            return;
        }
        const list = (this.selectedItems || []).filter(item => item.bindStatus == bindStatus);
        if (list.length > 0) {
            message.warning(bindStatus == 1 ? '选择的项存在已绑定的数据,请重新选择' : '选择的项存在未绑定的数据,请重新选择');
            return;
        }
        this.$refs.bindDialogRef.init({
            bindList: this.selectedItems,
            bindStatus: bindStatus
        });
    }

    //绑定/解绑
    handleBind(record: Vehicle, bindStatus: number) {
        this.$refs.bindDialogRef.init({
            bindList: [record],
            bindStatus: bindStatus
        });
    }

    handleVisibleOk() {
        this.modalVisible = false;
        this.downloadExcel();
    }

    downloadExcel(): void {
        this.exporting = true;
        let paramsData = {
            ...this.pagination.requestParams,
        }
        if (this.excelValue == '2') {
            if (!this.selectIds.length) {
                message.error('请选择需要导出的数据');
                this.exporting = false;
                return false
            } else {
                if (!paramsData.filters) {
                    paramsData.filters = []
                }
                paramsData.filters.push({ field: "id", logic: "and", operator: "in", value: this.selectIds, })
            }
        }
        DetectionController.inspectReportExport(this.axios, paramsData, { responseType: 'blob' }).then(response => {
            message.success('导出任务已创建,请在下载中心查看');
            ExportUtil.downloadExcelFile(response.data, this.getNewTime() + '-检测报告管理');
        }).catch(error => {
            console.error('Error downloading Word file:', error);
        }).finally(() => {
            this.exporting = false;
        });
    }

    getNewTime() {
        //获取当前年月日时分秒
        const date = new Date();
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        const monthStr = month < 10 ? '0' + month : month;
        const day = date.getDate();
        const dayStr = day < 10 ? '0' + day : day;
        const hour = date.getHours();
        const minute = date.getMinutes();
        const minuteStr = minute < 10 ? '0' + minute : minute;
        return `${year}-${monthStr}-${dayStr}-${hour}-${minuteStr}`
    }

}
</script>


<style scoped lang="less">
.carTypeNameBox {
    width: 100%;
    display: flex;
}

.carTypeNameBox_image {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    float: left;
}

.carTypeNameBox_text {
    width: 200px;
    float: left;
    margin-left: 8px;
}

.carTypeNameBox_name {
    width: 100%;
    height: 22px;
    color: #2f3133;
    font-size: 14px;
    font-weight: 400;
    font-family: "HarmonyOSSansSC";
    text-align: left;
    line-height: 22px;
    margin-top: 9px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.carTypeNameBox_vin {
    width: 100%;
    height: 20px;
    opacity: 1;
    color: #777c85;
    font-size: 12px;
    font-weight: 400;
    font-family: "HarmonyOSSansSC";
    text-align: left;
    line-height: 20px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.color_A {
    color: #00ad74;
}

.color_B {
    color: #fc8b0a;
}

.color_C {
    color: #eb2f2f;
}
</style>