| | |
| | | let previewRequest = 0 |
| | | let reordered = false |
| | | const addDialogVisible = ref(false) |
| | | const selectedCandidateId = ref<number | null>(null) |
| | | const selectedCandidateId = ref<string | null>(null) |
| | | const candidateGroupId = ref<number | null>(null) |
| | | const candidateQuery = ref('') |
| | | const batteryGroup = computed(() => selectedTests.value[0]?.group || '') |
| | | const candidateTests = computed(() => [...new Map(sources.value.filter(source => |
| | | const candidateTests = computed(() => sources.value.filter(source => |
| | | (!candidateGroupId.value || source.groupId === candidateGroupId.value) && |
| | | (!selectedTests.value.length || source.groupId === selectedTests.value[0]!.groupId) && |
| | | (source.name.includes(candidateQuery.value) || String(source.selection.testId).includes(candidateQuery.value))) |
| | | .map(source => [source.selection.testId, source])).values()]) |
| | | (source.name.includes(candidateQuery.value) || String(source.selection.testId).includes(candidateQuery.value) || source.batteryNo.includes(candidateQuery.value)))) |
| | | const candidateGroups = computed(() => [...new Map(sources.value.map(source => [source.groupId, source.group])).entries()]) |
| | | const commonBatteries = computed(() => selectedTests.value.length ? [...new Set(sources.value |
| | | .filter(source => source.selection.testId === selectedTests.value[0]!.selection.testId).map(source => source.batteryNo))] |
| | | .filter(battery => selectedTests.value.every(test => sources.value.some(source => |
| | | source.selection.testId === test.selection.testId && source.batteryNo === battery))) : []) |
| | | const selections = computed(() => selectedTests.value.flatMap(test => samples.value.flatMap(battery => { |
| | | const source = sources.value.find(source => source.selection.testId === test.selection.testId && source.batteryNo === battery) |
| | | return source ? [source.selection] : [] |
| | | }))) |
| | | const selections = computed(() => selectedTests.value.map(item => item.selection)) |
| | | const matrix = computed(() => savedReport.value || draftMatrix.value) |
| | | const statisticSettings = computed<SpliceSettings>(() => ({ |
| | | fieldStructure: fields.value, |
| | |
| | | // 来源移除后同步移除其人工值,仍在范围内的修改继续保留。 |
| | | statisticValues.value = Object.fromEntries(Object.entries(statisticValues.value).filter(([key]) => |
| | | selected.some(selection => key.startsWith(`${selection.testId}|${selection.testBatteryId}|`)))) |
| | | if (new Set(selected.map(item => item.testId)).size < 2 || !samples.value.length) { previewing.value = false; return } |
| | | if (selected.length < 2) { previewing.value = false; return } |
| | | previewing.value = true |
| | | try { |
| | | const result = await previewSpliceReport(selected) |
| | |
| | | |
| | | function openAddTest() { selectedCandidateId.value = null; candidateQuery.value = ''; addDialogVisible.value = true } |
| | | function addSpliceTest() { |
| | | const candidate = candidateTests.value.find(source => source.selection.testId === selectedCandidateId.value) |
| | | const candidate = candidateTests.value.find(source => `${source.selection.testId}:${source.selection.testBatteryId}` === selectedCandidateId.value) |
| | | if (!candidate) { ElMessage.warning('请选择需要拼接的测试'); return } |
| | | if (selectedTests.value.some(item => item.selection.testId === candidate.selection.testId && item.selection.testBatteryId === candidate.selection.testBatteryId)) { ElMessage.warning('该测试电池已添加'); return } |
| | | selectedTests.value.push(candidate) |
| | | if (!reordered) selectedTests.value.sort((a, b) => a.startedAt - b.startedAt || a.selection.testId - b.selection.testId) |
| | | samples.value = samples.value.length ? samples.value.filter(battery => commonBatteries.value.includes(battery)) : [...commonBatteries.value] |
| | | samples.value = [...new Set(selectedTests.value.map(item => item.batteryNo))] |
| | | addDialogVisible.value = false |
| | | } |
| | | function removeSpliceTest(index: number) { |
| | | selectedTests.value.splice(index, 1) |
| | | samples.value = samples.value.filter(battery => commonBatteries.value.includes(battery)) |
| | | samples.value = [...new Set(selectedTests.value.map(item => item.batteryNo))] |
| | | } |
| | | function moveTest(index: number, direction: number) { |
| | | const item = selectedTests.value[index] |
| | |
| | | <div class="dialog-form"> |
| | | <label><span>电池组</span><el-select v-model="candidateGroupId" clearable :disabled="selectedTests.length > 0" placeholder="全部"><el-option v-for="[id, name] in candidateGroups" :key="id" :label="name" :value="id" /></el-select></label> |
| | | <label><span>测试名称</span><el-input v-model="candidateQuery" placeholder="输入测试名称或ID搜索" /></label> |
| | | <label><span>选择测试</span><el-select v-model="selectedCandidateId" filterable clearable placeholder="选择检测完成测试"><el-option v-for="item in candidateTests" :key="item.selection.testId" :label="`${item.name}(${item.type},${item.group})`" :value="item.selection.testId" :disabled="selectedTests.some(test => test.selection.testId === item.selection.testId)" /></el-select></label> |
| | | <label><span>选择测试电池</span><el-select v-model="selectedCandidateId" filterable clearable placeholder="选择检测完成测试电池"><el-option v-for="item in candidateTests" :key="`${item.selection.testId}:${item.selection.testBatteryId}`" :label="`${item.name}(${item.group},${item.batteryNo})`" :value="`${item.selection.testId}:${item.selection.testBatteryId}`" :disabled="selectedTests.some(test => test.selection.testId === item.selection.testId && test.selection.testBatteryId === item.selection.testBatteryId)" /></el-select></label> |
| | | </div> |
| | | <template #footer><button class="secondary-button" type="button" @click="addDialogVisible = false">取消</button><button class="primary-button" type="button" @click="addSpliceTest"><el-icon><Plus /></el-icon>添加拼接</button></template> |
| | | </el-dialog> |