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.

191 lines
4.9 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}&cardRemainRealAmount=${e.currentTarget.dataset.cardRemainRealAmount}`,
  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 && 29900 >= file.remainingAmount) {
  121. file.background = '#7184E2'
  122. } else if (file.remainingAmount >= 30000 && 49900 >= file.remainingAmount) {
  123. file.background = '#63AAE6'
  124. } else if (file.remainingAmount >= 50000 && 99900 >= file.remainingAmount) {
  125. file.background = '#E2A471'
  126. } else if (file.remainingAmount >= 100000){
  127. file.background = '#E67663'
  128. }
  129. }
  130. });
  131. setTimeout(function() {
  132. that.setData({
  133. loading: false
  134. });
  135. }, 1400);
  136. if (pageNum >= res.data.pages) {
  137. that.setData({
  138. allow_load: false
  139. });
  140. }
  141. if (pageNum == 1) {
  142. that.setData({
  143. list: []
  144. })
  145. }
  146. var tmpArr = that.data.list;
  147. tmpArr.push.apply(tmpArr, res.data.list);
  148. that.setData({
  149. list: tmpArr
  150. })
  151. })
  152. .catch(err => {
  153. wx.showModal({
  154. title: '提示',
  155. content: err.errMsg,
  156. showCancel: false
  157. })
  158. })
  159. } else {
  160. that.setData({
  161. loading: true,
  162. content: "——— 再拉裤子就掉了啦 ———"
  163. });
  164. setTimeout(function() {
  165. that.setData({
  166. loading: false
  167. });
  168. }, 1400);
  169. }
  170. },
  171. handleChangeScroll({
  172. detail
  173. }) {
  174. this.setData({
  175. list: [],
  176. allow_load: true,
  177. current_scroll: detail.key,
  178. page: 1,
  179. });
  180. this.getList(detail.key, 1);
  181. },
  182. onReachBottom: function() {
  183. var that = this;
  184. that.data.page++;
  185. that.setData({
  186. page: that.data.page
  187. });
  188. that.getList(that.data.current_scroll, that.data.page);
  189. }
  190. });