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

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