proDetail.js 7.07 KB
// packagesList/pages/productDetail/components/proDetail/proDetail.js
// import { senceData, productData } from '~/pages/tab/storeAssistant/pages/discovery/constant/senceData'
const norTabList = ['海报案例', '测算营销', '产品介绍', '项目亮点']
Component({
  externalClasses: ['custom-class'],
  /**
   * 组件的属性列表
   */
  properties: {
    // 场景值下标
    // actNum: {
    //   type: Number,
    //   value: -1,
    //   observer(n) {
    //     this.getInfo()
    //     if (n == 3) {
    //       this.setVideoCtx()
    //     }
    //   }
    // },
    // // 选中的产品
    // activeNavIdx: {
    //   type: Number,
    //   value: 0
    // },
    // cardInfo: {
    //   type: Object,
    //   value: {}
    // },
    // // 配置url
    // activeUrl: {
    //   type: String,
    //   value: ''
    // },
    sharephone: {
      type: String,
      value: ''
    },
    showLeftFlag: {
      type: Boolean,
      value: false
    },
    detailType: {
      type: String,
      value: 'pro'
    },
    proDetail: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL: 'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/',
    videoBaseUrl: 'https://img02.glsx.com.cn/weapp/resource/saas/business-assistant/index/',
    // productData,
    proInfo: {},
    prodItemVideo: '', //选中的场景下的video的第一个
    tabAct: 0,
    scrollTop: 0,
    showCard: false,
    tabList: [],
    loadedNum: 0,
    imgTopArr: []
  },

//   lifetimes: {
//     attached() {
//       setTimeout(() => {
//         this.getImgHeight()
//       }, 800)
//     },
//   },

  /**
   * 组件的方法列表
   */
  methods: {
    setVideoCtx() {
      this.setData({
        videoCtx: wx.createVideoContext('video', this),
        crowdVideoCtx: wx.createVideoContext('crowd-video', this)
      })
    },
    handleVideoPlay(e) {
      let { attr } = e.currentTarget.dataset
      this.data[attr] && this.data[attr].pause()
    },
    // getInfo() {
    //   let { activeNavIdx, actNum } = this.data
    //   const spcList = [99] // 订阅模块需要特殊处理
    //   const senceList = this.data.productData[actNum].filter(item => item.name != '全部')
    //   for (let i = 0; i < senceList.length; i++) {
    //     let item = senceList[i]
    //     let proIdList = item?.productList.map(k => k.id)
    //     if (proIdList.includes(activeNavIdx)) {
    //       let proInfo = item.productList.find(k => k.id == activeNavIdx)
    //       this.setData({
    //         proInfo,
    //         productImgs: spcList.includes(actNum) ? proInfo.sceneImgs : (proInfo.productImgs ? proInfo.productImgs : item.productImgs),
    //         tabList: spcList.includes(actNum) ? proInfo.tabList : norTabList,
    //         prodItemVideo: item.videoList.length ? spcList.includes(actNum) ? item.videoList[proInfo.currentIndex] : item.videoList[activeNavIdx] : item.noVideoPicture[0]
    //       })
    //       break
    //     }
    //   }
    // },
    handleLongPress(e) {
      // 如果图片有长按事件 posterEventType: 1-无 2-有
      let {item} = e.currentTarget.dataset
      if (item.posterEventType == 1) return
      wx.downloadFile({
        url: item.posterEventUrl,
        success: function (res) {
          const filePath = res.tempFilePath
          wx.openDocument({
            filePath: filePath,
            success: function (res) {
            }
          })
        }
      })
        // let { actnum, index } = e.target.dataset
        // console.log(actnum, index)
        // // 膨胀金活动,合作方式
        // if (actnum == 99 && index == 4) {
        //   wx.downloadFile({
        //     // 示例 url,并非真实存在
        //     url: 'https://scrm.glsx.com.cn/frontpdf/expand_agreement.pdf',
        //     success: function (res) {
        //       const filePath = res.tempFilePath
        //       wx.openDocument({
        //         filePath: filePath,
        //         success: function (res) {
        //           console.log('打开文档成功')
        //         }
        //       })
        //     }
        //   })
        // }
    },
    async loadImg(e){
        this.data.loadedNum += 1
        if(e.currentTarget.dataset.len==this.data.loadedNum){
            let imgTopArr = [];
            const topList = await this.getDomInfo('.calc-wrap')
            const top = topList.reduce((prev, cur)=>{
                return prev + cur.height;
            }, 0)
            imgTopArr.push(top)
            const imgList = await this.getDomInfo('.img-items')
            imgList.reduce((prev, cur, index)=>{
                if(index<imgList.length-1){
                    imgTopArr.push(prev + cur.height)
                }
                return prev + cur.height;
            }, top)
            this.setData({
                imgTopArr
            })
        }
    },
    getDomInfo(dom){
        return new Promise((resolve,reject)=>{
            let query = wx.createSelectorQuery().in(this);
            query
            .selectAll(dom)
            .boundingClientRect((rt) => {
                resolve(rt)
            })
            .exec();
        })
    },
    getImgHeight() {
      let query = wx.createSelectorQuery().in(this)
      let heightArr = []
      let imgTopArr = []
      let s = 0
      let top
      let { scrollTop } = this.data
      let _this = this

      query
        .selectAll('.img-items')
        .boundingClientRect(react => {
          react.forEach((item, index) => {
            //44 tab的高度
            s = item.top - 44 + scrollTop
            imgTopArr.push(s)
          })
          _this.setData({
            imgTopArr
          })
        })
        .exec()
      // setTimeout(() => {
      //   console.log('imgTopArr',this.data.imgTopArr)
      // },500)
    },
    // 1.3查看活动详情按钮
    checkActive(e) {
      // let { activeUrl } = this.data
      // wx.$router.jumpH5(activeUrl);
      let { url } = e.currentTarget.dataset
      wx.$router.jumpH5(url);

    },
    onClickTab(event) {
      // console.log('event: ', event);
      let { index } = event.detail
      // console.log('index: ', index);
      this.setData({
        tabAct: index
      })
      let { imgTopArr } = this.data
      wx.pageScrollTo({
        scrollTop: imgTopArr[index] + 5
      })
    },
    pageSroll(e) {
      let { imgTopArr } = this.data
      wx.nextTick(() => {
        let idx
        if (imgTopArr[0] > e.scrollTop) {
          idx = 0
        } else if (imgTopArr[imgTopArr.length - 1] > e.scrollTop && imgTopArr[0] < e.scrollTop) {
          idx = imgTopArr.findIndex(item => item > e.scrollTop) - 1
        } else {
          idx = imgTopArr.length - 1
        }
        this.setData({
          tabAct: idx,
          scrollTop: e.scrollTop
        })
      })
    },
    selectCard() {
      //console.log(this.data.showCard)
      this.setData({
        showCard: !this.data.showCard
      })
    },
    phoneCall(e) {
      let { phone } = e.currentTarget.dataset;
      wx.$api.phoneCall(phone);
    },
    getUserInfo(e) {
      this.triggerEvent('getUserInfo', { detail: e.detail })
    },
  }
})