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.

189 lines
4.8 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. gotoBuy:function(){
  77. wx.navigateTo({
  78. url: '/pages/discountCardList/discountCardList',
  79. })
  80. },
  81. getList(key, pageNum) {
  82. var that = this;
  83. console.log(key)
  84. if (that.data.allow_load) {
  85. that.setData({
  86. loading: true,
  87. content: "小主,我在玩命加载中...",
  88. });
  89. if (key == 4) {
  90. var data = {
  91. pageNum: pageNum,
  92. pageSize: 6,
  93. couponType: "7",
  94. couponOrderStatus: 4
  95. }
  96. } else if (key == '5,6,7') {
  97. var data = {
  98. pageNum: pageNum,
  99. pageSize: 6,
  100. couponType: "7",
  101. statusStr: "5,6,7"
  102. }
  103. }
  104. Http.get({
  105. url: config.api.cardorderList,
  106. data: data
  107. })
  108. .then(res => {
  109. if (res.code == 200) {
  110. that.setData({
  111. showPage: true
  112. })
  113. }
  114. res.data.list.map(file => {
  115. file.expiredTime = util.fmtDate(file.expiredTime);
  116. if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7) {
  117. file.background = 'rgba(179,180,181,1)';
  118. file.showImg = true;
  119. } else if (file.couponOrderStatus == 4) {
  120. if (file.remainingAmount > 0 && 500 >= file.remainingAmount) {
  121. file.background = '#7184E2'
  122. } else if (file.remainingAmount > 500 && 5000 >= file.remainingAmount) {
  123. file.background = '#63AAE6'
  124. } else if (file.remainingAmount > 5000) {
  125. file.background = '#E2A471'
  126. }
  127. }
  128. });
  129. setTimeout(function() {
  130. that.setData({
  131. loading: false
  132. });
  133. }, 1400);
  134. if (pageNum >= res.data.pages) {
  135. that.setData({
  136. allow_load: false
  137. });
  138. }
  139. if (pageNum == 1) {
  140. that.setData({
  141. list: []
  142. })
  143. }
  144. var tmpArr = that.data.list;
  145. tmpArr.push.apply(tmpArr, res.data.list);
  146. that.setData({
  147. list: tmpArr
  148. })
  149. })
  150. .catch(err => {
  151. wx.showModal({
  152. title: '提示',
  153. content: err.errMsg,
  154. showCancel: false
  155. })
  156. })
  157. } else {
  158. that.setData({
  159. loading: true,
  160. content: "——— 再拉裤子就掉了啦 ———"
  161. });
  162. setTimeout(function() {
  163. that.setData({
  164. loading: false
  165. });
  166. }, 1400);
  167. }
  168. },
  169. handleChangeScroll({
  170. detail
  171. }) {
  172. this.setData({
  173. list: [],
  174. allow_load: true,
  175. current_scroll: detail.key,
  176. page: 1,
  177. });
  178. this.getList(detail.key, 1);
  179. },
  180. onReachBottom: function() {
  181. var that = this;
  182. that.data.page++;
  183. that.setData({
  184. page: that.data.page
  185. });
  186. that.getList(that.data.current_scroll, that.data.page);
  187. }
  188. });