|
@@ -74,13 +74,7 @@
|
|
|
}}
|
|
}}
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
- <!-- <el-table-column label="设备详情" align="center" prop="deviceDetails">
|
|
|
|
|
- <template #default="scope">
|
|
|
|
|
- <el-button link type="primary" @click="handleDeviceDetail(scope.row)">
|
|
|
|
|
- 查看
|
|
|
|
|
- </el-button>
|
|
|
|
|
- </template>
|
|
|
|
|
- </el-table-column> -->
|
|
|
|
|
|
|
+
|
|
|
<el-table-column :label="t('devicePerson.operation')" align="center" min-width="120px">
|
|
<el-table-column :label="t('devicePerson.operation')" align="center" min-width="120px">
|
|
|
<template #default="scope">
|
|
<template #default="scope">
|
|
|
<el-button link type="primary" @click="handleEdit(scope.row)"> 编辑 </el-button>
|
|
<el-button link type="primary" @click="handleEdit(scope.row)"> 编辑 </el-button>
|
|
@@ -171,7 +165,7 @@
|
|
|
v-for="device in selectedDevices"
|
|
v-for="device in selectedDevices"
|
|
|
:key="device.id"
|
|
:key="device.id"
|
|
|
:label="device.label"
|
|
:label="device.label"
|
|
|
- :value="isEdit ? device.deviceId : device.id"
|
|
|
|
|
|
|
+ :value="device.id"
|
|
|
/>
|
|
/>
|
|
|
</el-select>
|
|
</el-select>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
@@ -280,7 +274,7 @@ const getDeviceList = async (deptId) => {
|
|
|
try {
|
|
try {
|
|
|
const res = await IotDeviceApi.getIotDeviceSetOptions(deptId)
|
|
const res = await IotDeviceApi.getIotDeviceSetOptions(deptId)
|
|
|
deviceOptions.value = res.map((item) => ({
|
|
deviceOptions.value = res.map((item) => ({
|
|
|
- key: item.id,
|
|
|
|
|
|
|
+ key: item.id, // 始终使用id作为key
|
|
|
label: `${item.deviceName} (${item.deviceCode})`,
|
|
label: `${item.deviceName} (${item.deviceCode})`,
|
|
|
...item
|
|
...item
|
|
|
}))
|
|
}))
|
|
@@ -295,10 +289,6 @@ const selectedDeviceIds = ref([])
|
|
|
const selectedDevices = ref([])
|
|
const selectedDevices = ref([])
|
|
|
const mainDeviceId = ref('')
|
|
const mainDeviceId = ref('')
|
|
|
|
|
|
|
|
-const rightDeviceChange = (val) => {
|
|
|
|
|
- selectedDeviceIds.value = val
|
|
|
|
|
- updateSelectedDevices()
|
|
|
|
|
-}
|
|
|
|
|
/** 查询列表 */
|
|
/** 查询列表 */
|
|
|
const getList = async () => {
|
|
const getList = async () => {
|
|
|
loading.value = true
|
|
loading.value = true
|
|
@@ -336,61 +326,64 @@ const filterDeviceMethod = (query, item) => {
|
|
|
|
|
|
|
|
// 更新已选择的设备列表
|
|
// 更新已选择的设备列表
|
|
|
const updateSelectedDevices = () => {
|
|
const updateSelectedDevices = () => {
|
|
|
|
|
+ // 根据 selectedDeviceIds 从 deviceOptions 中找到对应的设备
|
|
|
selectedDevices.value = deviceOptions.value.filter((item) =>
|
|
selectedDevices.value = deviceOptions.value.filter((item) =>
|
|
|
- selectedDeviceIds.value.includes(item.id)
|
|
|
|
|
|
|
+ selectedDeviceIds.value.includes(item.key)
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
console.log('selectedDevices>>>>>>>>>>>>>>>>', selectedDevices.value)
|
|
console.log('selectedDevices>>>>>>>>>>>>>>>>', selectedDevices.value)
|
|
|
|
|
|
|
|
- if (isEdit.value) {
|
|
|
|
|
- formData.value.details = selectedDevices.value.map((item) => ({
|
|
|
|
|
- deviceId: item.deviceId,
|
|
|
|
|
- deviceName: item.deviceName,
|
|
|
|
|
- deviceCode: item.deviceCode,
|
|
|
|
|
- deptId: item.deptId,
|
|
|
|
|
- ifMaster: item.id === mainDeviceId.value ? true : false
|
|
|
|
|
- }))
|
|
|
|
|
- } else {
|
|
|
|
|
- formData.value.details = selectedDevices.value.map((item) => ({
|
|
|
|
|
- deviceId: item.id,
|
|
|
|
|
- deviceName: item.deviceName,
|
|
|
|
|
- deviceCode: item.deviceCode,
|
|
|
|
|
- deptId: item.deptId,
|
|
|
|
|
- ifMaster: item.id === mainDeviceId.value ? true : false
|
|
|
|
|
- }))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 构建 details 数据
|
|
|
|
|
+ formData.value.details = selectedDevices.value.map((item) => ({
|
|
|
|
|
+ deviceId: item.id,
|
|
|
|
|
+ deviceName: item.deviceName,
|
|
|
|
|
+ deviceCode: item.deviceCode,
|
|
|
|
|
+ deptId: item.deptId,
|
|
|
|
|
+ ifMaster: item.id === mainDeviceId.value ? true : false
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
// 如果主设备不在当前选择中,则清空主设备
|
|
// 如果主设备不在当前选择中,则清空主设备
|
|
|
- if (mainDeviceId.value && !selectedDeviceIds.value.includes(mainDeviceId.value)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ mainDeviceId.value &&
|
|
|
|
|
+ !selectedDevices.value.some((device) => device.id === mainDeviceId.value)
|
|
|
|
|
+ ) {
|
|
|
mainDeviceId.value = ''
|
|
mainDeviceId.value = ''
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const rightDeviceChange = (val) => {
|
|
|
|
|
+ selectedDeviceIds.value = val
|
|
|
|
|
+ updateSelectedDevices()
|
|
|
|
|
+
|
|
|
|
|
+ // 手动触发验证
|
|
|
|
|
+ if (formRef.value) {
|
|
|
|
|
+ formRef.value.validateField('devices')
|
|
|
|
|
+ if (val.length > 0) {
|
|
|
|
|
+ formRef.value.validateField('mainDevice')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 设置主设备
|
|
// 设置主设备
|
|
|
const setMainDevice = (val) => {
|
|
const setMainDevice = (val) => {
|
|
|
mainDeviceId.value = val
|
|
mainDeviceId.value = val
|
|
|
// 更新 details 中的 ifMaster 字段
|
|
// 更新 details 中的 ifMaster 字段
|
|
|
console.log('selectedDevices.value>>>>>>>>>>>>>>>>', selectedDevices.value)
|
|
console.log('selectedDevices.value>>>>>>>>>>>>>>>>', selectedDevices.value)
|
|
|
|
|
|
|
|
- if (isEdit.value) {
|
|
|
|
|
- formData.value.details = selectedDevices.value.map((item) => ({
|
|
|
|
|
- deviceId: item.deviceId,
|
|
|
|
|
- deviceName: item.deviceName,
|
|
|
|
|
- deviceCode: item.deviceCode,
|
|
|
|
|
- deptId: item.deptId,
|
|
|
|
|
- ifMaster: item.deviceId === mainDeviceId.value ? true : false
|
|
|
|
|
- }))
|
|
|
|
|
- } else {
|
|
|
|
|
- formData.value.details = selectedDevices.value.map((item) => ({
|
|
|
|
|
- deviceId: item.id,
|
|
|
|
|
- deviceName: item.deviceName,
|
|
|
|
|
- deviceCode: item.deviceCode,
|
|
|
|
|
- deptId: item.deptId,
|
|
|
|
|
- ifMaster: item.id === mainDeviceId.value ? true : false
|
|
|
|
|
- }))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ formData.value.details = selectedDevices.value.map((item) => ({
|
|
|
|
|
+ deviceId: item.id,
|
|
|
|
|
+ deviceName: item.deviceName,
|
|
|
|
|
+ deviceCode: item.deviceCode,
|
|
|
|
|
+ deptId: item.deptId,
|
|
|
|
|
+ ifMaster: item.id === mainDeviceId.value ? true : false
|
|
|
|
|
+ }))
|
|
|
|
|
|
|
|
console.log('formData.value.details>>>>>>>>>>>>>>>>', formData.value.details)
|
|
console.log('formData.value.details>>>>>>>>>>>>>>>>', formData.value.details)
|
|
|
|
|
+
|
|
|
|
|
+ // 手动触发验证
|
|
|
|
|
+ if (formRef.value) {
|
|
|
|
|
+ formRef.value.validateField('mainDevice')
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 显示新增对话框
|
|
// 显示新增对话框
|
|
@@ -404,27 +397,33 @@ const handleAdd = () => {
|
|
|
// 显示编辑对话框
|
|
// 显示编辑对话框
|
|
|
const handleEdit = (row) => {
|
|
const handleEdit = (row) => {
|
|
|
isEdit.value = true
|
|
isEdit.value = true
|
|
|
-
|
|
|
|
|
dialogTitle.value = '编辑成套设备'
|
|
dialogTitle.value = '编辑成套设备'
|
|
|
|
|
|
|
|
formData.value = {
|
|
formData.value = {
|
|
|
...row
|
|
...row
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getDeviceList(row.deptId)
|
|
|
|
|
|
|
+ // 先清空之前的选项
|
|
|
|
|
+ selectedDeviceIds.value = []
|
|
|
|
|
+ selectedDevices.value = []
|
|
|
|
|
+ deviceOptions.value = []
|
|
|
|
|
|
|
|
- selectedDeviceIds.value = row.details.map((item) => item.deviceId)
|
|
|
|
|
- mainDeviceId.value = row.details.find((item) => item.ifMaster)?.deviceId || ''
|
|
|
|
|
- selectedDevices.value = row.details.map((item) => ({
|
|
|
|
|
- id: item.deviceId,
|
|
|
|
|
- deviceId: item.deviceId,
|
|
|
|
|
- deviceName: item.deviceName,
|
|
|
|
|
- deviceCode: item.deviceCode,
|
|
|
|
|
- deptId: item.deptId,
|
|
|
|
|
- ifMaster: item.ifMaster,
|
|
|
|
|
- label: item.deviceName + ' (' + item.deviceCode + ')',
|
|
|
|
|
- ...item
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ // 获取设备列表后再设置已选择的设备
|
|
|
|
|
+ getDeviceList(row.deptId).then(() => {
|
|
|
|
|
+ // 设置已选择的设备IDs(使用deviceOptions中的key值)
|
|
|
|
|
+ selectedDeviceIds.value = row.details.map((item) => {
|
|
|
|
|
+ // 在编辑模式下,使用deviceOptions中对应项的key作为标识
|
|
|
|
|
+ const option = deviceOptions.value.find((opt) => opt.deviceId === item.deviceId)
|
|
|
|
|
+ return option ? option.key : item.deviceId
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ mainDeviceId.value = row.details.find((item) => item.ifMaster)?.deviceId || ''
|
|
|
|
|
+
|
|
|
|
|
+ // 更新selectedDevices数组
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ updateSelectedDevices()
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
dialogVisible.value = true
|
|
dialogVisible.value = true
|
|
|
}
|
|
}
|
|
@@ -475,19 +474,6 @@ const submit = async () => {
|
|
|
|
|
|
|
|
await formRef.value.validate(async (valid) => {
|
|
await formRef.value.validate(async (valid) => {
|
|
|
if (!valid) return
|
|
if (!valid) return
|
|
|
-
|
|
|
|
|
- // 检查是否选择了设备
|
|
|
|
|
- // if (selectedDeviceIds.value.length === 0) {
|
|
|
|
|
- // ElMessage.warning('请至少选择一个设备')
|
|
|
|
|
- // return
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // 检查是否设置了主设备
|
|
|
|
|
- // if (!mainDeviceId.value) {
|
|
|
|
|
- // ElMessage.warning('请选择主设备')
|
|
|
|
|
- // return
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
try {
|
|
try {
|
|
|
const data = {
|
|
const data = {
|
|
|
...formData.value
|
|
...formData.value
|