C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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