deviceList.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // pages/deviceList/deviceList.js
  2. import dRequest from '../../request/deviceListRequest'
  3. import routeUtil from '../../utils/route_util'
  4. import route_constant from '../../utils/route_constant.js'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. deviceList: [
  11. ],
  12. nvabarData: {
  13. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  14. title: '设备列表', //导航栏 中间的标题
  15. },
  16. },
  17. deviceTap(e) {
  18. console.log(e)
  19. let device = e.currentTarget.dataset.device
  20. if (!device) {
  21. console.log("设备为空")
  22. return;
  23. }
  24. let param = JSON.stringify(device)
  25. routeUtil.jumpParam(route_constant.connectMode, param)
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. let _this = this
  32. let app = getApp()
  33. if (app.globalData.classifyProducts.length > 0) {
  34. _this.setData({
  35. deviceList: app.globalData.classifyProducts
  36. })
  37. return;
  38. }
  39. dRequest.deviceList({}).then((res) => {
  40. // console.log("设备列表", res);
  41. let devices = []
  42. res.forEach(element => {
  43. if (element.applicationType.indexOf("0") >= 0) {
  44. devices.push(element)
  45. }
  46. });
  47. console.log("设备列表2:", devices)
  48. app.globalData.classifyProducts = devices;
  49. _this.setData({
  50. deviceList: devices
  51. })
  52. })
  53. // dRequest.deviceTypeList({}).then((res)=>{
  54. // console.log("设备类型", res);
  55. // })
  56. // dRequest.deviceCategoryList({}).then((res)=>{
  57. // console.log("设备分类列表", res);
  58. // })
  59. },
  60. })