邃芒智像相册
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

187 行
3.3 KiB

  1. const app = getApp()
  2. import request from '../../utils/request'
  3. import Dialog from '@vant/weapp/dialog/dialog';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isAgree: false,
  10. tmpUserId: ""
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. console.log(options, 'options');
  17. wx.hideHomeButton()
  18. if (options.scene) {
  19. this.setData({
  20. tmpUserId: options.scene
  21. })
  22. }
  23. app.tokenCallBack = token => {
  24. if (token) {
  25. this.bindUser()
  26. } else {
  27. }
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow() {
  34. },
  35. getPhoneNumber(e) {
  36. const that = this
  37. if (e.detail.iv) {
  38. const openId = wx.getStorageSync('openId')
  39. const appId = request.appId
  40. const iv = e.detail.iv
  41. const encryptedData = e.detail.encryptedData
  42. const data = {
  43. openId,
  44. appId,
  45. encryptedData,
  46. iv
  47. }
  48. that.loginWithPhone(data)
  49. } else {
  50. that.getPhoneNumberFail()
  51. wx.showToast({
  52. title: '授权失败',
  53. icon: "error"
  54. })
  55. }
  56. },
  57. checkUserPro() {
  58. if (!this.data.isAgree) {
  59. Dialog.confirm({
  60. title: '提示',
  61. message: '同意智像相机用户使用协议?',
  62. })
  63. .then(() => {
  64. this.setData({
  65. isAgree: true
  66. })
  67. })
  68. .catch(() => {
  69. // on cancel
  70. });
  71. }
  72. },
  73. // 用户协议状态变更
  74. checkboxChange(e) {
  75. if (e.detail.value[0]) {
  76. this.setData({
  77. isAgree: true
  78. })
  79. } else {
  80. this.setData({
  81. isAgree: false
  82. })
  83. }
  84. },
  85. // 查看用户协议
  86. goPro() {
  87. wx.navigateTo({
  88. url: '/pages/userProtocol/userProtocol',
  89. })
  90. },
  91. loginWithPhone(data) {
  92. const that = this
  93. request.post({
  94. url: '/api/miniApp/loginPhone',
  95. data
  96. }).then(res => {
  97. // 获取手机号之后,绑定用户与机器
  98. that.bindUser()
  99. }).catch(err => {
  100. console.log(err, 'err');
  101. })
  102. },
  103. // 绑定用户与机器
  104. bindUser() {
  105. const openId = wx.getStorageSync('openId')
  106. const tmpUserId = this.data.tmpUserId
  107. const data = {
  108. openId,
  109. tmpUserId
  110. }
  111. request.post({
  112. url: '/api/miniApp/bindUser',
  113. data
  114. }).then(res => {
  115. console.log(res, 'res');
  116. wx.showToast({
  117. title: '登录成功!',
  118. icon: "success",
  119. duration: 1500,
  120. complete: () => {
  121. setTimeout(() => {
  122. if (tmpUserId) {
  123. wx.setStorageSync('isPay', false)
  124. wx.redirectTo({
  125. url: `/pages/index/index?machineQrcodeId=${tmpUserId}`,
  126. })
  127. } else {
  128. wx.redirectTo({
  129. url: `/pages/index/index`,
  130. })
  131. }
  132. }, 1500);
  133. }
  134. })
  135. }).catch(err => {
  136. console.log(err, 'err');
  137. wx.showToast({
  138. title: '服务器异常,请稍后再试',
  139. icon: "none"
  140. })
  141. })
  142. },
  143. getPhoneNumberFail() {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh() {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom() {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage() {
  159. }
  160. })