From 56b3b0f438a48f3930874d90290c0a36e1d32185 Mon Sep 17 00:00:00 2001 From: tx <2622874537@qq.com> Date: Fri, 20 Dec 2024 16:25:49 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/system/device/index.vue | 267 +++++++++++++++++------------- src/views/system/model/index.vue | 8 +- 2 files changed, 154 insertions(+), 121 deletions(-) diff --git a/src/views/system/device/index.vue b/src/views/system/device/index.vue index e01cfd1..2b957d5 100644 --- a/src/views/system/device/index.vue +++ b/src/views/system/device/index.vue @@ -689,6 +689,7 @@ export default { //不分页 queryParams2: { pageNum: 1, + deptId: this.deptId, pageSize: 999 }, // 列信息 @@ -726,6 +727,10 @@ export default { sn: [{ required: true, message: "SN不能为空", trigger: "blur" }], mac: [{ required: true, message: "MAC不能为空", trigger: "blur" }], }, + deptAreas: {}, // 存储代理商对应的运营区和车型 {deptId: {areaList: [], modelList: []}} + areaInfo: {}, // 存储运营区对应的代理商和车型 {areaId: {deptId: null, modelList: []}} + allAreas: [], // 存储所有运营区 + allModels: [], // 存储所有车型 }; }, mounted() { @@ -826,29 +831,101 @@ export default { this.gettj(); } }, - handleDeptChange(val) { - if (!this.isUpdating) { - this.fetchData2(val); - } - }, + /** 当选择代理商时调用 */ +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; + } - // 处理运营区变化 - handleAreaChange(val) { - console.log('=调用了'); - - if (!this.isUpdating) { - this.fetchData3(val); - } - }, + // 如果没有选项,显示提示信息 + 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; + }); + } + } +}, - // 处理车型变化 - handleModelChange(val) { - console.log('=调用了'); - - if (!this.isUpdating) { - this.fetchData(val); - } - }, +/** 当选择运营区时调用 */ +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) { @@ -906,88 +983,29 @@ export default { }, /** 当选择车型时调用 */ fetchData(modelId) { - if (modelId) { - this.isUpdating = true; // 设置标志位 - getModel(modelId).then((response) => { - this.areaOptions = response.data.areaList; - let areaOptions = response.data.areaList; - if (response.data.operator) { - this.form.deptId = response.data.operator; - } else { - this.form.deptId = null; - } - areaOptions.length > 0 - ? (this.form.areaId = areaOptions[0].areaId) - : (this.form.areaId = null); - }).finally(() => { - this.isUpdating = false; // 清除标志位 - }); - } else { - this.reset2(); - } - }, - /** 当选择代理商时 根据代理商id,获取运营区和型号 */ - fetchData2(deptId) { - if (deptId) { - this.isUpdating = true; // 设置标志位 - selectAreaListByDeptId(deptId).then((response) => { - this.areaOptions = response.data.areaList; - let areaOptions = response.data.areaList; - areaOptions.length > 0 - ? (this.form.areaId = areaOptions[0].areaId) - : (this.form.areaId = null); - this.modelOptions = response.data.modelList; - let modelOptions = response.data.modelList; - // console.log("=======1111111111=======",this.modelOptions.length) - modelOptions.length > 0 - ? (this.form.modelId = modelOptions[0].modelId) - : (this.form.modelId = null); - }).finally(() => { - this.isUpdating = false; // 清除标志位 - }); - } else { - this.reset2(); - // this.form.areaId = null; - // this.form.modelId = null; - } - }, - /** 当选择代理商时 根据代理商id,获取运营区和型号 */ - fetchData4(deptId) { - if (deptId) { - // this.isUpdating = true; // 设置标志位 - selectAreaListByDeptId(deptId).then((response) => { - this.modelOptions = response.data.modelList; - let modelOptions = response.data.modelList; - modelOptions.length > 0 - ? (this.form.modelId = modelOptions[0].modelId) - : (this.form.modelId = null); - }).finally(() => { - // this.isUpdating = false; // 清除标志位 - }); - } else { - this.reset2(); - // this.form.areaId = null; - // this.form.modelId = null; - } - }, - /** 当选择运营区时 根据运营区id,获取代理商和型号 */ - fetchData3(areaId) { - if (areaId) { - this.isUpdating = true; // 设置标志位 - selectDeptByAreaId(areaId).then((response) => { - this.form.deptId = response.data.sysDept.deptId; - this.modelOptions = response.data.modelList; - let modelOptions = response.data.modelList; - modelOptions.length > 0 - ? (this.form.modelId = modelOptions[0].modelId) - : (this.form.modelId = null); - }).finally(() => { - this.isUpdating = false; // 清除标志位 - }); - } else { - this.reset2(); - } + // if (modelId) { + // this.isUpdating = true; // 设置标志位 + // getModel(modelId).then((response) => { + // this.areaOptions = response.data.areaList; + // let areaOptions = response.data.areaList; + // if (response.data.operator) { + // this.form.deptId = response.data.operator; + // } else { + // this.form.deptId = null; + // } + // areaOptions.length > 0 + // ? (this.form.areaId = areaOptions[0].areaId) + // : (this.form.areaId = null); + // }).finally(() => { + // this.isUpdating = false; // 清除标志位 + // }); + // } else { + // this.reset2(); + // } }, + + + /** 排序触发事件 */ handleSortChange(column, prop, order) { this.queryParams.orderByColumn = column.prop; @@ -1126,15 +1144,26 @@ export default { }, /** 查询设备列表 */ getList() { + console.log('111111111111111111111111'); this.loading = true; listDevice(this.queryParams).then((response) => { this.deviceList = response.rows; this.total = response.total; this.loading = false; }); - listModel(this.queryParams2).then((response) => { + 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() { @@ -1178,7 +1207,7 @@ export default { } ); } - // console.log(33333333333) + listModel(this.queryParams2).then((response) => { this.modelOptions = response.rows; }); @@ -1187,20 +1216,24 @@ export default { }); }, reset2() { - this.form.areaId = null; - this.form.deptId = null; - this.form.modelId = null; - 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; + this.form.areaId = null; + this.form.deptId = null; + 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; + }); + }, /** 搜索按钮操作 */ handleQuery() { this.queryParams.pageNum = 1; diff --git a/src/views/system/model/index.vue b/src/views/system/model/index.vue index 6a48948..d363917 100644 --- a/src/views/system/model/index.vue +++ b/src/views/system/model/index.vue @@ -140,7 +140,7 @@ - + - - +