liukangdong
2024-08-15 9a9af13c74e98dfdb61afd9cbe56b1b7ec8c3414
wechat_jiaxuan/components/disProduct/index.js
@@ -1,4 +1,6 @@
import { getCatalogList, getCataLogTagList, getZhongTaiProductPage } from '../../api/index'
import { eventBus } from '../../utils/eventBus'
let touchDot = 0
Component({
  /**
   * 组件的属性列表
@@ -11,6 +13,10 @@
   * 组件的初始数据
   */
  data: {
    // 动画
    showTouch: true,
    animationData: {},
    activeIndex: -1,
    activeParam: [],
    tagCodes: [],
@@ -23,7 +29,33 @@
    total: 0,
    query: '',
    sortType: '',
    catalogCode: ""
    catalogCode: "",
    scrollTop: 0
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      console.log('组件被展示');
      eventBus.once('productDeBack', (info) => {
        const datalist = this.data.datalist
        datalist.forEach(item => {
          if(item.id === info.id){
            console.log(item)
            console.log(info)
            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 =(item.viewCount||0) +1
          }
        })
        this.setData({ datalist })
      })
    },
  },
  attached() {
    this.getCatelist()
@@ -35,8 +67,48 @@
        getApp().globalData.catalogCode = ''
      }, 2000)
    }
    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() {
      getCatalogList({
        catalogCode: 'product_intro'
@@ -74,10 +146,12 @@
      getZhongTaiProductPage({
        catalogCode, pageNum, pageSize, sortType, query, tagCodes
      }).then(res => {
        this.setData({
          datalist: [...this.data.datalist, ...res.data.records],
          total: res.data.total
        })
        if (res.data && res.data.records) {
          this.setData({
            datalist: [...this.data.datalist, ...res.data.records],
            total: res.data.total
          })
        }
      }).finally(()=>{
        that.setData({isLoading:false})
      })
@@ -94,10 +168,6 @@
          icon: 'none'
        })
      }
    },
    scrolltoupper() {
      this.setData({ pageNum: 1, datalist: [], total: 0 })
      this.getList()
    },
    cateClick(e) {
      var {isLoading} = this.data
@@ -131,7 +201,7 @@
      console.log('code', code)
      console.log('tagCodes', tagCodes)
      console.log(secondCateList)
      if (index === -1) {
      if ( secondCateList[activeIndex].tempParamIndex==null ||      secondCateList[activeIndex].tempParamIndex != paramIndex) {
        // 同param里code重复
        // if (activeParam && activeParam.length > 0) {
        //   activeParam.forEach(item => {