devices.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const APP = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. //设备集合
  8. devices: [],
  9. //默认设备
  10. defaultDevice: 1,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. this.list()
  17. },
  18. /**
  19. * 设备列表
  20. */
  21. list() {
  22. const params = {
  23. openId: APP.globalData.openId
  24. }
  25. APP.Get(APP.Url.listBindDevices, params).then(res => {
  26. this.setData({
  27. devices: res.data
  28. })
  29. })
  30. },
  31. /**
  32. * 切换当前设备
  33. */
  34. changeDevice(event) {
  35. const that = this;
  36. const params = {
  37. openNum: event.currentTarget.dataset.opennum
  38. }
  39. wx.showModal({
  40. title: '提示',
  41. content: '确定切换到该设备吗',
  42. success(res) {
  43. if (res.confirm) {
  44. APP.Post(APP.Url.switchDefaultDevice, params).then(res => {
  45. APP.Modal.tips("切换成功");
  46. that.list();
  47. })
  48. }
  49. }
  50. })
  51. },
  52. unbind(event) {
  53. const that = this;
  54. const params = {
  55. openNum: event.currentTarget.dataset.opennum
  56. }
  57. wx.showModal({
  58. title: '提示',
  59. content: '确定解绑该设备吗?',
  60. success(res) {
  61. if (res.confirm) {
  62. APP.Post(APP.Url.unbind, params).then(res => {
  63. APP.Modal.tips("解除成功");
  64. that.list();
  65. })
  66. }
  67. }
  68. })
  69. }
  70. })