C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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