| | |
| | | items: [], |
| | | }, |
| | | ], |
| | | // 设备情况统计 |
| | | deviceSummary: '', |
| | | }, |
| | | methods: { |
| | | fetchAllDeviceInfo() { |
| | | const array = []; |
| | | [0, 1, 2].forEach(deviceTypeId => { |
| | | const f = this.fetchDeviceInfo(deviceTypeId); |
| | | array.push(f); |
| | | }); |
| | | return Promise.all(array).then(() => this.getDeviceSummary()); |
| | | }, |
| | | fetchDeviceInfo(deviceTypeId) { |
| | | const { scene } = this.data; |
| | | fetchDevices(scene.guid, deviceTypeId).then(res => { |
| | | return fetchDevices(scene.guid, deviceTypeId).then(res => { |
| | | this.setData({ |
| | | [`categories[${deviceTypeId}].items`]: res.data, |
| | | }); |
| | |
| | | }, |
| | | onSideBarChange(e) { |
| | | const { value } = e.detail; |
| | | this.fetchDeviceInfo(this.data.categories[value].type) |
| | | this.fetchDeviceInfo(this.data.categories[value].type); |
| | | this.setData({ sideBarIndex: value }); |
| | | }, |
| | | addNewDevice(e) { |
| | |
| | | }, |
| | | events: { |
| | | updateDeviceInfoOver: () => { |
| | | this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type) |
| | | this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type); |
| | | }, |
| | | }, |
| | | }); |
| | |
| | | }, |
| | | events: { |
| | | updateDeviceInfoOver: () => { |
| | | this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type) |
| | | this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type); |
| | | }, |
| | | }, |
| | | }); |
| | |
| | | }, |
| | | events: { |
| | | updateDeviceStatusOver: () => { |
| | | this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type) |
| | | this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type); |
| | | }, |
| | | }, |
| | | }); |
| | | } |
| | | }, |
| | | |
| | | getDeviceSummary() { |
| | | const { categories } = this.data; |
| | | let deviceCount = 0, |
| | | deviceCount0 = 0, |
| | | deviceCount1 = 0, |
| | | deviceCount2 = 0, |
| | | moved = 0, |
| | | tobeDismantled = 0, |
| | | tobeChecked = 0, |
| | | tobeUpdated = 0; |
| | | let lastestCheck = ''; |
| | | // 几台设备,其中有几台正常、几台移位、几台待拆,以及几台待核实、几台待更新,并且显示最新核查事件、距今多少天(若超过3个月就标红) |
| | | categories.forEach(c => { |
| | | c.items.forEach(d => { |
| | | deviceCount++; |
| | | if (c.type == 0) { |
| | | deviceCount0++; |
| | | } else if (c.type == 1) { |
| | | deviceCount1++; |
| | | } else if (c.type == 2) { |
| | | deviceCount2++; |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | this.setData({ |
| | | deviceSummary: `共有${deviceCount}台设备,监测设备${deviceCount0}台,治理设备${deviceCount1}台,生产设备${deviceCount2}台,`, |
| | | }); |
| | | }, |
| | | }, |
| | | }); |