C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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