C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

246 行
6.1 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. gotogame:function(){
  18. wx.navigateTo({
  19. url: '/pages/game/game',
  20. })
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onLoad: function(options) {
  26. var that = this;
  27. var scene = decodeURIComponent(options.scene);
  28. that.setData({
  29. scene:scene
  30. })
  31. console.log(that.data.scene)
  32. console.log(scene);
  33. app.getLocation();
  34. that.userLogin();
  35. },
  36. onShow:function(){
  37. let num = wx.getStorageSync('couponNum');
  38. if (num =='couponNum'){
  39. wx.showTabBarRedDot({
  40. index: 2
  41. })
  42. }
  43. },
  44. /**
  45. * 下拉刷新
  46. */
  47. onPullDownRefresh: function(e) {
  48. let that = this;
  49. that.userLogin();
  50. console.log(this.data.code);
  51. if (that.data.code == 0 || that.data.code == undefined) {
  52. that.selectComponent("#lists").getList(0, 1);
  53. wx.stopPullDownRefresh();
  54. console.log("下拉刷新");
  55. } else {
  56. that.selectComponent("#lists").getList(that.data.code, 1);
  57. wx.stopPullDownRefresh();
  58. };
  59. },
  60. onGetCode: function(e) {
  61. //子组件传递给父组件的值
  62. this.setData({
  63. code: e.detail.val,
  64. page: e.detail.pageNum
  65. });
  66. },
  67. /**
  68. * 用户登录
  69. */
  70. userLogin: function() {
  71. var that = this;
  72. // 登录
  73. wx.login({
  74. success: ({
  75. code
  76. }) => {
  77. var usrdata = {
  78. appId: config.weapp.AppId,
  79. code: code,
  80. sceneAddress: app.globalData.sceneAddress,
  81. scene: that.data.scene
  82. };
  83. if (app.globalData.locationInfo) {
  84. usrdata = {
  85. appId: config.weapp.AppId,
  86. code: code,
  87. sceneAddress: app.globalData.sceneAddress,
  88. latitude: "" + app.globalData.locationInfo.latitude,
  89. longitude: "" + app.globalData.locationInfo.longitude,
  90. scene: that.data.scene
  91. };
  92. }
  93. Http.post({
  94. url: config.api.login,
  95. data: usrdata
  96. })
  97. .then(res => {
  98. console.log("userlogin:app", res);
  99. app.globalData.token = res.data.token;
  100. Http.setToken(res.data.token);
  101. that.checkUserCarStatus();
  102. that.getUserInfo();
  103. that.getBannerlist();
  104. if (app.couponChannelListCallback) {
  105. app.couponChannelListCallback(app.globalData.token);
  106. }
  107. if (app.couponListCallback) {
  108. app.couponListCallback(app.globalData.token);
  109. }
  110. if (app.businessListCallback) {
  111. app.businessListCallback(app.globalData.token);
  112. }
  113. return Http.post({
  114. url: config.api.checkUserStatus,
  115. data: {}
  116. });
  117. })
  118. .then(res => {
  119. console.log("checkUserStatus:res", res);
  120. })
  121. .catch(err => {
  122. console.log("checkUserStatus:err", err);
  123. if (err.code == 11004) {
  124. // 用户昵称未授权
  125. wx.redirectTo({
  126. url: "/pages/getuserinfo/index"
  127. });
  128. }
  129. });
  130. }
  131. });
  132. },
  133. /**
  134. * banner
  135. */
  136. getBannerlist: function() {
  137. let that = this;
  138. Http.get({
  139. url: config.api.bannerlist,
  140. data: {
  141. pageNum: 1,
  142. pageSize: 7
  143. }
  144. }).then(res => {
  145. console.log(res);
  146. that.setData({
  147. list: res.data.list
  148. });
  149. });
  150. },
  151. /**
  152. * 检查用户是否有车
  153. */
  154. checkUserCarStatus: function() {
  155. var that = this;
  156. Http.get({
  157. url: config.api.userCarCount,
  158. data: {}
  159. }).then(res => {
  160. if (res.data > 0) {
  161. // 用户名下有车
  162. app.globalData.phone = res.data.phone;
  163. app.globalData.supportCar = true;
  164. // 共同登录
  165. that.userCarLogin();
  166. }
  167. });
  168. },
  169. /**
  170. * car共同登录
  171. */
  172. userCarLogin: function() {
  173. var that = this;
  174. if (!app.globalData.carLogin) {
  175. // 共同登录
  176. Http.post({
  177. url: config.api.carInit,
  178. data: {
  179. phone: app.globalData.phone
  180. }
  181. }).then(res => {
  182. app.globalData.carLogin = true;
  183. app.globalData.parkVendor = res.data.vendor;
  184. if (res.data.token != "undefined") {
  185. app.globalData.etcpToken = res.data.token;
  186. console.log("etcpToken", app.globalData.etcpToken);
  187. }
  188. });
  189. }
  190. },
  191. /**
  192. * 获取用户信息
  193. */
  194. getUserInfo: function() {
  195. // 获取用户信息
  196. wx.getSetting({
  197. success: res => {
  198. console.log("getSetting", res);
  199. if (res.authSetting["scope.userInfo"]) {
  200. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  201. wx.getUserInfo({
  202. success: res => {
  203. // 可以将 res 发送给后台解码出 unionId
  204. console.log("getUserInfo", res);
  205. }
  206. });
  207. }
  208. }
  209. });
  210. },
  211. //下拉加载更多
  212. onReachBottom: function() {
  213. let that = this;
  214. that.data.page++;
  215. that.setData({
  216. page: that.data.page
  217. });
  218. console.log("我是第" + that.data.page + "几页")
  219. //父组件获得子组件的方法
  220. //如果code == 0
  221. if (that.data.code == 0 || that.data.code == undefined) {
  222. that.selectComponent("#lists").getList(0, that.data.page);
  223. } else {
  224. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  225. }
  226. },
  227. // 用户点击右上角分享
  228. onShareAppMessage: function() {
  229. return {
  230. title: "富茂链客",
  231. desc: "分享个小程序,希望你喜欢",
  232. success: function(res) {
  233. wx.showToast({
  234. title: "分享成功",
  235. duration: 1000,
  236. icon: "success"
  237. });
  238. }
  239. };
  240. }
  241. });