let app = getApp();
//替换成开发者后台设置的安全域名
let domain = app.globalData.domain;
//获取用户信息的url
let mymessageUrl = domain + "/dingding/mymessage";
let myscheduleUrl = domain +"/dingding/myschedule";
let canclemeetingUrl = domain + "/dingding/canclemeeting";
let conferenceUrl = domain + "/dingding/conference";
var time = 0;
var touchDot = 0;//触摸时的原点
var interval = "";
var flag_hd = true;

Page({
  data: {
    font: "",
    arr: [],
    screenHeight: 0,
    screenWidth: 0,
    text: "没有滑动",
    currentData: 0,
    winHeight: "",//窗口高度
    dates: dateFtt("yyyy-MM-dd", new Date()),
    messsageList:[],
    mymessageList:[]

  },

    //  点击时间组件确定事件  
    bindDateChange(e) {
      this.setData({
        dates: e.detail.value
      })
      
      

    },

  onLoad: function(options) {
    var that = this;
    //高度自适应
   var userId= app.globalData.userId;
   

    dd.getSystemInfo({
      success: function(res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        //console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
  },
  TabSwiper: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    const that = this;

    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {

      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  meetjy: function(e){
    var mid = e.currentTarget.dataset.mid;
    let minutesCode = e.currentTarget.dataset.minutesCode;
    let messagePassword = e.currentTarget.dataset.messagePassword;
    
    console.log("minutesCode" ,minutesCode);
    if(minutesCode != ""  && minutesCode!=null ){
           dd.navigateTo({
            url: '../summary/summary?mid=' + mid + '&conferenceName=' + e.currentTarget.dataset.conferenceName + "&date=" + e.currentTarget.dataset.date
          })
     }else{
         dd.alert({
           content: '没有授权码，无法查看',
           buttonText: '我知道了',
       })
      }
  },
  onReady() {
    // 页面加载完成
  },

  onShow() {
    // 页面显示
            var that = this;
            var userId = app.globalData.userId;

            dd.httpRequest({
              url: mymessageUrl,
              method: 'POST',
              data: {
                userId: userId,
                date: that.data.dates,
                
              },
              dataType: 'json',
              success: function(res) {
                console.log('success我的预定----', res);
               
                var messageList = that.data.messageList;
                messageList=  res.data.result;
                
                that.setData({
                  
                  messageList
                });
                console.log('会议列表-----',that.data.messageList);
              },
              fail: function(res) {
                console.log("httpRequestFail---", res)
            //   dd.alert({ content: JSON.stringify(res) });
              },
              complete: function(res) {
                dd.hideLoading();
              }

            });

    dd.httpRequest({
      url: myscheduleUrl,
      method: 'POST',
      data: {
        userId: userId,
        date: that.data.dates
      },
      dataType: 'json',
      success: function(res) {
        console.log('success我的日程----', res)
        var mymessageList = that.data.mymessageList;
        mymessageList = res.data.result;
        that.setData({

          mymessageList
        });
        console.log(that.data.mymessageList);
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        //   dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });


    flag_hd = true; //重新进入页面之后，可以再次执行滑动切换页面代码
    clearInterval(interval); // 清除setInterval
    time = 0;
  },
  
  touchStart: function(e) {
    touchDot = e.touches[0].pageX; // 获取触摸时的原点
    // 使用js计时器记录时间
    interval = setInterval(function() {
      time++;
    }, 100);
  },
  // 触摸结束事件
  touchEnd: function(e) {
    var touchMove = e.changedTouches[0].pageX;
    // 向左滑动
    if (touchMove - touchDot <= -20 && time < 10) {
      //执行切换页面的方法
      //console.log('left');
      this.next()
    }
    // 向右滑动
    if (touchMove - touchDot >= 20 && time < 10) {
      //执行切换页面的方法
      // console.log('right');
      this.last()
    }
    clearInterval(interval); // 清除setInterval
    time = 0;

  },
  modify:function(e){
    //var mid= e.currentTarget.dataset.mid;
    let configValueId = e.currentTarget.dataset.configValueId;
     if( configValueId === 1){
          dd.alert({
            content: '会议进行中，不可修改',
            buttonText: '确定',
          })
         }else if(configValueId === 4){
           dd.alert({
            content: '会议已结束，不可修改',
            buttonText: '确定',
          })
         }else{
            dd.navigateTo({
            url: '../../conference/modifymeeting/modifymeeting?mid='+ e.currentTarget.dataset.mid
          })
          
         }
  },
  cancelmeeting:function (e){

      var mid= e.currentTarget.dataset.mid;
      let configValueId = e.currentTarget.dataset.configValueId;
        //  if( configValueId === 1 || configValueId === 4 || configValueId === 3 ){
        //   dd.alert({
        //     content: '会议结束或进行中，不可取消',
        //     buttonText: '确定',
        //   })
        //  }
        if( configValueId === 1){
          dd.alert({
            content: '会议进行中，不可取消',
            buttonText: '确定',
          })
         }else if(configValueId === 4){
           dd.alert({
            content: '会议已结束，不可取消',
            buttonText: '确定',
          })
         }
         else if(configValueId === 3){
           dd.alert({
            content: '会议暂停中，不可取消',
            buttonText: '确定',
          })
         }
         else {
          dd.httpRequest({
          url: canclemeetingUrl,
          method: 'POST',
          data: {
            mid: mid,
            configValueId: configValueId,
          },
          dataType: 'json',

          success: function(res) {
          console.log('success----', res);
          //console.log(e.currentTarget.dataset.configValueId);
       
          //if(res.data.success){
            dd.alert({
              title: '取消成功',
              content: '取消成功',
              buttonText: '确定',
              success: () => {
                dd.reLaunch({
                  url: '../record/record'
                });
              },
            });
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        //   dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });
         }
       

  },
  datePicker() {
    var that = this;
    dd.datePicker({
      success: (res) => {
        that.setData({
          dates: res.date
        });
       
        var userId = app.globalData.userId;


        dd.httpRequest({
          url: mymessageUrl,
          method: 'POST',
          data: {
            userId: userId,
            date: that.data.dates
          },
          dataType: 'json',
          success: function(res) {
            console.log('success----', res)
            var messageList = that.data.messageList;
            messageList = res.data.result;
            that.setData({

              messageList
            });
            console.log(that.data.messageList);
          },
          fail: function(res) {
            console.log("httpRequestFail---", res)
            //   dd.alert({ content: JSON.stringify(res) });
          },
          complete: function(res) {
            dd.hideLoading();
          }

        });

        dd.httpRequest({
          url: myscheduleUrl,
          method: 'POST',
          data: {
            userId: userId,
            date: that.data.dates
          },
          dataType: 'json',
          success: function(res) {
            console.log('success----', res)
            var mymessageList = that.data.mymessageList;
            mymessageList = res.data.result;
            that.setData({

              mymessageList
            });
            console.log(that.data.mymessageList);
          },
          fail: function(res) {
            console.log("httpRequestFail---", res)
            //   dd.alert({ content: JSON.stringify(res) });
          },
          complete: function(res) {
            dd.hideLoading();
          }

        });
      
      },
    })
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息

  },
});
function dateFtt(fmt, date) { //author: meizz   
  var o = {
    "M+": date.getMonth() + 1,                 //月份   
    "d+": date.getDate(),                    //日   
    "h+": date.getHours(),                   //小时   
    "m+": date.getMinutes(),                 //分   
    "s+": date.getSeconds(),                 //秒   
    "q+": Math.floor((date.getMonth() + 3) / 3), //季度   
    "S": date.getMilliseconds()             //毫秒   
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}