yiming
2024-04-29 4496721cd3af3c68ed4d55218d3e83ea0664c57e
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,8 @@
   * 页面的初始数据
   */
  data: {
    name: "测试watch",
    newPrice: '',
    loading: true,
    hidden: true,
    totalSize: '',
@@ -37,20 +39,14 @@
        },
        {
          value: 'jsek_bFHigherEducation',
          //重点项目
          price: 'jsek_higherEducation',
          label: '高等教育',
        },
        {
          value: 'jsek_bFVocationalEducation',
          //重点项目
          price: 'jsek_vocationalEducation',
          label: '职业教育',
        },
        {
          value: 'jsek_bFTeacherEducation',
          //重点项目
          price: 'jsek_teacherEducation',
          label: '教师教育',
        },
      ],
@@ -82,6 +78,7 @@
        },
      ],
    },
    newValue: ''
  },
@@ -91,7 +88,9 @@
   */
  onLoad(options) {
    // this.setData({
    //   'product.value': '*',
    // });
    const systInfo = wx.getSystemInfoSync();
    const menu = wx.getMenuButtonBoundingClientRect(); // 胶囊信息
    const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 导航栏高度
@@ -100,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 = []) {
      // singleSelectOptions.push({
      //   label: '暂无数据',
      //   value: 'disabled',
      //   disabled: true,
      // });
    } else {
      console.log(7889);
    }
    // 更新数据
    this.setData({
      'multipleSelect.options': singleSelectOptions,
    });
    //
    // watch.setWatcher(this);
    // let that = this;
    // setTimeout(function () {
    //   that.data.name = "测试watch变化了"
    // }, 500)
    console.log(11111);
  },
  watch: {
    name: function (newVal, oldVal) {
      //这里的this和onLoad里的this指向一样
      console.log(newVal, oldVal);
    },
    newPrice: function (newVal, oldVal) {
      console.log(newVal, oldVal);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
@@ -144,8 +128,7 @@
   */
  onShow() {
    this.bookExhibitionGet()
    this.keyProjectsGet()
    this.keyProjectsGet(this.data.newPrice)
  },
  /**
@@ -159,6 +142,8 @@
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
@@ -199,7 +184,6 @@
  onReachBottom() {
    if (this.data.page.size >= this.data.total) {
      Toast({
        context: this,
        selector: '#t-toast',
@@ -217,9 +201,6 @@
        'page.size': newSize
      });
      // this.bookExhibitionGet(); // 调用方法加载更多数据
    }
  },
@@ -267,7 +248,7 @@
    app.MG.store.getProductList({
      storeInfo: 'jsek_bookFair',
      path: newValue,
      path: this.data.newValue,
      queryType: '*',
      fields: {
        jsek_link: [],
@@ -299,7 +280,7 @@
      if (res.datas.length == 0) {
        this.setData({
          keynoteDisabled: true
          // keynoteDisabled: true
        })
      }
@@ -325,33 +306,82 @@
  },
  //重点项目接口
  keyProjectsGet(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)
      console.log(checkData);
      // 循环然后判断相匹配的数据赋值给filteredItems
      checkData.option.forEach(item => {
        if (newPrice == item.value) {
          this.setData({
            filteredItems: item.child || [] // 如果存在子项则赋值,否则赋值为空数组
          });
        }
      })
      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({
        'multipleSelect.options': singleSelectOptions,
      });
      // 取消骨架屏
      this.setData({
        loading: false,
        hidden: false,
      })
    })
    // if (newPrice) {
    //   this.setData({
    //     keynoteDisabled: false
    //   })
    // }
    // if (!newPrice) {
    //   this.setData({
    //     keynoteDisabled: true
    //   })
    // }
  },
@@ -360,73 +390,70 @@
  // 总分类
  // 总分类
  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
    // })
    if (newPrice) {
      this.setData({
        keynoteDisabled: false
      })
    }
    if (!newPrice) {
      this.setData({
        keynoteDisabled: true
      })
    }
    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') {
      newPrice = 'jsek_higherEducation'
      // this.setData({
      //   newPrice: 'jsek_higherEducation'
      // })
    } else if (newValue == 'jsek_bFVocationalEducation') {
      // this.setData({
      //   newPrice: 'jsek_vocationalEducation'
      // })
      newPrice = 'jsek_vocationalEducation'
    } else if (newValue == 'jsek_bFTeacherEducation') {
      // this.setData({
      //   newPrice: 'jsek_teacherEducation'
      // })
      newPrice = 'jsek_teacherEducation'
    } else {
      newPrice = ''
    }
    this.keyProjectsGet(newPrice)
    this.bookExhibitionGet(newValue);
    if (this.data.keynoteValue) {
      //如果有数据就清空并刷新页面
      this.data.keynoteValue = []
      this.bookExhibitionGet(newValue)
      this.onLoad()
    }
    // e.stopImmediatePropagation()
    this.onLoad()
  },
  // 重点项目
  handleMultipleSelect(e) {
    console.log(e);
    this.setData({
      'multipleSelect.value': e.detail.value,
    });
  },
  handleConfirm(event) {
    console.log(event);
    const {
      value
    } = event.detail;
    // 确认操作的处理逻辑
    // this.data.keynoteValue = value
    this.setData({
      keynoteValue: value,
    this.data.keynoteValue = value
    })
    this.bookExhibitionGet()
  },
  handleReset(e) {
    // 重置操作的处理逻辑
    this.data.keynoteValue = []
    this.bookExhibitionGet()