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.

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