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.

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