// pages/companyModule/companyMoreVideo/companyMoreVideo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    acted: false, //已经报名true
    showBeSureActed: false, //显示确认弹窗
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    active_id: '', //活动id
    info: '', //详情信息
    loaded:false,
  },
  onLoad(e) {
    this.setData({
      active_id: e.id
    })
  },
  onShow() {
    this.activesDetail(this.data.active_id);
  },

  /**
   * 现在报名
   */
  nowActed: function (e) {
    console.log()
    if (!e.currentTarget.dataset.acted) {
      this.setData({
        showBeSureActed: true,
      })
    } else {
      wx.showToast({
        icon: 'none',
        title: '已报名，等待活动开始',
      })
    }
  },
  /**
   * 关闭弹窗
   */
  close() {
    this.setData({
      showBeSureActed: false
    })
  },
  /**
   * 确认报名
   */
  beSure() {
    wx.login({
      success:res=>{
        wx.$api.companyModule.activesEnroll(res.code,this.data.active_id).then(res => {
          if(Number(this.data.info.price)>0){
            var resss=JSON.parse(res);
            console.log('可支付')
            wx.requestPayment({
              timeStamp: resss.timeStamp,
              nonceStr: resss.nonceStr,
              package: resss.package,
              signType: 'MD5',
              paySign: resss.paySign,
              success:res=>{
                this.close();
                wx.navigateTo({
                  url: '/pages/companyModule/activeSuccess/activeSuccess?cover='+this.data.info.pictures[0],
                })
              },
              fail(res) {
                wx.showToast({
                  title: '支付失败',
                })
              }
            })
    
          }else{
            console.log('不用支付')
            this.close();
            wx.navigateTo({
              url: '/pages/companyModule/activeSuccess/activeSuccess?cover='+this.data.info.pictures[0],
            })
          }
        })
      }
    })
  },
  /**
   * 获取详情
   */
  activesDetail() {
    wx.$api.companyModule.activesDetail(this.data.active_id).then(res => {
      var nodes = res.content.replace('<img', '<img style="max-width:100%;height:auto""');
      console.log(nodes);
      this.setData({
        info: res,
        content:nodes,
        loaded:true,
      })
    })
  },
  


})