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.

174 lines
4.1 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}`,
  50. })
  51. },
  52. fail: (res) => {
  53. console.log(res);
  54. }
  55. })
  56. },
  57. //点击跳转到券详情页面
  58. gotouse: function (e) {
  59. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  60. var mystatus = e.currentTarget.dataset.couponorderstatus;
  61. } else {
  62. var mystatus = this.data.mystatus;
  63. }
  64. wx.navigateTo({
  65. url: `/pages/couponorder/detail/index?quancode=${
  66. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  67. });
  68. },
  69. getList(key, pageNum) {
  70. var that = this;
  71. console.log(key)
  72. if (that.data.allow_load) {
  73. that.setData({
  74. loading: true,
  75. content: "小主,我在玩命加载中...",
  76. });
  77. if(key==4){
  78. var data = {
  79. pageNum: pageNum,
  80. pageSize: 6,
  81. couponType: "7",
  82. couponOrderStatus: 4
  83. }
  84. }else if(key=='5,6,7'){
  85. var data = {
  86. pageNum: pageNum,
  87. pageSize: 6,
  88. couponType: "7",
  89. statusStr: "5,6,7"
  90. }
  91. }
  92. Http.get({
  93. url: config.api.cardorderList,
  94. data:data
  95. })
  96. .then(res => {
  97. if(res.code == 200){
  98. that.setData({
  99. showPage:true
  100. })
  101. }
  102. res.data.list.map(file => {
  103. file.expiredTime = util.fmtDate(file.expiredTime);
  104. if (file.remainingAmount > 0 && 500 >= file.remainingAmount){
  105. file.background = '#7184E2'
  106. }
  107. else if (file.remainingAmount > 500 && 5000 >= file.remainingAmount) {
  108. file.background = '#63AAE6'
  109. }
  110. else if (file.remainingAmount > 5000) {
  111. file.background = '#E2A471'
  112. }
  113. });
  114. setTimeout(function () {
  115. that.setData({
  116. loading: false
  117. });
  118. }, 1400);
  119. if (pageNum >= res.data.pages) {
  120. that.setData({
  121. allow_load: false
  122. });
  123. }
  124. if (pageNum == 1) {
  125. that.setData({
  126. list: []
  127. })
  128. }
  129. var tmpArr = that.data.list;
  130. tmpArr.push.apply(tmpArr, res.data.list);
  131. that.setData({
  132. list: tmpArr
  133. })
  134. })
  135. .catch(err => {
  136. wx.showModal({
  137. title: '提示',
  138. content: err.errMsg,
  139. showCancel:false
  140. })
  141. })
  142. } else {
  143. that.setData({
  144. loading: true,
  145. content: "——— 再拉裤子就掉了啦 ———"
  146. });
  147. setTimeout(function () {
  148. that.setData({
  149. loading: false
  150. });
  151. }, 1400);
  152. }
  153. },
  154. handleChangeScroll({
  155. detail
  156. }) {
  157. this.setData({
  158. list: [],
  159. allow_load: true,
  160. current_scroll: detail.key,
  161. page:1,
  162. });
  163. this.getList(detail.key, 1);
  164. },
  165. onReachBottom: function () {
  166. var that = this;
  167. that.data.page++;
  168. that.setData({
  169. page: that.data.page
  170. });
  171. that.getList(that.data.current_scroll, that.data.page);
  172. }
  173. });