ll
liukangdong
2024-08-15 ebc6e7ee67f13e7aa311e737dfcb4c5caed112ee
wechat_jiaxuan/pages/productVideo/index.js
@@ -5,9 +5,15 @@
   * 页面的初始数据
   */
  data: {
    acVid: '',
    viewIdList: [],
    activeIndex: -1,
    activeParam: [],
    tagCodes: [],
    videoContext:null,
    category: [],
    tagCodes: '',
    videoUrl: '',
    showVideo: false,
    isShow:false,
@@ -17,6 +23,58 @@
    pageSize: 10,
    pageNum: 1,
  },
  changeShowParams(e) {
    const { category } = this.data
    const activeIndex = e.currentTarget.dataset.index
    if (activeIndex === this.data.activeIndex) {
      this.setData({ activeIndex: -1, activeParam: [] })
    } else {
      this.setData({
        activeIndex,
        activeParam: category[activeIndex].valueVos
      })
    }
  },
  cancelParam() {
    const { category } = this.data
    category.forEach(item => {
      item.tempParamIndex = item.paramIndex
      item.tempParamName =   item.paramName
      item.tempParamCode =  item.paramCode
    })
    this.setData({ activeParam: [],activeIndex: -1 ,category})
  },
  subParam() {
    const { category } = this.data
    var codes = []
    category.forEach(item => {
      item.paramIndex =  item.tempParamIndex
      item.paramName = item.tempParamName
      item.paramCode = item.tempParamCode
      if( item.paramIndex>-1 && item.tempParamCode){
        codes.push( item.tempParamCode)
      }
    })
    this.setData({tagCodes:codes})
    this.setData({ pageNum: 1, activeParam: [] ,activeIndex: -1, dataList: [], total: 0 })
    this.getList()
  },
  tagClick(e) {
    const code = e.currentTarget.dataset.code
    const paramIndex = e.currentTarget.dataset.index
    const { category, tagCodes, activeParam, activeIndex } = this.data
    const index = tagCodes.indexOf(code)
    if ( category[activeIndex].tempParamIndex==null || category[activeIndex].tempParamIndex != paramIndex) {
      category[activeIndex].tempParamIndex = paramIndex
      category[activeIndex].tempParamCode = code
      category[activeIndex].tempParamName = activeParam[paramIndex].labelValueName
    } else {
      category[activeIndex].tempParamIndex = -1
      category[activeIndex].tempParamCode = ''
      category[activeIndex].tempParamName = ''
    }
    this.setData({ category })
  },
  onReachBottom() {
    console.log('触底事件');
@@ -34,46 +92,60 @@
  getList() {
    const { pageSize, pageNum, tagCodes } = this.data
    getZhongTaiVideoPage({
      pageSize,pageNum, tagCodes: tagCodes ? [tagCodes] : null
      pageSize,pageNum, 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
        })
      }
    })
  },
  getTagList() {
    getCataLogTagList({
      catalogCode: 'video_rec'
    }).then(res => {
      this.setData({ category: res.data })
      if(res.data){
        this.setData({ category: [...res.data] })
      }
    })
  },
  itemClick(e) {
    const { videourl ,id} = e.currentTarget.dataset.item
    const { dataList } = this.data
    const { id } = e.currentTarget.dataset.item
    const { dataList, acVid, viewIdList } = this.data
    const index = viewIdList.findIndex(i => i === id)
    if(acVid){
      if(id != acVid){
        wx.createVideoContext(acVid).pause()
        wx.createVideoContext(id).play()
        this.setData({ acVid: id })
      }
    }else{
      this.setData({ acVid: id })
      wx.createVideoContext(id).play()
    }
    dataList.forEach(ite => {
      if(id === ite.id){
      if(id === ite.id && index === -1){
        ite.viewCount += 1
        viewIdList.push(id)
        actionDo({
          actionType: 'view',
          id: id
        })
        this.setData({ viewIdList })
      }
    })
    this.setData({ dataList })
    actionDo({
      actionType: 'view',
      id: id
    })
    // let videoPlay = this.selectComponent('.videoPlay');
    // if(videoPlay){
    //   videoPlay.startPlayVideo(videourl,this );
    // }
    // this.startPlayVideo(videourl)
    // wx.previewMedia({
    //   sources: [{ url: videourl, type: 'video' }]
    // })
  },
  cateClick(e) {
    const { code } = e.target.dataset
    this.setData({ tagCodes: code })
    const { code, index } = e.target.dataset
    if(this.data.activeIndex === index){
      this.setData({ tagCodes: [], activeIndex: -1 })
    }else{
      this.setData({ tagCodes: [code], activeIndex: index })
    }
    this.setData({ total: 0, dataList: [], pageNum: 1 })
    this.getList()
  },