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.

149 lines
3.9 KiB

  1. let config = require("../../config/config.js");
  2. let Http = require("../../utils/HttpBasics");
  3. const util = require("../../utils/util");
  4. const app = getApp();
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. linesUrl: imgurl.lines.url,
  12. loadingUrl: imgurl.loading.url,
  13. list: [],
  14. page: 1,
  15. allow_load: true,
  16. day: "",
  17. hour: "",
  18. minute: "",
  19. loading: true, //"上拉加载"的变量,默认false,隐藏
  20. content: "",
  21. showPage:false
  22. },
  23. //列表
  24. getList: function (page) {
  25. let that = this;
  26. app.couponChannelListCallback = token => {
  27. Http.setToken(token);
  28. /**
  29. * 判断用户是否加载完成
  30. */
  31. if (that.data.allow_load) {
  32. that.setData({
  33. loading: true,
  34. content: '小主,我在玩命加载中...'
  35. })
  36. Http.get({
  37. url: config.api.couponChannelList,
  38. data: {
  39. pageNum: page,
  40. pageSize: 8,
  41. targetAd: 2
  42. }
  43. })
  44. .then(res => {
  45. if(res.code == 200){
  46. that.setData({
  47. showPage:true
  48. })
  49. }
  50. if (page >= res.data.pages) {
  51. that.setData({
  52. allow_load: false
  53. });
  54. setTimeout(function () {
  55. that.setData({
  56. loading: false,
  57. })
  58. }, 1400);
  59. }
  60. setTimeout(function () {
  61. that.setData({
  62. loading: false,
  63. })
  64. }, 1400);
  65. var tmpArr = that.data.list;
  66. tmpArr.push.apply(tmpArr, res.data.list);
  67. that.setData({
  68. list: tmpArr
  69. })
  70. for (let i = 0; i < that.data.list.length; i++) {
  71. var startTime = util.formatTime(that.data.list[i].endTime, "yyyy-MM-dd hh:mm:ss");
  72. var alsell = Math.floor((that.data.list[i].inventory - (that.data.list[i].remainInventory))/(that.data.list[i].inventory)*100);
  73. util.timechuo(startTime);
  74. /**
  75. * 修改list的endtime
  76. * 渲染到页面
  77. */
  78. var endtime = 'list[' + i + '].endtime';
  79. var flags = 'list[' + i + '].flags';
  80. var alsells = 'list[' + i + '].alsells';
  81. if (util.timechuo(startTime).indexOf('-')==0){
  82. that.setData({
  83. [flags]: "end",
  84. [endtime]: util.timechuo(startTime),
  85. [alsells]: alsell
  86. });
  87. }
  88. else{
  89. that.setData({
  90. [endtime]: util.timechuo(startTime),
  91. [alsells]: alsell
  92. });
  93. }
  94. }
  95. })
  96. .catch(err => {
  97. wx.showModal({
  98. title: '提示',
  99. content: err.errMsg,
  100. showCancel:false
  101. })
  102. })
  103. } else {
  104. that.setData({
  105. loading: true,
  106. content: "——— 再拉裤子就掉了啦 ———"
  107. })
  108. setTimeout(function () {
  109. that.setData({
  110. loading: false,
  111. })
  112. }, 1400)
  113. }
  114. };
  115. if (app.globalData.token && app.globalData.token != null) {
  116. app.couponChannelListCallback(app.globalData.token);
  117. }
  118. },
  119. onReady: function () {
  120. let that = this;
  121. that.setData({
  122. list: []
  123. });
  124. that.getList(1);
  125. },
  126. //限时抢购的详情页面
  127. gotodetail: function (e) {
  128. wx.navigateTo({
  129. url: `/pages/coupon/detail/index?couponChannelId=${
  130. e.currentTarget.dataset.couponchannelid
  131. }&couponId=${e.currentTarget.dataset.couponid}`
  132. });
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {},
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function () {
  142. let that = this;
  143. that.data.page++;
  144. that.getList(that.data.page);
  145. },
  146. });