hardwareBind.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. const app = getApp();
  2. const request = require('../../utils/request.js');
  3. const tools = require('../../utils/tools.js');
  4. import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
  5. Page({
  6. data: {
  7. num: '',
  8. hardTypeArrAll: [],
  9. hardTypeArr: [],
  10. showPicker: false,
  11. index:''
  12. },
  13. onLoad: function (options) {
  14. this.setData({
  15. num: options.code
  16. })
  17. },
  18. async bd() {
  19. console.log(this.data.num)
  20. let options = {
  21. url: 'resource/miniapp/user/bindEquip',
  22. data: {
  23. devicenum: this.data.num,
  24. devicetype: this.data.hardTypeArrAll.filter((item,idx) => {
  25. return idx === this.data.index
  26. })[0].id,
  27. openId: wx.getStorageSync('openid'),
  28. type: app.globalData.type
  29. // 种类加上
  30. },
  31. method: 'post'
  32. }
  33. let res = await request.query(options);
  34. if (res.data.code === 200) {
  35. wx.showModal({
  36. title: '提示',
  37. content: '绑定成功',
  38. showCancel: false,
  39. success: (res) => {
  40. if (res.confirm) {
  41. wx.navigateTo({
  42. url: '/pages/hardwareDetails/hardwareDetails',
  43. })
  44. }
  45. }
  46. })
  47. } else {
  48. Toast.fail(res.data.msg);
  49. }
  50. },
  51. typeClick() {
  52. this.setData({
  53. showPicker: true
  54. })
  55. },
  56. onConfirm(e) {
  57. console.log(e)
  58. this.setData({
  59. showPicker: false,
  60. type: e.detail.value,
  61. index: e.detail.index
  62. })
  63. },
  64. onCancel() {
  65. this.setData({
  66. showPicker: false
  67. })
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. async getType() {
  75. let options = {
  76. url: 'resource/miniapp/user/getDeviceType',
  77. data: {},
  78. method: 'post'
  79. }
  80. let res = await request.query(options);
  81. if (res.data.code === 200) {
  82. let arr = [];
  83. res.data.data.map(item => {
  84. arr.push(item.name + '-' + item.model+'-'+item.manufactor)
  85. })
  86. this.setData({
  87. hardTypeArrAll: res.data.data,
  88. hardTypeArr: arr
  89. })
  90. console.log(res.data.data)
  91. } else {
  92. Toast.fail(res.data.msg);
  93. }
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow: function () {
  99. if (!wx.getStorageSync('userId')) {
  100. wx.showModal({
  101. title: '提示',
  102. content: '请扫描二维码进入小程序',
  103. showCancel: false,
  104. success: (res) => {
  105. if (res.confirm) {
  106. wx.navigateTo({
  107. url: '/pages/login/login',
  108. })
  109. }
  110. }
  111. })
  112. return false;
  113. }
  114. tools.isLogin().then((res) => {
  115. this.getType();
  116. }, (error) => {
  117. console.log(error);
  118. })
  119. },
  120. /**
  121. * 生命周期函数--监听页面隐藏
  122. */
  123. onHide: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面卸载
  127. */
  128. onUnload: function () {
  129. },
  130. /**
  131. * 页面相关事件处理函数--监听用户下拉动作
  132. */
  133. onPullDownRefresh: function () {
  134. },
  135. /**
  136. * 页面上拉触底事件的处理函数
  137. */
  138. onReachBottom: function () {
  139. },
  140. /**
  141. * 用户点击右上角分享
  142. */
  143. onShareAppMessage: function () {
  144. }
  145. })