diff --git a/src/store/device.js b/src/store/device.js index 9b8c841..9a52a06 100644 --- a/src/store/device.js +++ b/src/store/device.js @@ -17,7 +17,7 @@ export default { } }, actions: { // 小程序模块化访问失败 this.$store.dispatch('device/getStoreList') - getStoreList({ commit, state , rootState}, { stadium_id = '' } = {}){ + getStoreList({ commit, state , rootState}, { stadium_id = '', storeChange = false } = {}){ return deviceServer.get({ url: deviceApi.stadiumList, data: { brand_id: rootState.brandInfo.brand.id }, @@ -26,12 +26,10 @@ export default { .then(res=>{ let _list = res.list || []; commit('setStoreList', _list); - if(Object.keys(state.curStoreInfo)?.length ===0&&_list?.length){ - if(stadium_id&&_list.some(item=>item.id===stadium_id)){ - commit('setStoreInfo', _list.find(item=>item.id===stadium_id)); - }else{ - commit('setStoreInfo', _list[0]); - } + if(stadium_id&&_list.some(item=>item.id===stadium_id)){ + commit('setStoreInfo', _list.find(item=>item.id===stadium_id)); + }else{ + commit('setStoreInfo', _list?.[0] || {}); } return res; }) diff --git a/src/subpackage/device/js/device_api.js b/src/subpackage/device/js/device_api.js index 047c958..910232d 100644 --- a/src/subpackage/device/js/device_api.js +++ b/src/subpackage/device/js/device_api.js @@ -64,6 +64,12 @@ export const DEVICE_API = { // 【ID1001350】 20230815 小程序-商家助手小程序设备管理优化 ouxuanacList:`${ORIGIN}/admin/ouxuanac/list`, // 获取中控信息 + + // 20230816 新增品牌切换按钮 + currentUser:`${ORIGIN}/admin/assistant/currentUser`, // 获取用户信息 + brandList:`${ORIGIN}/stadium/brand/all`, // 获取品牌列表 + brandInfo:`${ORIGIN}/stadium/brand/get`, // 获取品牌信息 + } export default DEVICE_API; \ No newline at end of file diff --git a/src/subpackage/device/pages/index/index.vue b/src/subpackage/device/pages/index/index.vue index 9eabbbb..153fbf3 100644 --- a/src/subpackage/device/pages/index/index.vue +++ b/src/subpackage/device/pages/index/index.vue @@ -30,12 +30,22 @@ - 重启 + + 重启 + + 切换品牌 + + + @@ -90,6 +100,7 @@ export default { ...mapState({ storeList: state => state.device.storeList, curStoreInfo: state => state.device.curStoreInfo, + brandInfo: state => state.brandInfo, }), // showHardwareIdLs(){ @@ -108,9 +119,20 @@ export default { }, }, watch: { - curStoreInfo(nw, od){ + async curStoreInfo(nw, od){ this.getOuxuanacInfo(nw.device_name); - this.getHardwareTypeList(); + this.getHardwareTypeList(nw.id); + this.updateAC(nw.device_name); + console.log('curStoreInfo', nw, od); + }, + isBrandSwitch(nw, od){ + if(nw)this.getBrandList(); + }, + switchBrandInfo(nw, od){ + if(nw?.id === od?.id)return; + let { brandInfo } = this; + this.$store.commit('setBrandInfo', { ...brandInfo, brand: nw }); + this.$store.dispatch('getStoreList'); } }, data(){ @@ -123,6 +145,9 @@ export default { titleBarHeight: 0 }, oxAcInfo: {}, + isBrandSwitch: false, + brandList: [], + switchBrandInfo: {}, } }, async onLoad(options){ @@ -131,9 +156,9 @@ export default { let _brandInfo = await this.$store.dispatch('getBrandInfo'); await this.$store.dispatch('getStoreList', { stadium_id: +options.stadium_id || '' }); let { curStoreInfo } = this; - this.updateAC(); - await this.getHardwareTypeList(); - await this.getOuxuanacInfo(curStoreInfo.device_name); + this.getHardwareTypeList(curStoreInfo.id); + this.getOuxuanacInfo(curStoreInfo.device_name); + this.getBrandSwitch(); util.hideLoad(); }catch(err){ console.warn('onLoad err--->', err) @@ -142,13 +167,44 @@ export default { }, onShow() { - this.updateAC() // 更新中控信息 + let { curStoreInfo } = this; + if(curStoreInfo?.device_name)this.updateAC(curStoreInfo.device_name); // 更新中控信息 + }, onReady() { this.initSysBarInfo(); }, methods: { - + // 品牌切换 + brandChange(e){ + let { brandList } = this; + let { value } = e.detail; + this.switchBrandInfo = brandList?.[value] || {}; + this.getBrandInfo(brandList?.[value]?.id); + }, + // 获取品牌列表 + getBrandList(){ + return deviceServer.get({ + url: deviceApi.brandList, + data: {}, + failMsg: '加载品牌列表失败!' + }) + .then(res=>{ + console.log('getBrandList --->', res); + this.brandList = res || []; + }) + }, + getBrandInfo(bid){ + return deviceServer.get({ + url: deviceApi.brandInfo + `/${bid}`, + data: {}, + failMsg: '加载品牌信息失败!' + }) + .then(res=>{ + console.log('getBrandInfo --->', res); + this.switchBrandInfo = res || {}; + }) + }, initSysBarInfo(){ let wxBtn = uni.getMenuButtonBoundingClientRect(); let sysInfo = uni.getSystemInfoSync(); @@ -163,15 +219,18 @@ export default { let { showHardwareIdLs } = this; return showHardwareIdLs.includes(e.id); }, - getHardwareTypeList(){ - let { curStoreInfo } = this; + getHardwareTypeList(stadium_id){ + if(!stadium_id)console.log('getHardwareTypeList stadium_id is null'); this.tabArr = []; + this.hardwareTypeList = []; + util.showLoad(); return deviceServer.get({ url: deviceApi.hardwareTypeList, - data: { stadium_id: curStoreInfo.id }, + data: { stadium_id: stadium_id }, failMsg: '加载设备类型列表失败!' }) .then(res=>{ + util.hideLoad(); let _ls = res || []; if(_ls&&_ls.length)this.tabArr = tabArr; return this.hardwareTypeList = _ls || []; @@ -187,26 +246,25 @@ export default { } }); }, - updateAC(){ - if(!this.curStoreInfo.device_name)return + updateAC(device_name){ + this.deviceInfo = {}; + if(!device_name)return console.log('updateAC device_name is null'); + uni.removeStorageSync("deviceInfo"); util.showLoad(); - // id:"00-de-47-e9-3a-fc" deviceServer.get({ url: deviceApi.acUpdate, - data: {id:this.curStoreInfo.device_name}, + data: { id: device_name }, failMsg: '加载失败!' }) .then(res=>{ - util.hideLoad() - this.deviceInfo = res + util.hideLoad(); + this.deviceInfo = res || {}; uni.setStorageSync("deviceInfo",res) }) .catch(util.hideLoad) }, goBack(){ - uni.navigateBack({ - delta:1 - }) + uni.navigateBack({ delta:1 }); }, goTimingList(){ let timing_list = "/subpackage/device/pages/timing/timing_list" @@ -223,17 +281,16 @@ export default { }, // 获取中控重启参数 getOuxuanacInfo(id_ouxuanac){ - if(!id_ouxuanac){ - console.log('中控id不存在 id_ouxuanac ->', id_ouxuanac); - return Promise.resolve([]); - } + this.oxAcInfo = {}; + if(!id_ouxuanac)return console.log('getOuxuanacInfo id_ouxuanac is null'); + util.showLoad(); return deviceServer.get({ url: deviceApi.ouxuanacList, data: { id_ouxuanac }, failMsg: '加载中控信息失败!' }) .then(res=>{ - console.log('id_ouxuanac', res); + util.hideLoad(); this.initOuxuancInfo({ oxacLs: res?.list || [], id_ouxuanac }); return res }) @@ -243,36 +300,24 @@ export default { this.oxAcInfo = oxacLs.find(e=>e.id_ouxuanac == id_ouxuanac) || {}; }, restartBtn(){ - let { curStoreInfo, oxAcInfo } = this; + let { oxAcInfo } = this; let _dvName = oxAcInfo?.extension?.switch_device_name; this.operateReq({ deviceName: _dvName, op: 'off', }) .then(code=>{ if(code === 0){ - setTimeout(_=>{ this.operateReq({ deviceName: _dvName, op: 'on', }) }, 1000) + setTimeout(_=>{ this.operateReq({ deviceName: _dvName, op: 'on', isTip: true }) }, 1000) } }) - - // util.showNone('调试开发中!'); }, - // 操作接口请求 - operateReq({deviceName, op, isTip=true}){ - // let _query = { - // is_delay: true, - // name: "gate-switch", - // queue_group: "gate", - // value: { tcp: "", cid: "", op}, - // device: deviceName, - // hardware_id: "", - // } + // 重启操作接口请求 + operateReq({deviceName, op, isTip=false}){ let _query = { + "device": deviceName, "data": { - "name": "gate-switch", - "value":{ - "op": op - }, - "is_async":true - }, - "device": deviceName + "name": "gate-switch", + "value":{ "op": op }, + "is_async":true + } } util.showLoad(); return deviceServer.post({ @@ -299,6 +344,21 @@ export default { return Promise.reject(err); }) }, + // 获取用户是否有品牌切换权限 + getBrandSwitch(){ + return deviceServer.get({ + url: deviceApi.currentUser, + data: {}, + isDefaultGet: false, + }) + .then(res=>{ + if(res.data.code == 0){ + console.warn('getBrandSwitch--->', res.data); + this.isBrandSwitch = res?.data?.data?.extension?.ESP?.all_brand || false + } + + }) + }, } } @@ -307,7 +367,6 @@ export default { @import '~style/public.scss'; .ic-header{ width: 100%; - height: 620upx; background-image: linear-gradient(160deg, #89D499 0%, #33CCA9 81%); .ih-bar{ .ib-title-bar{ @@ -377,8 +436,12 @@ export default { } } } + .ic-btn-box{ + margin-top: 44upx; + @include centerFlex(center); + } .ic-btn{ - margin: 44upx auto 0; + margin: 0 10upx; width: 200upx; height: 68upx; line-height: 68upx; @@ -391,6 +454,10 @@ export default { font-weight: 500; color: $themeColor; text-shadow: 0 0.3upx 1upx rgba($color: #005F49, $alpha: .5); + &.select-brand{ + color: #0042fd; + text-shadow: 0 0.3upx 1upx rgba($color: #0042fd, $alpha: .5); + } } } }