const app = getApp() 
 | 
var util = require('../../utils/util.js'); 
 | 
var api = require('../../utils/service-api.js'); 
 | 
  
 | 
Page({ 
 | 
  
 | 
  /** 
 | 
   * 页面的初始数据 
 | 
   */ 
 | 
  data: { 
 | 
    opentc: false, 
 | 
    shopInfo: {}, 
 | 
    //day 0表示占位符,1可以预约,2已过期,3已选择  
 | 
    months: [], 
 | 
    weeks: [], 
 | 
    hours: [], 
 | 
    currentHoursIndex: 0, 
 | 
    //选中的日期 
 | 
    sellectDay: "", 
 | 
    preDay: "", 
 | 
    preTimeIndex: null, 
 | 
    isLogin: false, 
 | 
    hasChooseService: false, 
 | 
    service: {}, 
 | 
    masseuse: {}, 
 | 
    hasChooseMasseuse: false, 
 | 
    //不选美疗师 
 | 
    unneededMasseuse: true, 
 | 
    userInfo: {}, 
 | 
  
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 生命周期函数--监听页面加载 
 | 
   */ 
 | 
  onLoad: function(options) { 
 | 
    // 
 | 
    var _this = this; 
 | 
  
 | 
    this.setData({ 
 | 
        shopInfo: app.shopInfo, 
 | 
      }); 
 | 
  
 | 
    util.request({ 
 | 
      api: api.yuyue.getTimeList, 
 | 
      callback: function(data) { 
 | 
        _this.setData({ 
 | 
          months: data.rows, 
 | 
          userInfo: getApp().userInfo, 
 | 
        }); 
 | 
      }, 
 | 
  
 | 
    }); 
 | 
  
 | 
    let timeStr = new Date().Format("yyyy-MM-dd"); 
 | 
    this.setData({ 
 | 
      sellectDay: timeStr 
 | 
    }); 
 | 
    this.loadWeeks(timeStr);  
 | 
  }, 
 | 
  onShow: function() { 
 | 
    console.log("onShow"); 
 | 
    this.setData({ 
 | 
      isLogin: getApp().isLogin 
 | 
    }); 
 | 
    var _this = this; 
 | 
  
 | 
    var service = util.getOutStorage('chooseService') 
 | 
    if (util.isNotBlank(service)) { 
 | 
      _this.setData({ 
 | 
        service: service, 
 | 
        hasChooseService: true, 
 | 
      }); 
 | 
    } 
 | 
  
 | 
    this.setData({ 
 | 
      shopInfo: app.shopInfo, 
 | 
    }); 
 | 
  
 | 
    var masseuse = util.getOutStorage('masseuse'); 
 | 
    if (util.isNotBlank(masseuse)) { 
 | 
      if (masseuse == -1) { 
 | 
        _this.setData({ 
 | 
          unneededMasseuse: true, 
 | 
          hasChooseMasseuse: true, 
 | 
          masseuse: {}, 
 | 
        }); 
 | 
      } else { 
 | 
        _this.setData({ 
 | 
          masseuse: masseuse, 
 | 
          hasChooseMasseuse: true, 
 | 
          unneededMasseuse: false, 
 | 
        }); 
 | 
      } 
 | 
    } 
 | 
  
 | 
  }, 
 | 
  
 | 
  loadWeeks: function(timeStr) { 
 | 
    var _this = this; 
 | 
    util.request({ 
 | 
      api: api.yuyue.getYYDayAndWeek + "?time=" + timeStr, 
 | 
      callback: function(data) { 
 | 
        _this.setData({ 
 | 
          weeks: data.rows, 
 | 
          hours: data.rows[0].hours, 
 | 
        }); 
 | 
      }, 
 | 
  
 | 
    }); 
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  
 | 
  //UI控制函数 
 | 
  chooseService: function() { 
 | 
    console.log(getApp().userInfo.phoneNumber); 
 | 
  
 | 
  
 | 
    if (util.isBlank(getApp().userInfo.nickName)) { 
 | 
      wx.navigateTo({ 
 | 
        url: '/pages/welcome/welcome?url=/pages/yuyue/khyuyue', 
 | 
      }) 
 | 
    } else if (getApp().userInfo.phoneNumber == null || 
 | 
      getApp().userInfo.phoneNumber == "") { 
 | 
      wx.navigateTo({ 
 | 
        url: '/pages/phone/phone?url=/pages/yuyue/khyuyue', 
 | 
      }) 
 | 
    } else { 
 | 
      wx.navigateTo({ 
 | 
        url: '/pages/yuyue/choseService', 
 | 
      }) 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
  }, 
 | 
  
 | 
  closeTc: function() { 
 | 
    console.log("closeTc"); 
 | 
    this.setData({ 
 | 
      opentc: false, 
 | 
    }); 
 | 
  }, 
 | 
  openTc: function() { 
 | 
    console.log("openTc"); 
 | 
    this.setData({ 
 | 
      opentc: true, 
 | 
    }); 
 | 
  }, 
 | 
  //点击周选择 
 | 
  changeWeeks: function(e) { 
 | 
  
 | 
  
 | 
    //清空上次选中的时间 
 | 
    var hours = this.data.hours; 
 | 
    if (this.data.preTimeIndex != null) { 
 | 
      hours[this.data.preTimeIndex].status = 1; 
 | 
      hours[this.data.preTimeIndex].atlable = ""; 
 | 
      hours[this.data.preTimeIndex + 1].status = 1; 
 | 
    } 
 | 
    this.setData({ 
 | 
      hours: hours, 
 | 
      preTimeIndex: null, 
 | 
    }); 
 | 
  
 | 
  
 | 
    //切换时间 
 | 
    var _this = this; 
 | 
    var index = e.currentTarget.dataset.index; 
 | 
    var weeks = this.data.weeks[index]; 
 | 
  
 | 
    _this.setData({ 
 | 
      currentHoursIndex: index, 
 | 
      hours: weeks.hours, 
 | 
      sellectDay: weeks.fullDay, 
 | 
    }); 
 | 
  
 | 
  
 | 
    this.cleanSelectMasseuse(); 
 | 
  
 | 
  }, 
 | 
  
 | 
  
 | 
  //清空已经选中的美疗师 
 | 
  cleanSelectMasseuse: function() { 
 | 
    this.setData({ 
 | 
      unneededMasseuse: false, 
 | 
      hasChooseMasseuse: false, 
 | 
      masseuse: {}, 
 | 
  
 | 
    }); 
 | 
  }, 
 | 
  
 | 
  
 | 
  //点选技师 
 | 
  chooseMasseuse: function(e) { 
 | 
    var preTimeIndex = this.data.preTimeIndex; 
 | 
  
 | 
    if (util.isNotBlank(preTimeIndex)) { 
 | 
      var sellectDay = this.data.sellectDay; 
 | 
      var hours = this.data.hours; 
 | 
      var beginTime = sellectDay + " " + hours[preTimeIndex].hour; 
 | 
      var endTime = sellectDay + " " + hours[preTimeIndex + 1].hour; 
 | 
      var shopId = this.data.shopInfo.id; 
 | 
      wx.navigateTo({ 
 | 
        url: '/pages/yuyue/choseMasseuse?shopId=' + 
 | 
          shopId + '&beginTime=' + beginTime + '&endTime=' + endTime 
 | 
      }); 
 | 
    } else { 
 | 
      wx.showToast({ 
 | 
        title: '请先选择预约时间', 
 | 
        icon: 'none', 
 | 
      }) 
 | 
      return; 
 | 
    } 
 | 
  }, 
 | 
  //点选时间 
 | 
  chooseTime: function(e) { 
 | 
  
 | 
  
 | 
    var index = e.currentTarget.dataset.index; 
 | 
  
 | 
  
 | 
  
 | 
    var hours = this.data.hours; 
 | 
  
 | 
    if (index == hours.length - 1) { 
 | 
      wx.showToast({ 
 | 
        title: '该时间段不可选', 
 | 
        icon: 'none', 
 | 
      }) 
 | 
      return; 
 | 
    } 
 | 
  
 | 
    if (this.data.preTimeIndex != null) { 
 | 
      hours[this.data.preTimeIndex].status = 1; 
 | 
      hours[this.data.preTimeIndex].atlable = ""; 
 | 
      hours[this.data.preTimeIndex + 1].status = 1; 
 | 
    } 
 | 
  
 | 
    hours[index].status = 3; 
 | 
    hours[index].atlable = '到店'; 
 | 
    hours[index + 1].status = 3; 
 | 
  
 | 
    this.setData({ 
 | 
      hours: hours, 
 | 
      preTimeIndex: index 
 | 
    }); 
 | 
  
 | 
    this.cleanSelectMasseuse(); 
 | 
  
 | 
  
 | 
  }, 
 | 
  
 | 
  //点击选中天数 
 | 
  chooseDay: function(e) { 
 | 
    var _this = this; 
 | 
    var day = e.currentTarget.dataset.day; 
 | 
    var monIndex = e.currentTarget.dataset.monindex; 
 | 
    var dayIndex = e.currentTarget.dataset.dayindex; 
 | 
    var dayNode = 'months[' + monIndex + '].dates[' + dayIndex + '].status' 
 | 
    var preDay = this.data.preDay; 
 | 
    console.log(dayNode); 
 | 
    if (preDay.length > 0) { 
 | 
      this.setData({ 
 | 
        [dayNode]: 3, 
 | 
        preDay: dayNode, 
 | 
        [preDay]: 1, 
 | 
        currentHoursIndex: 0, 
 | 
        sellectDay: day, 
 | 
      }) 
 | 
    } else { 
 | 
  
 | 
      //清空初始赋值 
 | 
      var month = this.data.months[0]; 
 | 
      for (var i = 0; i < month.dates.length; i++) { 
 | 
        if (month.dates[i].status == 3) { 
 | 
          month.dates[i].status == 3 
 | 
          var initdayNode = 'months[0].dates[' + i + '].status' 
 | 
          this.setData({ 
 | 
            [initdayNode]: 1, 
 | 
          }) 
 | 
        } 
 | 
      } 
 | 
      //选中点击 
 | 
      this.setData({ 
 | 
        [dayNode]: 3, 
 | 
        preDay: dayNode, 
 | 
        currentHoursIndex: 0, 
 | 
        sellectDay: day, 
 | 
        preTimeIndex: null, 
 | 
      }) 
 | 
    } 
 | 
    this.loadWeeks(day); 
 | 
    this.closeTc(); 
 | 
    this.cleanSelectMasseuse(); 
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 选择技师 
 | 
   */ 
 | 
  
 | 
  
 | 
  /** 
 | 
   * 下一步 
 | 
   */ 
 | 
  continueYuyue: function() { 
 | 
    console.log("下一步"); 
 | 
  
 | 
  
 | 
  
 | 
    if (!this.data.hasChooseService) { 
 | 
      wx.showToast({ 
 | 
        title: '请选择服务', 
 | 
        icon: 'none', 
 | 
      }) 
 | 
      return; 
 | 
    } 
 | 
  
 | 
    var preTimeIndex = this.data.preTimeIndex; 
 | 
    if (!util.isNotBlank(preTimeIndex)) { 
 | 
      wx.showToast({ 
 | 
        title: '请先选择预约时间', 
 | 
        icon: 'none', 
 | 
      }) 
 | 
      return; 
 | 
    } 
 | 
  
 | 
  
 | 
    var sellectDay = this.data.sellectDay; 
 | 
    var hours = this.data.hours; 
 | 
    var beginTime = sellectDay + " " + hours[preTimeIndex].hour; 
 | 
  
 | 
    var serviceOrder = { 
 | 
      shopInfo: this.data.shopInfo, 
 | 
      time: beginTime, 
 | 
      shopProduct: this.data.service, 
 | 
    }; 
 | 
  
 | 
    if (!this.data.unneededMasseuse) { 
 | 
      serviceOrder['staffInfo'] = this.data.masseuse; 
 | 
    } 
 | 
    debugger 
 | 
    wx.setStorageSync("serviceOrder", serviceOrder); 
 | 
  
 | 
    wx.navigateTo({ 
 | 
      url: '/pages/yuyue/yyInfo?model=0', 
 | 
    }); 
 | 
    this.cleanSelectMasseuse(); 
 | 
  
 | 
  
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 生命周期函数--监听页面初次渲染完成 
 | 
   */ 
 | 
  onReady: function() { 
 | 
  
 | 
  }, 
 | 
  
 | 
  
 | 
  
 | 
  /** 
 | 
   * 生命周期函数--监听页面隐藏 
 | 
   */ 
 | 
  onHide: function() { 
 | 
  
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 生命周期函数--监听页面卸载 
 | 
   */ 
 | 
  onUnload: function() { 
 | 
  
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 页面相关事件处理函数--监听用户下拉动作 
 | 
   */ 
 | 
  onPullDownRefresh: function() { 
 | 
  
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 页面上拉触底事件的处理函数 
 | 
   */ 
 | 
  onReachBottom: function() { 
 | 
  
 | 
  }, 
 | 
  
 | 
  /** 
 | 
   * 用户点击右上角分享 
 | 
   */ 
 | 
  onShareAppMessage: function() { 
 | 
  
 | 
  } 
 | 
}) 
 |