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

login.js 5.1KB

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