index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // pages/coupon-list/index.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. 'navbar': '1',
  10. 'return': '1',
  11. 'title': '领取优惠券',
  12. 'color': false
  13. },
  14. couponsList:[],
  15. loading:false,
  16. loadend:false,
  17. page:1,
  18. limit:20,
  19. },
  20. /**
  21. * 授权回调
  22. */
  23. onLoadFun:function(){
  24. this.getUseCoupons();
  25. },
  26. getCoupon:function(e){
  27. var that = this;
  28. var id = e.currentTarget.dataset.id;
  29. var index = e.currentTarget.dataset.index;
  30. var list = that.data.couponsList;
  31. //领取优惠券
  32. app.basePost(app.U({ c: 'coupons_api', a: 'user_get_coupon' }), { couponId: id }, function (res) {
  33. list[index].is_use = true;
  34. that.setData({
  35. couponsList: list
  36. });
  37. app.Tips({ title: '领取成功' });
  38. },function(res){
  39. return app.Tips({title:res.msg});
  40. });
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. },
  47. /**
  48. * 获取领取优惠券列表
  49. */
  50. getUseCoupons:function(){
  51. var that=this
  52. if(this.data.loadend) return false;
  53. if(this.data.loading) return false;
  54. app.baseGet(app.U({ c: 'coupons_api', a:'get_issue_coupon_list',q:{page:this.data.page,limit:this.data.limit}}),function(res){
  55. var list=res.data,loadend=list.length < that.data.limit;
  56. var couponsList = app.SplitArray(list, that.data.couponsList);
  57. that.setData({
  58. loading: true,
  59. couponsList: couponsList,
  60. page:that.data.page+1,
  61. loadend: loadend
  62. });
  63. },function(res){
  64. that.setData({ loading:false});
  65. });
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. onReachBottom: function () {
  71. this.getUseCoupons();
  72. },
  73. })