DetectionOrderPage.vue 16.8 KB
<template>
    <a-card class="tabs-card" :bordered="false" :tab-list="tabs" :active-tab-key="tabKey"
        @tabChange="key => changeTab(key)">

        <!--查询栏-->
        <m-pagination-query-render :fields="pagination.filterFields" :form="pagination.queryForm"
            @onSearch="handlePageReload" @onReset="handleReset" :simpleFieldNum="4" />
        <!--查询栏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="downloadExcel('BATCH')" :disabled="exporting">批量导出</a-button>
            </div>
            <div class="flex justify-end" style="float: right;">
                <a-button type="primary" @click="handleAddOrder({})">创建工单</a-button>
                <a-button @click="downloadExcel('ALL')" :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 - 288px)' }"
            :row-selection="{ selectedRowKeys: selectIds, onChange: onSelectChange, type: 'checkbox', preserveSelectedRowKeys: true, }">

            <template #bodyCell="{ column, record }">

                <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 === 'custodianName'">
                    <div class="templateName" :title="record.vehicle?.custodianInfo?.custodianName || '-'">{{
                        record.vehicle?.custodianInfo?.custodianName || '-' }}</div>
                    <div class="templatePhone">{{ record.vehicle?.custodianInfo?.custodianPhone || '-' }}</div>
                </template>

                <template v-if="column.key === 'name'">
                    <div class="templateName" :title="record.inspector?.name || '-'">{{ record.inspector?.name || '-' }}
                    </div>
                    <div class="templatePhone">{{ record.inspector?.phone || '-' }}</div>
                </template>

                <template v-if="column.key === 'vehicleState'">
                    <vehicle-state-tag :vehicle-state="record.vehicle.vehicleState"></vehicle-state-tag>
                </template>

                <template v-if="column.key === 'status'">
                    <a-tag v-if="record.status == 1" color="#FFF3E5" :style="{ color: '#F0A700' }"
                        :bordered="false">待检测</a-tag>
                    <a-tag v-else-if="record.status == 2" color="#E7F2FE" :style="{ color: '#288BFA' }"
                        :bordered="false">检测中</a-tag>
                    <a-tag v-else-if="record.status == 3" color="#E8F8F2" :style="{ color: '#00AD74' }"
                        :bordered="false">已完成</a-tag>
                    <a-tag v-else-if="record.status == 4" color="#F0F2F5" :style="{ color: '#777C85' }"
                        :bordered="false">已取消</a-tag>
                </template>

                <template v-if="column.key === 'auditStatus'">
                    <a-tag v-if="record.auditStatus == 1" color="#FFF3E5" :style="{ color: '#F0A700' }"
                        :bordered="false">待审核</a-tag>
                    <a-tag v-else-if="record.auditStatus == 2" color="#E7F2FE" :style="{ color: '#288BFA' }"
                        :bordered="false">审核中</a-tag>
                    <a-tag v-else-if="record.auditStatus == 3" color="#E8F8F2" :style="{ color: '#00AD74' }"
                        :bordered="false">已通过</a-tag>
                    <a-tag v-else-if="record.auditStatus == 4" color="#FFEDED" :style="{ color: '#EB2F2F' }"
                        :bordered="false">已驳回</a-tag>
                </template>

                <template v-if="column.key === 'action'">

                    <router-link
                        :to="{ path: '/detection/order/view', query: { id: record.id, page: 'order', action: 'VIEW' } }">
                        <a-button type="link" size="small">详情</a-button>
                    </router-link>

                    <a-button v-if="record.status == 1" type="link" @click="handleAddOrder(record)"
                        size="small">编辑</a-button>

                    <a-button v-if="record.status == 1 || record.status == 2" type="link"
                        @click="handleCancelOrder(record)" size="small">取消工单</a-button>

                    <router-link v-if="record.status == 3 && record.auditStatus == 1"
                        :to="{ path: '/detection/order/view', query: { id: record.id, page: 'order', action: 'AUDIT' } }">
                        <a-button type="link" size="small">审核</a-button>
                    </router-link>

                    <router-link v-if="record.auditStatus == 3"
                        :to="{ path: '/detection/order/view', query: { id: record.id, page: 'order', action: 'VIEW' } }">
                        <a-button type="link" size="small">检测报告</a-button>
                    </router-link>

                </template>
            </template>
        </a-table>

        <!--新增/编辑工单弹窗-->
        <OrderAddForm ref="orderAddFormRef" @emitOk="pageLoad" />

        <!--取消工单弹窗-->
        <cancelDialog ref="cancelDialogRef" @emitOk="pageLoad" />

    </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 { Security } from "@/store";
import { ExportUtil } from "@/common/ExportUtil";

import { DetectionController } from "@/api/DetectionController";
import OrderAddForm from "@/views/detection/order/components/OrderAddForm.vue";
import cancelDialog from "@/views/detection/order/components/cancelDialog.vue";

@Component({
    components: { VehicleStateTag, OrderAddForm, cancelDialog }
})


export default class DetectionOrderPage extends PaginationComponent<Vehicle> {

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

    exporting = false;
    ccountByStatusData = {
        dispatchedCount: 0,
        inProgressCount: 0,
        completedCount: 0,
        canceledCount: 0,
    };
    auditStatusList = [
        { label: '待审核', value: 1 },
        // { label: '审核中', value: 2 },
        { label: '已通过', value: 3 },
        { label: '已驳回', value: 4 },
    ];

