import common from '../../utils/util';
import main from '../../utils/main';

var app = getApp();
var backgroundAudioManager;

Page({
  data: {
    PanelShow: 0,
    IsShowPay:false,
    IsShowMore:false,
    IsPlay:false,
    ImagePath: app.globalData.uploadImageUrl,
    officialAccounts:app.globalData.officialAccounts,
  },
  onLoad: function (options) {
    var that = this;
    backgroundAudioManager = wx.getBackgroundAudioManager();
    that.setData({
      Containnerheight: main.getWindowHeight(),
    });
      
    that.init(options.index);
  },
  init: function (index) {
    var that = this;
    if (!index)
      index=0;
    main.getData("GetMiaoguoNewUserImageList3126", function (data) {
      that.setData({
        List: data[index].Images,
        List2:data[1].Images,
        PageIndex:index,
      });
      wx.setNavigationBarTitle({
        title: data[index].Name
      });
      if (app.globalData.IsIPhoneX) {
       that.setData({
          IsIPad: "_IPhoneX",
        });
      }
      
    });
  },
  goto: function (e) {
    var url = e.currentTarget.dataset.url;
    
    wx.navigateTo({
      url: url,
    });
  },
  showPay:function(){
    var that = this;
    main.getData("GetClassList?Flag=0", function (data) {
      if (data && data.length>0) {
        var startDate=common.formatDateCHS(data[0].StartDate);
        that.setData({
          IsShowPay:true,
          StartDate: startDate,
        })
      }
    });
  },
  hidePay:function(){
    this.setData({
      IsShowPay:false,
    });
  },
  payMoney: function () {
    var that = this;
    var money = 1;
    var detail = {};
    detail.UserID = app.globalData.userInfo.UserID;
    detail.Introducer = app.globalData.userInfo.Introducer;
    detail.PayType=9;
    detail = JSON.stringify(detail);
    //console.log(detail);
    //console.log(money);
    var remark = null;
    main.payMoney(9, remark, money, detail, function () {
      that.setData({
        PanelShow:1,
      });
      wx.setNavigationBarColor({
        frontColor: "#000000",
        backgroundColorTop: "#ffffff",
        backgroundColor: "#ffffff",
      });
      if (app.globalData.userInfo.NickName=="陌生用户" && app.globalData.userInfo.IsShow == 1){
        wx.navigateTo({
          url: '../index/accredit?Type=1',
        });
      }
    });
  },
  gotoIndex: function () {
    wx.reLaunch({
      url: '../index/index',
    })
  },
  play:function(){
    var that=this;
    var isPlay=!that.data.IsPlay;
    if (isPlay){
      that.data.List[8].Image="bm_sy_banner-zc_pause.png";
      backgroundAudioManager.title = "暖暖爸致辞";
      backgroundAudioManager.src = app.globalData.uploadImageUrl+"web/_lesson/nuannuanbazhici.m4a";
    }
    else{
      that.data.List[8].Image="bm_sy_banner-zc_play.png";
      backgroundAudioManager.pause();
    }
    that.setData({
      List:that.data.List,
      IsPlay:isPlay,
    });
  },
  onShareAppMessage: function () {
    return {
      title: app.globalData.ShareTitle,
      path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
      imageUrl: app.globalData.ShareImage,
    }
  },
})