123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- // pages/yuezhan/search/index.js
- const { request, serverName, imgServer } = require('../../../utils/services');
- const { Toast } = require('../../../utils/util');
- const { defaultImg, noExhibitionImg, noExhibitionHallImg } = require('../../../utils/images');
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- tabs: ['展览', '展馆'],
- testImg: '../../../imgs/testImg/thumbSmallImg2.jpg',
- avatar: '../../../imgs/testImg/1.jpg',
- activeIndex:0,
- animationData: "",
- isLike:false,
- loading:false,
- currentPage:1,
- exhibitionList:[],
- pavilionList:[],
- totalElements:''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- searchText: options.searchText,
- serverName,
- imgServer
- });
- this.loadData();
- this.getKeywordCode()
-
- var animation = wx.createAnimation({
- duration: 400,
- timingFunction: 'ease-in-out',
- })
- this.animation = animation
- animation.scale(1.5, 1.5).step();
- animation.scale(1, 1).step();
- this.setData({
- animationData: animation.export(),
- noExhibitionImg,
- noExhibitionHallImg,
- defaultImg
- })
- console.log(options.searchText);
- this.setData({
- })
- },
- keywordSearch:function(e){
- let { keyword } = e.currentTarget.dataset;
- this.setData({
- searchText: keyword
- })
- console.log("s",e)
- this.loadData();
- },
- getKeywordCode:function(){
- request["getKeywordCode"]({}, "", res => {
- if (res.data.code > -1) {
- let {data:keyword} = res.data;
- this.setData({
- keyword
- })
- wx.stopPullDownRefresh();
- console.log(res)
- }
- }, err => {
- }, complete => {
- })
- },
- loadData: function () {
- // 通过activeIndex 判断应该load哪部分的数据
- const { activeIndex } = this.data;
- this.setData({
- exhibitionList: [],
- pavilionList: []
- });
- if (activeIndex == 0) {
- this.getExhibitionSearch(1);
- }
- else if (activeIndex == 1) {
- this.getPavilionSearch(1);
- }
- else {
- return
- }
- },
- addLike: function (e) {
- let { type, id, idx } = e.currentTarget.dataset;
- console.log(idx, type, id)
- let { collectedArr, collectedChange } = app.globalData, hasItem = true;
- let exhibitionList = this.data.exhibitionList;
- console.log('type', type)
- Toast.showToast2('loading');
- let loginSessionKey = wx.getStorageSync('token') || "";
- // if (loginSessionKey){
- request['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) {
- console.log("true")
- 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();
- })
- // }
- console.log(this.data.exhibitionList)
- },
- getExhibitionSearch:function(page){
- let name = this.data.searchText||"";
- this.setData({
- loading: true
- })
- request["getExhibitionSearch"]({
- name,
- page
- },"",res=>{
- if(res.data.code>-1){
- let tempContent = this.data.exhibitionList
- ? this.data.exhibitionList
- : [];
- let { last: lastPage, totalPages, content: exhibitionList } = res.data.data;
- this.setData({
- currentPage: res.data.data.number+1,
- lastPage,
- loading: false,
- exhibitionList: tempContent.concat(exhibitionList),
- totalElements: res.data.data.totalElements
- });
- console.log(exhibitionList)
- wx.stopPullDownRefresh();
- console.log(res)
- }
- },err=>{
-
- }, complete => {
- })
- },
- getPavilionSearch: function (page) {
- let name = this.data.searchText || "";
- this.setData({
- loading: true
- })
- request["getPavilionSearch"]({
- name,
- page
- }, "", res => {
- if (res.data.code > -1) {
- let tempContent = this.data.pavilionList
- ? this.data.pavilionList
- : [];
- let { last: lastPage, totalPages, content: pavilionList } = res.data.data;
- console.log(res)
- this.setData({
- currentPage: res.data.data.number+1,
- lastPage,
- loading: false,
- pavilionList: tempContent.concat(pavilionList),
- });
- console.log(pavilionList)
- wx.stopPullDownRefresh();
- console.log(res)
- }
- }, err => {
- }, complete => {
- })
- },
- searchByText: function () {
- this.loadData()
- },
- bindInput: function (event) {
- var obj = {},
- key = event.target.dataset['key'];
- // Toast.showToast('success', event.detail.value);
- obj[key] = event.detail.value;
- this.setData(obj);
- console.log(this.data.searchText)
- },
- loadMore: function () {
- const { activeIndex } = this.data;
- // const loadDataFn =
- // activeIndex == 0 ? this.loadOneToOrderData : this.loadClassroomData;
- let loadDataFn;
- if ( activeIndex == 0) {
- loadDataFn = this.getExhibitionSearch;
- }
- else if ( activeIndex == 1) {
- loadDataFn = this.getPavilionSearch;
- }
- else {
- return
- }
- if (!this.data.lastPage) {
- this.setData({
- loading: true
- });
- console.log(this.data.currentPage + 1)
- loadDataFn(this.data.currentPage + 1);
- } else {
- return;
- }
- },
- onReachBottom: function () {
- if (!this.data.loading) {
- this.loadMore();
- console.log('reach Bottom');
- }
- },
- tabClick: function (e) {
- let { activeIndex } = this.data;
- this.setData({
- loading: true,
- activeIndex: e.currentTarget.id
- })
- this.loadData();
- console.log(e.currentTarget.id)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let { collectedArr, collectedChange } = app.globalData;
- let { exhibitionList } = this.data
- let isLogin = app.globalData.isLogin;
- // this.setData({
- // exhibitionList: []
- // });
- // this.getBanner();
- // this.getList(1);
- console.log('dwdwasda', isLogin)
- this.setData({
- isLogin
- })
- 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;
- }
- }
- }
- // console.log(collectedArr.status, collectedArr.collectedId)
- }
- this.setData({
- exhibitionList,
- })
- }
- // app.globalData.clickToSelect = false;
- // app.globalData.collectedChange = false;
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|