检测计划统计弹窗下拉框内容调整

This commit is contained in:
caozehui
2026-05-29 09:58:24 +08:00
parent 19ea08d5e0
commit ee08263e4a
2 changed files with 43 additions and 23 deletions

View File

@@ -75,6 +75,11 @@ export namespace Plan {
unqualifiedCount: number; unqualifiedCount: number;
} }
export interface PlanStatisticsOption {
id: string;
name: string;
}
export interface PlanStatistics { export interface PlanStatistics {
planId: string; planId: string;
planName: string; planName: string;
@@ -92,6 +97,8 @@ export namespace Plan {
thirdOrMorePassRate: number; thirdOrMorePassRate: number;
unqualifiedRate: number; unqualifiedRate: number;
itemDistributions: PlanStatisticsItem[]; itemDistributions: PlanStatisticsItem[];
manufacturerOptions: PlanStatisticsOption[];
devTypeOptions: PlanStatisticsOption[];
} }

View File

@@ -18,7 +18,7 @@
filterable filterable
placeholder="全部" placeholder="全部"
class="filter-select" class="filter-select"
@change="reloadStatistics" @change="reloadStatistics('manufacturer')"
> >
<el-option label="全部" value="" /> <el-option label="全部" value="" />
<el-option <el-option
@@ -35,7 +35,7 @@
filterable filterable
placeholder="全部" placeholder="全部"
class="filter-select" class="filter-select"
@change="reloadStatistics" @change="reloadStatistics('devType')"
> >
<el-option label="全部" value="" /> <el-option label="全部" value="" />
<el-option <el-option
@@ -81,16 +81,15 @@ import { computed, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { getPlanStatistics } from '@/api/plan/plan' import { getPlanStatistics } from '@/api/plan/plan'
import { getPqDev } from '@/api/device/device'
import type { Plan } from '@/api/plan/interface' import type { Plan } from '@/api/plan/interface'
import type { Device } from '@/api/device/interface/device'
import { useDictStore } from '@/stores/modules/dict'
interface SelectOption { interface SelectOption {
id: string id: string
name: string name: string
} }
type FilterField = 'manufacturer' | 'devType'
const emptyStatistics = (): Plan.PlanStatistics => ({ const emptyStatistics = (): Plan.PlanStatistics => ({
planId: '', planId: '',
planName: '', planName: '',
@@ -107,7 +106,9 @@ const emptyStatistics = (): Plan.PlanStatistics => ({
secondPassRate: 0, secondPassRate: 0,
thirdOrMorePassRate: 0, thirdOrMorePassRate: 0,
unqualifiedRate: 0, unqualifiedRate: 0,
itemDistributions: [] itemDistributions: [],
manufacturerOptions: [],
devTypeOptions: []
}) })
const dialogVisible = ref(false) const dialogVisible = ref(false)
@@ -122,8 +123,7 @@ const filters = reactive({
manufacturer: '', manufacturer: '',
devType: '' devType: ''
}) })
const dictStore = useDictStore() const manufacturerOptions = ref<SelectOption[]>([])
const manufacturerOptions = computed<SelectOption[]>(() => dictStore.getDictData('Dev_Manufacturers') as SelectOption[])
const devTypeOptions = ref<SelectOption[]>([]) const devTypeOptions = ref<SelectOption[]>([])
let rateChart: echarts.ECharts | null = null let rateChart: echarts.ECharts | null = null
let itemChart: echarts.ECharts | null = null let itemChart: echarts.ECharts | null = null
@@ -172,16 +172,15 @@ const open = async (row: Partial<Plan.ReqPlan>) => {
filters.devType = '' filters.devType = ''
planName.value = row.name || '' planName.value = row.name || ''
dialogVisible.value = true dialogVisible.value = true
await loadFilterOptions()
await loadStatistics() await loadStatistics()
} }
const reloadStatistics = async () => { const reloadStatistics = async (changedField?: FilterField) => {
if (!dialogVisible.value || !currentPlanId.value) return if (!dialogVisible.value || !currentPlanId.value) return
await loadStatistics() await loadStatistics(changedField)
} }
const loadStatistics = async () => { const loadStatistics = async (changedField?: FilterField) => {
loading.value = true loading.value = true
try { try {
@@ -190,11 +189,21 @@ const loadStatistics = async () => {
manufacturer: filters.manufacturer || undefined, manufacturer: filters.manufacturer || undefined,
devType: filters.devType || undefined devType: filters.devType || undefined
}) })
const nextManufacturerOptions = data?.manufacturerOptions || []
const nextDevTypeOptions = data?.devTypeOptions || []
Object.assign(statisticsData, { Object.assign(statisticsData, {
...emptyStatistics(), ...emptyStatistics(),
...data, ...data,
itemDistributions: data?.itemDistributions || [] itemDistributions: data?.itemDistributions || [],
manufacturerOptions: nextManufacturerOptions,
devTypeOptions: nextDevTypeOptions
}) })
manufacturerOptions.value = nextManufacturerOptions
devTypeOptions.value = nextDevTypeOptions
if (clearInvalidFilters(changedField)) {
await loadStatistics()
return
}
await nextTick() await nextTick()
renderCharts() renderCharts()
} catch (error) { } catch (error) {
@@ -205,17 +214,21 @@ const loadStatistics = async () => {
} }
} }
const loadFilterOptions = async () => { const clearInvalidFilters = (changedField?: FilterField) => {
if (devTypeOptions.value.length) return let cleared = false
try { if (
const { data } = await getPqDev() changedField !== 'manufacturer' &&
devTypeOptions.value = ((data || []) as Device.ResDev[]).map(item => ({ filters.manufacturer &&
id: item.id, !manufacturerOptions.value.some(item => item.id === filters.manufacturer)
name: item.name ) {
})) filters.manufacturer = ''
} catch (error) { cleared = true
devTypeOptions.value = []
} }
if (changedField !== 'devType' && filters.devType && !devTypeOptions.value.some(item => item.id === filters.devType)) {
filters.devType = ''
cleared = true
}
return cleared
} }
const renderCharts = () => { const renderCharts = () => {