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.

198 line
5.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. onShow: function() {
  31. let that = this;
  32. that.getList(4,1);
  33. wx.setStorage({
  34. key: 'couponNum2',
  35. data: "couponNum3",
  36. })
  37. wx.hideTabBarRedDot({
  38. index: 2
  39. })
  40. },
  41. // 扫一扫去支付
  42. gotoPay: function(e) {
  43. let that = this;
  44. wx.scanCode({
  45. success: (res) => {
  46. console.log(JSON.parse(res.result).merchant_id)
  47. if(JSON.parse(res.result).merchant_id&&e.currentTarget.dataset.cardid&&e.currentTarget.dataset.remainingamount){
  48. wx.navigateTo({
  49. url: `/pages/scanPay/scanPay?merChant=${res.result}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
  50. })
  51. }else{
  52. wx.showToast({
  53. title:"未识别到商户二维码",
  54. icon:"none",
  55. mask: false
  56. })
  57. }
  58. },
  59. fail: (res) => {
  60. console.log(res);
  61. }
  62. })
  63. },
  64. // 跳转到详情
  65. gotoConsumeDetail: function(e) {
  66. console.log(e.currentTarget.dataset.id)
  67. wx.navigateTo({
  68. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
  69. })
  70. },
  71. //点击跳转到券详情页面
  72. gotouse: function(e) {
  73. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  74. var mystatus = e.currentTarget.dataset.couponorderstatus;
  75. } else {
  76. var mystatus = this.data.mystatus;
  77. }
  78. wx.navigateTo({
  79. url: `/pages/couponorder/detail/index?quancode=${
  80. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  81. });
  82. },
  83. gotoBuy:function(){
  84. wx.navigateTo({
  85. url: '/pages/discountCardList/discountCardList',
  86. })
  87. },
  88. getList(key, pageNum) {
  89. var that = this;
  90. console.log(key)
  91. if (that.data.allow_load) {
  92. that.setData({
  93. loading: true,
  94. content: "小主,我在玩命加载中...",
  95. });
  96. if (key == 4) {
  97. var data = {
  98. pageNum: pageNum,
  99. pageSize: 6,
  100. couponType: "7",
  101. couponOrderStatus: 4
  102. }
  103. } else if (key == '5,6,7') {
  104. var data = {
  105. pageNum: pageNum,
  106. pageSize: 6,
  107. couponType: "7",
  108. statusStr: "5,6,7"
  109. }
  110. }
  111. Http.get({
  112. url: config.api.cardorderList,
  113. data: data
  114. })
  115. .then(res => {
  116. if (res.code == 200) {
  117. that.setData({
  118. showPage: true
  119. })
  120. }
  121. res.data.list.map(file => {
  122. file.expiredTime = util.fmtDate(file.expiredTime);
  123. if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7) {
  124. file.background = 'rgba(179,180,181,1)';
  125. file.showImg = true;
  126. } else if (file.couponOrderStatus == 4) {
  127. if (file.remainingAmount > 0 && 29900 >= file.remainingAmount) {
  128. file.background = '#7184E2'
  129. } else if (file.remainingAmount >= 30000 && 49900 >= file.remainingAmount) {
  130. file.background = '#63AAE6'
  131. } else if (file.remainingAmount >= 50000 && 99900 >= file.remainingAmount) {
  132. file.background = '#E2A471'
  133. } else if (file.remainingAmount >= 100000){
  134. file.background = '#E67663'
  135. }
  136. }
  137. });
  138. setTimeout(function() {
  139. that.setData({
  140. loading: false
  141. });
  142. }, 1400);
  143. if (pageNum >= res.data.pages) {
  144. that.setData({
  145. allow_load: false
  146. });
  147. }
  148. if (pageNum == 1) {
  149. that.setData({
  150. list: []
  151. })
  152. }
  153. var tmpArr = that.data.list;
  154. tmpArr.push.apply(tmpArr, res.data.list);
  155. that.setData({
  156. list: tmpArr
  157. })
  158. })
  159. .catch(err => {
  160. wx.showModal({
  161. title: '提示',
  162. content: err.errMsg,
  163. showCancel: false
  164. })
  165. })
  166. } else {
  167. that.setData({
  168. loading: true,
  169. content: "——— 再拉裤子就掉了啦 ———"
  170. });
  171. setTimeout(function() {
  172. that.setData({
  173. loading: false
  174. });
  175. }, 1400);
  176. }
  177. },
  178. handleChangeScroll({
  179. detail
  180. }) {
  181. this.setData({
  182. list: [],
  183. allow_load: true,
  184. current_scroll: detail.key,
  185. page: 1,
  186. });
  187. this.getList(detail.key, 1);
  188. },
  189. onReachBottom: function() {
  190. var that = this;
  191. that.data.page++;
  192. that.setData({
  193. page: that.data.page
  194. });
  195. that.getList(that.data.current_scroll, that.data.page);
  196. }
  197. });