psdView.js 3.19 KB
// pages/psdView/psdView.js
import {
  psdApi
} from '../../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    params: {},
    html: '',
    showLogin: true
  },
  loginCallBack(data) {
    this.check(data)
  },
  check(data) {
    if (data) {
      if (data.isLogin) {
        this.setData({
          userInfo: data
        })
        this.viewReadBuriedPoint()
      } else {
        this.setData({
          showLogin: true
        })
      }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},
  viewReadBuriedPoint() {
    let {
      id,
      merchantId,
      staffUuid
    } = this.options
    this.getPsdDetail()
    if(!staffUuid) return
    let {
      phone
    } = this.data.userInfo
    psdApi.viewReadBuriedPoint({
      type: 2,
      materialId: id,
      merchantId,
      staffUuid,
      phone
    }).then(res => {
      console.log(res)
    })
    wx.$Track.setTrack({
      type: 2,
      materialId: id,
      merchantId,
      staffUuid,
      phone
    }, 6)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  getPsdDetail() {
    let {
      id
    } = this.options
    wx.$util.showLoading()
    psdApi.getPsdDetail({
      id
    }).then(({
      data,
      code,
      message
    }) => {
      wx.hideLoading()
      if (code == 0) {
        console.log(data)
        this.setData({
          obj: data,
          flag: true
        })
        // materialType	 素材类型 1 PDF 2 自定义链接 else 富文本
        wx.setNavigationBarTitle({
          title: data.materialName
        })
        if (data.materialType == 1) {
          wx.$util.showLoading('打开中...')
          wx.downloadFile({
            url: data.materialUrl,
            header: {
              'content-type': 'application/json'
            },
            success(res) {
              wx.hideLoading()
              wx.openDocument({
                filePath: res.tempFilePath
              })
            },
            fail(res) {
              wx.hideLoading()
              wx.$util.showToast('打开失败')
            }
          })
        } else if (data.materialType == 2) {
          console.log('链接')
        } else {
          this.setData({
            html: decodeURIComponent(data.materialUrl).replace(/\"/g, `'`)
          })
        }
      } else {
        wx.showModal({
          title: '提示',
          content: message,
          showCancel: false,
          confirmText: '知道了',
          confirmColor: '#FC5B32'
        }).then(res => {
          if (res.confirm) {
            wx.$router.goHome()
          }
        })
      }
    })
  },
  cancel() {
    wx.$router.goHome()
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.$util.customerbehavior(2)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})