bound.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/bound/bound.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { UntieDerver, BindConch} from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. baseImgUrl,
  14. thumbnail,
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function (options) {
  20. console.log(options)
  21. this.setData(options);
  22. },
  23. /**
  24. * 生命周期函数--监听页面初次渲染完成
  25. */
  26. onReady: function () {
  27. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  28. for (const i in obj) {
  29. this[i] = obj[i]
  30. }
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面卸载
  44. */
  45. onUnload: function () {
  46. },
  47. /**
  48. * 页面相关事件处理函数--监听用户下拉动作
  49. */
  50. onPullDownRefresh: function () {
  51. },
  52. /**
  53. * 页面上拉触底事件的处理函数
  54. */
  55. onReachBottom: function () {
  56. },
  57. /**
  58. * 用户点击右上角分享
  59. */
  60. onShareAppMessage: function () {
  61. },
  62. /**
  63. * 获取定位经纬度
  64. */
  65. getLocation: function () {
  66. wx.showLoading({
  67. title: '定位中'
  68. })
  69. wx.getLocation({
  70. type: 'wgs84',
  71. success: res => {
  72. this.setData({
  73. longitude: res.longitude, // '113.36403' ||
  74. latitude: res.latitude // '23.14203' ||
  75. })
  76. this.getBindConch()
  77. },
  78. fail: res => {
  79. wx.showToast({
  80. title: '定位失败',
  81. icon: 'none'
  82. })
  83. },
  84. complete: res => {
  85. wx.hideLoading()
  86. }
  87. })
  88. },
  89. /**
  90. * 获取数据
  91. */
  92. getData: function (cb) {
  93. const continuousFn = { fn: this.getData, param: { ...arguments } }
  94. const { derver } = this.data
  95. UntieDerver({ data: { derver }, continuousFn }).then(res => {
  96. wx.showToast({
  97. title: '解绑成功',
  98. icon: 'none'
  99. })
  100. this.setData({ derver:""})
  101. if (isFn(cb)) cb()
  102. }).catch(res => {
  103. this.setData({ isLoaded: true })
  104. if (isFn(cb)) cb()
  105. })
  106. },
  107. /**
  108. * 去绑定
  109. */
  110. getBindConch: function (cb) {
  111. const continuousFn = { fn: this.getBindConch, param: { ...arguments } }
  112. const { vipId,longitude, latitude } = this.data
  113. var that=this
  114. wx.scanCode({
  115. onlyFromCamera: true,
  116. success: (e) => {
  117. console.log(e)
  118. // if (e.result.indexOf('https://t.sharingschool.com') != -1) {
  119. BindConch({ data: { vipId, qrCode: e.result, longitude, latitude }, continuousFn }).then(res => {
  120. const {derver}=this.data;
  121. that.setData({derver})
  122. wx.showToast({
  123. title: '绑定成功',
  124. icon: 'none'
  125. })
  126. if (isFn(cb)) cb()
  127. }).catch(res => {
  128. this.setData({ isLoaded: true })
  129. if (isFn(cb)) cb()
  130. })
  131. // } else {
  132. // wx.showToast({
  133. // title: '二维码不正确',
  134. // icon: 'none',
  135. // duration: 1000
  136. // })
  137. // }
  138. }
  139. })
  140. }
  141. })