ll
liukangdong
2024-08-27 2c08a98f7e85ec7c9376f27a7933e75e44d672f7
wechat_jiaxuan/components/disCase/index.js
@@ -1,4 +1,6 @@
import { getCataLogTagList, getZhongTaiWholecasePage, actionDo } from '../../api/index'
import { eventBus } from '../../utils/eventBus'
let touchDot = 0
Component({
  /**
   * 组件的属性列表
@@ -7,6 +9,10 @@
    menuButtonInfo: Object
  },
  data: {
    // 动画
    showTouch: true,
    animationData: {},
    activeIndex: -1,
    activeParam: [],
    selParam: '',
@@ -22,10 +28,74 @@
    sortType: '',
    catalogCode: 'whole_case'
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      console.log('组件被展示');
      eventBus.once('caseDeBack', (info) => {
        const dataList = this.data.dataList
        dataList.forEach(item => {
          if(item.id === info.id){
            if(item.isCollection != info.isCollection){
              if(!item.isCollection){
                item.collectCount = (item.collectCount || 0)+1
              }else if(item.collectCount >0){
                item.collectCount = (item.collectCount || 0)-1
              }
            }
            item.isCollection = info.isCollection
            item.viewCount ++
          }
        })
        this.setData({ dataList })
      })
    },
  },
  attached() {
    this.getCatelist()
    this.getList()
    this.animation = wx.createAnimation({
      duration: 600,
      timingFunction: 'ease',
    });
  },
  methods: {
    bindscrolltoupper() {
      this.setData({ showTouch: true })
      this.fadeIn();
    },
    touchstart(e){
      touchDot = e.detail.scrollTop;
    },
    touchmove(e) {
      var touchMove = e.detail.scrollTop;
      if(touchMove - touchDot > 24){
        touchDot = touchMove
        this.fadeOut();
      }
      if(touchDot - touchMove > 24){
        touchDot = touchMove
        setTimeout(() => {
          this.setData({ showTouch: true })
          this.fadeIn();
        }, 200)
      }
    },
    fadeIn: function () {
      this.animation.opacity(1).step();
      this.setData({
        animationData: this.animation.export()
      });
    },
    fadeOut: function () {
      this.animation.opacity(0).step();
      this.setData({
        animationData: this.animation.export()
      });
      setTimeout(() => {
        this.setData({ showTouch: false });
      }, 200); // 动画持续时间
    },
    getCatelist() {
      const { catalogCode } = this.data
      getCataLogTagList({
@@ -35,9 +105,6 @@
          this.setData({
            cateList: res.data
          })
          setTimeout(() => {
            this.getList()
          }, 300)
        }
      })
    },
@@ -50,7 +117,7 @@
      getZhongTaiWholecasePage({
        catalogCode, pageNum, pageSize, tagCodes, sortType, query
      }).then(res => {
        if (res.data) {
        if (res.data && res.data.records) {
          this.setData({
            total: res.data.total,
            dataList: [...this.data.dataList, ...res.data.records],
@@ -104,7 +171,7 @@
      const { cateList, tagCodes, activeParam, activeIndex } = this.data
      const index = tagCodes.indexOf(code)
      if (index === -1) {
      if (cateList[activeIndex].tempParamIndex==null ||     cateList[activeIndex].tempParamIndex != paramIndex) {
        // // 同param里code重复
        // if (activeParam && activeParam.length > 0) {
        //   activeParam.forEach(item => {