diff --git a/src/views/system/device/device_detail.vue b/src/views/system/device/device_detail.vue
index 2ad7f0c..34f27c8 100644
--- a/src/views/system/device/device_detail.vue
+++ b/src/views/system/device/device_detail.vue
@@ -44,10 +44,9 @@
电门:
-
- {{ deviceInfo.quality === '1' ? '开' : '关' }}
+
+ {{ deviceInfo.quality === 1 ? '开' : '关' }}
-
锁信号:
diff --git a/src/views/system/device/index.vue b/src/views/system/device/index.vue
index 01cc990..65786c4 100644
--- a/src/views/system/device/index.vue
+++ b/src/views/system/device/index.vue
@@ -357,17 +357,17 @@
-
-
@@ -375,17 +375,17 @@
-
-
@@ -393,16 +393,16 @@
-
-
@@ -414,17 +414,17 @@
-
-
@@ -840,100 +840,102 @@ export default {
}
},
/** 当选择代理商时调用 */
-handleDeptChange(val) {
- if (!this.isUpdating) {
- if (val) {
- this.isUpdating = true;
- selectAreaListByDeptId(val).then((response) => {
- // 更新运营区选项
- this.areaOptions = response.data.areaList || [];
- this.modelOptions = response.data.modelList || [];
-
- // 清空现有值
- this.form.areaId = null;
- this.form.modelId = null;
-
- // 只有在有选项时才设置默认值
- if (this.areaOptions.length > 0) {
- this.form.areaId = this.areaOptions[0].areaId;
- }
- if (this.modelOptions.length > 0) {
- this.form.modelId = this.modelOptions[0].modelId;
- }
+ handleDeptChange(val) {
+ if (!this.isUpdating) {
+ if (val) {
+ this.isUpdating = true;
+ selectAreaListByDeptId(val).then((response) => {
+ // 更新运营区选项
+ this.areaOptions = response.data.areaList || [];
+ this.modelOptions = response.data.modelList || [];
- // 如果没有选项,显示提示信息
- if (this.areaOptions.length === 0) {
- this.$message.warning('该代理商暂无运营区');
- }
- if (this.modelOptions.length === 0) {
- this.$message.warning('该代理商暂无可用车型');
- }
- }).finally(() => {
- this.isUpdating = false;
- });
- } else {
- // 当代理商为空时,加载所有运营区
- this.isUpdating = true;
- listArea(this.queryParams2).then((response) => {
- this.areaOptions = response.rows || [];
- this.form.areaId = null;
- this.form.modelId = null;
- this.modelOptions = [];
- }).finally(() => {
- this.isUpdating = false;
- });
- }
- }
-},
-
-/** 当选择运营区时调用 */
-handleAreaChange(val) {
- if (!this.isUpdating) {
- if (val) {
- this.isUpdating = true;
- selectDeptByAreaId(val).then((response) => {
- // 只有在代理商为空时,才设置代理商
- if (!this.form.deptId && response.data.sysDept) {
- this.form.deptId = response.data.sysDept.deptId;
-
- // 获取该代理商下的车型列表
- selectAreaListByDeptId(this.form.deptId).then((deptResponse) => {
- this.modelOptions = deptResponse.data.modelList || [];
- if (this.modelOptions.length > 0) {
- this.form.modelId = this.modelOptions[0].modelId;
- } else {
- this.form.modelId = null;
- this.$message.warning('该代理商暂无可用车型');
+ // 如果当前选中的运营区或车型不在新的选项中,清空选择
+ if (!this.areaOptions.find(area => area.areaId === this.form.areaId)) {
+ this.form.areaId = null;
}
+ if (!this.modelOptions.find(model => model.modelId === this.form.modelId)) {
+ this.form.modelId = null;
+ }
+
+ // 如果有选项且当前未选择,则自动选择第一个
+ if (this.areaOptions.length > 0 && !this.form.areaId) {
+ this.form.areaId = this.areaOptions[0].areaId;
+ }
+ if (this.modelOptions.length > 0 && !this.form.modelId) {
+ this.form.modelId = this.modelOptions[0].modelId;
+ }
+
+ }).catch(() => {
+ this.areaOptions = [];
+ this.modelOptions = [];
+ this.form.areaId = null;
+ this.form.modelId = null;
+ }).finally(() => {
+ this.isUpdating = false;
});
} else {
- // 如果已有代理商,则使用现有的车型列表
- this.modelOptions = response.data.modelList || [];
- if (!this.form.modelId && this.modelOptions.length > 0) {
- this.form.modelId = this.modelOptions[0].modelId;
- } else if (this.modelOptions.length === 0) {
+ // 当代理商为空时,加载所有运营区
+ this.isUpdating = true;
+ listArea(this.queryParams2).then((response) => {
+ this.areaOptions = response.rows || [];
+ this.form.areaId = null;
this.form.modelId = null;
- this.$message.warning('该运营区暂无可用车型');
- }
+ this.modelOptions = [];
+ }).finally(() => {
+ this.isUpdating = false;
+ });
}
- }).finally(() => {
- this.isUpdating = false;
- });
- } else {
- // 清空车型,但保留代理商
- this.form.modelId = null;
- this.modelOptions = [];
- }
- }
-},
+ }
+ },
- /** 当选择车型时调用 */
- handleModelChange(val) {
- // 移除车型变化时对其他字段的影响
- if (!val) {
- this.form.modelId = null;
- }
- },
+ /** 当选择运营区时调用 */
+ handleAreaChange(val) {
+ if (!this.isUpdating) {
+ if (val) {
+ this.isUpdating = true;
+ selectDeptByAreaId(val).then((response) => {
+ // 只有在代理商为空时,才设置代理商
+ if (!this.form.deptId && response.data.sysDept) {
+ this.form.deptId = response.data.sysDept.deptId;
+
+ // 获取该代理商下的车型列表
+ selectAreaListByDeptId(this.form.deptId).then((deptResponse) => {
+ this.modelOptions = deptResponse.data.modelList || [];
+ if (this.modelOptions.length > 0) {
+ this.form.modelId = this.modelOptions[0].modelId;
+ } else {
+ this.form.modelId = null;
+ this.$message.warning('该代理商暂无可用车型');
+ }
+ });
+ } else {
+ // 如果已有代理商,则使用现有的车型列表
+ this.modelOptions = response.data.modelList || [];
+ if (!this.form.modelId && this.modelOptions.length > 0) {
+ this.form.modelId = this.modelOptions[0].modelId;
+ } else if (this.modelOptions.length === 0) {
+ this.form.modelId = null;
+ this.$message.warning('该运营区暂无可用车型');
+ }
+ }
+ }).finally(() => {
+ this.isUpdating = false;
+ });
+ } else {
+ // 清空车型,但保留代理商
+ this.form.modelId = null;
+ this.modelOptions = [];
+ }
+ }
+ },
+
+ /** 当选择车型时调用 */
+ handleModelChange(val) {
+ // 移除车型变化时对其他字段的影响
+ if (!val) {
+ this.form.modelId = null;
+ }
+ },
// 处理硬件版本变化
handleHardwareVersionChange(val) {
@@ -1012,8 +1014,8 @@ handleAreaChange(val) {
// }
},
-
-
+
+
/** 排序触发事件 */
handleSortChange(column, prop, order) {
this.queryParams.orderByColumn = column.prop;
@@ -1162,16 +1164,16 @@ handleAreaChange(val) {
if(this.queryParams2.deptId){
selectAreaListByDeptId(this.queryParams2.deptId).then((deptResponse) => {
this.modelOptions = deptResponse.data.modelList || [];
-
+
});
}else{
listModel(this.queryParams2).then((response) => {
-
-
+
+
this.modelOptions = response.rows;
});
}
-
+
},
// 取消按钮
cancel() {
@@ -1215,7 +1217,7 @@ handleAreaChange(val) {
}
);
}
-
+
listModel(this.queryParams2).then((response) => {
this.modelOptions = response.rows;
});
@@ -1229,14 +1231,14 @@ handleAreaChange(val) {
this.form.modelId = null;
this.areaOptions = [];
this.modelOptions = [];
-
+
// 重新加载代理商列表
if (this.userName === "admin") {
listDept2({ status: "0", pageNum: 1, pageSize: 999 }).then((response) => {
this.deptOptions = response.rows;
});
}
-
+
// 重新加载运营区列表
listArea(this.queryParams2).then((response) => {
this.areaOptions = response.rows;
@@ -1271,7 +1273,7 @@ handleAreaChange(val) {
},
/** 详情按钮 */
handleView(row) {
- const deviceId = row.deviceId
+ const deviceId = row.deviceId
this.$router.push(`/system/deviceDetail/index/${deviceId}`)
// this.$router.push({
// path: '/system/deviceDetail/index',
@@ -1343,39 +1345,53 @@ handleAreaChange(val) {
getDevice(deviceId).then((response) => {
this.form = response.data;
+ this.selectHardwareVersion(response.data.hardwareVersionId);
- this.selectHardwareVersion(response.data.hardwareVersionId)
- // this.fetchData3(response.data.areaId)
- // this.fetchData(response.data.deptId)
- // this.open = true;
- // this.title = "修改设备1";
-
+ // 如果没有绑定代理商
+ if (!response.data.deptId) {
+ // 重置运营区和车型选项
+ this.modelOptions = [];
+ this.areaOptions = [];
+
+ // 如果是管理员,加载所有运营区
+ if (this.userName === 'admin') {
+ listArea(this.queryParams2).then((response) => {
+ this.areaOptions = response.rows || [];
+ });
+ }
+
+ this.open = true;
+ this.title = "修改设备";
+ this.isUpdating = false;
+ } else {
+ // 有绑定代理商,获取对应的运营区和车型
selectAreaListByDeptId(response.data.deptId).then((res) => {
- // 方案1: 使用Vue.set确保响应式更新
- setTimeout(() => {
- console.log('=调用了11');
-
- this.$set(this, 'modelOptions', []);
- this.$set(this, 'areaOptions', []);
- this.$set(this, 'modelOptions', res.data.modelList);
- this.$set(this, 'areaOptions', res.data.areaList);
- this.$forceUpdate()
+ this.modelOptions = res.data.modelList || [];
+ this.areaOptions = res.data.areaList || [];
+
+ // 如果当前选中的运营区或车型不在新的选项中,清空选择
+ if (this.areaOptions.length > 0 && !this.areaOptions.find(area => area.areaId === this.form.areaId)) {
+ this.form.areaId = null;
+ }
+ if (this.modelOptions.length > 0 && !this.modelOptions.find(model => model.modelId === this.form.modelId)) {
+ this.form.modelId = null;
+ }
+
+ this.open = true;
+ this.title = "修改设备";
+ }).catch(() => {
+ // 获取失败时也显示弹窗,但清空选项
+ this.modelOptions = [];
+ this.areaOptions = [];
this.open = true;
this.title = "修改设备";
- }, 800);
-
-
- // 方案2: 使用nextTick确保DOM更新
- // this.$nextTick(() => {
- // this.modelOptions = res.data.modelList;
- // this.areaOptions = res.data.areaList;
- // },600);
-
- // 不再需要setTimeout和$forceUpdate
}).finally(() => {
this.isUpdating = false;
});
-
+ }
+ }).catch(() => {
+ this.isUpdating = false;
+ this.$modal.msgError("获取设备信息失败");
});
},
handleListing(row) {