let app=getApp();
let domain = app.globalData.domain;
//获取用户信息的url
let addmeetingeUrl = domain + "/dingding/addmeeting";
let conferenceUrl = domain + "/dingding/conference";
let messageListUrl = domain + "/dingding/messageList"; 
let generateMidUrl = domain + "/dingding/generateMid"; 
let conferenceListUrl = domain + "/dingding/conferenceList"; 
let getUsernameUrl=  domain+"/dingding/getUsername";
Page({

  data: {
    showModal: false,
    showView: true,
    conferenceList: [],
    mid:null,
    //msgArray: ['无提醒', '提前十分钟', '提前半小时', '提前一小时'],
    noticeList: [{ name: 'dingding', value: '钉钉' }, { name: 'wechat', value: '微信' }, { name: 'mailbox', value: '邮箱' }, { name: 'note', value: '短信' }],
    showView: false,
    dates: dateFtt("yyyy-MM-dd", new Date()),
    topicList: [""],
    text: '',
    cnum:'',
    departments:'全体',
    allTime: {
      hours: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
      minutes: [0, 15, 30, 45]
    },
    timeList:[],     
    msgTime:[],
    time:{
      startIndex:null,
      endIndex:null,
       startTime:null,
       endTIme:null,
       min:0,

     },
    username:"",
    message:{},
    maxBookDay: '',
    maxBookTime: ''
  },
  //方式选项点击
  clicks: function(e) {
    let index = e.currentTarget.dataset.index;
    let arrs = this.data.checks;
    if (arrs[index].checked == false) {
      arrs[index].checked = true;
    } else {
      arrs[index].checked = false;
    }
    this.setData({
      checks: arrs
    })

  },
  //是否安排座位
  switch: function() {
    //console.log("点击");
    
    var mid=this.data.mid;
    console.log("会议室", this.data.cnum)
    
    var _this=this;
    dd.httpRequest({
      url: conferenceUrl,
      method: 'POST',
      data: {
        cnum: _this.data.cnum
      },
      dataType: 'json',
      success: function(res) {
          console.log('success----', res)
        dd.navigateTo({
          url: '../seat/seat?mid=' + mid + "&seatNumber=" + res.data.result.maxPerson
        })
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });
   
  },
  //显示隐藏（方式选项）
  onChangeShowState: function() {
    var that = this;
    that.setData({
      showView: (!that.data.showView),
      se_btn_hide: false
    })
  },
  formSubmit: function(e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value);
    var conferenceList=this.data.conferenceList;
  //  dd.showLoading({
  //   content: '预定中...',
  //  });
    var startTime =  this.data.dates+" "+this.data.time.startTime  ;
    var endTime = this.data.dates + " "+ this.data.time.endTime ;
     
     var _this=this;
    // if (typeof (e.detail.value.conferenceName) == "undefined") {
    //   dd.alert({
    //     title: "参数错误",
    //     content: "会议室没有选择",
    //     buttonText: '确定'
    //   })
    //   return false;
    // }
    if (e.detail.value.remindMethod.length==0){
      dd.alert({
        title:"参数错误",
        content:"提醒方式没有选择",
        buttonText: '确定'
      })
      return false;
    }
    if (e.detail.value.remindTime.length == 0) {
      dd.alert({
        title: "参数错误",
        content: "提醒时间没有选择",
        buttonText: '确定'
      })
      return false;
    }
    if (e.detail.value.messageName == "") {
      dd.alert({
        title: "参数错误",
        content: "会议名称没有填写",
        buttonText: '确定'
      })
      return false;
    }
    if (e.detail.value.messageCompere == "") {
      dd.alert({
        title: "参数错误",
        content: "会议主持人没有填写",
        buttonText: '确定'
      })
      return false;
    }
    //console.log(this.data.time.startTime);
    if ((this.data.time.startTime == ""|| this.data.time.startTime == null) && (this.data.time.endTime=="" ||  this.data.time.endTime == null)) {
      dd.alert({
        title: "参数错误",
        content: "会议时间没有选择",
        buttonText: '确定'
      })
      return false;
    }
   var topicList=this.data.topicList;
    console.log(this.data.topicList);
    dd.httpRequest({
      url: addmeetingeUrl,
      method: 'POST',
      data: {
        mid: _this.data.mid,
        cnum: _this.data.cnum,
        startTime: startTime,
        endTime: endTime,   
        departments: _this.data.departments,
        userId: app.globalData.userId,
        messageName: e.detail.value.messageName,
        messageCompere: e.detail.value.messageCompere,
        topicList: topicList,
        messageContent: e.detail.value.messageContent,
        remindMethod : e.detail.value.remindMethod,
        remindTime: e.detail.value.remindTime,
        conferenceName:  _this.data.conferenceName,
        messagePassword: e.detail.value.messagePassword,
      },
      dataType: 'json',
      success: function(res) {
      console.log('success----', res)
      

        if (res.data.success){
         //console.log("预定成功");
          dd.vibrate({
            success: () => {
              dd.alert({
                //title: '预定成功',
                content: '预定成功',
                buttonText: '确定',
                success: () => {
                  dd.reLaunch({
                    url: '../index/index'
                  });
                },
              });
            }
          });
         
       }else {
         dd.showToast({
           type: 'fail',
           content: res.data.message,
           duration: 3000,
           success: () => {
            //  dd.navigateTo({
            //    url: '../index/index'
            //  });
           },
         });
       }
      },
      fail: function(res) {
 //console.log("httpRequestFail---", res)
        //dd.alert({ content: JSON.stringify(res) });

      },
      complete: function(res) {
        dd.hideLoading();
      }

    });



  },

 /**
  * 
  *  显示时间轴
  */
  showTimeList:(_this,cnum)=>{
           //查询当天会议时间段
    var timeList = _this.data.timeList;
    var hours = _this.data.allTime.hours;
    var minutes = _this.data.allTime.minutes;
 
    //清空原來的
    timeList = [];
    _this.setData({
      timeList
    });
    var msgTime = _this.data.msgTime;
    var nowHour = new Date().getHours();
    var nowMinute = new Date().getMinutes();
    msgTime = [];
    _this.setData({
      msgTime
    });
    
    dd.httpRequest({
      url: messageListUrl,
      method: 'POST',
      data: {
        date: _this.data.dates,
        cnum: cnum
      },
      dataType: 'json',
      success: function(res) {
        console.log('success----message', res);
      //  this.clearTime(timeList,hours,minutes,this);
        var msg = res.data.result;
        for (var i = 0; i < msg.length; i++) {
          var json = {};
          json["startTime"] = msg[i].startTimeFormat;
          json["endTime"] = msg[i].endTimeFormat;
          msgTime.push(json);
        }
        _this.setData({
          msgTime
        });
        if (timeList.length == 0) {
          for (var i = 0; i < hours.length; i++) {
            var arr = new Array;

            for (var j = 0; j < minutes.length; j++) {
              var json = {};
              json["hour"] = hours[i];
              json["minute"] = minutes[j];
                if (dateCompare(dateFtt("yyyy-MM-dd", new Date()), _this.data.dates) == 0) {
                    json["color"] = "#ABABAB";
                    json["unclick"] = true;
                  } else if (dateCompare(dateFtt("yyyy-MM-dd", new Date()), _this.data.dates) == 1) {
                    if (nowHour > hours[i]) {

                      json["color"] = "#ABABAB";
                      json["unclick"] = true;
                        
                    } else {
                      json["color"] = "";
                      json["unclick"] = false;
                    }
                    if (nowHour == hours[i]) {
                      if (nowMinute > minutes[j]) {
                        
                        json["color"] = "#ABABAB";
                        json["unclick"] = true;
                        
                      } else {
                        json["color"] = "";
                        json["unclick"] = false;
                      }
                    }
                  }
                  else if (dateCompare(dateFtt("yyyy-MM-dd", new Date()), _this.data.dates) == 2) {
                    json["color"] = "";
                    json["unclick"] = false;
                  }
              // console.log(msgTime);
              if (msgTime.length > 0) {
                for (var k = 0; k < msgTime.length; k++) {
                  var msgstart = Number(msgTime[k].startTime.split(":")[0]);
                  var msgend = Number(msgTime[k].endTime.split(":")[0]);
                  var msgstartmin = Number(msgTime[k].startTime.split(":")[1]) - 15;
                  var msgendmin = Number(msgTime[k].endTime.split(":")[1]);
                  console.log("会议开始时间", msgstart + ":" + msgstartmin);
                  //  console.log(msgTime[k].startTime.split(":")[0]);

                  if (time_range(msgstart + ":" + msgstartmin, msgTime[k].endTime, hours[i] + ":" + minutes[j])) {
                    json["color"] = "#EEAD0E";
                    json["unclick"] = true;
                  } 

                }


              }
              // console.log("json",json);
              //console.log(this.data.time.allTime.hours[i] + this.data.time.allTime.minutes[j])
              arr.push(json);


            }
            timeList.push(arr);

          }
        }
        //console.log(status);
        _this.setData({
          timeList
        })
        console.log("timeList", timeList)
        dd.hideLoading();
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
       // dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        //dd.hideLoading();
      }

    });
 },
          

//点击时间格
datePicker() {
    var timeList = this.data.timeList;
    var hours = this.data.allTime.hours;
    var minutes = this.data.allTime.minutes;

    var _this = this;
    dd.datePicker({
      success: (res) => {
       
        if(datedifference(dateFtt("yyyy-MM-dd", new Date()),res.date)>Number(_this.data.maxBookDay)){
          dd.alert({
           content: '该时间段不可选择',
            buttonText: '我知道了',
            success:()=>{
             _this.setData({
                dates: dateFtt("yyyy-MM-dd", new Date())
              });
                    this.showTimeList(_this,_this.data.cnum)
            }
          })
          
        }else {
          _this.setData({
             dates: res.date
          });
          this.showTimeList(_this,_this.data.cnum)
        }
        //查询当天会议时间段
        //清空原來的
        
      }
    })
  },

  /***
   * 清空预定时间
   * ***/
clearBox:(startTime,endTime,startIndex,endIndex,timeList,_this)=>{
      
      if (startIndex[0] == endIndex[0]) {
        for (var j = startIndex[1]; j <= endIndex[1]; j++) {
          timeList[startIndex[0]][j].color = "";
        }
      }
      if (startIndex[0] < endIndex[0]) {
        for (var i = startIndex[0]; i <= endIndex[0]; i++) {
          if (i == startIndex[0]) {
            for (var j = startIndex[1]; j <= 3; j++) {
              timeList[i][j].color = "";
            }
          }
          if (i > startIndex[0] && i < endIndex[0]) {
            for (var j = 0; j <= 3; j++) {
              timeList[i][j].color = "";
            }
          }
          if (i == endIndex[0]) {
            for (var j = 0; j <= endIndex[1]; j++) {
              timeList[i][j].color = "";
            }
          }
        }
      }
       endTime =null;
      startTime = null;
      startIndex=null;
      endIndex = null;
      _this.setData({
        "time.endTime": endTime,
        "time.startTime": startTime,
        "time.startIndex": startIndex,
        "time.endIndex": endIndex,
        "time.min": 0,
        timeList
      });


  },

  //点击小方块
  selTime:function(e){

    var startTime=this.data.time.startTime;
    var endTime = this.data.time.endTime;
    var startIndex = this.data.time.startIndex;
    var endIndex = this.data.time.endIndex;
    var timeList = this.data.timeList;
    var unclick= e.currentTarget.dataset.unclick;
   // console.log('startIndex----', startIndex);
   console.log(e);

    if(unclick){
      dd.alert({
        content: '该时间段不可选择',
        buttonText: '我知道了',
      })
    }
    if (!unclick){
     if(startTime==null){
       if (e.currentTarget.dataset.hour<10){
         var hour = "0" + e.currentTarget.dataset.hour
       if (e.currentTarget.dataset.minute==0){
         startTime = hour + ":00" ;
       }else {
         startTime = hour+ ":" + e.currentTarget.dataset.minute;
       }
       }else {
         if (e.currentTarget.dataset.minute == 0) {
           startTime = e.currentTarget.dataset.hour + ":00";
         } else {
           startTime = e.currentTarget.dataset.hour + ":" + e.currentTarget.dataset.minute;
         }
       }
       console.log("会议开始时间"+startTime);
      
       timeList[e.currentTarget.dataset.hourIndex][e.currentTarget.dataset.minIndex].color ="#4876FF";
       this.setData({
         "time.startTime": startTime,
         "time.startIndex": [e.currentTarget.dataset.hourIndex, e.currentTarget.dataset.minIndex]
          ,timeList});
          

     }
    if (startTime != null && endTime == null && startIndex!=null){

      if (startIndex[0] == e.currentTarget.dataset.hourIndex){
        for (var j = startIndex[1]; j <= e.currentTarget.dataset.minIndex; j++) {
          timeList[e.currentTarget.dataset.hourIndex][j].color = "#4876FF";
        }
      }
      if (startIndex[0] < e.currentTarget.dataset.hourIndex) {
        for (var i = startIndex[0]; i <= e.currentTarget.dataset.hourIndex; i++) {
          if (i == startIndex[0]){
            for (var j = startIndex[1]; j <=3; j++){
              timeList[i][j].color = "#4876FF";
            }
          }
          if (i > startIndex[0] && i < e.currentTarget.dataset.hourIndex) {
            for (var j =0; j <= 3; j++) {
              timeList[i][j].color = "#4876FF";
            }
          }
          if (i== e.currentTarget.dataset.hourIndex) {
            for (var j = 0; j <= e.currentTarget.dataset.minIndex; j++) {
              timeList[i][j].color = "#4876FF";
            }
          }
        }
      }
      
      if (e.currentTarget.dataset.hour < 10) {
        var hour = "0" + e.currentTarget.dataset.hour
        endTime = hour+ ":" + (e.currentTarget.dataset.minute + 15);
      } else {
        endTime = e.currentTarget.dataset.hour + ":" + (e.currentTarget.dataset.minute + 15);
      }
     
      console.log("会议结束时间" + endTime);
       
      var sh =Number(this.data.time.startTime.split(":")[0]);
      var sm = Number (this.data.time.startTime.split(":")[1]);
      var eh = Number(e.currentTarget.dataset.hour);
      var em = Number(e.currentTarget.dataset.minute + 15);
 


      var minutes=(eh*60+em) -(sh*60+sm);
      var hours= minutes/60;
      var maxBookTime = e.currentTarget.dataset.maxBookTime;
      this.setData({
        "time.endTime": endTime,
        "time.endIndex": [e.currentTarget.dataset.hourIndex, e.currentTarget.dataset.minIndex],
        "time.min": minutes,
        timeList,
        hours,
        //maxBookTime
      });

      
    

    }
     var hours= this.data.time.min/60;
      var maxBookTime = e.currentTarget.dataset.maxBookTime;
        //console.log('minutes----', this.data.hours);
       
    if(hours > maxBookTime){
        dd.alert({
          content: '超过最大预定时长，请重新选择',
          buttonText: '我知道了',
          success: () => {
               
            var startTime=this.data.time.startTime;
            var endTime = this.data.time.endTime;
            var startIndex = this.data.time.startIndex;
            var endIndex = this.data.time.endIndex;
            var timeList = this.data.timeList;
           this.clearBox(startTime,endTime,startIndex,endIndex,timeList,this);
    
                 }
        });
         
      }
    if (startTime != null && endTime != null && startIndex != null && endIndex != null) {
       this.clearBox(startTime,endTime,startIndex,endIndex,timeList,this);
    }
    }else {
      return false;
    }
    // console.log(e.currentTarget.dataset.hour);
    // console.log(e.currentTarget.dataset.minute);
  //  console.log(e.currentTarget.dataset.hourIndex);
  //  console.log(e.currentTarget.dataset.minIndex);
  },
  getSite:function(){
    dd.chooseDepartments({
      title: "选择与会人",            //标题
      multiple: true,            //是否多选
      limitTips: "超出了",          //超过限定人数返回提示
      maxDepartments: 100,            //最大选择部门数量
      pickedDepartments: [],          //已选部门
      disabledDepartments: [],        //不可选部门
      requiredDepartments: [],        //必选部门（不可取消选中状态）
      appId: 158,              //微应用的Id
      permissionType: "xxx",          //选人权限，目前只有GLOBAL这个参数
      success: function(res) {
        /**
        {
            userCount:1,                              //选择人数
            departmentsCount:1，//选择的部门数量
            departments:[{"id":,"name":"","number":}]//返回已选部门列表，列表中每个对象包含id（部门id）、name（部门名称）、number（部门人数）
        }
        */
      },
      fail: function(err) {
      }
    });

  },
     
  
  //消息选择
  bindPickerChange: function(e) {

//  var  conferenceList=  this.data.conferenceList;
    //console.log('picker发送选择改变，携带值为', conferenceList[e.detail.value].conferenceNumber);
    this.setData({
      index: e.detail.value,
     // cnum: conferenceList[e.detail.value].conferenceNumber
    });
},
  //多项选择框
checkboxChange: function(e) {
    var temp1 = e.detail.value
    var temp2 = ''
    console.log(temp1)
    if (temp1.length != 0) {
      for (var i = 0, len = temp1.length; i < len; i++) {

        if (temp1[i]=="minTen"){
          temp2 = temp2 + "提前十分钟" + ','
        }
        if (temp1[i] == "halfHour") {
          temp2 = temp2 + "提前半小时" + ','
        }
        if (temp1[i] == "oneHour") {
          temp2 = temp2 + "提前一小时" + ','
        }
      }
      this.setData({
        text: temp2
      })
    } else {
      this.setData({
        text: ''
      })
    }
  },
  bindDateChange: function(e) {
    this.setData({
      dates: e.detail.value
    });
   

  },
  //添加议题
  addTopic: function() {
    var topicList = this.data.topicList;
    var newData ="";
    topicList.push(newData);//实质是添加lists数组内容，使for循环多一次
    this.setData({
      topicList: topicList,
    })
  },
  //删除议题
  delTopic: function() {
    var topicList = this.data.topicList;
    topicList.pop();      //实质是删除lists数组内容，使for循环少一次
    this.setData({
      topicList: topicList,
    })
  },
  inputTopic:function (e){
   // console.log(e);
    var topicList = this.data.topicList;
   var index= e.currentTarget.dataset.index;
   topicList[index]=e.detail.value;
   this.setData({
     topicList
   })
  console.log( this.data.topicList)
  },
//时间
  modaltime: function() {
    this.setData({
      showModal2: true
    })
  },

  preventTouchMove: function() {

  },

  mask: function() {
    this.setData({
      showModal: false
    })
  },
  mask2: function(e) {
    this.setData({
      showModal2: false,
    })
    //this.items.value = e.detail.value
  },
  onLoad: function(query) {
   //showView: (options.showView == "true" ? true : false);
   var _this = this;
   console.log(query)
    //再次预定 数据回显
     var message=  _this.data.message;
      message['conferenceName'] =query.conferenceName;
      message['cnum'] =query.cnum;
      message['messageName'] =query.messageName;
      message['messageCompere'] =query.messageCompere;
      message['messageContent'] =query.messageContent;
      message['messagePassword'] = query.messagePassword;

       _this.setData({
          message,
          cnum:query.cnum,
          maxBookTime:query.maxBookTime,
          maxBookDay:query.maxBookDay,
        })
    
    // console.log("maxBookTime---", this.data.maxBookTime);
    // console.log("maxBookDay---", this.data.maxBookDay);
    this.showTimeList(_this,query.cnum);
   
 //  console.log(hours);
  // console.log(minutes);
   
//查询所有会议室
    dd.httpRequest({
      url: conferenceListUrl,
      method: 'POST',
      data: {
        userId: app.globalData.userId,
        corpId: app.globalData.corpId
      },
      dataType: 'json',
      success: function(res) {
      var conferenceList=  _this.data.conferenceList;
        conferenceList=res.data.result;
        console.log('success----', res)
        _this.setData({
          conferenceList
        })
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });
//查询主持人名称
    dd.httpRequest({
      url: getUsernameUrl,
      method: 'POST',
      data: {
        userId: app.globalData.userId
      },
      dataType: 'json',
      success: function(res) {
        var username  = res.data.result;
        console.log('success----', res)
        _this.setData({
          "username":username
        })
      },
      fail: function(res) {
        console.log("httpRequestFail---", res)
        dd.alert({ content: JSON.stringify(res) });
      },
      complete: function(res) {
        dd.hideLoading();
      }

    });

    //  var employeeList= _this.data.employeeList;
    //  var pages = getCurrentPages(); //当前页面栈
   
    //   if(pages.length >=2){
           
    //       var beforePage = pages[pages.length - 2]; //获取上一个页面的实例对象
    //         //_this.data.employeeList = [];
    //          employeeList = [];
    //       _this.setData({
    //         employeeList
    //       })
    //       }


  },

  addlist: function() {
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },
  //点击添加删除class
  clickNum: function(e) {
    this.setData({
      num: e.target.dataset.num
    })
  },

  onReady() {
    // 页面加载完成
     var _this = this;
    if (_this.data.mid==null){
      dd.httpRequest({
        url: generateMidUrl,
        method: 'POST',
        dataType: 'json',
        success: function(res) {
    
        var  mid = res.data.result;
        var topicList = _this.data.topicList;
          console.log('mid----', res)
          _this.setData({
            mid: mid,
            topicList:[]
          })
        },
        fail: function(res) {
          console.log("httpRequestFail---", res)
          //dd.alert({ content: JSON.stringify(res) });
        },
        complete: function(res) {
          dd.hideLoading();
        }

      });
    }
  
   // console.log(this.data.timeList);
  },

// changeParentData: function(){
//   var pages = getCurrentPages(); //当前页面栈
//   if(pages.length > 1){
//     var beforePage = pages[pages.length - 2]; //获取上一个页面的实例对象
//     beforePage.changeData(); // 触发父页面中的方法
//   }

// },

  onShow() {
    // 页面显示

  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {

    var _this = this;
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
});
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;
}
function dateCompare(nowDate, selectDate) {
  var aStart = nowDate.split('-'); //转成成数组，分别为年，月，日，下同
  var aEnd = selectDate.split('-');
  var startDateTemp = aStart[0] + "/" + aStart[1] + "/" + aStart[2];
  var endDateTemp = aEnd[0] + "/" + aEnd[1] + "/" + aEnd[2];
  
  if (startDateTemp > endDateTemp)
    return 0;
  else if (startDateTemp == endDateTemp)
    return 1;
  else if (startDateTemp < endDateTemp)
   return 2;
  
}
var time_range = function(beginTime, endTime, nowTime) {
  var strb = beginTime.split(":");
  if (strb.length != 2) {
    return false;
  }

  var stre = endTime.split(":");
  if (stre.length != 2) {
    return false;
  }

  var strn = nowTime.split(":");
  if (stre.length != 2) {
    return false;
  }
  var b = new Date();
  var e = new Date();
  var n = new Date();

  b.setHours(strb[0]);
  b.setMinutes(strb[1]);
  e.setHours(stre[0]);
  e.setMinutes(stre[1]);
  n.setHours(strn[0]);
  n.setMinutes(strn[1]);

  if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
    return true;
  } else {
    //console.log("当前时间是：" + n.getHours() + ":" + n.getMinutes() + "，不在该时间范围内！");
    return false;
  }
}
function datedifference(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式  
        var dateSpan,
            tempDate,
            iDays;
        sDate1 = Date.parse(sDate1);
        sDate2 = Date.parse(sDate2);
        dateSpan = sDate2 - sDate1;
        dateSpan = Math.abs(dateSpan);
        iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
        return iDays
};
