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

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