|
|
@@ -210,11 +210,21 @@
|
|
|
</el-form>
|
|
|
<el-table v-loading="bindLoading" :data="bindTableData" border row-key="equipmentId"
|
|
|
@selection-change="handleBindSelectionChange" ref="bindTableRef">
|
|
|
- <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
|
|
|
+ <el-table-column type="selection" width="55" align="center" :reserve-selection="true"
|
|
|
+ :selectable="isEquipmentSelectable" />
|
|
|
<el-table-column label="设备名称" prop="equipmentName" min-width="120" />
|
|
|
<el-table-column label="设备编号" prop="equipmentCode" min-width="120" />
|
|
|
<el-table-column label="设备类型" prop="equipmentTypeName" min-width="100" />
|
|
|
<el-table-column label="安装位置" prop="installLocation" min-width="120" />
|
|
|
+ <el-table-column label="关联状态" min-width="180">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <span v-if="selectedEquipmentIds.includes(String(row.equipmentId))" style="color: #67c23a;">当前选择</span>
|
|
|
+ <span v-else-if="boundEquipmentMap[String(row.equipmentId)]" style="color: #e6a23c;">
|
|
|
+ 已关联:{{ boundEquipmentMap[String(row.equipmentId)] }}
|
|
|
+ </span>
|
|
|
+ <span v-else>未关联</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
</el-table>
|
|
|
<el-pagination v-model:current-page="bindPageNum" v-model:page-size="bindPageSize" :total="bindTotal"
|
|
|
:page-sizes="[10, 20, 50]" layout="total, sizes, prev, pager, next, jumper"
|
|
|
@@ -238,7 +248,8 @@ import {
|
|
|
deleteWaterlogging,
|
|
|
getEquipmentPage,
|
|
|
getEquipmentById,
|
|
|
- bindWaterloggingEquipment
|
|
|
+ bindWaterloggingEquipment,
|
|
|
+ getDrainageBoundEquipmentIds
|
|
|
} from '@/api/drainage'
|
|
|
|
|
|
// 地图标记创建(用Label+img代替Marker)
|
|
|
@@ -722,6 +733,7 @@ const bindQueryParams = ref({ equipmentName: '', equipmentTypeId: 'drainage' })
|
|
|
const selectedEquipmentIds = ref([])
|
|
|
const currentPartitionId = ref('')
|
|
|
const bindTableRef = ref(null)
|
|
|
+const boundEquipmentMap = ref({})
|
|
|
|
|
|
function handleBind(row) {
|
|
|
currentPartitionId.value = row.id
|
|
|
@@ -729,7 +741,7 @@ function handleBind(row) {
|
|
|
bindPageNum.value = 1
|
|
|
bindQueryParams.value.equipmentName = ''
|
|
|
if (row.equipmentId) {
|
|
|
- selectedEquipmentIds.value = row.equipmentId.split(',')
|
|
|
+ selectedEquipmentIds.value = row.equipmentId.split(',').map(id => id.trim()).filter(Boolean)
|
|
|
} else {
|
|
|
selectedEquipmentIds.value = []
|
|
|
}
|
|
|
@@ -746,10 +758,25 @@ function handleBindQuery() {
|
|
|
async function loadBindData() {
|
|
|
bindLoading.value = true
|
|
|
try {
|
|
|
- const res = await getEquipmentPage(bindPageNum.value, bindPageSize.value, bindQueryParams.value)
|
|
|
+ const [equipmentResult, boundResult] = await Promise.allSettled([
|
|
|
+ getEquipmentPage(bindPageNum.value, bindPageSize.value, bindQueryParams.value),
|
|
|
+ getDrainageBoundEquipmentIds('waterlogging', currentPartitionId.value)
|
|
|
+ ])
|
|
|
+ if (equipmentResult.status === 'rejected') {
|
|
|
+ throw equipmentResult.reason
|
|
|
+ }
|
|
|
+ const res = equipmentResult.value
|
|
|
const pageData = res.code !== undefined ? res.data : res
|
|
|
bindTableData.value = pageData.records || []
|
|
|
bindTotal.value = pageData.total || 0
|
|
|
+ if (boundResult.status === 'fulfilled') {
|
|
|
+ const boundRes = boundResult.value
|
|
|
+ const boundData = boundRes.code !== undefined ? boundRes.data : boundRes
|
|
|
+ boundEquipmentMap.value = boundData && typeof boundData === 'object' ? boundData : {}
|
|
|
+ } else {
|
|
|
+ boundEquipmentMap.value = {}
|
|
|
+ console.warn('加载设备关联状态失败,设备列表仍正常显示', boundResult.reason)
|
|
|
+ }
|
|
|
await nextTick()
|
|
|
if (selectedEquipmentIds.value.length > 0 && bindTableRef.value) {
|
|
|
bindTableData.value.forEach(row => {
|
|
|
@@ -759,6 +786,8 @@ async function loadBindData() {
|
|
|
})
|
|
|
}
|
|
|
} catch (e) {
|
|
|
+ bindTableData.value = []
|
|
|
+ bindTotal.value = 0
|
|
|
console.error('加载设备列表失败', e)
|
|
|
} finally {
|
|
|
bindLoading.value = false
|
|
|
@@ -766,13 +795,19 @@ async function loadBindData() {
|
|
|
}
|
|
|
|
|
|
function handleBindSelectionChange(selection) {
|
|
|
- selectedEquipmentIds.value = selection.map(item => item.equipmentId)
|
|
|
+ selectedEquipmentIds.value = selection.map(item => String(item.equipmentId))
|
|
|
+}
|
|
|
+
|
|
|
+function isEquipmentSelectable(row) {
|
|
|
+ const id = String(row.equipmentId)
|
|
|
+ return !boundEquipmentMap.value[id] || selectedEquipmentIds.value.includes(id)
|
|
|
}
|
|
|
|
|
|
function closeBindDialog() {
|
|
|
bindDialogVisible.value = false
|
|
|
bindTableData.value = []
|
|
|
selectedEquipmentIds.value = []
|
|
|
+ boundEquipmentMap.value = {}
|
|
|
}
|
|
|
|
|
|
async function submitBind() {
|