业务交流通
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. if (!!e.detail.iv && !!e.detail.encryptedData) {
  40. const iv = e.detail.iv
  41. const encryptedData = e.detail.encryptedData
  42. this.appletLogin(iv, encryptedData)
  43. } else {
  44. wx.showToast({
  45. title: '请允许授权',
  46. icon: "none",
  47. duration: 3000
  48. })
  49. }
  50. },
  51. // 保存用户信息
  52. appletLogin(iv, encryptedData) {
  53. wx.showLoading({
  54. title: '登录中...',
  55. mask: true
  56. })
  57. let { nickName, gender, country, city, province, avatarUrl } = this.data.userInfo;
  58. $request.get('/com/appletLogin.action', {
  59. // openid: app.globalData.openid,
  60. iv: iv,
  61. encryptedData: encryptedData,
  62. sessionKey: app.globalData.sessionKey,
  63. loginState: "需求对对碰",
  64. avatarUrl,
  65. gender,
  66. nickName,
  67. country,
  68. province,
  69. city
  70. }).then(res => {
  71. this.getUserSession()
  72. }).catch(error => {
  73. console.log(error, 'error appletLogin')
  74. })
  75. },
  76. // 获取用户信息弹框
  77. onCheckboxChange() {
  78. if (!this.data.hasUserInfo) {
  79. if (!this.data.userInfo) {
  80. this.getUserProfile()
  81. } else {
  82. this.setData({
  83. hasUserInfo: true
  84. })
  85. }
  86. } else {
  87. this.setData({
  88. hasUserInfo: false
  89. })
  90. }
  91. },
  92. // 获取用户信息
  93. getUserProfile(e) {
  94. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
  95. // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  96. wx.getUserProfile({
  97. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  98. lang:"zh_CN",
  99. success: (res) => {
  100. this.setData({
  101. userInfo: res.userInfo,
  102. hasUserInfo: true
  103. })
  104. wx.setStorageSync('userInfo', res.userInfo)
  105. },
  106. fail: () => {
  107. wx.showToast({
  108. title: '请允许授权',
  109. icon: "none",
  110. duration: 3000
  111. })
  112. }
  113. })
  114. },
  115. // 保存个人信息后拿到新数据
  116. getUserSession() {
  117. let that = this
  118. $request.post('/script/getSession.action', {}).then(res => {
  119. wx.hideLoading()
  120. let businessCommunicationCustomer = res.data.businessCommunicationCustomer;
  121. app.globalData.customerId = businessCommunicationCustomer.customerId;
  122. app.globalData.customer = res.data.customer;
  123. app.globalData.businessCommunicationCustomer = businessCommunicationCustomer;
  124. wx.setStorageSync('businessCommunicationCustomer', businessCommunicationCustomer)
  125. let pages = getCurrentPages();
  126. let Page = pages[pages.length - 1];//当前页
  127. let prevPage = pages[pages.length - 2]; //上一个页面
  128. let info = prevPage.data //取上页data里的数据也可以修改
  129. // 如果是上一页是我的页面
  130. if (prevPage.route == "pages/myModule/index") {
  131. if (res.data.customer.paidByMonth) {
  132. businessCommunicationCustomer.nickName = res.data.customer.nickName;
  133. businessCommunicationCustomer.isPartner = true;
  134. } else {
  135. businessCommunicationCustomer.isPartner = false;
  136. }
  137. prevPage.setData({
  138. user: businessCommunicationCustomer,
  139. isLogin:true
  140. })
  141. wx.navigateBack()
  142. } else {
  143. wx.navigateBack()
  144. }
  145. // let tempListData = info.listData;
  146. // tempListData.forEach(el => {
  147. // if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  148. // el.info = Page.data.detailValue
  149. // }
  150. // })
  151. // prevPage.setData({ listData: tempListData })//设置数据
  152. // wx.navigateBack()
  153. }).catch(error => {
  154. console.log(error, "获取error")
  155. })
  156. },
  157. })