This repository has been archived on 2024-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
yoshop-wechat/pages/user/coupon/coupon.js

81 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-04-25 22:59:04 +08:00
const App = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
// 选项卡标示
dataType: 'not_use',
// 列表高度
swiperHeight: 0,
// 优惠券列表
list: [],
// show
notcont: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
// 设置swiper的高度
this.setSwiperHeight();
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
// 获取优惠券列表
this.getCouponList();
},
/**
* 获取优惠券列表
*/
getCouponList: function() {
let _this = this;
App._get('user.coupon/lists', {
data_type: _this.data.dataType
}, function(result) {
_this.setData({
list: result.data.list,
notcont: !result.data.list.length
});
});
},
/**
* 设置swiper的高度
*/
setSwiperHeight: function() {
// 获取系统信息(拿到屏幕宽度)
let systemInfo = wx.getSystemInfoSync(),
rpx = systemInfo.windowWidth / 750, // 计算rpx
tapHeight = Math.floor(rpx * 80) + 1, // tap高度
swiperHeight = systemInfo.windowHeight - tapHeight; // swiper高度
this.setData({
swiperHeight
});
},
/**
* 点击tab切换
*/
swichNav: function(e) {
let _this = this;
_this.setData({
list: {},
dataType: e.target.dataset.current
}, function() {
// 获取优惠券列表
_this.getCouponList();
});
},
});