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.

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