litian
2024-09-02 c3086cda662e2b908cf96b6b3ff599713eb924d6
pages/bookExhibitionList/index.js
@@ -1,54 +1,52 @@
// pages/bookExhibitionList/index.js
import Toast from 'tdesign-miniprogram/toast/index';
const app = getApp()
import Toast from "tdesign-miniprogram/toast/index";
import watch from "./watch/watch";
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    name: "测试watch",
    newPrice: "",
    loading: true,
    hidden: true,
    totalSize: "",
    start: 0,
    isMore: null,
    keynoteDisabled: true,
    value: '',
    keyword: '',
    value: "",
    keyword: "",
    nameSort: null,
    total: null,
    page: {
      start: 0,
      size: 16
      size: 16,
    },
    keynoteValue: null,
    keynoteValue: [],
    filteredItems: [],
    newValue: null,
    bookExhibitionList: [],
    sorter: {
      value: 'default',
      value: "default",
    },
    product: {
      value: '*',
      options: [
        {
          value: '*',
          label: '总分类',
      value: "*",
      options: [{
          value: "*",
          label: "总分类",
        },
        {
          value: 'jsek_bFHigherEducation',
          //重点项目
          price: 'jsek_higherEducation',
          label: '高等教育',
          value: "jsek_bFHigherEducation",
          label: "高等教育",
        },
        {
          value: 'jsek_bFVocationalEducation',
          //重点项目
          price: 'jsek_vocationalEducation',
          label: '职业教育',
          value: "jsek_bFVocationalEducation",
          label: "职业教育",
        },
        {
          value: 'jsek_bFTeacherEducation',
          //重点项目
          price: 'jsek_teacherEducation',
          label: '教师教育',
          value: "jsek_bFTeacherEducation",
          label: "教师教育",
        },
      ],
    },
@@ -56,322 +54,374 @@
      value: [],
      options: [],
    },
    navBarHeight: '',
    barHeight: '',
    windowHeight: '',
    navBarHeight: "",
    barHeight: "",
    windowHeight: "",
    sorter: {
      value: "timeAsc",
      options: [{
          value: "nameAsc",
          label: "名称正序",
        },
        {
          value: "nameDesc",
          label: "名称倒序",
        },
        {
          value: "timeAsc",
          label: "出版时间正序",
        },
        {
          value: "timeDesc",
          label: "出版时间倒序",
        },
      ],
    },
    newValue: "",
    disbaleProject: true,
    disabledSort: false
  },
  /**
    * 生命周期函数--监听页面加载
    */
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log(this.data.filteredItems, 88888);
    // this.setData({
    //   'product.value': '*',
    // });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    const navBarHeight =
      (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
    this.setData({
      navBarHeight: navBarHeight,
      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);
    }
    // 更新数据
    this.setData({
      'multipleSelect.options': singleSelectOptions,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.bookExhibitionGet()
    this.keyProjectsGet()
    this.bookExhibitionGet();
    this.keyProjectsGet(this.data.newPrice);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  onHide() {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  onUnload() {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  onPullDownRefresh() {
    this.data.page.size = 16 //更改显示的值
    this.bookExhibitionGet(); // 调用方法加载更多数据
  onPullDownRefresh() {},
  onScrollToLower() {
    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,
        });
      }, 300);
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  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',
        message: '没有更多了',
        direction: 'column',
        selector: "#t-toast",
        message: "没有更多了",
        direction: "column",
        duration: 1000,
        preventScrollThrough: true,
        icon: 'poweroff',
        icon: "poweroff",
      });
    } else {
      // const currentPage = this.data.page.start + 1; // 获取当前页数并加1
      const newSize = this.data.page.size + 10; // 原来的基础上加10
      this.setData({
        // 'page.start': currentPage,
        'page.size': newSize
        "page.size": newSize,
      });
      this.bookExhibitionGet(); // 调用方法加载更多数据
      // this.bookExhibitionGet(); // 调用方法加载更多数据
    }
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  },
  onShareAppMessage() {},
  // 图片数据的接口
  bookExhibitionGet(newValue) {
    wx.showLoading({
      title: '加载中...',
    this.setData({
      disabledSort: false
    })
    let searchObj = {
      'Name*': this.data.keyword,
      '||subtitle*': this.data.keyword
    }
    // console.log(this.data.keynoteValue);
    let sort = {
      Name: this.data.nameSort || 'Desc'
    }
    app.MG.store.getProductList({
      storeInfo: 'jsek_bookFair',
      path: newValue,
      queryType: '*',
      fields: {
        jsek_link: [],
        subtitle: [],
        'bookClassification*': this.data.keynoteValue || [],
        ...searchObj
      "Name*": this.data.keyword,
      "||subtitle*": this.data.keyword,
    };
    let sort = {};
    const sortOptions = {
      "*": {
        CreateDate: "Asc",
      },
      paging: this.data.page,
      sort: sort,
      // coverSize: {
      //   width: 100
      // },
    }).then(res => {
      res.datas.forEach((item) => {
        item.subtitleName = item.subtitle + item.name
      nameAsc: {
        Name: "Asc",
      },
      nameDesc: {
        Name: "Desc",
      },
      timeAsc: {
        CreateDate: "Asc",
      },
      timeDesc: {
        CreateDate: "Desc",
      },
    };
    sort = sortOptions[this.data.product.value] || {};
    app.MG.store
      .getProductList({
        storeInfo: "jsek_bookFair",
        path: this.data.newValue,
        queryType: "*",
        fields: {
          jsek_link: [],
          subtitle: [],
          "bookClassification*": this.data.keynoteValue || [],
          ...searchObj,
        },
        paging: {
          start: "0",
          size: this.data.start * 10,
        },
        sort: sort,
        // coverSize: {
        //   width: 100
        // },
      })
      console.log(res, 'item');
      this.data.total = res.total
      //  list.push(res.datas)
      const list = [...res.datas]
      this.setData({
        bookExhibitionList: list
      })
      //取消
      wx.hideLoading()
      // console.log(this.data.bookExhibitionList, '数据');
    })
      .then((res) => {
        res.datas.forEach((item) => {
          if (item.subtitle == undefined) {
            item.subtitle = "";
          }
          item.subtitleName = item.subtitle + item.name;
        });
        this.data.total = res.total;
        if (res.datas.length == 0) {
          this.setData({
            disabledSort: true
          })
          if (!this.data.keynoteValue.length) {
            this.setData({
              disbaleProject: true
            });
          }
        }
        const list = [...res.datas];
        this.setData({
          bookExhibitionList: list,
          totalSize: res.total,
        });
        this.setData({
          loading: false,
          hidden: false,
        });
      });
  },
  //重点项目接口
  keyProjectsGet(newPrice) {
    // console.log(newPrice, 'newPrice');
    this.setData({
      filteredItems: [], // 如果存在子项则赋值,否则赋值为空数组
    });
    //骨架屏
    this.setData({
      loading: true,
      hidden: true,
    });
    // 参数
    let parms = {
      refCodes: ['bookClassification']
    }
    app.MG.store.getProductTypeField(parms).then(res => {
      const checkData = JSON.parse(res[0].config)
      checkData.option.forEach(item => {
      refCodes: ["bookClassification"],
    };
    //请求数据
    app.MG.store.getProductTypeField(parms).then((res) => {
      // 格式化数据
      const checkData = JSON.parse(res[0].config);
      // 循环然后判断相匹配的数据赋值给filteredItems
      checkData.option.forEach((item) => {
        if (newPrice == item.value) {
          this.setData({
            filteredItems: item.child || [] // 如果存在子项则赋值,否则赋值为空数组
            filteredItems: item.child || [], // 如果存在子项则赋值,否则赋值为空数组
          });
          // console.log(this.data.filteredItems);
        }
      })
      this.onLoad();
    })
      });
      let singleSelectOptions = [];
      // 单列选择器选项
      // 单列选择器选项
      this.data.filteredItems.forEach((item) => {
        singleSelectOptions.push({
          label: item.name,
          value: item.value,
        });
      });
      if (singleSelectOptions.length === 0) {
        singleSelectOptions.push({
          label: "暂无数据",
        });
        this.setData({
          disbaleProject: true
        })
      }
      // 更新数据
      this.setData({
        "multipleSelect.options": singleSelectOptions,
      });
      // 取消骨架屏
      this.setData({
        loading: false,
        hidden: false,
      });
    });
    // if (newPrice) {
    //   this.setData({
    //     keynoteDisabled: false
    //   })
    // }
    // if (!newPrice) {
    //   this.setData({
    //     keynoteDisabled: true
    //   })
    // }
  },
  // 总分类
  // 总分类
  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;
    console.log(newValue, 'newValue');
    console.log(newPrice, 'newPrice');
    if (newPrice) {
      this.setData({
        keynoteDisabled: false
      })
    } else {
      this.setData({
        keynoteDisabled: true
      })
    }
    this.setData({
      'product.value': newValue,
      'product.price': newPrice, // 将选中的 price 值保存在数据中
      "product.value": newValue,
      newValue: newValue,
      disbaleProject: false,
      loading: true
    });
    this.bookExhibitionGet(newValue);
    let newPrice = "";
    if (newValue == "jsek_bFHigherEducation") {
      newPrice = "jsek_higherEducation";
    } else if (newValue == "jsek_bFVocationalEducation") {
      newPrice = "jsek_vocationalEducation";
    } else if (newValue == "jsek_bFTeacherEducation") {
      newPrice = "jsek_teacherEducation";
    } else {
      // 选择总分类
      this.setData({
        disbaleProject: true
      })
      newPrice = "";
    }
    this.keyProjectsGet(newPrice);
    // 调用更新页面数据的函数,传入新的 value 和 price 值
    this.bookExhibitionGet(newValue);
    if (this.data.keynoteValue) {
      //如果有数据就清空并刷新页面
      this.data.keynoteValue = []
      this.bookExhibitionGet(newValue)
      this.onLoad()
      console.log('true');
    } else {
      // this.bookExhibitionGet(newValue);
      // this.keyProjectsGet(newPrice);
      console.log('fals');
      this.data.keynoteValue = [];
      this.bookExhibitionGet(newValue);
    }
  },
  // 重点项目
  handleMultipleSelect(e) {
    this.setData({
      'multipleSelect.value': e.detail.value,
      "multipleSelect.value": e.detail.value,
    });
  },
  handleConfirm(event) {
    const { value } = event.detail;
    const {
      value
    } = event.detail;
    // 确认操作的处理逻辑
    console.log('确认操作,选中的值为:', value);
    this.data.keynoteValue = value
    this.bookExhibitionGet()
    // this.data.keynoteValue = value
    this.setData({
      keynoteValue: value,
      loading: true
    });
    this.bookExhibitionGet();
  },
  handleReset() {
  handleReset(e) {
    // 重置操作的处理逻辑
    this.data.keynoteValue = []
    console.log('重置操作');
    this.bookExhibitionGet()
    this.data.keynoteValue = [];
    this.bookExhibitionGet();
  },
  onSwapRight() {
    // console.log('xxxxxx');
    // this.data.nameSort = 'Asc'
    if (!this.data.nameSort) {
      this.setData({
        nameSort: 'Desc',
        nameSort: "Desc",
      });
    } else if (this.data.nameSort == 'Desc') {
    } else if (this.data.nameSort == "Desc") {
      this.setData({
        nameSort: 'Asc',
        nameSort: "Asc",
      });
    } else if (this.data.nameSort == 'Asc') {
    } else if (this.data.nameSort == "Asc") {
      this.setData({
        nameSort: '',
        nameSort: "",
      });
    }
    this.bookExhibitionGet()
    this.bookExhibitionGet();
  },
  onSwapLeft() {
    this.data.nameSort = 'Desc'
    // console.log('sssssss');
    this.bookExhibitionGet()
    this.data.nameSort = "Desc";
    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参数
      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()
      keyword: e.detail.value,
    });
    this.bookExhibitionGet();
  },
  goBack() {
    wx.navigateBack();
  },
})
  onSort(e) {
    this.setData({
      "product.value": e.detail.value,
    });
    this.bookExhibitionGet();
  },
  onOpend() {},
});