riku
2024-11-07 5036880fc037e5d112206b93a729f60be12bf8ab
pages/inspection/scene/info/devicelist-proxy.js
@@ -1,3 +1,5 @@
import { fetchDevices, fetchDeviceStatus } from '../../../../services/inspection/fetchDevice';
/**
 * 设备信息管理
 */
@@ -26,8 +28,17 @@
    ],
  },
  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) {
@@ -43,7 +54,58 @@
            mode: 'add',
          });
        },
        events: {
          updateDeviceInfoOver: () => {
            this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type)
          },
        },
      });
    },
    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,
          });
        },
        events: {
          updateDeviceInfoOver: () => {
            this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type)
          },
        },
      });
    },
    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,
          });
        },
        events: {
          updateDeviceStatusOver: () => {
            this.fetchDeviceInfo(this.data.categories[this.data.sideBarIndex].type)
          },
        },
      });
    }
  },
});