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.

152 lines
3.7 KiB

  1. // pages/index/sw/index.js
  2. let config = require("../../../config/config.js");
  3. let Http = require("../../../utils/HttpBasics");
  4. let app = getApp();
  5. // 请求数据
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {},
  11. /**
  12. * 组件的初始数据
  13. */
  14. data: {
  15. tabs: [],
  16. list: [],
  17. flag: "",
  18. return_list: [],
  19. current: 0,
  20. current_scroll: 0,
  21. pageNum: 1, // 设置加载的第几次,默认是第一次
  22. pageSize: 10, //返回数据的个数
  23. searchLoading: false, //"上拉加载"的变量,默认false,隐藏
  24. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  25. allow_load: true // 是否允许继续加载标识 默认 true 允许,false 加载完成
  26. },
  27. /**
  28. * 组件的方法列表
  29. */
  30. methods: {
  31. handleChange({ detail }) {
  32. this.setData({
  33. current: detail.key
  34. });
  35. },
  36. handleChangeScroll({ detail }) {
  37. let that = this;
  38. // 切换tab时重新初始化下list 和 allow_load
  39. that.setData({
  40. current_scroll: detail.key,
  41. flag: "click",
  42. list: [],
  43. allow_load: true
  44. });
  45. this.getList(detail.key, 1);
  46. var val = detail.key;
  47. //通过这个传递数据
  48. var myEventDetail = {
  49. val: val,
  50. pageNum: 1
  51. };
  52. // detail对象,提供给事件监听函数
  53. this.triggerEvent("myevent", myEventDetail);
  54. },
  55. getList(key, pageNum) {
  56. var that = this;
  57. app.couponListCallback = token => {
  58. Http.setToken(token);
  59. // 券list获取
  60. if (that.data.allow_load) {
  61. wx.showLoading({
  62. title: "飞速加载中"
  63. });
  64. // 根据 key == 0 区分全部或其它tab,决定是否传参数 business
  65. if (key == 0) {
  66. var param = {
  67. pageNum: pageNum,
  68. pageSize: 8,
  69. targetAd: 1
  70. };
  71. } else {
  72. var param = {
  73. pageNum: pageNum,
  74. pageSize: 8,
  75. business: key,
  76. targetAd: 1
  77. };
  78. }
  79. // 请求接口
  80. Http.get({
  81. url: config.api.couponChannelList,
  82. data: param
  83. }).then(res => {
  84. console.log(res);
  85. if (pageNum >= res.data.pages) {
  86. // wx.showToast({
  87. // title: "加载完成喽",
  88. // icon: "success"
  89. // });
  90. that.setData({
  91. allow_load: false
  92. });
  93. }
  94. /**
  95. * 先赋值后渲染页面
  96. * concat 不会改变原数组值
  97. * push 会改变原数组值,但不会一条一条插入,而是整个数组插入
  98. */
  99. that.data.list = that.data.list.concat(res.data.list);
  100. that.setData({
  101. list: that.data.list
  102. });
  103. });
  104. setTimeout(function() {
  105. wx.hideLoading();
  106. }, 1000);
  107. } else {
  108. console.info("allow_load==false 已禁止加载");
  109. }
  110. };
  111. if (app.globalData.token && app.globalData.token != null) {
  112. app.couponListCallback(app.globalData.token);
  113. }
  114. }
  115. },
  116. ready() {
  117. let that = this;
  118. app.businessListCallback = token => {
  119. Http.setToken(token);
  120. // business获取
  121. Http.get({
  122. url: config.api.businessList,
  123. data: {
  124. pageNum: 1,
  125. pageSize: 10,
  126. type: 1
  127. }
  128. }).then(res => {
  129. that.setData({
  130. tabs: res.data.list
  131. });
  132. });
  133. };
  134. if (app.globalData.token && app.globalData.token != null) {
  135. app.businessListCallback(app.globalData.token);
  136. }
  137. that.getList(0, 1);
  138. }
  139. });