123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- import util from '../../../utils/util.js'
- const App = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // 当前tab索引
- currentTab: 0,
- // 列表容器高度
- scrollHeight: null,
- // 列表容器滚动的位置
- scrollTop: 0,
- noMore: false, // 没有更多数据
- isLoading: true, // 是否正在加载中
- page: 1, // 当前页码
- // 时间记录
- countDownList: [],
- // 砍价会场商品列表
- activeList: [],
- // 我的砍价列表
- myList: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let _this = this;
- // 设置scroll-view高度
- _this._setListHeight();
- // 设置当前tab索引
- _this._setCurrentTab(options);
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- let _this = this;
- if (_this.data.scrollTop == 0) {
- // 获取列表数据
- _this._getList();
- }
- },
- /**
- * 设置当前tab索引
- */
- _setCurrentTab(options) {
- let _this = this;
- if (options.hasOwnProperty('tab')) {
- _this.setData({
- currentTab: options.tab
- });
- }
- },
- /**
- * 设置商品列表高度
- */
- _setListHeight() {
- let _this = this;
- let systemInfo = wx.getSystemInfoSync(),
- rpx = systemInfo.windowWidth / 750, // 计算rpx
- tapHeight = Math.floor(rpx * (92 + 20)), // tap高度
- scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
- _this.setData({
- scrollHeight
- });
- },
- /**
- * 获取砍价活动列表
- */
- getActiveList(isPage) {
- let _this = this;
- App._get('bargain.active/lists', {
- page: _this.data.page || 1,
- }, (result) => {
- let resList = result.data.activeList,
- dataList = _this.data.activeList;
- if (isPage == true) {
- _this.setData({
- 'activeList.data': dataList.data.concat(resList.data),
- isLoading: false,
- });
- } else {
- _this.setData({
- activeList: resList,
- isLoading: false,
- });
- }
- });
- },
- /**
- * 获取我的砍价列表
- */
- getMyList(isPage) {
- let _this = this;
- App._get('bargain.task/lists', {
- page: _this.data.page || 1,
- }, (result) => {
- let resList = result.data.myList,
- dataList = _this.data.myList;
- if (isPage == true) {
- _this.setData({
- 'myList.data': dataList.data.concat(resList.data),
- isLoading: false,
- });
- } else {
- _this.setData({
- myList: resList,
- isLoading: false,
- });
- }
- // 初始化倒计时组件
- _this._initCountDownData(result.data);
- });
- },
- /**
- * 初始化倒计时组件
- */
- _initCountDownData(data) {
- // let _this = this;
- // // 记录活动到期时间
- // let countDownList = _this.data.countDownList;
- // data.myList.data.forEach((item) => {
- // countDownList.push({
- // date: item.end_time
- // })
- // })
- },
- /**
- * 记录滚动的位置
- */
- onScrollEvent(e) {
- let _this = this;
- _this.setData({
- scrollTop: e.detail.scrollTop
- })
- },
- /**
- * 切换tabbar
- */
- onToggleTab(e) {
- let _this = this;
- // 设置当前tabbar索引,并重置数据
- _this.setData({
- currentTab: e.currentTarget.dataset.index,
- activeList: [],
- myList: [],
- page: 1,
- isLoading: true,
- noMore: false,
- });
- // 获取列表数据
- _this._getList();
- },
- /**
- * 跳转到砍价商品详情
- */
- onTargetActive(e) {
- wx.navigateTo({
- url: `../goods/index?active_id=${e.detail.target.dataset.id}`,
- })
- },
- /**
- * 跳转到砍价任务详情
- */
- onTargetTask(e) {
- wx.navigateTo({
- url: `../task/index?task_id=${e.detail.target.dataset.id}`,
- })
- },
- /**
- * 下拉到底部加载下一页
- */
- onScrollToLower() {
- let _this = this,
- listData = _this.data.currentTab == 0 ? _this.data.activeList : _this.data.myList;
- // 已经是最后一页
- if (_this.data.page >= listData.last_page) {
- _this.setData({
- noMore: true
- });
- return false;
- }
- // 加载下一页列表
- _this.setData({
- page: ++_this.data.page
- });
- _this._getList(true);
- },
- /**
- * 获取列表数据
- */
- _getList(isPage) {
- let _this = this;
- _this.data.currentTab == 0 ? _this.getActiveList(isPage) : _this.getMyList(isPage);
- },
- /**
- * 分享当前页面
- */
- onShareAppMessage() {
- const _this = this;
- // 构建页面参数
- const params = App.getShareUrlParams();
- return {
- title: '砍价专区',
- path: `/pages/bargain/index/index?${params}`
- };
- },
- /**
- * 分享到朋友圈
- * 本接口为 Beta 版本,暂只在 Android 平台支持,详见分享到朋友圈 (Beta)
- * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
- */
- onShareTimeline() {
- const _this = this;
- // 构建页面参数
- const params = App.getShareUrlParams();
- return {
- title: '砍价专区',
- path: `/pages/bargain/index/index?${params}`
- };
- },
- })
|