C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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