// pages/activeDetails/activeDetails.js
import Dialog from '../../dist/dialog/dialog';
import Notify from '../../dist/notify/notify';
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    isMember:'',
    volunteerEventDat:[],
    zhuangtai:'',
    quanzhu:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    var config = wx.getStorageSync('config');
    var location = wx.getStorageSync('location');
    wx: wx.request({
      url: app.url + 'ajax_get_volunteer_event_detail.php',
      data: {
        unionId: config.unionId,
        eventId: options.id,
        circleId:1
      },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        console.log(res)
        if(res.statusCode==200){
          that.setData({
            volunteerEventDat:res.data.result.volunteerEventDat,
            isMember: res.data.result.isMember
          })
          if(res.data.result.isMember==false){
            that.setData({
              zhuangtai:'报名参加'
            })
          }else{
            if(res.data.result.isEnrollFinish==false){
              that.setData({
                zhuangtai: '上传凭证'
              })
            }else{
              that.setData({
                zhuangtai: '取消报名'
              })
            }
          }
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  onChange(event) {
    
  },
  btnBaoming(){
    var config = wx.getStorageSync('config');
    // if(this.data.zhuangtai=='报名参加'){
    //   if(this.data.quanzhu==true){
    //     Dialog.confirm({
    //       title: '',
    //       message: '检测到您为圈主,是否团队报名?',
    //       confirmButtonText:'是',
    //       cancelButtonText:'否'
    //     }).then(() => {
    //       Dialog.confirm({
    //         title: '',
    //         message: '是否团队报名?'
    //       }).then(() => {
    //         wx: wx.request({
    //           url: app.url + 'ajax_attend_volunteer_event_circle.php',
    //           header: { 'content-type': 'application/json' },
    //           method: 'GET',
    //           dataType: 'json',
    //           success: function (res) {
    //             if (res.statusCode == 200) {
    //               Notify({ type: 'success', message: '成功团队报名?' });
    //             }
    //           },
    //           fail: function (res) {
    //             Notify({ type: 'danger', message: '团队报名失败' });},
    //           complete: function (res) { },
    //         })
    //       }).catch(() => {
    //         Notify({ type: 'danger', message: '取消团队报名?' });
    //       });
    //     }).catch(() => {
    //       Dialog.confirm({
    //         title: '',
    //         message: '是否个人报名?'
    //       }).then(() => {
    //         wx:wx.request({
    //           url: app.url +'ajax_attend_volunteer_event_personal.php',
    //           header: { 'content-type': 'application/json'},
    //           method: 'GET',
    //           dataType: 'json',
    //           success: function(res) {
    //             console.log(res)
    //             if(res.statusCode==200){
    //               Notify({ type: 'success', message: '成功个人报名?' });
    //             }
    //           },
    //           fail: function(res) {
    //             Notify({ type: 'danger', message: '个人报名失败' });
    //           },
    //           complete: function(res) {},
    //         })
    //       }).catch(() => {
    //         Notify({ type: 'danger', message: '取消个人报名?' });
    //       });
    //     });
    //   }
    // }
    Dialog.confirm({
      title: '标题',
      message: '是否上传凭证?'
    }).then(() => {
      wx.navigateTo({
        url: '../uploadDocuments/uploadDocuments',
      })
    }).catch(() => {
      // on cancel
      Notify({ type: 'danger', message: '取消报名' });
    });
    // wx: wx.request({
    //   url: app.url + 'ajax_cancel_volunteer_event_personal.php',
    //   header: { 'content-type': 'application/json' },
    //   data:{
    //     unionId: config.unionId,
    //     age:4
    //   },
    //   method: 'GET',
    //   dataType: 'json',
    //   success: function (res) {
    //     console.log(res)
    //     if (res.statusCode == 200) {
    //       Notify({ type: 'success', message: '成功取消报名?' });
    //     }
    //   },
    //   fail: function (res) {
    //     Notify({ type: 'danger', message: '取消报名失败' });
    //   },
    //   complete: function (res) { },
    // })
  }
})