    tabKey = "";
    /**
     * 表格列配置
     */
    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: 'woId', key: 'woId', align: 'center', fixed: 'left', width: 170, 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: 286, resizable: true, ellipsis: true },
        { title: '车牌号', dataIndex: ['vehicle', 'baseInfo', "licensePlate"], key: 'licensePlate', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '所属门店', dataIndex: ['vehicle', 'venue', 'venueName'], key: 'venueName', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '车辆所在地址', dataIndex: ['vehicle', 'custodianInfo', "handoverAddress"], key: 'handoverAddress', width: 240, resizable: true, ellipsis: true },
        { title: '车辆保管人', dataIndex: ['vehicle', 'custodianInfo', "custodianName"], key: 'custodianName', align: 'left', width: 170, resizable: true, ellipsis: true },
        { title: '车辆状态', dataIndex: ['vehicle', "vehicleState"], key: 'vehicleState', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '检测师', dataIndex: ['inspector', "name"], key: 'name', align: 'left', width: 170, resizable: true, ellipsis: true },
        { title: '检测地址', dataIndex: 'inspectionAddress', key: 'inspectionAddress', align: 'center', width: 240, resizable: true, ellipsis: true },
        { title: '检测单状态', dataIndex: 'status', key: 'status', align: 'center', width: 170, resizable: true, ellipsis: true },
        { title: '审核状态', dataIndex: 'auditStatus', key: 'auditStatus', width: 170, align: 'center', resizable: true, ellipsis: true },
        { title: '创建时间', dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: true },
        { title: '完成检测时间', dataIndex: 'inspectionCompletedTime', key: 'inspectionCompletedTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: true },
        { title: '操作', key: 'action', width: 190, align: 'center', fixed: 'right' },
    ];

    getPagination() {
        return this.pagination;
    }

    /**
     * 初始化配置
     */
    created(): void {
        this.getinspectOrderCountByStatus();
        this.init(this.axios, DetectionController.PAGE_INSPECTOR_ORDER);
        this.buildQueryForm({
            keyword: [null, { label: '关键字', field: 'keyword', placeholder: '搜索工单单号、车源号、VIN码、车牌', operator: Operator.like }],
            vehicleState: [null, {
                label: '审核状态', field: 'auditStatus', type: 'select', allowClear: true, optionItems: this.auditStatusList, operator: Operator.eq
            }],
            woTime: [null, { label: '派单时间', field: 'woTime', operator: Operator.dateBetween, type: 'date-range' }],
        });

        const routeData = this.$route.query;
        if (routeData.tabKey) {
            this.tabKey = routeData.tabKey || '';
            this.pagination.queryForm.keyword = routeData.phone || '';
        }

        this.pagination.setDefaultSort('createTime', Order.desc);
        this.changeTab(this.tabKey);
    }

    getinspectOrderCountByStatus() {
        DetectionController.inspectOrderCountByStatus(this.axios, {}).then(res => {
            this.ccountByStatusData = res.data.data || {};
        });
    }

    get tabs() {
        const totalCount = (this.ccountByStatusData.dispatchedCount || 0) + (this.ccountByStatusData.inProgressCount || 0) + (this.ccountByStatusData.completedCount || 0) + (this.ccountByStatusData.canceledCount || 0);
        let tabs = [
            { key: "", tab: `全部 (${totalCount || 0})` },
            { key: "DISPATCHED", tab: `待检测 (${this.ccountByStatusData.dispatchedCount || 0})` },
            { key: "IN_PROGRESS", tab: `检测中 (${this.ccountByStatusData.inProgressCount || 0})` },
            { key: "COMPLETED", tab: `已完成 (${this.ccountByStatusData.completedCount || 0})` },
            { key: "CANCELED", tab: `已取消 (${this.ccountByStatusData.canceledCount || 0})` }
        ];
        return tabs;
    }

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

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

    // 新增工单 编辑
    handleAddOrder(data) {
        this.$refs.orderAddFormRef.init(data);
    }

    // 取消工单
    handleCancelOrder(data) {
        this.$refs.cancelDialogRef.init(data);
    }

    changeTab(status: string): void {
        this.tabKey = status;
        switch (this.tabKey) {
            case "":
                this.pagination.removeDefaultFilter('status');
                break;
            case "DISPATCHED":
                this.pagination.addDefaultFilter('status', 1, Operator.eq);
                break;
            case "IN_PROGRESS":
                this.pagination.addDefaultFilter('status', 2, Operator.eq);
                break;
            case "COMPLETED":
                this.pagination.addDefaultFilter('status', 3, Operator.eq);
                break;
            case "CANCELED":
                this.pagination.addDefaultFilter('status', 4, Operator.eq);
                break;
        }
        this.loading = true;
        this.pagination.reload().then(res => { }).finally(() => this.loading = false);
    }

    onSelectChange(selectedRowKeys: number[], selectedRows: []): void {
        this.selectIds = selectedRowKeys;
        this.selectedItems = selectedRows;
    }

    downloadExcel(type: string): void {
        this.exporting = true;
        let paramsData = {
            ...this.pagination.requestParams,
        }
        if (type == 'BATCH') {
            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: Operator.in, value: this.selectIds, })
            }
        }
        DetectionController.inspectOrderExport(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">
.templateName {
    width: 100%;
    color: #2f3133;
    font-size: 14px;
    font-weight: 400;
    font-family: "HarmonyOSSansSC";
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.templatePhone {
    color: #777c85;
    font-size: 12px;
    font-weight: 400;
    font-family: "HarmonyOSSansSC";
    text-align: left;
}

.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;
}
</style>