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.

262 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: '../game/index',
  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. app.globalData.token = res.data.token;
  116. Http.setToken(res.data.token);
  117. that.checkUserCarStatus();
  118. that.getUserInfo();
  119. that.getBannerlist();
  120. if (app.couponChannelListCallback) {
  121. app.couponChannelListCallback(app.globalData.token);
  122. }
  123. if (app.couponListCallback) {
  124. app.couponListCallback(app.globalData.token);
  125. }
  126. if (app.businessListCallback) {
  127. app.businessListCallback(app.globalData.token);
  128. }
  129. return Http.post({
  130. url: config.api.checkUserStatus,
  131. data: {}
  132. });
  133. })
  134. .then(res => {
  135. console.log("checkUserStatus:res", res);
  136. })
  137. .catch(err => {
  138. console.log("checkUserStatus:err", err);
  139. if (err.code == 11004) {
  140. // 用户昵称未授权
  141. wx.redirectTo({
  142. url: "/pages/getuserinfo/index"
  143. });
  144. }
  145. });
  146. }
  147. });
  148. },
  149. /**
  150. * banner
  151. */
  152. getBannerlist: function() {
  153. let that = this;
  154. Http.get({
  155. url: config.api.bannerlist,
  156. data: {
  157. pageNum: 1,
  158. pageSize: 7
  159. }
  160. }).then(res => {
  161. console.log(res);
  162. that.setData({
  163. list: res.data.list
  164. });
  165. });
  166. },
  167. /**
  168. * 检查用户是否有车
  169. */
  170. checkUserCarStatus: function() {
  171. var that = this;
  172. Http.get({
  173. url: config.api.userCarCount,
  174. data: {}
  175. }).then(res => {
  176. if (res.data > 0) {
  177. // 用户名下有车
  178. app.globalData.phone = res.data.phone;
  179. app.globalData.supportCar = true;
  180. // 共同登录
  181. that.userCarLogin();
  182. }
  183. });
  184. },
  185. /**
  186. * car共同登录
  187. */
  188. userCarLogin: function() {
  189. var that = this;
  190. if (!app.globalData.carLogin) {
  191. // 共同登录
  192. Http.post({
  193. url: config.api.carInit,
  194. data: {
  195. phone: app.globalData.phone
  196. }
  197. }).then(res => {
  198. app.globalData.carLogin = true;
  199. app.globalData.parkVendor = res.data.vendor;
  200. if (res.data.token != "undefined") {
  201. app.globalData.etcpToken = res.data.token;
  202. console.log("etcpToken", app.globalData.etcpToken);
  203. }
  204. });
  205. }
  206. },
  207. /**
  208. * 获取用户信息
  209. */
  210. getUserInfo: function() {
  211. // 获取用户信息
  212. wx.getSetting({
  213. success: res => {
  214. console.log("getSetting", res);
  215. if (res.authSetting["scope.userInfo"]) {
  216. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  217. wx.getUserInfo({
  218. success: res => {
  219. // 可以将 res 发送给后台解码出 unionId
  220. console.log("getUserInfo", res);
  221. }
  222. });
  223. }
  224. }
  225. });
  226. },
  227. //下拉加载更多
  228. onReachBottom: function() {
  229. let that = this;
  230. that.data.page++;
  231. that.setData({
  232. page: that.data.page
  233. });
  234. console.log("我是第" + that.data.page + "几页")
  235. //父组件获得子组件的方法
  236. //如果code == 0
  237. if (that.data.code == 0 || that.data.code == undefined) {
  238. that.selectComponent("#lists").getList(0, that.data.page);
  239. } else {
  240. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  241. }
  242. },
  243. // 用户点击右上角分享
  244. onShareAppMessage: function() {
  245. return {
  246. title: this.data.title,
  247. desc: this.data.desc,
  248. success: function(res) {
  249. wx.showToast({
  250. title: "分享成功",
  251. duration: 1000,
  252. icon: "success"
  253. });
  254. }
  255. };
  256. }
  257. });