|
@@ -70,33 +70,47 @@
|
|
|
</el-row>
|
|
|
|
|
|
<!-- 暂存关联列表 -->
|
|
|
- <div class="temp-list card">
|
|
|
- <h3>设备责任人调整记录</h3>
|
|
|
- <el-table :data="tempRelations" style="width: 100%">
|
|
|
- <el-table-column prop="deviceNames" label="设备" width="200" />
|
|
|
- <el-table-column prop="userNames" label="关联责任人" />
|
|
|
- <el-table-column label="操作" width="120">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-button
|
|
|
- type="danger"
|
|
|
- size="small"
|
|
|
- @click="removeTempRelation(row.deviceIds)"
|
|
|
- >
|
|
|
- 删除
|
|
|
- </el-button>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
-
|
|
|
- <div class="submit-area">
|
|
|
- <el-button
|
|
|
- type="primary"
|
|
|
- size="large"
|
|
|
- @click="submitRelations"
|
|
|
- :disabled="tempRelations.length === 0"
|
|
|
- >
|
|
|
- 保 存
|
|
|
- </el-button>
|
|
|
+ <div class="submit-area">
|
|
|
+ <div class="card">
|
|
|
+ <el-input
|
|
|
+ v-model="formData.reason"
|
|
|
+ placeholder="请输入调整原因"
|
|
|
+ class="reason-input"
|
|
|
+ type="textarea"
|
|
|
+ :rows="3"
|
|
|
+ @input="handleReasonInput"
|
|
|
+ :disabled="!selectedDevice || selectedUsers.length === 0"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <div class="temp-list card">
|
|
|
+ <h3>设备责任人调整记录</h3>
|
|
|
+ <el-table :data="tempRelations" style="width: 100%">
|
|
|
+ <el-table-column prop="deviceNames" label="设备" width="200" />
|
|
|
+ <el-table-column prop="userNames" label="关联责任人" />
|
|
|
+ <el-table-column prop="reason" label="调整原因" />
|
|
|
+ <el-table-column label="操作" width="120">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ size="small"
|
|
|
+ @click="removeTempRelation(row.deviceIds)"
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+
|
|
|
+ <div class="submit-area">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ size="large"
|
|
|
+ @click="submitRelations"
|
|
|
+ :disabled="tempRelations.length === 0"
|
|
|
+ >
|
|
|
+ 保 存
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -111,17 +125,11 @@ import {IotDeviceApi, IotDeviceVO} from "@/api/pms/device";
|
|
|
import {IotDevicePersonApi, IotDevicePersonVO} from "@/api/pms/iotdeviceperson";
|
|
|
import * as UserApi from "@/api/system/user";
|
|
|
import {simpleUserList, UserVO} from "@/api/system/user";
|
|
|
+import { useRouter } from 'vue-router'
|
|
|
+const router = useRouter()
|
|
|
|
|
|
defineOptions({ name: 'ConfigDevicePerson' })
|
|
|
|
|
|
-// 模拟数据
|
|
|
-const deviceList = ref([
|
|
|
- { id: 'd1', name: '数控机床', type: '生产设备' },
|
|
|
- { id: 'd2', name: '检测仪', type: '检测设备' },
|
|
|
- { id: 'd3', name: '包装机', type: '包装设备' },
|
|
|
- // 更多设备...
|
|
|
-])
|
|
|
-
|
|
|
const simpleDevices = ref<IotDeviceVO[]>([])
|
|
|
const simpleUsers = ref<UserVO[]>([])
|
|
|
|
|
@@ -137,6 +145,7 @@ const formData = ref({
|
|
|
deptId1: undefined as string | undefined,
|
|
|
deviceStatus: undefined,
|
|
|
assetProperty: undefined,
|
|
|
+ reason: '',
|
|
|
picUrl: undefined,
|
|
|
})
|
|
|
|
|
@@ -147,19 +156,6 @@ const queryParams = reactive({
|
|
|
|
|
|
const emit = defineEmits(['success', 'node-click']) // 定义 success 树点击 事件,用于操作成功后的回调
|
|
|
|
|
|
-const departmentList = ref([
|
|
|
- { id: 'dept1', name: '生产部' },
|
|
|
- { id: 'dept2', name: '质检部' },
|
|
|
- { id: 'dept3', name: '设备部' },
|
|
|
-])
|
|
|
-
|
|
|
-const userList = ref([
|
|
|
- { id: 'u1', name: '张三', position: '工程师', deptId: 'dept1' },
|
|
|
- { id: 'u2', name: '李四', position: '技术员', deptId: 'dept1' },
|
|
|
- { id: 'u3', name: '王五', position: '质检员', deptId: 'dept2' },
|
|
|
- // 更多用户...
|
|
|
-])
|
|
|
-
|
|
|
// 响应式数据
|
|
|
const selectedDevice = ref<number>(0)
|
|
|
const selectedDept = ref('')
|
|
@@ -169,22 +165,9 @@ const tempRelations = ref<Array<{
|
|
|
deviceNames: string
|
|
|
userIds: number[]
|
|
|
userNames: string
|
|
|
+ reason: string
|
|
|
}>>([])
|
|
|
|
|
|
-// 计算属性
|
|
|
-const filteredUsers = computed(() => {
|
|
|
- return userList.value.filter(user => user.deptId === selectedDept.value)
|
|
|
-})
|
|
|
-
|
|
|
-const canSave = computed(() => {
|
|
|
- return !!selectedDevice.value && selectedUsers.value.length > 0
|
|
|
-})
|
|
|
-
|
|
|
-// 方法
|
|
|
-const loadUsers = () => {
|
|
|
- selectedUsers.value = []
|
|
|
-}
|
|
|
-
|
|
|
// 添加设备选择监听
|
|
|
watch(selectedDevice, (newVal) => {
|
|
|
if (newVal) {
|
|
@@ -192,6 +175,7 @@ watch(selectedDevice, (newVal) => {
|
|
|
selectedUsers.value = []
|
|
|
// 可选:清空部门选择
|
|
|
formData.value.deptId = undefined
|
|
|
+ formData.value.reason = ''
|
|
|
simpleUsers.value = []
|
|
|
}
|
|
|
})
|
|
@@ -210,6 +194,10 @@ const handleUserSelectionChange = (value: number[]) => {
|
|
|
|
|
|
// 新增或更新关联关系
|
|
|
updateDeviceRelation(device, value)
|
|
|
+ // 自动同步原因(如果已输入)
|
|
|
+ if (formData.value.reason) {
|
|
|
+ handleReasonInput(formData.value.reason)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 修改 暂时 保存关联方法
|
|
@@ -283,6 +271,15 @@ const getUserList = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 新增输入处理方法
|
|
|
+const handleReasonInput = (value: string) => {
|
|
|
+ formData.value.reason = value
|
|
|
+ if (selectedDevice.value && selectedUsers.value.length > 0) {
|
|
|
+ const device = simpleDevices.value.find(d => d.id === selectedDevice.value)
|
|
|
+ device && updateDeviceRelation(device, selectedUsers.value)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 更新设备关联关系
|
|
|
const updateDeviceRelation = (device: IotDeviceVO, userIds: number[]) => {
|
|
|
// 获取当前选择的人员
|
|
@@ -292,7 +289,8 @@ const updateDeviceRelation = (device: IotDeviceVO, userIds: number[]) => {
|
|
|
deviceIds: [device.id],
|
|
|
deviceNames: `${device.deviceCode} (${device.deviceName})`,
|
|
|
userIds: users.map(u => u.id),
|
|
|
- userNames: users.map(u => u.nickname).join(', ')
|
|
|
+ userNames: users.map(u => u.nickname).join(', '),
|
|
|
+ reason: formData.value.reason
|
|
|
}
|
|
|
|
|
|
// 查找是否已存在该设备的关联
|
|
@@ -332,7 +330,8 @@ const submitRelations = async () => {
|
|
|
const submitData = tempRelations.value.flatMap(relation => {
|
|
|
return relation.deviceIds.map(deviceId => ({
|
|
|
deviceId,
|
|
|
- userIds: relation.userIds
|
|
|
+ userIds: relation.userIds,
|
|
|
+ reason: relation.reason
|
|
|
}))
|
|
|
})
|
|
|
await IotDevicePersonApi.saveDevicePersonRelation(submitData)
|
|
@@ -340,6 +339,7 @@ const submitRelations = async () => {
|
|
|
console.log('提交数据:', submitData)
|
|
|
ElMessage.success('提交成功')
|
|
|
tempRelations.value = []
|
|
|
+ router.back()
|
|
|
} catch (error) {
|
|
|
ElMessage.error('提交失败,请重试')
|
|
|
}
|