// pages/warn/warn.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    courseVideoPlay: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABUCAYAAADplZtxAAAAAXNSR0IArs4c6QAAB1lJREFUeF7tnXmsX0MUx7/fEGKPnVoSpRKhkkqbWmpJbbEUKbEHQWmUFrWFiBJLLFGKRpHQRKyxk0ZoLSHtHypFI8QWWymxNSJE4iunmV/dd9/c+7vLzO/9KnOSl9e+N3Pm3M87v3Pnnjkzl+gDkbQbgBEAtgCwZcH39QAsz3x9n/v/cpKv98HlDDKBQ2WUpIMATABwJIDhgez4CcDTAJ4DMJ/kn4H0tlLTM8iSNgRwGIBDARwCYJtWlnfv/IcDPt8B/7p7lzgtokOWtCOAiwGcAGDTOJfRVes/AF4EMHMoQko0yJLWBnCRA7x5VwwDG5gXfue+LPbav38HsDWAYZnvTf5oswHcTvKzmjY1bh4FsqRTHeA9KlhmH+MXADzZAUtyRYV+kLRWBvp4AEcDGFOh748G2nn2XxXat2oSFLKkAxzco7pYtRTAq3aDCv3xlbSTi/12Q7XYXybvOtAPt6LYpXMwyJJuAnBFyXi/ArjD4JJ8O+ZFdXRngJ8DwKaJRfIMgOkkv4hhV2vIkjYAYHHOQkSR3AvgTpIfxbiIbjolrQ/gQgDTAGxW0P4TAJeQfL6bvrq/bwVZ0i4Anijxkmcd3L54SHCebaDPLwF1Fckb64Isa98YsiSLdy8XKF/k4D4W0thQuiSNc159XIHOR0meHGq8RpAlXQfg6gIjbC5q8+K+F0nTAdxWYOhSkiNDXERtyJJeAWCPxD6ZRPKBEIb1SoekUwDcB2Bd35gkazPK66mlQNL9AM4uADCuV7OG0H8AF6st9PlyKAtJ7t1mzMqQJV0J4AbPYF8CGEXylzaG9ENfSW8A2M9jS6sQWAmypJMAPOIZfBHJvfoBUCgbJF0DYIZH32SSc5qM0xWyJINomax1cgOsILlRk0H7vY8km9ef67FzIkl7cKklpZAlbeWmabt7tO5K8sNao61GjSXZHN9yIXn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HHLlKVx6GGkOufLDSHqsbgC57mN1ShA1g1wrQZRSnc0g+yKAP9Vp+iWlpH1N0LWS9g5yWn6qD7n28pNvd2laSC0A33QhNZUE1PDkRiUBLmSk4paKoBsVtzjIqUyrAuS2ZVqp4LAaZF8xeLWCQ+fNqXS2BHTr0lkHORWBl0P2eXG9InAHOm1n8IAOtp3BQU4bc/yQw23McaDTFrMM6OBbzBzktFlyIGSfF1dekE3bfrtM26Jt+3XenDawx97A7kCnoxhiHsXgIKdDRQaHk7CHijjQ6Xic/0CHPx6nozsd9LSSRLyDnjKg05FlFRJIviZdT9PKdkqH7zWjXAuyi9HpGMmarGtDdqDTgag1QDeC7ECno30rgm4M2YFOh1RXAN0KsgOdjlvvAro15MwUL704oAB2MMjOq9MrMDygg0LOeHV6mUsGdhTIzqvTa4kc6GiQM16dXrBVYQYSpEl6VVwQjPWUpJce1uPVuvX//fWd/wKUcmKRHKvirQAAAABJRU5ErkJggg==',
    animationDisappearArray: [],
    videoCVArray: [],
    warnList: [
      {
        title: '安全生产警示教育片之密闭空间涂装',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/1.png',
        fileUrl: 'http://39.102.232.151:8030/video/1.mp4',
        type: 'video'
      },
      {
        title: '安全生产十大禁令',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/2.png',
        fileUrl: 'http://39.102.232.151:8030/video/2.mp4',
        type: 'video'
      },
      {
        title: '叉车事故警示录',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/3.png',
        fileUrl: 'http://39.102.232.151:8030/video/3.mp4',
        type: 'video'
      },
      {
        title: '城市燃气安全教育片',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/4.png',
        fileUrl: 'http://39.102.232.151:8030/video/4.mp4',
        type: 'video'
      },
      {
        title: '触电事故警示案例',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/5.png',
        fileUrl: 'http://39.102.232.151:8030/video/5.mp4',
        type: 'video'
      },
      {
        title: '吊装作业事故',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/6.png',
        fileUrl: 'http://39.102.232.151:8030/video/6.mp4',
        type: 'video'
      },
      // {
      //   title: '安全生产警示教育片之密闭空间涂装',
      //   instroduce: '',
      //   coverUrl: 'https://img0.baidu.com/it/u=2265254049,1802113800&fm=26&fmt=auto&gp=0.jpg',
      //   fileUrl: 'http://39.102.232.151:8030/pdf/1.pdf',
      //   type: 'pdf'
      // },
      {
        title: '道路交通事故案例',
        instroduce: '',
        coverUrl: 'http://39.102.232.151:8030/warncover/7.png',
        fileUrl: 'http://39.102.232.151:8030/video/7.mp4',
        type: 'video'
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // animationDisappearArray: [],
    // videoCVArray: [],
    for (let i = 0; i < this.data.warnList.length; i++) {
      this.data.animationDisappearArray.push({})
      this.data.videoCVArray.push(wx.createVideoContext('video' + i))
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.setNavigationBarTitle({
      title: '警示教育'
    })
    wx.setNavigationBarColor({
      backgroundColor: '#090D9C',
      frontColor: '#ffffff',
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 点击类似 pdf 的展示文件
   */
  clickToShowFile(event) {
    // console.log(event.target.dataset.index)
    // wx.downloadFile({
    //   url: this.data.warnList[event.target.dataset.index].fileUrl,
    //   success: function(res) {
    //     const filePath = res.tempFilePath
    //     wx.openDocument({
    //       filePath: filePath,
    //       success: function(res) {
    //         console.log('打开文件成功')
    //       }
    //     })
    //   }
    // })
    wx.openDocument({
      filePath: this.data.warnList[event.target.dataset.index].fileUrl,
      success: function(res) {
        console.log(res, '打开文件成功')
      }
    })
  },
  playvideo(event) {
    const repAnimation = wx.createAnimation({
      duration: 50,
      timingFunction: 'step-start'
    })
    this.repAnimation = repAnimation
    repAnimation.translateX('-100%').step()
    this.data.animationDisappearArray[event.target.dataset.index] = repAnimation.export()
    this.setData({
      animationDisappearArray: this.data.animationDisappearArray
    })
    this.data.videoCVArray[event.target.dataset.index].play()
  }
})