C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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