C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

180 řádky
4.3 KiB

  1. const util = require("../../../utils/util.js");
  2. const config = require("../../../config/config.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. let app = getApp();
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. data: {
  8. couponUrl: imgurl.coupon.url,
  9. linessUrl: imgurl.liness.url,
  10. loadingUrl: imgurl.loading.url,
  11. tabs: [{
  12. key: 4,
  13. name: "使用中"
  14. },
  15. {
  16. key: "5,6,7",
  17. name: "已失效"
  18. }
  19. ],
  20. list: [],
  21. current: "4",
  22. current_scroll: "4",
  23. page: 1,
  24. allow_load: true,
  25. loading: true, //"上拉加载"的变量,默认false,隐藏
  26. content: "",
  27. mystatus: '',
  28. showPage:false
  29. },
  30. onLoad() {
  31. this.getList(4, 1);
  32. },
  33. onShow: function () {
  34. let that = this;
  35. wx.setStorage({
  36. key: 'couponNum',
  37. data: "couponNum1",
  38. })
  39. wx.hideTabBarRedDot({
  40. index:2
  41. })
  42. },
  43. // 扫一扫去支付
  44. gotoPay:function(e){
  45. let that = this;
  46. wx.scanCode({
  47. success: (res) => {
  48. wx.navigateTo({
  49. url: `/pages/scanPay/scanPay?merChant=${res.result}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
  50. })
  51. },
  52. fail: (res) => {
  53. console.log(res);
  54. }
  55. })
  56. },
  57. // 跳转到详情
  58. gotoConsumeDetail:function(e){
  59. console.log(e.currentTarget.dataset.id)
  60. wx.navigateTo({
  61. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
  62. })
  63. },
  64. //点击跳转到券详情页面
  65. gotouse: function (e) {
  66. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  67. var mystatus = e.currentTarget.dataset.couponorderstatus;
  68. } else {
  69. var mystatus = this.data.mystatus;
  70. }
  71. wx.navigateTo({
  72. url: `/pages/couponorder/detail/index?quancode=${
  73. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  74. });
  75. },
  76. getList(key, pageNum) {
  77. var that = this;
  78. console.log(key)
  79. if (that.data.allow_load) {
  80. that.setData({
  81. loading: true,
  82. content: "小主,我在玩命加载中...",
  83. });
  84. if(key==4){
  85. var data = {
  86. pageNum: pageNum,
  87. pageSize: 6,
  88. couponType: "7",
  89. couponOrderStatus: 4
  90. }
  91. }else if(key=='5,6,7'){
  92. var data = {
  93. pageNum: pageNum,
  94. pageSize: 6,
  95. couponType: "7",
  96. statusStr: "5,6,7"
  97. }
  98. }
  99. Http.get({
  100. url: config.api.cardorderList,
  101. data:data
  102. })
  103. .then(res => {
  104. if(res.code == 200){
  105. that.setData({
  106. showPage:true
  107. })
  108. }
  109. res.data.list.map(file => {
  110. file.expiredTime = util.fmtDate(file.expiredTime);
  111. if (file.remainingAmount > 0 && 500 >= file.remainingAmount){
  112. file.background = '#7184E2'
  113. }
  114. else if (file.remainingAmount > 500 && 5000 >= file.remainingAmount) {
  115. file.background = '#63AAE6'
  116. }
  117. else if (file.remainingAmount > 5000) {
  118. file.background = '#E2A471'
  119. }
  120. });
  121. setTimeout(function () {
  122. that.setData({
  123. loading: false
  124. });
  125. }, 1400);
  126. if (pageNum >= res.data.pages) {
  127. that.setData({
  128. allow_load: false
  129. });
  130. }
  131. if (pageNum == 1) {
  132. that.setData({
  133. list: []
  134. })
  135. }
  136. var tmpArr = that.data.list;
  137. tmpArr.push.apply(tmpArr, res.data.list);
  138. that.setData({
  139. list: tmpArr
  140. })
  141. })
  142. .catch(err => {
  143. wx.showModal({
  144. title: '提示',
  145. content: err.errMsg,
  146. showCancel:false
  147. })
  148. })
  149. } else {
  150. that.setData({
  151. loading: true,
  152. content: "——— 再拉裤子就掉了啦 ———"
  153. });
  154. setTimeout(function () {
  155. that.setData({
  156. loading: false
  157. });
  158. }, 1400);
  159. }
  160. },
  161. handleChangeScroll({
  162. detail
  163. }) {
  164. this.setData({
  165. list: [],
  166. allow_load: true,
  167. current_scroll: detail.key,
  168. page:1,
  169. });
  170. this.getList(detail.key, 1);
  171. },
  172. onReachBottom: function () {
  173. var that = this;
  174. that.data.page++;
  175. that.setData({
  176. page: that.data.page
  177. });
  178. that.getList(that.data.current_scroll, that.data.page);
  179. }
  180. });