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.

101 line
2.6 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. if (app.globalData.token && app.globalData.token != null) {
  24. } else {
  25. // 由于是网络请求,可能会在 Page.onLoad 之后才返回
  26. // 所以此处加入 callback 以防止这种情况
  27. wx.login({
  28. success: ({ code }) => {
  29. console.log(code);
  30. Http.post({
  31. url: config.api.login,
  32. data: {
  33. appId: config.weapp.AppId,
  34. code: code,
  35. sceneAddress: app.globalData.sceneAddress
  36. }
  37. }).then(res => {
  38. //banner渲染
  39. app.globalData.token = res.data.token;
  40. Http.setToken(res.data.token);
  41. if (res.code == 200) {
  42. Http.get({
  43. url: config.api.bannerlist,
  44. data: {
  45. pageNum: 1,
  46. pageSize: 10
  47. }
  48. }).then(res => {
  49. that.setData({
  50. list: res.data.list
  51. });
  52. });
  53. }
  54. });
  55. }
  56. });
  57. }
  58. },
  59. onGetCode: function(e) {
  60. //子组件传递给父组件的值
  61. this.setData({
  62. code: e.detail.val,
  63. page: e.detail.pageNum
  64. });
  65. },
  66. //下拉加载更多
  67. onReachBottom: function() {
  68. let that = this;
  69. console.info("before++ " + that.data.page);
  70. that.data.page++;
  71. console.info("after++ " + that.data.page);
  72. that.setData({
  73. page: that.data.page
  74. });
  75. //父组件获得子组件的方法
  76. //如果code == 0
  77. if (that.data.code == 0 || that.data.code == undefined) {
  78. that.selectComponent("#lists").getList(0, that.data.page);
  79. } else {
  80. that.selectComponent("#lists").getList(that.data.code, that.data.page);
  81. }
  82. },
  83. // 用户点击右上角分享
  84. onShareAppMessage: function() {
  85. return {
  86. title: "富茂链客",
  87. desc: "分享个小程序,希望你喜欢",
  88. success: function(res) {
  89. wx.showToast({
  90. title: "分享成功",
  91. duration: 1000,
  92. icon: "success"
  93. });
  94. }
  95. };
  96. }
  97. });