123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- //index.js
- const { request, serverName, imgServer } = require('../../utils/services');
- const {
- newRequestFns,
- newServerName
- } = require('../../utils/newServices.js');
- const { Toast } = require('../../utils/util.js');
- const { defaultImg, noExhibitionImg } = require('../../utils/images');
- const WxParse = require('../../common/component/wxParse/wxParse.js');
- const app = getApp();
- Page({
- data: {
- animationData: {},
- loading: false,
- isLike: true,
- imgServer,
- commodityImgs: [],
- testImg: '../../imgs/testImg/fdkz.png',
- currentPage: 1,
- exhibitionList: [],
- likes: {},
- tag: 1
- },
- onLoad: function () {
- this.setData({
- serverName,
- defaultImg,
- noExhibitionImg,
- })
- this.getList(1);
- },
- loadMore: function () {
- if (!this.data.lastPage) {
- this.getList(this.data.currentPage + 1);
- } else {
- return;
- }
- },
- onReachBottom: function () {
- if (!this.data.loading) {
- this.loadMore();
- }
- },
- onShareAppMessage: function () {
- },
- onShow: function () {
- let { collectedArr, collectedChange } = app.globalData;
- let { exhibitionList } = this.data
- // this.setData({
- // exhibitionList: []
- // });
- // this.getBanner();
- // this.getList(1);
- if (collectedChange) {
- for (let i = 0; i < exhibitionList.length; i++) {
- for (let j = 0; j < collectedArr.length; j++) {
- if (collectedArr[j].collectedId == exhibitionList[i].id) {
- exhibitionList[i].hasCollect = collectedArr[j].status
- if (exhibitionList[i].hasCollect) {
- exhibitionList[i].collectionsCount += 1;
- }
- else {
- exhibitionList[i].collectionsCount -= 1;
- }
- if (exhibitionList[i].collectionsCount < 0) {
- exhibitionList[i].collectionsCount = 0
- }
- }
- }
- }
- this.setData({
- exhibitionList
- })
- }
- app.globalData.clickToSelect = false;
- app.globalData.collectedChange = false;
- },
- enablePullDownRefresh: function () {
- this.setData({
- exhibitionList: [],
- currentPage: 1
- });
- this.getList(1);
- this.getBanner();
- },
- onPullDownRefresh: function () {
- this.setData({
- exhibitionList: [],
- currentPage: 1
- });
- this.getList(1);
- },
- getList: function (page) {
- let type = this.data.tag;
- this.setData({
- loading: true
- })
- newRequestFns["getExhibitionList"]({
- page: page,
- type: type
- }, '', res => {
- let tempContent = this.data.exhibitionList
- ? this.data.exhibitionList
- : [];
- let { pageData: exhibitionList, total } = res.data.data;
- // 判断是否为最后一页(返回空数组表示没有更多数据)
- let isLastPage = !exhibitionList || exhibitionList.length === 0;
- if (isLastPage) {
- this.setData({
- loading: false,
- lastPage: true // 标记为最后一页
- });
- wx.stopPullDownRefresh();
- return;
- }
- exhibitionList.forEach((currentValue) => {
- currentValue.product ? currentValue.product.link = escape(currentValue.product.link) : '';
- currentValue.product ? currentValue.product.imageUrl = escape(currentValue.product.imageUrl) : '';
- })
- // 拼接新数据
- let newExhibitionList = tempContent.concat(exhibitionList);
- this.setData({
- currentPage: page,
- lastPage: false, // 有数据时设为false
- loading: false,
- exhibitionList: newExhibitionList,
- });
- wx.stopPullDownRefresh();
- // WxParse.wxParseTemArray("replyTemArray", 'reply', replyArr.length, that)
- }, err => {
- }, complete => {
- })
- },
- addLike: function (e) {
- let { type, id, idx } = e.currentTarget.dataset;
- let likes = this.data.likes;
- likes[id] = !likes[id];
- let exhibitionList = this.data.exhibitionList;
- let { collectedArr, collectedChange } = app.globalData, hasItem = true;
- this.setData({
- likes: likes
- })
- Toast.showToast2('loading');
- let loginSessionKey = wx.getStorageSync('token') || "";
- // if (loginSessionKey){
- newRequestFns['isCollect']({
- loginSessionKey,
- exhibitionId: id,
- type: Number(type),
- }, "post", res => {
- if (res.data.code > -1) {
- for (let i = 0; i < collectedArr.length; i++) {
- if (collectedArr[i].collectedId && id == collectedArr[i].collectedId) {
- collectedArr[i] = {
- collectedId: id,
- status: res.data.data.hasCollect,
- }
- hasItem = false;
- }
- }
- if (hasItem) {
- collectedArr.push({
- collectedId: id,
- status: res.data.data.hasCollect,
- })
- }
- app.globalData.collectedArr = collectedArr;
- app.globalData.collectedChange = true;
-
- exhibitionList[idx].hasCollect = res.data.data.hasCollect
- this.setData({
- exhibitionList: exhibitionList
- })
- }
- }, err => {
- }, complete => {
-
- Toast.hideLoading();
- })
- // }
- },
- to_search: function () {
- wx.navigateTo({
- url: './search/index',
- success: function (res) { },
- fail: function (res) { },
- complete: function (res) { },
- })
- },
- })
|