index.js 2.31 KB
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import { enterPageTrack } from "../../api/api"
Component({

  properties: {
    listItem: Object,
    noResult: Boolean,
    isMaxScreen:Boolean
  },

  data: {
    templateInfo: {
      IMG_URL,
    }
  },


  methods: {
    toDetail(e) {
      console.log(e);
      const { item, type } = e.currentTarget.dataset;
      let url = '', tempArr = []
      if (item.materialDetailInfoList && item.materialDetailInfoList.length) {
        item.materialDetailInfoList.forEach(el => {
          tempArr.push(el.image)
        })
      }
      if (type == 'PDF') {
        this.openPDF(tempArr[0],item)
        return
      }
      url = JSON.stringify(tempArr)
      wx.setStorageSync('pageQueryOfcontent', url);
      let pageUrl = `/packageEquity/pages/trainingMaterials/pages/playVideo/index`
      let target = pageUrl + `?type=${type}&title=${item.title}&id=${item.id}`
      wx.navigateTo({
        url: target
      });
    },
    // 打开PDF
    openPDF(url,item) {
      wx.showLoading()
      this.openPdf = false
      let _this = this
      wx.downloadFile({
        url: url,
        success: function (res) {
          const manage = wx.getFileSystemManager()
          let fileName = item.title
          manage.saveFile({
            tempFilePath: res.tempFilePath,
            filePath: wx.env.USER_DATA_PATH + '/' + fileName,
            success: function (res) {
              wx.openDocument({
                filePath: wx.env.USER_DATA_PATH + '/' + fileName,
                fileType: 'pdf',
                showMenu: false,
                success: function (res) {
                  wx.hideLoading();
                  _this.openPdf = true
                  _this.toAddTrack(item.id)
                }
              })
            }
          })
        },
        fail() {
          wx.hideLoading();
        }
      })
    },
    toAddTrack(id) {
      const userInfo = wx.$util.getUserInfo()
      const params = {
        goodsId: id,
        goodsType: 0,
        merchantId: userInfo.default4SStoreInfo.merchantId,
        merchantName: userInfo.default4SStoreInfo.merchantName
      }
      enterPageTrack(params).then(res => {
        // this.trackId = res.data
        wx.setStorageSync('pageQueryOfcontent_trackId', res.data);
      })
    },
  }
})