diff --git a/src/api/deviceuser/index.ts b/src/api/deviceuser/index.ts index abf3d0f3b..d16263dab 100644 --- a/src/api/deviceuser/index.ts +++ b/src/api/deviceuser/index.ts @@ -11,7 +11,7 @@ export interface DeviceuserVO { updateby: string // 更新人 username: string // 用户姓名 devicetype: string // 设备类型 - familyid: string // 家庭组号 + familyid: number // 家庭组号 } // 设备人员关联 API diff --git a/src/views/person/devicebind.vue b/src/views/person/devicebind.vue index 1619f1653..8ff47e04b 100644 --- a/src/views/person/devicebind.vue +++ b/src/views/person/devicebind.vue @@ -231,12 +231,14 @@ const list = ref([]) const boundList = ref([]) const personId = ref() const personName = ref() -const familyId = ref() +const familyId = ref() const queryParams = reactive({ pageNo: 1, pageSize: 10, orgid: undefined, + devicecode: undefined as string | undefined, + devicetype: undefined as string | undefined }) const queryFormRef = ref() @@ -342,19 +344,43 @@ const getDeviceStatusType = (status: number) => { } /** 绑定设备 */ -const handleBind = async (row: DeviceVO) => { +const handleBind = async (row: DeviceVO & { familyid?: number }) => { try { if (!personId.value) { message.error('人员ID不能为空') return } - // 检查是否已经绑定 - const bindData = await DeviceuserApi.getDeviceuserByDeviceId(row.devicecode) - if (bindData && bindData.some((item: DeviceuserVO) => item.userid === personId.value)) { - message.error('该设备已经绑定过此用户') + + // 检查家庭组号匹配情况 + if (familyId.value && row.familyid && familyId.value !== row.familyid) { + message.error('该设备属于其他家庭组,无法绑定') return } + // 检查主页面传递的家庭组号为空,但设备有家庭组号的情况 + if (!familyId.value && row.familyid) { + message.error('当前人员未分配家庭组,无法绑定已有家庭组的设备') + return + } + + // 检查设备是否已被绑定 + const bindData = await DeviceuserApi.getDeviceuserByDeviceId(row.devicecode) + if (bindData && bindData.length > 0) { + // 检查是否已经被当前用户绑定 + const isBoundByCurrentUser = bindData.some(item => item.userid === personId.value) + if (isBoundByCurrentUser) { + message.error('该设备已经绑定过此用户') + return + } + + // 检查是否被同一家庭组的其他用户绑定 + const isBoundBySameFamily = bindData.some(item => item.familyid === familyId.value) + if (!isBoundBySameFamily) { + message.error('该设备已被其他家庭组的用户绑定') + return + } + } + const datetime = dayjs().format('YYYY-MM-DD HH:mm:ss') const data: DeviceuserVO = { id: 0, // 新增时后端会自动生成 @@ -362,7 +388,7 @@ const handleBind = async (row: DeviceVO) => { devicetype: row.devicetype, userid: personId.value, username: personName.value || '', - familyid: familyId.value || '', + familyid: familyId.value || 0, createtime: datetime, updatetime: datetime, createby: userProfile.value.nickname, @@ -406,7 +432,7 @@ const handleUnbind = async (row: DeviceVO) => { const open = (id: number, name: string, familyid: string) => { personId.value = id personName.value = name - familyId.value = familyid + familyId.value = parseInt(familyid) dialogVisible.value = true getList() getBoundList()