var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData;
  var ut = require("../../../utils/util.js");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    inurl: a.url, //接口网址
    iurl: a.imghost, //服务器网址
    store: 0, //是否显示服务门店列表
    
    placeholder: "填写备注", //备注为空的placeholder
    store_list: [], //门店列表
   
	store_name: "", //选择的服务门店
    fir_pick_index: 0, //选择的门店下标
    curpage: 1, //当前分页数
    pageSize: 8, //页大小
    total: 0,
    ismore: 0, //是否加载完毕
   
    isScroll: true, //scroll-y是否可以滑动
    key_word: "", //是否按门店文字查询
    is_service_read: 0, //是否调用过门店接口
    is_search: 0, //是否通过key_word调用接口
    is_success: 0, //是否提交成功
    remarks: "", //备注
    storageId: "", //线下门店id
    url: "/packageA/pages/my_service/appment_main", //本页面地址路径用于选择时间页面跳转回来
  
    tment_count: "", //可预约人数
    lat: "", //纬度坐标
    lon: "", //经度坐标
    is_gps: 1, //是否开启gps
    validay: "", //服务项目有效期
    is_sub: 0, //判断是否重复提交
    is_textea: 1, //备注是否是可输入
    
	write: [0, 0], //定位参数
	scrolltop: 0,//据顶部距离
	v:{},
	
	//project: ['项目1', '项目2', '项目3', '项目4', '项目5', '项目6', '项目7'],
	//md: [{name:'美导1',time:'08:30-22:00'},{name:'美导2',time:'09:30-18:00'},],
	timeList: [],
	deltaX: 0,
	col_arr:[],	
	wp:[],
	datet:null,
	s_top:0,
	
	cur_sele_i:-1,
	cur_sele_j:-1

  },
  //控制备注输入
  check_text: function() {
    var th = this;
    var is_textea = th.data.is_textea;
    th.setData({
      is_textea: 1,
      beautician: 0
    })
  },
  
  onclickstore: function() {
    var th = this;
    var store = th.data.store;
    if (store) {
      th.setData({
        store: 0,
        is_textea: 1
      })
    } else {
      th.setData({
        beautician: 0,
        store: 1,
        is_textea: 0
      })
      if (th.data.store_list.length < 1) {
        wx.showLoading({
          title: '加载中',
        })
		
		//获取门店
        th.query_store();
      }
    }
  },
  //输入的备注
  input_remarks: function(e) {
    var remarks = e.detail.value;
    this.setData({
      remarks: remarks
    })
  },
  
  
  //单个预约的提交成功及发送模版代码
  success: function() {
    var user_id=getApp().globalData.userInfo.user_id;	    
	wx.showLoading({ title: '加载中', });  		
    var th = this;
    var store = th.data.store_name; //门店名称
    var datet = th.data.datet; //预约时间   
    //接口路径
	var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/batchinsert"; 
	var req_arr={
		"storageId": th.data.storageId,
		"storeId": a.stoid,
		"userId": user_id,
		"remark": '',
		"isxz": 1,
		"states": 0,
		"list":[]
	};
    for(var i in this.data.v){
		for(var j in this.data.v[i]){
			  var item=this.data.v[i][j];			  
			  var md=this.data.md[i];					
			  var tn=this.data.timeArr[j];										
			  var json = {
			    "arrangeTime":datet+' '+ tn + ":00",
			    "beauticianId":encodeURIComponent(md.staffid) ,
			    "buyType": item.BuyType,
			    //"effectiveDay": "",
			    //"number": "",
			    "projectId": item.ProjectID,			
			    "serviceId": item.ServiceID,			    		   
			    "validay": item.Validay,			   
			  }
			  req_arr.list.push(json);			 			 
		}
	}	
	//console.log(req_arr);
	//return false;
    //var js_data = JSON.stringify(req_arr);

    getApp().request.promisePost(url, {
          data: req_arr,is_json:1,is_normal:1
    }).then(res => {
        th.setData({ is_sub: 0})
        wx.hideLoading();
        if (res.data.code == 0) {
            getApp().my_warnning("预约成功", 1, th); 
			
			if(res.data.data.length>1){
				 var number = res.data.data[0].Number;
				 wx.redirectTo({
				   url: "/packageA/pages/my_service/tment_order_list?number=" + number+"&userid="+user_id,
				 });
				
			}else{
				 var number = res.data.data[0].Number;
				 wx.redirectTo({
				   url: "/packageA/pages/my_service/tment_details?number=" + number+"&userid="+user_id,
				 });
			}
		    
        } else {
          getApp().my_warnning(res.data.msg, 0, th);
          th.settime();
        }

    })
  },
  
  
  //定时显示texteat
  settime: function() {
    var th = this;
    setTimeout(function() {
      th.setData({
        is_textea: 1
      })
    }, 2000);
  },
  
  
  //-- 提交预约 --
  sub_success: function(e) {
    var th = this;
    //和推送消息有关系
	var temp_url = th.data.inurl + "/api/wx/weappSendlist/page";
    var template_id = "";

    //门店名称
	var store = th.data.store_name; 
    //提交预约前的判断
    if (store == "") {
       getApp().my_warnning("请选择服务门店", 0, th);
       return false;
    } 
	
	if(Object.keys(th.data.v).length === 0){
		getApp().my_warnning("请选择美导和预约时间", 0, th);
		return false;
	}
	
	if(th.data.is_sub) return false;
	th.setData({ is_sub: 1});
						  
			  
	//获取模版id
	getApp().request.get(temp_url, {
			    data: {
			      store_id: a.stoid,
			      typeid: "1011"
			    },
					  success:function(res){
						  if (res.data.code == 0 && res.data.data.pageData.length > 0) {
						    template_id = res.data.data.pageData[0].template_id;
						    // //授权订阅
						    wx.requestSubscribeMessage({
						      tmplIds: [template_id],
						      success(res) {
						        th.success();
						      },
						      fail(res) {
						        th.success();
						      }
						    })
						  } else {
						    th.success();
						  }
					  }
			  })
		 
  },
 
  //点击选择门店
  choose_for_store: function(e) {
    var th = this;
    var index_c = e.currentTarget.dataset.ind;
    var fir_pick_index = th.data.fir_pick_index;
    //判断是否点击选中的门店，防止重复点击重复设置选中下标
    if (index_c == fir_pick_index) {
      return false;
    } else {
      th.setData({
        fir_pick_index: index_c,
        beautician_name: "",
        time: "",
        tment_count: ""
      })
    }
  },
  
  //确认选择门店
  choice_store: function() {
    var th = this;
    var index = th.data.fir_pick_index;
    var store_name = th.data.store_list[index].StorageName;
    var Id = th.data.store_list[index].Id;
    th.setData({
      store: 0,
      store_name: store_name,
      storageId: Id,
      is_textea: 1
    })

	th.get_project_guide();

  },
  
  //获取美导和项目
  get_project_guide(){  
	  var th=this,user=getApp().globalData.userInfo;
	  var req={
		  storeId:os.stoid,
		  userId:user.user_id,
   		  StorageId:encodeURIComponent(this.data.storageId),
	  }  
	  getApp().request.get("/api/weshop/marketing/reservation/sm/pageNew",{
	  		  data:req,
	  		  success:function(res){
	  			  if(ut.ajax_ok(res)){
					  th.setData({project:res.data.data.pageData})
				  }
	  		  }
	  })
	  
      req.SeekTime=this.data.datet;
	  getApp().request.get("/api/weshop/marketing/reservation/listStaffAndTime",{
		  data:req,
		  success:function(res){
			   if(ut.ajax_ok2(res)){
				  th.setData({v:{},col_arr:[]})
				  //-- 有些时间是全部没有的 --
				  th.setTimeShow(res.data.data)
			   }else{
				   th.setData({md:[]});
			   }
		  }
	  }) 
	  
	  //获取第一个元素的位置
	  setTimeout(function(){
	  	 th.queryMultipleNodes(); 
	  },1000)
	 	  
  },
  
  
  onGetBottom: function() {
    var th = this;
    if (this.data.total <= th.data.pageSize) return;
    if (this.data.ismore) return;

    wx.showLoading({
      title: '加载中...',
    })
    th.query_store();
  },
  
  //分页查询门店信息
  query_store: function() {
    var th = this;
    th.setData({
      is_textea: 0
    })
    var itemId = th.data.itemId; //服务id
    var url = "/api/weshop/marketing/reservation/service/storage/page";
    var key_word = th.data.key_word;
    key_word = key_word.replace(/\s+/g, "");
    getApp().request.promiseGet(url, {
      data: {
		userId: getApp().globalData.user_id,  
        storeId: a.stoid,
        latitude: th.data.lat,
        longitude: th.data.lon,
        page: th.data.curpage,
        pageSize: th.data.pageSize,
        keyWord: key_word
      }
    }).then(res => {
      wx.hideLoading();
      if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length>0) {
        th.data.curpage++;
        var arr1 = th.data.store_list;
        var arr2 = res.data.data.pageData;
        var arr3 = [...arr1, ...arr2];
        var ismore = 0;
        if (arr3.length == res.data.data.total) ismore = 1
        th.setData({
          store_list: arr3,
          total: res.data.data.total,
          ismore: ismore,
          is_service_read: 1,
        }), wx.stopPullDownRefresh(); //停止下拉刷新
        if (key_word != "" && res.data.data.pageData.length < 1) {
          th.setData({
            is_search: 1
          })
        }
      } else {
        getApp().my_warnning(res.data.msg, 0, th);
        th.settime();
      }
    })
  },
  //查询
  query_beautician: function() {
    var th = this;
    th.setData({
      is_textea: 0
    });
		
    if (th.data.store_name == "") {
      getApp().my_warnning("请选择服务门店", 0, th);
      th.settime();
    } else {
      wx.showLoading({
        title: '加载中',
      })
      var itemid = th.data.itemId; //正式使用的项目id
      var storageId = th.data.storageId; //正式使用的线下门店id
      var url = "/api/weshop/marketing/reservation/staff/pagenew"; //接口地址
      
	  getApp().request.promiseGet(url, {
        data: {
          storeId: a.stoid,
          userId: th.data.options.userid,
          serviceId: itemid,
          storageId: storageId
        }
      }).then(res => {
        wx.hideLoading();
        if (res.data.code == 0) {
          th.setData({
            beautician_list: res.data.data
          })
          if (res.data.data.length < 1) {
            getApp().my_warnning("暂无美容师", 0, th);
            th.settime();
          } else {
            if (th.data.beautician == 0) {
              th.setData({
                beautician: 1,
              })
            } else {
              th.setData({
                beautician: 0,
              })
            }
          }
        } else {
          getApp().my_warnning(res.data.msg, 0, th);
          th.settime();
        }
      })
    }
  },
	
  choice_beautician: function(e) {
    var th = this;
    var bea_index = e.currentTarget.dataset.baaindex;
    var bea_name = th.data.beautician_list[bea_index].StaffName;
    var BeauticianID = th.data.beautician_list[bea_index].staffid;
	var StorageId=th.data.beautician_list[bea_index].StorageId
	
    th.setData({
      beautician_name: bea_name,
      beautician: 0,
      bea_index: bea_index,
      beauticianID: BeauticianID,
      time: "",
      tment_count: "",
      is_textea: 1,
	  StorageId:StorageId
    })

  },
  //获取搜索门店输入的值
  input_store: function(e) {
    this.setData({
      key_word: e.detail.value
    })
  },
  //搜索门店
  search_store: function() {
    var th = this;
    var key_word = th.data.key_word;
    var store_list = th.data.store_list;
    th.setData({
      curpage: 1,
      is_search: 0,
      store_list: []
    })
    wx.showLoading({
      title: '加载中',
    })
    th.query_store();
  },
  //美容师预约跳转页面
  nav_bea: function() {
    var th = this;
    th.setData({
      beautician: 0
    })
    var storageId = th.data.storageId; //线下门店id
    var itemId = th.data.itemId; //服务id
    var project_id = th.data.project_id;
    if (storageId == "") {
      getApp().my_warnning("请选择服务门店", 0, th);
      th.settime();
    } else {
      th.setData({
        is_textea: 1
      })
	
	  console.log('optionsxxx===>', this.data.options);
	  // console.log('1-->', "/packageG/pages/user/my_service/cosmetology_list?userid=" + th.data.options.userid + 'storageId=' + storageId + '&' + 'itemId=' + itemId + '&' + "projectId=" + project_id);
      wx.navigateTo({
        url: "/packageA/pages/my_service/cosmetology_list?userid=" + this.data.options.userid + '&storageId=' + storageId + '&itemId=' + itemId + "&projectId=" + project_id
      });

    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
	  
	  
	// 如果数值位数为1，则补0
	function appendZero(obj) {
		if (obj < 10) {
			return "0" + "" + obj;
		} else {
			return obj;
		}
	};  

	this.getTimeList(23, 30);
    var th = this;
	var now_date = new Date();
	var md = now_date.getFullYear()+"-"+appendZero(now_date.getMonth() + 1) + "-" + appendZero(now_date.getDate());
		
    th.setData({
	  options,
      itemId: options.service_id,
      buyType: options.BuyType,
      project_id: options.ProjectID,
      validay: options.Validay,
	  datet:md,
	  nowDate:md
    });
    wx.getLocation({
      type: 'gcj02',
      success: function(res) {
        th.data.lat = res.latitude;
        th.data.lon = res.longitude;
        th.data.is_get_local_ok = 1;
        th.setData({
          is_gps: 1
        });
      },
      fail: function(res) {
        if (res.errCode == 2) {
          th.setData({
            is_gps: 0
          });
          if (th.data.is_gps == 0) {
            getApp().confirmBox("请开启GPS定位", null, 25000, !1);
            th.settime();
          }
        } else {
          th.setData({
            is_gps: "3"
          });
        }

        th.data.is_get_local_ok = 1;
      }
    });
	
	//--先判断会员状态--
	var user_info = getApp().globalData.userInfo;
	if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
	  wx.navigateTo({
	    url: '/packageE/pages/togoin/togoin',
	  })
	  return false;
	}
  },
  

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var th = this;
    th.setData({
      is_textea: 1
    })
  
  },
  
  
  //获取单个服务项目信息
  query_project: function() {
    var th = this;
    var url = "/api/weshop/marketing/reservation/sm/page"; //获取服务项目接口
    var project_id = th.data.project_id; //服务项目id
    getApp().request.promiseGet(url, {
      data: {
        storeId: a.stoid,
        userId: th.data.options.userid,
        projectId: project_id
      }
    }).then(res => {
      if (res.data.code == 0) {
        th.setData({
          validay: res.data.data.pageData[0].Validay
        })
      } else {
        getApp().my_warnning(res.data.msg, 0, th);
        th.settime();
      }
    })
  },
 

 
	   //开始拖拽项目列表
	   touchmove1: function (e) {  	
			 var that = this;
			 var position = [e.touches[0].pageX-15, e.touches[0].pageY-that.data.s_top];
			 that.setData({
			   wp: position
			 });
	  },

	   //开始拖拽
	   touchmove: function (e) {
         if(!this.data.copy_btn) return false;
	      var that = this;
		  var position = [e.touches[0].pageX + this.data.deltaX-15, e.touches[0].pageY-15];
	      that.setData({
	        write: position
	      });
	   },
	
      //-- 点击空格选择 --
      sele_tab:function(e){		  
		  if(!this.data.sele_project){
			  wx.showToast({
			    title: "请选择要预约的项目",
			    icon: 'none',
			    duration: 2000
			  })
			  return false;
		  }
		  	  
		  var th=this;
		  var arr=this.data.col_arr;
		  var i=e.currentTarget.dataset.index;
		  var j=e.currentTarget.dataset.subindex;
		  
		  var item=this.data.md[i];    //获得美导
		  var tn=this.data.timeArr[j]; //获得时间
		  
		  //查看时间段能不能预约
		  if(!item.listtime[j].iskyy){
			  wx.showToast({
			    title: "该时间不可以预约",
			    icon: 'none',
			    duration: 2000
			  })
			  return false;
		  }
		  //查看时间有没有被预约了
		  if(this.data.v && this.data.v[i] && this.data.v[i][j]){
			  wx.showToast({
				title: "该时间已被预约",
				icon: 'none',
				duration: 2000
			  })
			  return false;
		  }
		  
		  if(!item.listtime[j].itemids){
			  wx.showToast({
				title: "该时间不可预约该项目",
				icon: 'none',
				duration: 1500
			  })
			  return false;
		  }
		    
		  var project_arr=item.listtime[j].itemids.split(',');	
		  
		  if(project_arr.indexOf(this.data.sele_project.ServiceID)==-1){
			  wx.showToast({
				title: "该时间不可预约该项目",
				icon: 'none',
				duration: 1500
			  })
			  return false;
		  }
		  	    
		  //同一美导同一项目，能选择两次，只要时间段不重复
		  if(this.data.v[i] && Object.keys(this.data.v[i]).length){
			   for(var sj in this.data.v[i]){
				   if(this.data.v[i][sj] && this.data.v[i][sj].ProjectID==this.data.sele_project.ProjectID){					   					  						   
						th.checK_is_can_yy(item,tn,function(res){
							if(res){
								if(res>1){
									wx.showToast({
										title: '当前项目预约次数已超出项目剩余数,请先修改', icon: 'none', duration: 2000
									});
									return false;
								}
								wx.showModal({
									title: "当前项目已有预约是否修改？",
									success: function (res) {										
										if(res.confirm){
											delete th.data.v[i][sj];
											if(!th.data.v[i]) 
											    th.data.v[i]={}
											th.data.v[i][j]=th.data.sele_project;
											var ind=arr.indexOf(sj);	  	
											arr.splice(ind, 1); 
											arr.push(j); 
											th.setData({
												v: th.data.v,col_arr:arr
											});	
											
										}											
									}
								})
								return false;
							}else{
							    var txt="v["+i+"]["+j+"]";
								arr.push(j);
								th.setData({
									[txt]: th.data.sele_project,
									col_arr:arr
								});	
								return false;
							}																   
						})
						                     					   
				   }
			   }
			  
		  }
		  
		  th.checK_is_can_yy(item,tn,function(res){ 				  
			if(res){
				if(res>1){
					wx.showToast({
						title: '当前项目预约次数已超出项目剩余数,请先修改', icon: 'none', duration: 2000
					});
					return false;
				}  
			
				wx.showModal({
					title: "当前项目已有预约是否修改？",
					success: function (res) {										
						if(res.confirm){
							
							var ii=th.data.cur_sele_i;
							var jj=th.data.cur_sele_j;							
							delete th.data.v[ii][jj];
							if(!th.data.v[i])
							     th.data.v[i]={}
							th.data.v[i][j]=th.data.sele_project;
							var ind=arr.indexOf(jj);	  	
							arr.splice(ind, 1); 
							arr.push(j); 
							th.setData({
								v: th.data.v,col_arr:arr
							});	
						}											
					}
				})	
				
			}else{
				var txt="v["+i+"]["+j+"]";
				arr.push(j);
				th.setData({
				  [txt]: th.data.sele_project,
				  col_arr:arr
				});	
			}
			

			 
		 });		  		 
	  },





      //删除响应的预约
      close_this:function (e){
           var txt=e.currentTarget.dataset.txt;
           var sindex=parseInt(e.currentTarget.dataset.sindex);
           var arr=this.data.col_arr;    			  
		   var ind=arr.indexOf(sindex);	  			  
           arr.splice(ind,1)
           this.setData({[txt]:null,col_arr:arr})
      },

      //计算滚蛋的距离
      onPageScroll(e) { this.data.scrolltop = e.scrollTop;},
	 
	  //确认有没有预约
	  checK_is_can_yy(item, tn, back) {
			var th = this;
			var req = {
				beauticianId: encodeURIComponent(item.staffid),
				seekTime: this.data.datet + " " + tn + ":00",
				serviceId: encodeURIComponent(this.data.sele_project.ServiceID),
				storageId: encodeURIComponent(this.data.storageId),
				storeId: os.stoid
			}
			getApp().request.get("/api/weshop/marketing/reservation/can/reservation/countnew", {
				data: req,
				success: function (res) {
					th.setData({ copy_btn: 0 });
					if (res.data.code == 0) {
						if (!res.data.data.CanReservation && parseInt(res.data.data.canReservation) <= 0) {
							wx.showToast({
								title: '该项目不可以预约', icon: 'none', duration: 2000
							});
							return false;
						}

						if (!th.data.v) { back(); return false; }

						var arr = Object.keys(th.data.v);
						if (arr.length == 0) { back(); return false; }

						var num = 0;
						var sele_arr=[];
						for (var i in th.data.v) {
							if (!th.data.v[i]) continue;
							for (var j in th.data.v[i]) {
								if (th.data.v[i][j] && th.data.v[i][j].ServiceID == th.data.sele_project.ServiceID) {
									num++;
								    th.data.cur_sele_i=i;
								    th.data.cur_sele_j=j;
								}
							}
						}

						if (!num) { back(); return false; }

						//如果已经超出次数的时候，就不能预约了					 
						if (num >= parseInt(res.data.data.CanReservation)) {
														
							back(num);
							return false;
						}
						back();

					} else {
						wx.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						})
					}
				}
			})
		},

	  //声明节点查询的方法
	  queryMultipleNodes: function() {
		  var th=this;
	      const query = wx.createSelectorQuery()                // 创建节点查询器 query
	      query.select('.content_view').boundingClientRect()    // 这段代码的意思是选择Id=productServe的节点，获取节点位置信息的查询请求
	      query.selectViewport().scrollOffset()                 // 这段代码的意思是获取页面滑动位置的查询请求
	      query.exec(res => {
			  if(!res || res.length==0) return false;
              if(!res[0]) return false;

	          console.log(res);
			  th.data.f_x=res[0].left;
			  th.data.f_y=res[0].top;
			  th.data.f_hei=res[0].height;
			  th.data.f_width=res[0].width;
	      })
		
		},

     /*--  
	 getcopy(e) {
		 
	 },--*/
     //项目元素点击后的效果
	 getName(e) {		 
		 var that=this;
		 console.log('e', e);
		 var x=e.currentTarget.dataset.offsetLeft;
		 var y=e.currentTarget.dataset.offsetTop;
		 var position = [x, y];
		 that.setData({
		    write: position,copy_btn:1
		 });	 
		 // console.log('e1', e);		
		 let index = e.currentTarget.dataset.index;
		 let name = this.data.project[index];
		 
		  
		 this.setData({
			 sele_project: name,prj_index:index
		 });
		 
	 },
	 
	 //-- 项目列表长按 --
	 setmove1(){
		this.setData({move1:1}); 
	 },

	 //-- 生成时间段 --
	 getTimeList(hours,step) {
		  var minutes=60;
		  var timeArr = [];
		  hours = hours;
		  step = step;
		  
		  // 如果数值位数为1，则补0
		  function appendZero(obj) {
		  	if (obj < 10) {
		  		return "0" + "" + obj;
		  	} else {
		  		return obj;
		  	}
		  };  
		  
		  var now_date=new Date();
		  var md = now_date.getFullYear()+"-"+appendZero(now_date.getMonth() + 1) + "-" + appendZero(now_date.getDate());
		     
		  for(var i = 8; i < hours; i++){
				var str = '';
				if(i < 10) {
					str = 0 + '' + i;
				} else {
					str = '' + i;
				};
			 
				for(var j = 0; j < minutes; j++) {
					if(j % step == 0){
						var s =  ':' +  appendZero(j);
						s = str + s;	
						//-- 不是当天 --
						if(this.data.datet && this.data.datet!=md){
							timeArr.push(s);
						}else{
							var d1=md+" "+s;
							var date1=new Date(d1);
							//必须是大于
							if(date1.getTime()>now_date.getTime()){
								timeArr.push(s);
							} 
						}
															
					};
				};
			};
	    		
			this.setData({timeArr,});

		},
				
		scroll(e) {
			// console.log('e', e.detail.deltaX);
			let deltaX = e.detail.deltaX;
			// if(deltaX < 0) {
			// 	deltaX = -deltaX;
			// };
			this.data.deltaX = -deltaX;
		},
			
		pickerTap:function() {
		    var date = new Date();
		    var monthDay = ['今天','明天'];
		    // 月-日
		    for (var i = 2; i <= 14; i++) {
		      var date1 = new Date(date);
		      date1.setDate(date.getDate() + i);
		      var md = (date1.getFullYear()+"-"+date1.getMonth() + 1) + "-" + date1.getDate();
		      monthDay.push(md);
		    }	
		    this.setData(monthDay);
		},
		
		
		//-- 选择时间的时候 --
		bindDateChenge: function(e) {					
			var th=this;			
			var nd=new Date(this.data.nowDate);
			var nd1=new Date(e.detail.value);
			if(nd1.getTime()<nd.getTime()){
				wx.showToast({
				  title: "选择的日期不能小于今天",
				  icon: 'none',
				  duration: 2000
				})			
				return false;
			}
					
		    this.setData({
		       datet: e.detail.value
		    });	
			this.getTimeList(23, 30);	
			//当时间变化的时候
			if(this.data.storageId){
				 var req={
					  storeId:os.stoid,
					  userId:getApp().globalData.userInfo.user_id,
					  StorageId:encodeURIComponent(this.data.storageId),
				 }  
				 req.SeekTime=this.data.datet;
				 getApp().request.get("/api/weshop/marketing/reservation/listStaffAndTime",{
				 		  data:req,
				 		  success:function(res){
				 			   if(ut.ajax_ok2(res)){
				 			  		th.setData({v:{},col_arr:[]})
									//-- 有些时间是全部没有的 --
									th.setTimeShow(res.data.data)
				 			   }else{
								  th.setData({md:[]});
							   }
				 		  }
				 })
			}	
		},

		onPageScroll: function(e) {
			this.data.s_top=e.scrollTop;
		},
		
		//-- 时间段有些不显示,出来的时间和显示的对应 --
		setTimeShow:function(data){			
			// 如果数值位数为1，则补0
			function appendZero(obj) {
				if (obj < 10) {
					return "0" + "" + obj;
				} else {
					return obj;
				}
			};  
			
			var now_date=new Date();
			var md = now_date.getFullYear()+"-"+appendZero(now_date.getMonth() + 1)+ "-" + appendZero(now_date.getDate());
					 
			if(this.data.datet && this.data.datet!=md){
			     this.setData({md:data});
				 return false;	
			}

            for (var i in data) {
                var ti_time_arr = data[i].listtime;
                var arr = [];
                for (var j in ti_time_arr) {
                    var d1 = md + " " + ti_time_arr[j].stime;
                    var date1 = new Date(d1);
                    //必须是大于
                    if (date1.getTime() > now_date.getTime()) {
                        arr.push(ti_time_arr[j]);
                    }
                }
                data[i].listtime = arr;
            }
			this.setData({md:data});

           

		},
		
	
	  
})