diff --git a/App.vue b/App.vue index e69f315..63cf9bf 100644 --- a/App.vue +++ b/App.vue @@ -35,6 +35,12 @@ onShow: function() { console.log('App Show') const that = this; + //监听公司点击 + uni.$off("notify-add-land"); + uni.$on("notify-add-land", (data) => { + that.getLand(data); + }); + //监听地块选择 uni.$off("notify-update-land"); uni.$on("notify-update-land", (data) => { // console.error("index监听地块更新:", data) @@ -88,17 +94,35 @@ } } }, + getLand(e) { + this.ijs.getLand(e.node).then(data => { + // this.$refs.landRef.addLand(e, data); + this.sendMsgEvent("land", { + type: "add", + data: { + item: e, + lands: data + } + }); + }); + }, getWoList(land, wo) { const that = this; if (land && wo) { that.dc.setData(land, wo); that.mqttSubscribes(); - that.sendMsgEvent("land", wo); + that.sendMsgEvent("land", { + type: "wo", + data: wo + }); } that.ijs.getWoList(land).then(res => { that.dc.setData(land, res.data); that.mqttSubscribes(); - that.sendMsgEvent("land", res.data); + that.sendMsgEvent("land", { + type: "wo", + data: res.data + }); uni.hideLoading(); }).catch(() => { uni.hideLoading(); diff --git a/components/custom-select-land/custom-select-land.vue b/components/custom-select-land/custom-select-land.vue index 6ef434d..d03e22d 100644 --- a/components/custom-select-land/custom-select-land.vue +++ b/components/custom-select-land/custom-select-land.vue @@ -213,6 +213,7 @@ } // 如果没更新过数据,则异步的去更新数据 this.$emit('getLand', item); + uni.$emit('notify-add-land', item); }, /** * 添加地块 @@ -241,8 +242,12 @@ }); } if (index !== -1) { + const keys = that.datamap[item.key].keys; let addLand = []; lands.forEach(land => { + if (keys.includes(`l${land.id}`)) { + return; + } land = { id: land.id, label: land.landName, @@ -260,8 +265,13 @@ newItem.show = that.datamap[item.key].show; that.datamap[land.key] = newItem; }); - that.datalist.splice(index + 1, 0, ...addLand); - item.keys = that.datamap[item.key].keys; + if (addLand.length) { + that.datalist.splice(index + 1, 0, ...addLand); + item.keys = that.datamap[item.key].keys; + } + that.datamap[item.key].show = true; + that.datamap[item.key].expand = true; + that.checkExpandedChange(that.datamap[item.key], true) } }, // 选中地块数据 diff --git a/pages/index-map.vue b/pages/index-map.vue index 7f428de..1d1d4f7 100644 --- a/pages/index-map.vue +++ b/pages/index-map.vue @@ -449,7 +449,7 @@ - + @@ -509,8 +509,12 @@ } }); getApp().on("land", "land_map", function(e) { - that.title = that.ijs?.land?.landName || null; - that.mapOnload(); + if (e.type == "wo") { + that.title = that.ijs?.land?.landName || null; + that.mapOnload(); + } else if (e.type == "add") { + that.$refs.landRef.addLand(e.data.item, e.data.lands); + } else {} }); }, onShow() { @@ -536,12 +540,6 @@ }; }, methods: { - // 获取地块信息 - getLand(e) { - this.ijs.getLand(e.node).then(res => { - this.$refs.landRef.addLand(e, res.data); - }); - }, //初始化完成回调 mapOnload(e) { if (!this.ijs.wo) { diff --git a/pages/index.vue b/pages/index.vue index 7bab7bd..5a9e8c6 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -141,7 +141,6 @@ - @@ -539,7 +538,7 @@ - + @@ -589,13 +588,17 @@ } else if (e.type == "msg") {} }); getApp().on("land", "land_index", function(e) { - that.title = that.ijs?.land?.landName || null; - that.$nextTick(() => { - setTimeout(() => { - that.$refs.collapseStationRef.resize(); - that.$refs.collapseRef.resize(); - }, 500) - }) + if (e.type == "wo") { + that.title = that.ijs?.land?.landName || null; + that.$nextTick(() => { + setTimeout(() => { + that.$refs.collapseStationRef.resize(); + that.$refs.collapseRef.resize(); + }, 500) + }) + } else if (e.type == "add") { + that.$refs.landRef.addLand(e.data.item, e.data.lands); + } else {} }); }, onShow() { @@ -628,12 +631,6 @@ mqttSubscribes() { getApp().mqttSubscribes(); }, - // 获取地块信息 - getLand(e) { - this.ijs.getLand(e.node).then(res => { - this.$refs.landRef.addLand(e, res.rows); - }); - }, // 去扫码 async toQRCode() { // // 权限检测成功则返回 { isSuc : true} ,未授权则弹出权限询问弹窗以及权限说明窗口 diff --git a/utils/indexUtil/index.js b/utils/indexUtil/index.js index 2a9c82f..156050a 100644 --- a/utils/indexUtil/index.js +++ b/utils/indexUtil/index.js @@ -22,6 +22,7 @@ import { const cacheKey = "cacheData"; class indexUtil { static companys = null; //公司选择的列表 + static companyLands = {}; //地块的数据列表 static land = null; //选中的数据 static wo = null; //地块的数据列表 static cacheData = { @@ -34,6 +35,16 @@ class indexUtil { //接收创建来的数据 constructor(eventHandler) { this.eventHandler = eventHandler; + this.companys = null; //公司选择的列表 + this.companyLands = {}; //地块的数据列表 + this.land = null; //选中的数据 + this.wo = null; //地块的数据列表 + this.cacheData = { + userId: null, + companys: null, + land: null, + wo: null, + } } /** @@ -92,23 +103,29 @@ class indexUtil { // 获取地块信息 getLand(company) { const that = this; + const keyName = company.companyId; return new Promise((resolve, reject) => { - const query = { - companyGroupId: company.companyId, - companyId: company.rootCompanyId, - status: 0, - delFlag: 0, - } - getLandAndDevice(query).then(res => { - if (res.rows && res.rows.length) { - let companys = that.cacheData.companys || []; - that.findObjectById(companys, company.companyId, res.rows); - that.setStorage(constant.companys, companys); + if (that.companyLands.hasOwnProperty(keyName)) { + resolve(that.companyLands[keyName]) + } else { + const query = { + companyGroupId: company.companyId, + companyId: company.rootCompanyId, + status: 0, + delFlag: 0, } - resolve(res) - }).catch(error => { - reject(error) - }) + getLandAndDevice(query).then(res => { + if (res.rows && res.rows.length) { + let companys = that.cacheData.companys || []; + that.findObjectById(companys, company.companyId, res.rows); + that.setStorage(constant.companys, companys); + that.companyLands[keyName] = res.rows; + } + resolve(res.rows || []) + }).catch(error => { + reject(error) + }) + } }) }