const util = require('../../../utils/util.js');
const app = getApp();
Page({
  data: {
    src:'',
    id:0,
    title:'',
    currentPages:1,
    coverImg:''
  },
  onLoad: function (options) {
    this.setData({id:options.id});
  },
  onShow: function () {
    let that = this;
    if(getCurrentPages().length == 1){
      // var getLocation = util.promise();
      // getLocation.then(function(value) {
        that.getData();
      // }, function(error) {
      // });
    }else{
      that.getData();
    }
    this.setData({currentPages:getCurrentPages().length});
  },
  getData:function(){
    let that = this;
    util.ajax({
      func:"video/detail",
      data:{"id":that.data.id},
      load:false
    },function(res){
      if(res.code == 0){
        wx.setNavigationBarTitle({
          title: res.data.title
        });
        that.setData({ src: res.data.url, title: res.data.title, coverImg:res.data.sharePic});
      }else{
        util.showTips(res.reason);
      }
    });
  },
  binderror:function(e){
    util.showTips('视频加载失败');
    if(this.data.currentPages == 1){
      wx.redirectTo({
        url: '/pages/home/index'
      });
    }else{
      setTimeout(function(){
        wx.navigateBack();
      },2300);
    }
  },
  onShareAppMessage: function () {
    let that = this;
    return {
      title: that.data.title,
      path: '/pages/public/video/play?id=' + that.data.id,
      imageUrl:!util.isEmpty(that.data.coverImg)?that.data.coverImg:'http://img.bbztx.com/image_test/upload/thumbs/20210430/logo/1619766863529068803.jpg'
    }
  }
})