confirm.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import Dialog from '@vant/weapp/dialog/dialog';
  2. const util = require('../../../../utils/util.js');
  3. const api = require('../../../../config/api.js');
  4. const user = require('../../../../utils/user.js');
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. loginCode: '',
  12. detail: '',
  13. userName: '',
  14. avatarUrl: '',
  15. codeShow: false,
  16. code: '',
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. this.setData({
  23. userName: app.globalData.recommend.userName,
  24. avatarUrl: app.globalData.recommend.avatarUrl
  25. })
  26. },
  27. getPhoneNumber(e) {
  28. console.log(e);
  29. this.setData({
  30. detail: e.detail
  31. })
  32. this.getDenPhone();
  33. },
  34. getDenPhone() {
  35. util.request(api.GetDenPhone, {
  36. code: this.data.loginCode,
  37. encryptedData: this.data.detail.encryptedData,
  38. errMsg: this.data.detail.errMsg,
  39. iv: this.data.detail.iv
  40. }, "POST")
  41. .then((res) => {
  42. if (res.errno == 0) {
  43. let isNew = res.data.isNew;
  44. if (isNew) {
  45. app.globalData.recommend.phone = res.data.phone;
  46. app.globalData.recommend.unionId = res.data.unionId;
  47. app.globalData.recommend.openId = res.data.openId;
  48. app.globalData.recommend.sessionKey = res.data.sessionKey;
  49. wx.navigateTo({
  50. url: '../register/register',
  51. })
  52. } else {
  53. // 不是新人,则跳转到首页
  54. Dialog.alert({
  55. title: '引荐失败',
  56. message: '您已是鲸致商城用户,当前引荐人计划只面向新用户,敬请期待',
  57. }).then(() => {
  58. // on close
  59. wx.switchTab({
  60. url: '/pages/index/index',
  61. });
  62. });
  63. }
  64. } else {
  65. util.showErrorToast(res.errmsg);
  66. this.getLoginCode();
  67. }
  68. });
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function () {
  74. },
  75. getLoginCode() {
  76. let that = this;
  77. user.login().then(res => {
  78. that.setData({
  79. loginCode: res.code
  80. })
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. this.getLoginCode();
  88. },
  89. showDialog() {
  90. this.setData({
  91. codeShow: true
  92. })
  93. },
  94. onClickHide() {
  95. this.setData({
  96. codeShow: false
  97. })
  98. },
  99. codeInput(e) {
  100. this.setData({
  101. code: e.detail.value
  102. })
  103. },
  104. confirm() {
  105. if (this.data.code == '') {
  106. wx.showToast({
  107. title: '请输入邀请码',
  108. icon: 'none',
  109. duration: 2000
  110. })
  111. } else {
  112. util.request(api.RefBcodeInfo, {
  113. bcode: this.data.code,
  114. }, "GET")
  115. .then((res) => {
  116. if (res.errno == 0) {
  117. app.globalData.recommend = {
  118. bCode: res.data.refereeCode,
  119. userName: res.data.refereeName,
  120. avatarUrl: res.data.refereeAvatar
  121. };
  122. app.globalData.rId = res.data.refereeId;
  123. this.setData({
  124. userName: res.data.refereeName,
  125. avatarUrl: res.data.refereeAvatar,
  126. codeShow: false
  127. })
  128. } else {
  129. util.showErrorToast(res.errmsg);
  130. }
  131. });
  132. }
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function () {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function () {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function () {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function () {
  158. }
  159. })