quan.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. params.pageNum = this.data.pageNum
  80. util.apiPost(url, params).then(rs => {
  81. let list = rs.list
  82. this.setData({
  83. 'hasNextPage': rs.hasNextPage,
  84. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  85. 'list': this.data.list.concat(list)
  86. })
  87. })
  88. }
  89. },
  90. changeIndex: function (e) {
  91. if (e.detail == 0) {
  92. this.setData({ status: '0' })
  93. } else {
  94. this.setData({ status: '2' })
  95. }
  96. this.setData({
  97. list: [],
  98. loading: '上拉加载',
  99. pageNum: 0
  100. })
  101. this.queryList()
  102. },
  103. submitCilck: function (e) {console.log(JSON.stringify(e))
  104. const urls = urlDef.urls;
  105. let item = this.data.list[e.currentTarget.dataset.index]
  106. if (item.receiveDate) {
  107. wx.showToast({ title: '已领取过该优惠券', icon: 'none' });
  108. return;
  109. }
  110. wx.showLoading({
  111. title: '正在领取...',
  112. mask: true
  113. })
  114. util.apiPost(urls.coupon_receive + '?publishId=' + item.publishId + '&couponId=' + item.couponId).then((rs) => {
  115. wx.hideLoading({})
  116. if (rs.message) {
  117. wx.showToast({ title: rs.message, icon: 'none' });
  118. return;
  119. }
  120. item.receiveDate = new Date();
  121. wx.showToast({ title: '领取成功', icon: 'success' });
  122. this.setData({ list: [], pageNum: 0 })
  123. this.queryList();
  124. })
  125. }
  126. })