// pages/classDetails/classDetails.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mediaId: 0,
    courseTitle:'',
    teacherName: '',
    teacherProfile: '',
    frontImage: '',
    mediaCount: '',
    mediaList: [],
    show1:false,
    show2: false,
    show3: false,
    show4: false,
    videoHeight:'150',
    play:0,
    fufeiPage:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      mediaId: options.mediaId
    })
    //获取详细信息
    this.classDetails()
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

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

  },

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

  },

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

  },
  cliLearn(e){
    let index = e.currentTarget.dataset['index'];
    if(index==1){
      this.setData({
        show1:!this.data.show1
      })
    }
    if (index == 2) {
      this.setData({
        show2: !this.data.show2
      })
    }
    if (index == 3) {
      this.setData({
        show3: !this.data.show3
      })
    }
    if (index == 4) {
      this.setData({
        show4: !this.data.show4
      })
    }
  },
  // 查询课程详细
  classDetails(){
    var that = this;
    var config = wx.getStorageSync('config');
    // var location = wx.getStorageSync('location');
    wx: wx.request({
      url: app.url + 'ajax_get_course_detail.php',
      data: {
        unionId: config.unionId,
        mediaId:that.data.mediaId
      },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        console.log(res)
        if (res.statusCode == 200) {
          that.setData({
            courseTitle:res.data.result.courseTitle,
            teacherName: res.data.result.teacherName,
            teacherProfile: res.data.result.teacherProfile,
            frontImage: res.data.result.frontImage,
            mediaCount: res.data.result.mediaCount,
            mediaList: res.data.result.mediaList
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  videoplay(){
    if(this.data.show1){
      this.setData({
        fufeiPage:1
      })
      this.fufeilook()
    }else{
      this.setData({
        play: 1
      })
      this.classDerails();
      var query = wx.createSelectorQuery();
      var that = this;
      query.select('.video').boundingClientRect(function (rect) {
        var videoHeight = (rect.width * 9) / 16;
        that.setData({
          videoHeight: videoHeight
        })
      }).exec();
    }
  },
  backplay(){
    this.setData({
      play:0
    })
  },
  // 付费观看
  fufeilook(){
    var config = wx.getStorageSync('config');
    wx: wx.request({
      url: app.url + 'ajax_set_buy_media.php',
      data: {
        unionId: config.unionId,
        openId:1,
        courseId:1,
        mediaId:1
      },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        console.log(res)
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  backfufei(){
    this.setData({
      fufeiPage:0
    })
  },
  surefufei(){
    this.setData({
      fufeiPage: 0
    })
  }
})