|
|
|
|
@ -34,7 +34,7 @@
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item :label="t('MoldManagement.MoldInspectionPlan.subjectName')" prop="subjectIds">
|
|
|
|
|
<el-select
|
|
|
|
|
<!-- <el-select
|
|
|
|
|
v-model="formData.subjectIds"
|
|
|
|
|
multiple
|
|
|
|
|
filterable
|
|
|
|
|
@ -43,7 +43,10 @@
|
|
|
|
|
class="!w-full"
|
|
|
|
|
>
|
|
|
|
|
<el-option v-for="item in subjectOptions" :key="item.id" :label="item.subjectName" :value="item.id" />
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-select>-->
|
|
|
|
|
<el-input :model-value="displayItemDevice" readonly clearable class="device-ledger-selection-input"
|
|
|
|
|
:placeholder="t('MoldManagement.MoldInspectionPlan.placeholderSubjectSelect')"
|
|
|
|
|
@click="openCriticalComponentDialog" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
@ -52,13 +55,40 @@
|
|
|
|
|
<el-button @click="dialogVisible = false">{{ t('common.cancel') }}</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</Dialog>
|
|
|
|
|
<TableSelectDialog
|
|
|
|
|
ref="deviceSelectDialogRef"
|
|
|
|
|
title="选择设备"
|
|
|
|
|
:columns="deviceColumns"
|
|
|
|
|
:fetch-api="fetchDeviceLedgerPage"
|
|
|
|
|
row-key="id"
|
|
|
|
|
@confirm="handleDeviceSelectConfirm"
|
|
|
|
|
:query-params="mergedQueryParams"
|
|
|
|
|
:default-selected-keys="ids"
|
|
|
|
|
>
|
|
|
|
|
<!-- 使用 header 插槽插入查询表单 -->
|
|
|
|
|
<template #header>
|
|
|
|
|
<el-form ref="searchFormRef" :model="searchParams" :inline="true" >
|
|
|
|
|
<el-form-item label="设备编号" prop="deviceCode">
|
|
|
|
|
<el-input v-model="searchParams.deviceCode" placeholder="请输入编号" clearable />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="设备名称" prop="deviceName">
|
|
|
|
|
<el-input v-model="searchParams.deviceName" placeholder="请输入名称" clearable />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button type="primary" @click="handleSearch">{{ t('FactoryModeling.ProductInformation.searchButtonText') }}</el-button>
|
|
|
|
|
<el-button @click="resetSearch">{{ t('FactoryModeling.ProductInformation.resetButtonText') }}</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</template>
|
|
|
|
|
</TableSelectDialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import type { FormRules } from 'element-plus'
|
|
|
|
|
import { DvSubjectApi, DvSubjectVO } from '@/api/mold/inspectionItems'
|
|
|
|
|
import { PlanMaintenanceApi, PlanMaintenanceVO } from '@/api/mold/planmaintenance'
|
|
|
|
|
|
|
|
|
|
import {DeviceLedgerApi, DeviceLedgerVO} from "@/api/mes/deviceledger";
|
|
|
|
|
import TableSelectDialog from '@/components/TableSelectDialog/TableSelectDialog.vue'
|
|
|
|
|
defineOptions({ name: 'MoldInspectionPlanForm' })
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
@ -74,6 +104,7 @@ const ensureSubjectOptionsLoaded = async () => {
|
|
|
|
|
if (subjectOptions.value.length) return
|
|
|
|
|
const res = await DvSubjectApi.getMoldSubjectAllList()
|
|
|
|
|
const list = Array.isArray(res) ? res : res?.list
|
|
|
|
|
itemList.value = (list ?? []) as DvSubjectVO[]
|
|
|
|
|
subjectOptions.value = (list ?? []) as DvSubjectVO[]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -97,7 +128,94 @@ const parseIds = (value: any): Array<number | string> => {
|
|
|
|
|
})
|
|
|
|
|
.filter((v): v is number | string => v !== undefined)
|
|
|
|
|
}
|
|
|
|
|
const ids = ref([])
|
|
|
|
|
const itemList = ref<DvSubjectVO[]>([])
|
|
|
|
|
const selectedDeviceRows = ref<any[]>([])
|
|
|
|
|
const deviceSelectDialogRef = ref(false)
|
|
|
|
|
const mergedQueryParams = computed(() => ({ ...searchParams }))
|
|
|
|
|
const deviceColumns = [
|
|
|
|
|
{ label: '项目编码', prop: 'subjectCode', minWidth: 140 },
|
|
|
|
|
{ label: '项目名称', prop: 'subjectName', minWidth: 160 },
|
|
|
|
|
{ label: '项目类型', prop: 'subjectType', minWidth: 140 },
|
|
|
|
|
{ label: '项目内容', prop: 'subjectContent', minWidth: 140 }
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const fetchDeviceLedgerPage = async (params: Record<string, any>) => {
|
|
|
|
|
const res = await DvSubjectApi.getDvSubjectPage({
|
|
|
|
|
...params,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const list = res.list || []
|
|
|
|
|
|
|
|
|
|
// 合并已选数据(防止分页丢失)
|
|
|
|
|
const selectedMap = new Map(
|
|
|
|
|
selectedDeviceRows.value.map((item) => [item.id, item])
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...res,
|
|
|
|
|
list: list.map((item) => ({
|
|
|
|
|
...item,
|
|
|
|
|
...selectedMap.get(item.id)
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 1. 自定义表单的查询参数
|
|
|
|
|
const searchParams = reactive({
|
|
|
|
|
subjectCode: undefined,
|
|
|
|
|
subjectName: undefined,
|
|
|
|
|
})
|
|
|
|
|
const displayItemDevice = computed( () => {
|
|
|
|
|
if (!ids.value.length)return ''
|
|
|
|
|
if (!itemList.value.length) {
|
|
|
|
|
return formData.value.subjectIds ? String(formData.value.subjectIds) : ''
|
|
|
|
|
}
|
|
|
|
|
const map = new Map(itemList.value.map((item) => [item.id, item.subjectName]))
|
|
|
|
|
const names = ids.value
|
|
|
|
|
.map((id) => map.get(id))
|
|
|
|
|
.filter((name) => name)
|
|
|
|
|
return names.join(',')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const openCriticalComponentDialog = async () => {
|
|
|
|
|
searchParams.subjectCode=''
|
|
|
|
|
searchParams.subjectName=''
|
|
|
|
|
const rows = selectedDeviceRows.value.length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//deviceSelectDialogRef.value?.open(rows)
|
|
|
|
|
let initIds= formData.value.subjectIds!=undefined?formData.value.subjectIds.toString().split(","):[]
|
|
|
|
|
deviceSelectDialogRef.value?.open([], {
|
|
|
|
|
defaultSelectedKeys: initIds
|
|
|
|
|
})
|
|
|
|
|
ids.value=initIds.map((id) => Number(id))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleDeviceSelectConfirm = (payload: { ids: (number | string)[]; rows: any[] }) => {
|
|
|
|
|
formData.value.subjectIds = payload.rows
|
|
|
|
|
.map((item) => {
|
|
|
|
|
const id = Number(item.id)
|
|
|
|
|
if (!Number.isFinite(id)) return undefined
|
|
|
|
|
return {
|
|
|
|
|
id,
|
|
|
|
|
name: item.subjectName || item.name || item.code || `设备ID:${id}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter((item): item is { id: number; name: string } => Boolean(item))
|
|
|
|
|
selectedDeviceRows.value = payload.rows
|
|
|
|
|
formData.value.subjectIds = payload.ids.join(',')
|
|
|
|
|
ids.value = payload.ids.map((id) => Number(id))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
|
|
// 触发弹窗内部重新加载数据
|
|
|
|
|
deviceSelectDialogRef.value?.reload?.()
|
|
|
|
|
}
|
|
|
|
|
const searchFormRef = ref()
|
|
|
|
|
const resetSearch = () => {
|
|
|
|
|
searchFormRef.value?.resetFields()
|
|
|
|
|
handleSearch()
|
|
|
|
|
}
|
|
|
|
|
const initFormData = () => ({
|
|
|
|
|
id: undefined as PlanMaintenanceVO['id'],
|
|
|
|
|
planName: '' as string,
|
|
|
|
|
@ -141,6 +259,9 @@ const open = async (type: 'create' | 'update', row?: Partial<PlanMaintenanceVO>)
|
|
|
|
|
description: (row.description as any) ?? '',
|
|
|
|
|
subjectIds: parseIds((row as any).subjectIds ?? (row as any).subjectIdS)
|
|
|
|
|
}
|
|
|
|
|
ids.value=parseIds((row as any).subjectIds ?? (row as any).subjectIdS)
|
|
|
|
|
}else{
|
|
|
|
|
ids.value=[]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|