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.

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