litian
2024-04-17 db7fdd2cd77a20876d534ae020477b39b5f74faa
pages/bookExhibitionList/index.js
@@ -8,6 +8,27 @@
   * 页面的初始数据
   */
  data: {
    product: {
      value: 'all',
      options: [{
          value: 'all',
          label: '全部产品',
        },
        {
          value: 'new',
          label: '最新产品',
        },
        {
          value: 'hot',
          label: '最火产品',
        },
      ],
    },
    loading: true,
    hidden: true,
    totalSize: '',
    start: 0,
    isMore: null,
    keynoteDisabled: true,
    value: '',
    keyword: '',
@@ -24,32 +45,32 @@
    sorter: {
      value: 'default',
    },
    product: {
      value: '*',
      options: [{
          value: '*',
          label: '总分类',
        },
        {
          value: 'jsek_bFHigherEducation',
          //重点项目
          price: 'jsek_higherEducation',
          label: '高等教育',
        },
        {
          value: 'jsek_bFVocationalEducation',
          //重点项目
          price: 'jsek_vocationalEducation',
          label: '职业教育',
        },
        {
          value: 'jsek_bFTeacherEducation',
          //重点项目
          price: 'jsek_teacherEducation',
          label: '教师教育',
        },
      ],
    },
    // product: {
    //   value: '*',
    //   options: [{
    //       value: '*',
    //       label: '总分类',
    //     },
    //     {
    //       value: 'jsek_bFHigherEducation',
    //       //重点项目
    //       price: 'jsek_higherEducation',
    //       label: '高等教育',
    //     },
    //     {
    //       value: 'jsek_bFVocationalEducation',
    //       //重点项目
    //       price: 'jsek_vocationalEducation',
    //       label: '职业教育',
    //     },
    //     {
    //       value: 'jsek_bFTeacherEducation',
    //       //重点项目
    //       price: 'jsek_teacherEducation',
    //       label: '教师教育',
    //     },
    //   ],
    // },
    multipleSelect: {
      value: [],
      options: [],
@@ -57,7 +78,26 @@
    navBarHeight: '',
    barHeight: '',
    windowHeight: '',
    sorter: {
      value: 'timeAsc',
      options: [{
          value: 'nameAsc',
          label: '名称正序',
        },
        {
          value: 'nameDesc',
          label: '名称倒序',
        },
        {
          value: 'timeAsc',
          label: '出版时间正序',
        },
        {
          value: 'timeDesc',
          label: '出版时间倒序',
        },
      ],
    },
  },
@@ -145,9 +185,32 @@
  onPullDownRefresh() {
  },
  onPullDownRefresh() {
    this.data.page.size = 16 //更改显示的值
    this.bookExhibitionGet(); // 调用方法加载更多数据
  // onPullDownRefresh() {
  //   this.data.page.size = 16 //更改显示的值
  //   this.bookExhibitionGet(); // 调用方法加载更多数据
  // },
  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,
        start: this.data.start + 1
      })
      this.bookExhibitionGet()
    } else {
      this.setData({
        isMore: true,
      })
      setTimeout(() => {
        this.setData({
          isMore: false
        })
        console.log('300');
      }, 300)
    }
  },
  /**
   * 页面上拉触底事件的处理函数
@@ -173,7 +236,7 @@
        // 'page.start': currentPage,
        'page.size': newSize
      });
      this.bookExhibitionGet(); // 调用方法加载更多数据
      // this.bookExhibitionGet(); // 调用方法加载更多数据
@@ -198,9 +261,30 @@
      '||subtitle*': this.data.keyword
    }
    // console.log(this.data.keynoteValue);
    let sort = {
      Name: this.data.nameSort || 'Desc'
    }
    let sort = {};
    const sortOptions = {
      '*': {
        CreateDate: 'Asc'
      },
      'nameAsc': {
        Name: 'Asc'
      },
      'nameDesc': {
        Name: 'Desc'
      },
      'timeAsc': {
        CreateDate: 'Asc'
      },
      'timeDesc': {
        CreateDate: 'Desc'
      }
    };
    sort = sortOptions[this.data.product.value] || {};
    console.log(sort);
    app.MG.store.getProductList({
      storeInfo: 'jsek_bookFair',
      path: newValue,
@@ -211,13 +295,19 @@
        'bookClassification*': this.data.keynoteValue || [],
        ...searchObj
      },
      paging: this.data.page,
      paging: {
        start: '0',
        size: this.data.start * 10
      },
      sort: sort,
      // coverSize: {
      //   width: 100
      // },
    }).then(res => {
      res.datas.forEach((item) => {
        if (item.subtitle == undefined) {
          item.subtitle = ''
        }
        item.subtitleName = item.subtitle + item.name
      })
      console.log(res, 'item');
@@ -234,9 +324,10 @@
      }
      const list = [...res.datas]
      console.log(res);
      this.setData({
        bookExhibitionList: list
        bookExhibitionList: list,
        totalSize: res.total
      })
      // 判断数据长度
      console.log(list.length, 'list.length');
@@ -245,89 +336,102 @@
      //取消
      wx.hideLoading()
      // console.log(this.data.bookExhibitionList, '数据');
      this.setData({
        loading: false,
        hidden: false,
      })
    })
  },
  //重点项目接口
  keyProjectsGet(newPrice) {
    this.setData({
      loading: true,
      hidden: true,
    })
    // console.log(newPrice, 'newPrice');
    let parms = {
      refCodes: ['bookClassification']
    }
    app.MG.store.getProductTypeField(parms).then(res => {
      const checkData = JSON.parse(res[0].config)
      checkData.option.forEach(item => {
        if (newPrice == item.value) {
          this.setData({
            filteredItems: item.child || [] // 如果存在子项则赋值,否则赋值为空数组
          });
          // console.log(this.data.filteredItems);
        }
      })
      this.onLoad();
      this.setData({
        loading: false,
        hidden: false,
      })
    })
  },
  // 总分类
  // 总分类
  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
      })
    }
    this.setData({
      'product.value': newValue,
      'product.price': newPrice, // 将选中的 price 值保存在数据中
    });
    this.bookExhibitionGet(newValue);
    this.keyProjectsGet(newPrice);
    // 调用更新页面数据的函数,传入新的 value 和 price 值
    if (this.data.keynoteValue) {
      //如果有数据就清空并刷新页面
      this.data.keynoteValue = []
      this.bookExhibitionGet(newValue)
      this.onLoad()
    }
    console.log(e);
  },
  // 总分类
  // 总分类
  // 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
  //     })
  //   }
  //   console.log(newValue);
  //   this.setData({
  //     'product.value': newValue,
  //     'product.price': newPrice, // 将选中的 price 值保存在数据中
  //   });
  //   this.bookExhibitionGet(newValue);
  //   this.keyProjectsGet(newPrice);
  //   // 调用更新页面数据的函数,传入新的 value 和 price 值
  //   if (this.data.keynoteValue) {
  //     //如果有数据就清空并刷新页面
  //     this.data.keynoteValue = []
  //     this.bookExhibitionGet(newValue)
  //     this.onLoad()
  //   }
  // },
  // 重点项目
  handleMultipleSelect(e) {
    this.setData({
      'multipleSelect.value': e.detail.value,
    });
  },
  handleConfirm(event) {
    const {
      value
@@ -338,11 +442,12 @@
    this.data.keynoteValue = value
    this.bookExhibitionGet()
  },
  handleReset() {
  handleReset(e) {
    // 重置操作的处理逻辑
    this.data.keynoteValue = []
    console.log('重置操作');
    this.bookExhibitionGet()
  },
  onSwapRight() {
@@ -369,12 +474,14 @@
    this.bookExhibitionGet()
  },
  onBookExhibitionDetails: function (event) {
    console.log(456);
    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({
@@ -386,4 +493,14 @@
  goBack() {
    wx.navigateBack();
  },
  onSort(e) {
    this.setData({
      'product.value': e.detail.value,
    });
    console.log(e.detail.value, 'e.detail.value');
    this.bookExhibitionGet()
  },
  onTest() {
    console.log(7555);
  }
})