manager.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const APP = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. showMore: false,//显示更多
  8. showModify: false, //显示修改框
  9. deviceList: [],
  10. currentDevice: null,//当前选中的设备
  11. },
  12. onShow: function () {
  13. this.getDeviceList();
  14. },
  15. /**
  16. * 请求设备集合
  17. */
  18. getDeviceList: function () {
  19. APP.Get(APP.Url.getListByUserId, {}, false).then(res => {
  20. this.setData({
  21. deviceList: res.data,
  22. })
  23. APP.globalData.deviceList = res.data;
  24. })
  25. },
  26. /**
  27. * 切换当前设备
  28. */
  29. changeDefaultDevice: function (event) {
  30. const params = {
  31. deviceNum: event.currentTarget.dataset.num
  32. }
  33. APP.Post(APP.Url.changeDefaultDevice, params).then(res => {
  34. APP.Modal.tips("设置成功");
  35. this.getDeviceList();
  36. })
  37. },
  38. /**
  39. * 解除设备
  40. */
  41. unbind: function () {
  42. const that = this;
  43. const params = {
  44. deviceNum: this.data.currentDevice.deviceNum,
  45. }
  46. wx.showModal({
  47. title: '提示',
  48. content: '确定解绑这台设备吗?',
  49. success(res) {
  50. if (res.confirm) {
  51. APP.Post(APP.Url.unbind, params).then(res => {
  52. that.hideAll();
  53. APP.Modal.tips("解绑成功");
  54. that.getDeviceList();
  55. })
  56. }
  57. }
  58. })
  59. },
  60. /**
  61. * 显示重命名框
  62. */
  63. showModify: function () {
  64. this.setData({
  65. showMore: false,
  66. showModify: true,
  67. })
  68. },
  69. /**
  70. * 修改设备名
  71. */
  72. modifyName: function (form) {
  73. const that = this;
  74. const params = {
  75. num: this.data.currentDevice.deviceNum,
  76. name: form.detail.value.deviceName
  77. }
  78. APP.Post(APP.Url.modifyDeviceName, params).then(res => {
  79. APP.Modal.tips("修改成功");
  80. that.hideAll();
  81. that.getDeviceList();
  82. })
  83. },
  84. /**
  85. * 跳转至添加设备
  86. */
  87. toAddDevice: function () {
  88. APP.Route.routeTo(APP.Route.path.addition);
  89. },
  90. /**
  91. * 显示更多
  92. */
  93. showMore: function (event) {
  94. let deviceNum = event.currentTarget.dataset.num;
  95. for (let i = 0; i < this.data.deviceList.length; i++) {
  96. if (this.data.deviceList[i].deviceNum == deviceNum) {
  97. this.setData({
  98. currentDevice: this.data.deviceList[i],
  99. showMore: true,
  100. showModify: false,
  101. })
  102. break;
  103. }
  104. }
  105. },
  106. /**
  107. * 隐藏所有模态框
  108. */
  109. hideAll: function () {
  110. this.setData({
  111. showMore: false,
  112. showModify: false,
  113. })
  114. },
  115. })