C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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