import { fetchDevices, fetchDeviceStatus } from '../../../../services/inspection/fetchDevice'; /** * 设备信息管理 */ export const useDeviceList = Behavior({ data: { sideBarIndex: 0, categories: [ { label: '监测设备', type: 0, badgeProps: {}, items: [], }, { label: '治理设备', type: 1, badgeProps: {}, items: [], }, { label: '生产设备', type: 2, badgeProps: {}, items: [], }, ], }, methods: { fetchDeviceInfo(deviceTypeId) { const { scene } = this.data; 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.setData({ sideBarIndex: value }); }, addNewDevice(e) { const { type } = e.currentTarget.dataset; const { scene } = this.data; wx.navigateTo({ url: `/pages/inspection/scene/info/device-info/index`, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 res.eventChannel.emit('acceptDeviceData', { type, scene, mode: 'add', }); }, }); }, updateDevice(e) { const { type, index } = e.currentTarget.dataset; const { scene, categories } = this.data; const [i0, i1] = index; const deviceInfo = categories[i0].items[i1]; wx.navigateTo({ url: `/pages/inspection/scene/info/device-info/index`, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 res.eventChannel.emit('acceptDeviceData', { type, scene, mode: 'update', deviceInfo, }); }, }); }, updateStatus(e) { const { type, index } = e.currentTarget.dataset; const { scene, categories } = this.data; const [i0, i1] = index; const deviceInfo = categories[i0].items[i1]; wx.navigateTo({ url: `/pages/inspection/scene/info/device-status/index`, success: function (res) { // 通过 eventChannel 向被打开页面传送数据 res.eventChannel.emit('acceptDeviceStatusData', { type, scene, deviceInfo, }); }, }); } }, });