C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

256 行
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. merChantDetail = encodeURIComponent(merChantDetail)
  86. wx.navigateTo({
  87. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
  88. })
  89. }
  90. }
  91. })
  92. .catch(err => {
  93. console.log(err)
  94. })
  95. } else {
  96. wx.showToast({
  97. title: "未识别到商户二维码",
  98. icon: "none",
  99. mask: false
  100. })
  101. }
  102. } else {
  103. wx.showToast({
  104. title: "未识别到商户二维码",
  105. icon: "none",
  106. mask: false
  107. })
  108. }
  109. },
  110. fail: (res) => {
  111. wx.showToast({
  112. title: "未识别到商户二维码",
  113. icon: "none",
  114. mask: false
  115. })
  116. }
  117. })
  118. },
  119. // 跳转到详情
  120. gotoConsumeDetail: function(e) {
  121. if (e.currentTarget.dataset.id){
  122. wx.navigateTo({
  123. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
  124. })
  125. }
  126. },
  127. //点击跳转到券详情页面
  128. gotouse: function(e) {
  129. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  130. var mystatus = e.currentTarget.dataset.couponorderstatus;
  131. } else {
  132. var mystatus = this.data.mystatus;
  133. }
  134. if (e.currentTarget.dataset.quancode) {
  135. wx.navigateTo({
  136. url: `/pages/couponorder/detail/index?quancode=${
  137. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  138. });
  139. }
  140. },
  141. gotoBuy: function() {
  142. wx.navigateTo({
  143. url: '/pages/discountCardList/discountCardList',
  144. })
  145. },
  146. getList(key, pageNum) {
  147. var that = this;
  148. // if (that.data.allow_load) {
  149. that.setData({
  150. loading: true,
  151. content: "小主,我在玩命加载中...",
  152. });
  153. if (key == "4") {
  154. var data = {
  155. pageNum: pageNum,
  156. pageSize: 6,
  157. couponType: "100",
  158. couponOrderStatus: 4
  159. }
  160. } else if (key == '5,6,7') {
  161. var data = {
  162. pageNum: pageNum,
  163. pageSize: 6,
  164. couponType: "100",
  165. statusStr: "5,6,7"
  166. }
  167. }
  168. Http.get({
  169. url: config.api.cardorderList,
  170. data: data
  171. })
  172. .then(res => {
  173. console.log(res)
  174. if (res.code == 200) {
  175. that.setData({
  176. showPage: true
  177. })
  178. }
  179. res.data.list.map(file => {
  180. file.expiredTime = util.formatTime(file.expiredTime, "yyyy.MM.dd")
  181. if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7 || file.couponOrderStatus == 8) {
  182. file.background = 'rgba(179,180,181,1)';
  183. file.showImg = true;
  184. } else if (file.couponOrderStatus == 4) {
  185. if (file.remainingAmount > 0 && 29900 >= file.remainingAmount) {
  186. file.background = '#7184E2'
  187. } else if (file.remainingAmount >= 30000 && 49900 >= file.remainingAmount) {
  188. file.background = '#63AAE6'
  189. } else if (file.remainingAmount >= 50000 && 99900 >= file.remainingAmount) {
  190. file.background = '#E2A471'
  191. } else if (file.remainingAmount >= 100000) {
  192. file.background = '#E67663'
  193. }
  194. }
  195. });
  196. setTimeout(function() {
  197. that.setData({
  198. loading: false
  199. });
  200. }, 1400);
  201. if (pageNum >= res.data.pages && pageNum != 1) {
  202. that.setData({
  203. allow_load: false
  204. });
  205. }
  206. if (pageNum == 1) {
  207. that.setData({
  208. list: []
  209. })
  210. }
  211. var tmpArr = that.data.list;
  212. tmpArr.push.apply(tmpArr, res.data.list);
  213. that.setData({
  214. list: tmpArr
  215. })
  216. })
  217. .catch(err => {
  218. wx.showModal({
  219. title: '提示',
  220. content: err.errMsg,
  221. showCancel: false
  222. })
  223. })
  224. // } else {
  225. // that.setData({
  226. // loading: true,
  227. // content: "——— 再拉裤子就掉了啦 ———"
  228. // });
  229. // setTimeout(function() {
  230. // that.setData({
  231. // loading: false
  232. // });
  233. // }, 1400);
  234. // }
  235. },
  236. handleChangeScroll({
  237. detail
  238. }) {
  239. this.setData({
  240. list: [],
  241. allow_load: true,
  242. current_scroll: detail.key,
  243. page: 1,
  244. });
  245. this.getList(detail.key, 1);
  246. },
  247. onReachBottom: function() {
  248. var that = this;
  249. that.data.page++;
  250. that.setData({
  251. page: that.data.page
  252. });
  253. that.getList(that.data.current_scroll, that.data.page);
  254. }
  255. });