quan.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // pages/quan/quan.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. status: '0',
  11. list: [
  12. ],
  13. loading: '上拉加载',
  14. flag: 0,
  15. pageNum: 0,
  16. hasNextPage: true,
  17. switchTitle: [
  18. '可使用', '已使用'
  19. ]
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.queryList();
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面卸载
  44. */
  45. onUnload: function () {
  46. },
  47. /**
  48. * 页面相关事件处理函数--监听用户下拉动作
  49. */
  50. onPullDownRefresh: function () {
  51. },
  52. /**
  53. * 页面上拉触底事件的处理函数
  54. */
  55. onReachBottom: function () {
  56. if (this.data.hasNextPage) {
  57. let pn = this.data.pageNum
  58. this.setData({ loading: '加载中', 'pageNum': ++pn })
  59. this.queryList()
  60. }
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. queryList: function () {
  68. const urls = urlDef.urls;
  69. let stu = wx.getStorageSync('student');
  70. if (stu) {
  71. let params = { 'q.studentId': stu.studentId, 'q.orgId': stu.orgId }
  72. let url = null;
  73. if (this.data.status == '0') { // 待领取 + 已领取
  74. url = urls.coupon_receive_list;
  75. } else if (this.data.status == '2') { // 已经使
  76. url = urls.my_coupon;
  77. params['q.status'] = '2';
  78. }
  79. console.log(url)
  80. params.pageNum = this.data.pageNum
  81. util.apiPost(url, params).then(rs => {
  82. let list = rs.list
  83. this.setData({
  84. 'hasNextPage': rs.hasNextPage,
  85. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  86. 'list': this.data.list.concat(list)
  87. })
  88. })
  89. }
  90. },
  91. changeIndex: function (e) {
  92. if (e.detail == 0) {
  93. this.setData({ status: '0' })
  94. } else {
  95. this.setData({ status: '2' })
  96. }
  97. this.setData({
  98. list: [],
  99. loading: '上拉加载',
  100. pageNum: 0
  101. })
  102. this.queryList()
  103. },
  104. submitCilck: function (e) {
  105. const urls = urlDef.urls;
  106. let item = this.data.list[e.currentTarget.dataset.index]
  107. if (item.receiveDate) {
  108. wx.showToast({ title: '已领取过该优惠券', icon: 'none' });
  109. return;
  110. }
  111. wx.showLoading({
  112. title: '正在领取...',
  113. mask: true
  114. })
  115. util.apiPost(urls.coupon_receive + '?publishId=' + item.publishId + '&couponId=' + item.couponId).then((rs) => {
  116. wx.hideLoading({})
  117. if (rs.message) {
  118. wx.showToast({ title: rs.message, icon: 'none' });
  119. return;
  120. }
  121. item.receiveDate = new Date();
  122. wx.showToast({ title: '领取成功', icon: 'success' });
  123. this.setData({ list: [], pageNum: 0 })
  124. this.queryList();
  125. })
  126. }
  127. })