yiming
2024-04-28 9ba507bed7688a1a9eee31255e40add8bf1a8689
pages/bookExhibitionList/index.js
@@ -1,6 +1,6 @@
// pages/bookExhibitionList/index.js
import Toast from 'tdesign-miniprogram/toast/index';
import watch from './watch/watch'
const app = getApp()
Page({
@@ -8,6 +8,10 @@
   * 页面的初始数据
   */
  data: {
    name: "测试watch",
    newPrice: '',
    loading: true,
    hidden: true,
    totalSize: '',
    start: 0,
    isMore: null,
@@ -35,26 +39,20 @@
        },
        {
          value: 'jsek_bFHigherEducation',
          //重点项目
          price: 'jsek_higherEducation',
          label: '高等教育',
        },
        {
          value: 'jsek_bFVocationalEducation',
          //重点项目
          price: 'jsek_vocationalEducation',
          label: '职业教育',
        },
        {
          value: 'jsek_bFTeacherEducation',
          //重点项目
          price: 'jsek_teacherEducation',
          label: '教师教育',
        },
      ],
    },
    multipleSelect: {
      value: [],
      // value: [],
      options: [],
    },
    navBarHeight: '',
@@ -64,22 +62,23 @@
      value: 'timeAsc',
      options: [{
          value: 'nameAsc',
          label: '名称从高到低',
          label: '名称正序',
        },
        {
          value: 'nameDesc',
          label: '名称从低到高',
          label: '名称倒序',
        },
        {
          value: 'timeAsc',
          label: '创建时间从高到低',
          label: '出版时间正序',
        },
        {
          value: 'timeDesc',
          label: '创建时间从底到高',
          label: '出版时间倒序',
        },
      ],
    },
    newValue: ''
  },
@@ -88,9 +87,10 @@
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(this.data.keynoteDisabled, 'keynoteDisabled');
    // console.log(this.data.filteredItems, 88888);
    console.log(this.data.multipleSelect.options.length, '44444');
    // this.setData({
    //   'product.value': '*',
    // });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
