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

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