业务交流通
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // pages/login/login.js
  2. const app = getApp()
  3. const $request = require('../../utils/request.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userInfo: null,
  10. // 是否获取到了用户信息
  11. hasUserInfo: false,
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. const userInfo = wx.getStorageSync('userInfo') || null;
  18. if (app.globalData.userInfo || userInfo) {
  19. this.setData({
  20. userInfo
  21. })
  22. }
  23. },
  24. onShow(){
  25. this.setData({
  26. currentIndex: 2
  27. })
  28. },
  29. // 没有授权用户信息点授权手机提示
  30. showTotal(){
  31. wx.showToast({
  32. title: '请先允许访问头像、昵称及地区信息',
  33. icon: "none",
  34. duration: 2000
  35. })
  36. },
  37. // 获取手机号授权
  38. getPhoneNumber(e) {
  39. console.log(e);
  40. if (!!e.detail.iv && !!e.detail.encryptedData) {
  41. const iv = e.detail.iv
  42. const encryptedData = e.detail.encryptedData
  43. this.appletLogin(iv, encryptedData)
  44. } else {
  45. wx.showToast({
  46. title: '请允许授权',
  47. icon: "none",
  48. duration: 3000
  49. })
  50. }
  51. },
  52. // 保存用户信息
  53. appletLogin(iv, encryptedData) {
  54. wx.showLoading({
  55. title: '登录中...',
  56. mask: true
  57. })
  58. let { nickName, gender, country, city, province, avatarUrl } = this.data.userInfo;
  59. $request.get('/com/appletLogin.action', {
  60. // openid: app.globalData.openid,
  61. iv: iv,
  62. encryptedData: encryptedData,
  63. sessionKey: app.globalData.sessionKey,
  64. loginState: "需求对对碰",
  65. avatarUrl,
  66. gender,
  67. nickName,
  68. country,
  69. province,
  70. city
  71. }).then(res => {
  72. console.log(res, '保存用户信息返回的Res')
  73. this.getUserSession()
  74. }).catch(error => {
  75. console.log(error, 'error appletLogin')
  76. })
  77. },
  78. // 获取用户信息弹框
  79. onCheckboxChange() {
  80. if (!this.data.hasUserInfo) {
  81. if (!this.data.userInfo) {
  82. this.getUserProfile()
  83. } else {
  84. this.setData({
  85. hasUserInfo: true
  86. })
  87. }
  88. } else {
  89. this.setData({
  90. hasUserInfo: false
  91. })
  92. }
  93. },
  94. // 获取用户信息
  95. getUserProfile(e) {
  96. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  97. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  98. wx.getUserProfile({
  99. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  100. lang:"zh_CN",
  101. success: (res) => {
  102. this.setData({
  103. userInfo: res.userInfo,
  104. hasUserInfo: true
  105. })
  106. wx.setStorageSync('userInfo', res.userInfo)
  107. },
  108. fail: () => {
  109. wx.showToast({
  110. title: '请允许授权',
  111. icon: "none",
  112. duration: 3000
  113. })
  114. }
  115. })
  116. },
  117. // 保存个人信息后拿到新数据
  118. getUserSession() {
  119. let that = this
  120. $request.post('/script/getSession.action', {}).then(res => {
  121. wx.hideLoading()
  122. console.log(res, '返回的res')
  123. let businessCommunicationCustomer = res.data.businessCommunicationCustomer;
  124. app.globalData.customerId = businessCommunicationCustomer.customerId;
  125. app.globalData.customer = res.data.customer;
  126. app.globalData.businessCommunicationCustomer = businessCommunicationCustomer;
  127. wx.setStorageSync('businessCommunicationCustomer', businessCommunicationCustomer)
  128. let pages = getCurrentPages();
  129. let Page = pages[pages.length - 1];//当前页
  130. let prevPage = pages[pages.length - 2]; //上一个页面
  131. let info = prevPage.data //取上页data里的数据也可以修改
  132. // 如果是上一页是我的页面
  133. if (prevPage.route == "pages/myModule/index") {
  134. if (res.data.customer.paidByMonth) {
  135. businessCommunicationCustomer.nickName = res.data.customer.nickName;
  136. businessCommunicationCustomer.isPartner = true;
  137. } else {
  138. businessCommunicationCustomer.isPartner = false;
  139. }
  140. prevPage.setData({
  141. user: businessCommunicationCustomer,
  142. isLogin:true
  143. })
  144. wx.navigateBack()
  145. } else {
  146. wx.navigateBack()
  147. }
  148. // let tempListData = info.listData;
  149. // tempListData.forEach(el => {
  150. // if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  151. // el.info = Page.data.detailValue
  152. // }
  153. // })
  154. // prevPage.setData({ listData: tempListData })//设置数据
  155. // wx.navigateBack()
  156. }).catch(error => {
  157. console.log(error, "获取error")
  158. })
  159. },
  160. })