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.

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