deviceList.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const app = getApp()
  2. import dRequest from '../../request/deviceListRequest'
  3. import routeUtil from '../../utils/route_util'
  4. import route_constant from '../../utils/route_constant.js'
  5. import strings from '../../utils/strings.js';
  6. import store from '../../utils/store.js';
  7. Page({
  8. data: {
  9. nvabarData: {
  10. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  11. title: '设备列表', //导航栏 中间的标题
  12. },
  13. deviceList: app.globalData.classifyProducts,
  14. },
  15. onLoad(options) {
  16. var that = this
  17. var classifyProducts = app.globalData.classifyProducts;
  18. if (!strings.isEmpty(classifyProducts)) {
  19. that.setDeviceList(classifyProducts);
  20. }
  21. ///数据请求
  22. dRequest.deviceList({}).then((res) => {
  23. if (res) {
  24. store.setStore("classifyProducts", res);
  25. that.setDeviceList(res);
  26. }
  27. });
  28. },
  29. ///设备列表赋值
  30. setDeviceList(res) {
  31. var that = this;
  32. try {
  33. var devices = [];
  34. res.forEach(element => {
  35. if (element.applicationType.indexOf("0") >= 0) {
  36. devices.push(element)
  37. }
  38. });
  39. that.setData({
  40. deviceList: devices
  41. });
  42. } catch (e) {}
  43. },
  44. deviceTap(e) {
  45. var device = e.currentTarget.dataset.device;
  46. if (!device) {
  47. console.log("设备为空")
  48. return;
  49. }
  50. var param = JSON.stringify(device);
  51. routeUtil.jumpParam(route_constant.deviceConnect0, param);
  52. },
  53. })