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

255 рядки
6.8 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px';
  2. const util = require("../../../utils/util.js");
  3. const config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../../utils/imgurl");
  7. Page({
  8. data: {
  9. navigationBarHeight,
  10. noCoupon: imgurl.noCoupon.url,
  11. couponUrl: imgurl.coupon.url,
  12. linessUrl: imgurl.liness.url,
  13. wmhome: imgurl.wmhome.url,
  14. wmdiscount: imgurl.wmdiscount.url,
  15. loadingUrl: imgurl.loading.url,
  16. canTransferred: imgurl.canTransferred.url,
  17. weixinTitle: imgurl.weixinTitle.url,
  18. shixiao: imgurl.shixiao.url,
  19. tabs: [{
  20. key: 4,
  21. name: "使用中"
  22. },
  23. {
  24. key: "5,6,7",
  25. name: "已失效"
  26. }
  27. ],
  28. list: [],
  29. current: "4",
  30. current_scroll: "4",
  31. page: 1,
  32. allow_load: true,
  33. loading: true, //"上拉加载"的变量,默认false,隐藏
  34. content: "",
  35. mystatus: '',
  36. showPage: false
  37. },
  38. goback: function () {
  39. wx.switchTab({
  40. url: '/index/index',
  41. })
  42. },
  43. onLoad: function() {
  44. let that = this;
  45. if (that.data.current_scroll == "4") {
  46. that.getList(4, 1);
  47. } else {
  48. that.getList('5,6,7', 1);
  49. }
  50. wx.setStorage({
  51. key: 'couponNum2',
  52. data: "couponNum3",
  53. })
  54. wx.hideTabBarRedDot({
  55. index: 3
  56. })
  57. },
  58. userule: function() {
  59. wx.navigateTo({
  60. url: '/pages/cardorder/userule/userule',
  61. })
  62. },
  63. // 扫一扫去支付
  64. gotoPay: function(e) {
  65. /* wx.navigateTo({
  66. url: `/pages/scanPay/scanPay`,
  67. })
  68. return */
  69. let that = this;
  70. wx.scanCode({
  71. success: (res) => {
  72. if (util.isJSON(res.result)) {
  73. let value = JSON.parse(res.result);
  74. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
  75. Http.get({
  76. url: config.api.findByCode,
  77. data: {
  78. merchantCode: value.ID,
  79. }
  80. })
  81. .then(res => {
  82. if (res.code == 200) {
  83. let merChantDetail = JSON.stringify(res.data);
  84. if (merChantDetail && e.currentTarget.dataset.cardid && e.currentTarget.dataset.remainingamount) {
  85. wx.navigateTo({
  86. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
  87. })
  88. }
  89. }
  90. })
  91. .catch(err => {
  92. console.log(err)
  93. })
  94. } else {
  95. wx.showToast({
  96. title: "未识别到商户二维码",
  97. icon: "none",
  98. mask: false
  99. })
  100. }
  101. } else {
  102. wx.showToast({
  103. title: "未识别到商户二维码",
  104. icon: "none",
  105. mask: false
  106. })
  107. }
  108. },
  109. fail: (res) => {
  110. wx.showToast({
  111. title: "未识别到商户二维码",
  112. icon: "none",
  113. mask: false
  114. })
  115. }
  116. })
  117. },
  118. // 跳转到详情
  119. gotoConsumeDetail: function(e) {
  120. if (e.currentTarget.dataset.id){
  121. wx.navigateTo({
  122. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
  123. })
  124. }
  125. },
  126. //点击跳转到券详情页面
  127. gotouse: function(e) {
  128. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  129. var mystatus = e.currentTarget.dataset.couponorderstatus;
  130. } else {
  131. var mystatus = this.data.mystatus;
  132. }
  133. if (e.currentTarget.dataset.quancode) {
  134. wx.navigateTo({
  135. url: `/pages/couponorder/detail/index?quancode=${
  136. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  137. });
  138. }
  139. },
  140. gotoBuy: function() {
  141. wx.navigateTo({
  142. url: '/pages/discountCardList/discountCardList',
  143. })
  144. },
  145. getList(key, pageNum) {
  146. var that = this;
  147. // if (that.data.allow_load) {
  148. that.setData({
  149. loading: true,
  150. content: "小主,我在玩命加载中...",
  151. });
  152. if (key == "4") {
  153. var data = {
  154. pageNum: pageNum,
  155. pageSize: 6,
  156. couponType: "100",
  157. couponOrderStatus: 4
  158. }
  159. } else if (key == '5,6,7') {
  160. var data = {
  161. pageNum: pageNum,
  162. pageSize: 6,
  163. couponType: "100",
  164. statusStr: "5,6,7"
  165. }
  166. }
  167. Http.get({
  168. url: config.api.cardorderList,
  169. data: data
  170. })
  171. .then(res => {
  172. console.log(res)
  173. if (res.code == 200) {
  174. that.setData({
  175. showPage: true
  176. })
  177. }
  178. res.data.list.map(file => {
  179. file.expiredTime = util.formatTime(file.expiredTime, "yyyy.MM.dd")
  180. if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7 || file.couponOrderStatus == 8) {
  181. file.background = 'rgba(179,180,181,1)';
  182. file.showImg = true;
  183. } else if (file.couponOrderStatus == 4) {
  184. if (file.remainingAmount > 0 && 29900 >= file.remainingAmount) {
  185. file.background = '#7184E2'
  186. } else if (file.remainingAmount >= 30000 && 49900 >= file.remainingAmount) {
  187. file.background = '#63AAE6'
  188. } else if (file.remainingAmount >= 50000 && 99900 >= file.remainingAmount) {
  189. file.background = '#E2A471'
  190. } else if (file.remainingAmount >= 100000) {
  191. file.background = '#E67663'
  192. }
  193. }
  194. });
  195. setTimeout(function() {
  196. that.setData({
  197. loading: false
  198. });
  199. }, 1400);
  200. if (pageNum >= res.data.pages && pageNum != 1) {
  201. that.setData({
  202. allow_load: false
  203. });
  204. }
  205. if (pageNum == 1) {
  206. that.setData({
  207. list: []
  208. })
  209. }
  210. var tmpArr = that.data.list;
  211. tmpArr.push.apply(tmpArr, res.data.list);
  212. that.setData({
  213. list: tmpArr
  214. })
  215. })
  216. .catch(err => {
  217. wx.showModal({
  218. title: '提示',
  219. content: err.errMsg,
  220. showCancel: false
  221. })
  222. })
  223. // } else {
  224. // that.setData({
  225. // loading: true,
  226. // content: "——— 再拉裤子就掉了啦 ———"
  227. // });
  228. // setTimeout(function() {
  229. // that.setData({
  230. // loading: false
  231. // });
  232. // }, 1400);
  233. // }
  234. },
  235. handleChangeScroll({
  236. detail
  237. }) {
  238. this.setData({
  239. list: [],
  240. allow_load: true,
  241. current_scroll: detail.key,
  242. page: 1,
  243. });
  244. this.getList(detail.key, 1);
  245. },
  246. onReachBottom: function() {
  247. var that = this;
  248. that.data.page++;
  249. that.setData({
  250. page: that.data.page
  251. });
  252. that.getList(that.data.current_scroll, that.data.page);
  253. }
  254. });