|
@@ -16,6 +16,7 @@
|
|
filterable
|
|
filterable
|
|
:placeholder="t('configPerson.deviceListHolder')"
|
|
:placeholder="t('configPerson.deviceListHolder')"
|
|
@node-click="handleDeptDeviceTreeNodeClick"
|
|
@node-click="handleDeptDeviceTreeNodeClick"
|
|
|
|
+ @clear="handleClearDeptForDevice"
|
|
/>
|
|
/>
|
|
</div>
|
|
</div>
|
|
<!-- 设备搜索框 -->
|
|
<!-- 设备搜索框 -->
|
|
@@ -23,6 +24,7 @@
|
|
<el-input
|
|
<el-input
|
|
v-model="deviceFilterText"
|
|
v-model="deviceFilterText"
|
|
:placeholder="t('devicePerson.filterDevicePlaceholder')"
|
|
:placeholder="t('devicePerson.filterDevicePlaceholder')"
|
|
|
|
+ :disabled="!devicesLoaded"
|
|
clearable
|
|
clearable
|
|
prefix-icon="Search"
|
|
prefix-icon="Search"
|
|
/>
|
|
/>
|
|
@@ -59,6 +61,7 @@
|
|
filterable
|
|
filterable
|
|
:placeholder="t('configPerson.rpHolder')"
|
|
:placeholder="t('configPerson.rpHolder')"
|
|
@node-click="handleDeptUserTreeNodeClick"
|
|
@node-click="handleDeptUserTreeNodeClick"
|
|
|
|
+ @clear="handleClearDeptForPerson"
|
|
/>
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@@ -67,6 +70,7 @@
|
|
<el-input
|
|
<el-input
|
|
v-model="userFilterText"
|
|
v-model="userFilterText"
|
|
:placeholder="t('devicePerson.filterUserPlaceholder')"
|
|
:placeholder="t('devicePerson.filterUserPlaceholder')"
|
|
|
|
+ :disabled="!personLoaded"
|
|
clearable
|
|
clearable
|
|
prefix-icon="Search"
|
|
prefix-icon="Search"
|
|
/>
|
|
/>
|
|
@@ -181,11 +185,9 @@ const queryParams = reactive({
|
|
const emit = defineEmits(['success', 'node-click']) // 定义 success 树点击 事件,用于操作成功后的回调
|
|
const emit = defineEmits(['success', 'node-click']) // 定义 success 树点击 事件,用于操作成功后的回调
|
|
|
|
|
|
// 响应式数据
|
|
// 响应式数据
|
|
-const selectedDevice = ref<number>(0)
|
|
|
|
const selectedDevices = ref<number[]>([])
|
|
const selectedDevices = ref<number[]>([])
|
|
// 责任人过滤文本
|
|
// 责任人过滤文本
|
|
const userFilterText = ref('')
|
|
const userFilterText = ref('')
|
|
-const selectedDept = ref('')
|
|
|
|
const selectedUsers = ref<number[]>([])
|
|
const selectedUsers = ref<number[]>([])
|
|
const tempRelations = ref<Array<{
|
|
const tempRelations = ref<Array<{
|
|
deviceIds: number[]
|
|
deviceIds: number[]
|
|
@@ -225,6 +227,15 @@ watch(selectedDevices, (newVal, oldVal) => {
|
|
})
|
|
})
|
|
|
|
|
|
const handleUserSelectionChange = (userIds: number[]) => {
|
|
const handleUserSelectionChange = (userIds: number[]) => {
|
|
|
|
+ // 处理清空责任人的情况
|
|
|
|
+ if (userIds.length === 0) {
|
|
|
|
+ tempRelations.value.forEach(relation => {
|
|
|
|
+ relation.userIds = []
|
|
|
|
+ relation.userNames = ''
|
|
|
|
+ })
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
if (selectedDevices.value.length === 0) {
|
|
if (selectedDevices.value.length === 0) {
|
|
ElMessage.warning('请先选择设备')
|
|
ElMessage.warning('请先选择设备')
|
|
selectedUsers.value = []
|
|
selectedUsers.value = []
|
|
@@ -258,11 +269,18 @@ const isSaveDisabled = computed(() => {
|
|
/** 获得 部门下的设备 列表 */
|
|
/** 获得 部门下的设备 列表 */
|
|
const getDeviceList = async () => {
|
|
const getDeviceList = async () => {
|
|
try {
|
|
try {
|
|
|
|
+ // 查询到数据后才能进行搜索 筛选
|
|
|
|
+ devicesLoaded.value = false
|
|
|
|
+
|
|
const params = { deptId: formData.value.deptId1 }
|
|
const params = { deptId: formData.value.deptId1 }
|
|
const data = await IotDeviceApi.simpleDevices(params)
|
|
const data = await IotDeviceApi.simpleDevices(params)
|
|
simpleDevices.value = data || []
|
|
simpleDevices.value = data || []
|
|
|
|
+
|
|
|
|
+ devicesLoaded.value = true
|
|
} catch (error) {
|
|
} catch (error) {
|
|
simpleDevices.value = []
|
|
simpleDevices.value = []
|
|
|
|
+ // 即使失败也启用搜索框(避免卡在禁用状态)
|
|
|
|
+ devicesLoaded.value = true
|
|
console.error('获取设备列表失败:', error)
|
|
console.error('获取设备列表失败:', error)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -277,18 +295,31 @@ const handleDeptUserTreeNodeClick = async (row: { [key: string]: any }) => {
|
|
/** 获得 部门下的人员 列表 */
|
|
/** 获得 部门下的人员 列表 */
|
|
const getUserList = async () => {
|
|
const getUserList = async () => {
|
|
try {
|
|
try {
|
|
|
|
+ // 开始加载时禁用搜索框
|
|
|
|
+ personLoaded.value = false
|
|
|
|
+
|
|
const params = {
|
|
const params = {
|
|
deptId: formData.value.deptId,
|
|
deptId: formData.value.deptId,
|
|
pageNo: 1,
|
|
pageNo: 1,
|
|
pageSize: 10 }
|
|
pageSize: 10 }
|
|
const data = await UserApi.simpleUserList(params)
|
|
const data = await UserApi.simpleUserList(params)
|
|
simpleUsers.value = data || []
|
|
simpleUsers.value = data || []
|
|
|
|
+
|
|
|
|
+ personLoaded.value = true
|
|
} catch (error) {
|
|
} catch (error) {
|
|
simpleUsers.value = []
|
|
simpleUsers.value = []
|
|
|
|
+ // 即使失败也启用搜索框(避免卡在禁用状态)
|
|
|
|
+ personLoaded.value = true
|
|
console.error('获取人员列表失败:', error)
|
|
console.error('获取人员列表失败:', error)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 设备加载状态标记 只有加载完设备才能通过文本框筛选
|
|
|
|
+const devicesLoaded = ref(false)
|
|
|
|
+
|
|
|
|
+// 人员加载状态标记 只有加载完人员才能通过文本框筛选
|
|
|
|
+const personLoaded = ref(false)
|
|
|
|
+
|
|
// 设备过滤文本
|
|
// 设备过滤文本
|
|
const deviceFilterText = ref('')
|
|
const deviceFilterText = ref('')
|
|
|
|
|
|
@@ -344,6 +375,28 @@ const updateDeviceRelation = (device: IotDeviceVO, userIds: number[]) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 处理 设备关联 部门选择清空事件
|
|
|
|
+const handleClearDeptForDevice = () => {
|
|
|
|
+ simpleDevices.value = []
|
|
|
|
+ selectedDevices.value = []
|
|
|
|
+ devicesLoaded.value = false // 清空时禁用搜索框
|
|
|
|
+ deviceFilterText.value = ''
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 处理 人员关联 部门选择清空事件
|
|
|
|
+const handleClearDeptForPerson = () => {
|
|
|
|
+ simpleUsers.value = []
|
|
|
|
+ selectedUsers.value = []
|
|
|
|
+ personLoaded.value = false // 清空时禁用搜索框
|
|
|
|
+ userFilterText.value = ''
|
|
|
|
+
|
|
|
|
+ // 清空所有暂存记录中的责任人
|
|
|
|
+ tempRelations.value.forEach(relation => {
|
|
|
|
+ relation.userIds = []
|
|
|
|
+ relation.userNames = ''
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
// 过滤后的人员列表计算属性
|
|
// 过滤后的人员列表计算属性
|
|
const filteredUsers = computed(() => {
|
|
const filteredUsers = computed(() => {
|
|
const searchText = userFilterText.value.toLowerCase().trim()
|
|
const searchText = userFilterText.value.toLowerCase().trim()
|
|
@@ -354,12 +407,6 @@ const filteredUsers = computed(() => {
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
|
|
-const clearSelection = () => {
|
|
|
|
- selectedDevice.value = ''
|
|
|
|
- selectedUsers.value = []
|
|
|
|
- selectedDept.value = ''
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
const removeTempRelation = (deviceIds: number[]) => {
|
|
const removeTempRelation = (deviceIds: number[]) => {
|
|
tempRelations.value = tempRelations.value.filter(
|
|
tempRelations.value = tempRelations.value.filter(
|
|
r => r.deviceIds.join() !== deviceIds.join()
|
|
r => r.deviceIds.join() !== deviceIds.join()
|
|
@@ -372,14 +419,25 @@ const removeTempRelation = (deviceIds: number[]) => {
|
|
|
|
|
|
const submitRelations = async () => {
|
|
const submitRelations = async () => {
|
|
try {
|
|
try {
|
|
|
|
+ // 校验必须选择设备
|
|
|
|
+ if (selectedDevices.value.length === 0) {
|
|
|
|
+ ElMessage.error(t('iotMaintain.deviceHolder')) // 请选择设备
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ // 校验必须选择责任人
|
|
|
|
+ if (selectedUsers.value.length === 0) {
|
|
|
|
+ ElMessage.error(t('configPerson.selectPersons')) // 请选择责任人
|
|
|
|
+ return
|
|
|
|
+ }
|
|
// 校验所有调整原因
|
|
// 校验所有调整原因
|
|
const hasEmptyReason = tempRelations.value.some(
|
|
const hasEmptyReason = tempRelations.value.some(
|
|
item => !item.reason?.trim()
|
|
item => !item.reason?.trim()
|
|
)
|
|
)
|
|
if (hasEmptyReason) {
|
|
if (hasEmptyReason) {
|
|
- ElMessage.error('请填写调整原因')
|
|
|
|
|
|
+ ElMessage.error(t('configPerson.rfaHolder'))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ // 校验 设备 责任人 必须都选择 不能为空
|
|
// 转换为后端需要的格式
|
|
// 转换为后端需要的格式
|
|
const submitData = tempRelations.value.flatMap(relation => {
|
|
const submitData = tempRelations.value.flatMap(relation => {
|
|
return relation.deviceIds.map(deviceId => ({
|
|
return relation.deviceIds.map(deviceId => ({
|