coupon.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const App = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. // 选项卡标示
  8. dataType: 'not_use',
  9. // 列表高度
  10. swiperHeight: 0,
  11. // 优惠券列表
  12. list: [],
  13. // show
  14. notcont: false
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function(options) {
  20. // 设置swiper的高度
  21. this.setSwiperHeight();
  22. },
  23. /**
  24. * 生命周期函数--监听页面显示
  25. */
  26. onShow: function() {
  27. // 获取优惠券列表
  28. this.getCouponList();
  29. },
  30. /**
  31. * 获取优惠券列表
  32. */
  33. getCouponList: function() {
  34. let _this = this;
  35. App._get('user.coupon/lists', {
  36. data_type: _this.data.dataType
  37. }, function(result) {
  38. _this.setData({
  39. list: result.data.list,
  40. notcont: !result.data.list.length
  41. });
  42. });
  43. },
  44. /**
  45. * 设置swiper的高度
  46. */
  47. setSwiperHeight: function() {
  48. // 获取系统信息(拿到屏幕宽度)
  49. let systemInfo = wx.getSystemInfoSync(),
  50. rpx = systemInfo.windowWidth / 750, // 计算rpx
  51. tapHeight = Math.floor(rpx * 80) + 1, // tap高度
  52. swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
  53. this.setData({
  54. swiperHeight
  55. });
  56. },
  57. /**
  58. * 点击tab切换
  59. */
  60. swichNav: function(e) {
  61. let _this = this;
  62. _this.setData({
  63. list: {},
  64. dataType: e.target.dataset.current
  65. }, function() {
  66. // 获取优惠券列表
  67. _this.getCouponList();
  68. });
  69. },
  70. });