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.

280 lines
7.5 KiB

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