@@ -99,38 +99,23 @@
      barHeight: systInfo.statusBarHeight,
    })
    // 单列选择器选项
    const singleSelectOptions = this.data.filteredItems.map(item => ({
      label: item.name,
      value: item.value,
      disabled: false,
    }))
    if (this.data.filteredItems = []) {
      console.log(11111);
      // singleSelectOptions.push({
      //   label: '暂无数据',
      //   value: 'disabled',
      //   disabled: true,
      // });
    } else {
      console.log(7889);
    }
    console.log(this.data.bookExhibitionList.length, 'this.data.bookExhibitionList.length');
    // 更新数据
    this.setData({
      'multipleSelect.options': singleSelectOptions,
    });
    // watch.setWatcher(this);
    // let that = this;
    // setTimeout(function () {
    //   that.data.name = "测试watch变化了"
    // }, 5000)
    // 
  },
  watch: {
    name: function (newVal, oldVal) {
      //这里的this和onLoad里的this指向一样
      console.log(newVal, oldVal);
    },
    newPrice: function (newVal, oldVal) {
      console.log(newVal, oldVal);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
@@ -142,8 +127,11 @@
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // debugger
    this.bookExhibitionGet()
    this.keyProjectsGet()
    this.keyProjectsGet(this.data.newPrice)
  },
@@ -159,6 +147,8 @@
   */
  onUnload() {
  },
  /**
@@ -173,9 +163,7 @@
  // },
  onScrollToLower() {
    console.log(789);
    console.log(this.data.bookExhibitionList.length);
    console.log(this.data.totalSize);
    if (this.data.bookExhibitionList.length < this.data.totalSize) {
      this.setData({
        isMore: true,
@@ -190,7 +178,7 @@
        this.setData({
          isMore: false
        })
        console.log('300');
      }, 300)
    }
  },
@@ -198,10 +186,8 @@
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // console.log(this.data.page.size);
    // console.log(this.data.total);
    if (this.data.page.size >= this.data.total) {
      console.log('已加载完所有数据');
      Toast({
        context: this,
        selector: '#t-toast',
@@ -218,10 +204,7 @@
        // 'page.start': currentPage,
        'page.size': newSize
      });
      this.bookExhibitionGet(); // 调用方法加载更多数据
      // this.bookExhibitionGet(); // 调用方法加载更多数据
    }
  },
@@ -242,7 +225,7 @@
      'Name*': this.data.keyword,
      '||subtitle*': this.data.keyword
    }
    // console.log(this.data.keynoteValue);
    let sort = {};
    const sortOptions = {
@@ -265,11 +248,11 @@
    sort = sortOptions[this.data.product.value] || {};
    console.log(sort);
    app.MG.store.getProductList({
      storeInfo: 'jsek_bookFair',
      path: newValue,
      path: this.data.newValue,
      queryType: '*',
      fields: {
        jsek_link: [],
@@ -292,60 +275,129 @@
        }
        item.subtitleName = item.subtitle + item.name
      })
      console.log(res, 'item');
      this.data.total = res.total
      // list.push(res.datas)
      console.log(res.datas.length);
      if (res.datas.length == 0) {
        this.setData({
          keynoteDisabled: true
          // keynoteDisabled: true
        })
      }
      const list = [...res.datas]
      console.log(res);
      this.setData({
        bookExhibitionList: list,
        totalSize: res.total
      })
      // 判断数据长度
      console.log(list.length, 'list.length');
      //取消
      wx.hideLoading()
      // console.log(this.data.bookExhibitionList, '数据');
      this.setData({
        loading: false,
        hidden: false,
      })
    })
  },
  //重点项目接口
  keyProjectsGet(newPrice) {
    // console.log(newPrice, 'newPrice');
  keyProjectsGet() {
    // debugger
    if (this.data.multipleSelect.options.length !== 0) {
      console.log('张一鸣');
      this.setData({
        'multipleSelect.options': [],
      });
    }
    //骨架屏
    this.setData({
      loading: true,
      hidden: true,
    })
    // 参数
    let parms = {
      refCodes: ['bookClassification']
    }
    //请求数据
    app.MG.store.getProductTypeField(parms).then(res => {
      // 格式化数据
      const checkData = JSON.parse(res[0].config)
      console.log(checkData);
      // 循环然后判断相匹配的数据赋值给filteredItems
      checkData.option.forEach(item => {
        if (newPrice == item.value) {
        if (this.data.newPrice == item.value) {
          if (this.data.filteredItems.length !== 0) {
            this.setData({
              filteredItems: [] // 如果存在子项则赋值,否则赋值为空数组
            });
          }
          this.setData({
            filteredItems: item.child || [] // 如果存在子项则赋值,否则赋值为空数组
          });
          // console.log(this.data.filteredItems);
        }
      })
      this.onLoad();
      this.setData({
        'multipleSelect.options': [],
      });
      const singleSelectOptions = []
      console.log(this.data.multipleSelect.options, 'multipleSelect.options');
      console.log(singleSelectOptions, 'singleSelectOptions');
      // 单列选择器选项
      // 单列选择器选项
      this.data.filteredItems.forEach(item => {
        singleSelectOptions.push({
          label: item.name,
          value: item.value,
        });
      });
      if (singleSelectOptions.length === 0) {
        singleSelectOptions.push({
          label: '暂无数据',
        });
      }
      // 更新数据
      this.setData({
        'multipleSelect.options': singleSelectOptions,
      });
      // 取消骨架屏
      this.setData({
        loading: false,
        hidden: false,
      })
    })
    // if (newPrice) {
    //   this.setData({
    //     keynoteDisabled: false
    //   })
    // }
    // if (!newPrice) {
    //   this.setData({
    //     keynoteDisabled: true
    //   })
    // }
  },
@@ -355,67 +407,63 @@
  // 总分类
  onChange(e) {
    this.data.page.size = 16 //更改显示的值
    const newValue = e.detail.value;
    const selectedOption = this.data.product.options.find(option => option.value === newValue);
    const newPrice = selectedOption ? selectedOption.price : null;
    const bookExhibitionListsubsidiary = []
    this.setData({
      bookExhibitionListsubsidiary: this.data.bookExhibitionList
    })
    console.log(bookExhibitionListsubsidiary, 'bookExhibitionListsubsidiary');
    console.log(newValue, 'newValue');
    console.log(newPrice, 'newPrice');
    if (newPrice) {
      this.setData({
        keynoteDisabled: false
      })
    }
    if (!newPrice) {
      this.setData({
        keynoteDisabled: true
      })
    }
      'multipleSelect.options': [],
    });
    console.log(this.data.multipleSelect.options);
    const newValue = e.detail.value;
    console.log(newValue);
    this.setData({
      'product.value': newValue,
      'product.price': newPrice, // 将选中的 price 值保存在数据中
      newValue: newValue
    });
    this.bookExhibitionGet(newValue);
    this.keyProjectsGet(newPrice);
    // 调用更新页面数据的函数,传入新的 value 和 price 值
    // let newPrice = ''
    if (newValue == 'jsek_bFHigherEducation') {
      this.setData({
        newPrice: 'jsek_higherEducation'
      })
    } else if (newValue == 'jsek_bFVocationalEducation') {
      this.setData({
        newPrice: 'jsek_vocationalEducation'
      })
    } else if (newValue == 'jsek_bFTeacherEducation') {
      this.setData({
        newPrice: 'jsek_teacherEducation'
      })
    }
    this.keyProjectsGet(this.data.newPrice)
    this.bookExhibitionGet(newValue);
    if (this.data.keynoteValue) {
      //如果有数据就清空并刷新页面
      this.data.keynoteValue = []
      this.bookExhibitionGet(newValue)
      this.onLoad()
    }
    this.onLoad()
  },
  // 重点项目
  handleMultipleSelect(e) {
    console.log(e);
    this.setData({
      'multipleSelect.value': e.detail.value,
    });
  },
  handleConfirm(event) {
    console.log(event);
    const {
      value
    } = event.detail;
    // 确认操作的处理逻辑
    console.log('确认操作,选中的值为:', value);
    this.data.keynoteValue = value
    this.bookExhibitionGet()
  },
  handleReset() {
  handleReset(e) {
    // 重置操作的处理逻辑
    this.data.keynoteValue = []
    console.log('重置操作');
    this.bookExhibitionGet()
  },
  onSwapRight() {
@@ -438,22 +486,23 @@
  },
  onSwapLeft() {
    this.data.nameSort = 'Desc'
    // console.log('sssssss');
    this.bookExhibitionGet()
  },
  onBookExhibitionDetails: function (event) {
    const item = event.currentTarget.dataset.item;
    console.log(item);
    wx.navigateTo({
      url: '/pages/bookExhibitionDetails/index?id=' + item.id + '&bookName=' + item.name + '&subtitleName=' + item.subtitleName // 假设跳转到详情页面,并传递了id参数
    });
  },
  // 搜索框
  onSearchSubmit(e) {
    this.setData({
      keyword: e.detail.value
    })
    console.log(this.data.keyword, 'keyword');
    this.bookExhibitionGet()
  },
  goBack() {
@@ -463,8 +512,10 @@
    this.setData({
      'product.value': e.detail.value,
    });
    console.log(e.detail.value, 'e.detail.value');
    this.bookExhibitionGet()
  },
  onOpend() {
  }
})