C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

186 wiersze
4.8 KiB

  1. const Http = require("../../utils/HttpBasics");
  2. const config = require("../../config/config");
  3. let app = getApp();
  4. Page({
  5. data: {
  6. market: app.globalData.market,
  7. list: [],
  8. swiperCurrent: 0,
  9. scrollTop: 0,
  10. page: 1 // 刷新进入页面时已经加载了第一页数据,onReachBottom时 page++,从第2页开始加载
  11. },
  12. swiperChange: function(e) {
  13. this.setData({
  14. swiperCurrent: e.detail.current
  15. });
  16. },
  17. /**
  18. * 生命周期函数--监听页面初次渲染完成
  19. */
  20. onLoad: function(options) {
  21. var that = this;
  22. var scene = decodeURIComponent(options.scene);
  23. app.getLocation();
  24. },
  25. onShow: function() {
  26. this.userLogin()
  27. },
  28. onGetCode: function(e) {
  29. //子组件传递给父组件的值
  30. this.setData({
  31. code: e.detail.val,
  32. page: e.detail.pageNum
  33. });
  34. },
  35. /**
  36. * 用户登录
  37. */
  38. userLogin: function() {
  39. var that = this;
  40. // 登录
  41. wx.login({
  42. success: ({
  43. code
  44. }) => {
  45. Http.post({
  46. url: config.api.login,
  47. data: {
  48. appId: config.weapp.AppId,
  49. code: code,
  50. sceneAddress: app.globalData.sceneAddress,
  51. latitude: '' + app.globalData.locationInfo.latitude,
  52. longitude: '' + app.globalData.locationInfo.longitude,
  53. }
  54. })
  55. .then(res => {
  56. console.log("userlogin:app", res);
  57. app.globalData.token = res.data.token;
  58. Http.setToken(res.data.token);
  59. that.checkUserCarStatus();
  60. that.getUserInfo();
  61. if (app.couponChannelListCallback) {
  62. app.couponChannelListCallback(app.globalData.token);
  63. }
  64. if (app.couponListCallback) {
  65. app.couponListCallback(app.globalData.token);
  66. }
  67. if (app.businessListCallback) {
  68. app.businessListCallback(app.globalData.token);
  69. }
  70. return Http.post({
  71. url: config.api.checkUserStatus,
  72. data: {}
  73. });
  74. })
  75. .then(res => {
  76. console.log("checkUserStatus:res", res);
  77. })
  78. .catch(err => {
  79. console.log("checkUserStatus:err", err);
  80. if (err.code == 11004) {
  81. // 用户昵称未授权
  82. wx.redirectTo({
  83. url: "/pages/getuserinfo/index"
  84. });
  85. }
  86. });
  87. }
  88. });
  89. },
  90. /**
  91. * 检查用户是否有车
  92. */
  93. checkUserCarStatus: function() {
  94. var that = this;
  95. Http.get({
  96. url: config.api.userCarCount,
  97. data: {}
  98. }).then(res => {
  99. if (res.data > 0) {
  100. // 用户名下有车
  101. app.globalData.phone = res.data.phone;
  102. app.globalData.supportCar = true;
  103. // 共同登录
  104. that.userCarLogin();
  105. }
  106. });
  107. },
  108. /**
  109. * car共同登录
  110. */
  111. userCarLogin: function() {
  112. var that = this;
  113. if (!app.globalData.carLogin) {
  114. // 共同登录
  115. Http.post({
  116. url: config.api.carInit,
  117. data: {
  118. phone: app.globalData.phone
  119. }
  120. }).then(res => {
  121. app.globalData.carLogin = true;
  122. app.globalData.parkVendor = res.data.vendor;
  123. if (res.data.token != "undefined") {
  124. app.globalData.etcpToken = res.data.token;
  125. console.log("etcpToken", app.globalData.etcpToken);
  126. }
  127. });
  128. }
  129. },
  130. /**
  131. * 获取用户信息
  132. */
  133. getUserInfo: function() {
  134. // 获取用户信息
  135. wx.getSetting({
  136. success: res => {
  137. console.log("getSetting", res);
  138. if (res.authSetting["scope.userInfo"]) {
  139. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  140. wx.getUserInfo({
  141. success: res => {
  142. // 可以将 res 发送给后台解码出 unionId
  143. console.log("getUserInfo", res);
  144. }
  145. });
  146. }
  147. }
  148. });
  149. },
  150. //下拉加载更多
  151. onReachBottom: function() {
  152. let that = this;
  153. console.info("before++ " + that.data.page);
  154. that.data.page++;
  155. console.info("after++ " + that.data.page);
  156. that.setData({
  157. page: that.data.page
  158. });
  159. //父组件获得子组件的方法
  160. //如果code == 0
  161. if (that.data.code == 0 || that.data.code == undefined) {
  162. that.selectComponent("#lists").getList(0, that.data.page);
  163. } else {
  164. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  165. }
  166. },
  167. // 用户点击右上角分享
  168. onShareAppMessage: function() {
  169. return {
  170. title: "富茂链客",
  171. desc: "分享个小程序,希望你喜欢",
  172. success: function(res) {
  173. wx.showToast({
  174. title: "分享成功",
  175. duration: 1000,
  176. icon: "success"
  177. });
  178. }
  179. };
  180. }
  181. });