123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- const app = getApp()
- import { news_type } from '../../utils/dict';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '资讯', leftArrow: false, useBar: true },
- tabs: {
- active: '0',
- list: [
- { title: '推荐', name: '0' },
- { title: '羽毛球', name: '1' },
- ],
- },
- //查询条件
- searchInfo: {},
- list: [],
- typeList: news_type,
- },
- // 跳转菜单
- tabPath(e) {
- let { route } = e.detail.detail;
- if (route) wx.redirectTo({ url: `/${route}` })
- },
- // 详情页
- toView: function (e) {
- let { id } = e.currentTarget.dataset;
- wx.navigateTo({ url: `/pages/news/info?id=${id}` })
- },
- // 选项卡
- tabsChange: function (e) {
- const that = this;
- that.setData({ 'tabs.active': e.detail.name });
- that.watchLogin();
- },
- //搜索
- onSearch: function (e) {
- const that = this;
- that.setData({ 'searchInfo.title': e.detail.value });
- that.watchLogin()
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const that = this;
- },
- watchLogin: function () {
- const that = this;
- let searchInfo = that.data.searchInfo;
- let type = that.data.tabs.active;
- wx.getStorage({
- key: 'user',
- success: async (res) => {
- let info = { skip: 0, limit: 1000 };
- if (searchInfo && searchInfo.title) info.title = searchInfo.title;
- info.type = type; info.is_show = "0";
- const arr = await app.$get(`/newCourt/api/news`, { ...info });
- if (arr.errcode == '0') {
- that.setData({ list: arr.data })
- } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
- },
- fail: async (res) => {
- wx.redirectTo({ url: '/pages/index/index' });
- },
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.watchLogin();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|