123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- // pages/tagDetail/tagDetail.js
- const net = require("../../utils/net.js");
- const utils = require("../../utils/util.js");
- const {
- api_material_topic_info,
- api_news_list,
- api_topic_type_list,
- } = require("../../utils/api.js");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- categoryList: [],
- tagId: null,
- selectTab: 0,
- topicInfo: {},
- scrollH: 500,
- listData: [],
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options && options.tagId) {
- this._tagId = options.tagId;
- this.loadTopicInfo();
- this.loadCategoryListData();
- }
- },
- tapNavBarAction() {
- const { topicInfo } = this.data;
- const { isAuthor, isAttention } = topicInfo;
- if (!isAuthor && isAttention == 0) {
- let pages = getCurrentPages(); /*在内存中的所有页面栈对象*/
- let reloadPage = pages[pages.length - 2]; /*我的页面对象*/
- reloadPage && reloadPage.cancelAttention && reloadPage.cancelAttention();
- }
- },
- loadTopicInfo() {
- let params = {};
- params.url = api_material_topic_info;
- params.data = {
- id: this._tagId,
- };
- net.req(params, true).then(
- (data) => {
- this.setData({
- topicInfo: data,
- });
- },
- (e) => {
- utils.showToast({ title: e.msg || "" });
- }
- );
- },
- loadCategoryListData() {
- let params = {};
- params.url = api_topic_type_list;
- params.data = { tagId: this._tagId, type: 1 };
- net.req(params, true).then(
- (data) => {
- this.setData(
- {
- categoryList: data,
- },
- () => {
- this._selectTab = 0;
- this.loadNewsData({ isRefresh: true });
- this.getScrollH();
- }
- );
- },
- (e) => {
- utils.showToast({ title: e.msg || "" });
- }
- );
- },
- loadNewsData(obj) {
- const { limit, listData, categoryList } = this.data;
- let params = {};
- params.url = api_news_list;
- params.data = {
- tagId: this._tagId,
- limit: limit,
- type: categoryList[this._selectTab].type,
- };
- const len = listData.length;
- if (!obj.isRefresh && len) {
- params.data.lastId = listData[len - 1].id;
- }
- net.req(params, true).then(
- (data) => {
- if (obj.isRefresh) {
- this.setData({
- listData: data.list,
- isEnd: data.list.length < limit,
- });
- this._refresh = false;
- this._isload = false;
- } else {
- if (data.list.length) {
- this.setData({
- listData: listData.concat(data.list),
- isEnd: data.list.length < limit,
- });
- }
- this._isload = data.list.length < limit;
- }
- },
- (e) => {
- obj.isRefresh ? (this._refresh = false) : (this._isload = false);
- }
- );
- },
- tapAttentionAction(e) {
- const { attentionNum } = e.detail;
- this.setData({
- ["topicInfo.attentionNum"]: attentionNum,
- });
- },
- getScrollH() {
- const _this = this;
- wx.createSelectorQuery()
- .select("#fixedTop")
- .boundingClientRect(function (res) {
- const sys = wx.getSystemInfoSync();
- _this.setData({
- scrollH: sys.windowHeight - res.height,
- });
- })
- .exec();
- },
- handleTabAction(e) {
- const { index, item } = e.detail;
- const { categoryList } = this.data;
- const newCategoryId = item.type;
- const oldCategoryId = categoryList[this._selectTab].type;
- if (oldCategoryId != newCategoryId) {
- this.setData({
- scrollTop: 0,
- });
- this._selectTab = index;
- this.loadNewsData({ isRefresh: true });
- }
- },
- scrollToLower() {
- if (this._isload) return;
- this._isload = true;
- this.loadNewsData({ isRefresh: false });
- },
- refreshCallback() {
- this.loadNewsData({ isRefresh: true });
- },
- });
|