123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- // pages/reservation/reservation.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- timeList:[],
- chargStationId:'',
- chargPileName:'加载中',
- chargPileId:'',
- chargPileIdId:'',
- userId:'',
- chargStationName:'',
- earliestReservTime:'',
- advanceReservDays:'',
- minReservTime:'',
- maxReservTime:'',
- maxEarlyExerciseTime:'',
- maxReservOvertime:'',
- current:[],
- second:[],
- three:[],
- four:[],
- dayIndex:1,
- dayFlag1:'',
- dayFlag2:'',
- dayFlag3:'',
- dayFlag4:'',
- reservationBtn: false,
- breakPunishCount: 0
- },
- goReservation(){
- let {
- chargStationId,
- chargPileName,
- chargPileId,
- chargPileIdId,
- chargStationName,
- userId,
- earliestReservTime,
- advanceReservDays,
- minReservTime,
- maxReservTime,
- maxEarlyExerciseTime,
- maxReservOvertime
- } = this.data;
- let url = `/pages/reservation/reservationEdit?chargStationId=` + chargStationId + `&chargPileName=` + chargPileName +
- `&chargPileId=` + chargPileId +
- `&chargPileIdId=` + chargPileIdId +
- "&chargStationName=" + chargStationName +
- "&earliestReservTime=" + earliestReservTime +
- "&advanceReservDays=" + advanceReservDays+
- "&minReservTime=" + minReservTime +
- "&maxReservTime=" + maxReservTime +
- "&maxEarlyExerciseTime=" + maxEarlyExerciseTime +
- "&maxReservOvertime=" + maxReservOvertime +
- "&userId=" + userId;
- wx.navigateTo({
- url
- });
- },
- switchDay(e){
- let dayIndex = e.currentTarget.dataset.idx;
- let timeList = [];
- if(dayIndex==1){
- timeList = this.data.current;
- }else if(dayIndex==2){
- timeList = this.data.second;
- }else if(dayIndex==3){
- timeList = this.data.three;
- }else if(dayIndex==4){
- timeList = this.data.four;
- };
- this.setData({
- dayIndex,
- timeList
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let that = this;
- let {
- chargStationId,
- chargPileName,
- chargPileId,
- chargPileIdId,
- userId,
- chargStationName
- } = options;
- this.setData({
- chargStationId,
- chargPileName,
- chargPileId,
- chargPileIdId,
- userId,
- chargStationName
- }
- )
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- let that = this;
- let {
- chargStationId,
- chargPileName,
- chargPileId,
- chargPileIdId,
- userId,
- chargStationName
- } = this.data;
- wx.request({
- url: getApp().globalData.postHeadAgreement +'/restapi/wechat/ReservOrder?userId=' + userId + '&pileId=' + chargPileIdId + '&stationId=' + chargStationId + '&reservPileNo=' +chargPileId ,
- data: {
- },
- method: 'POST',
- success(res) {
- if(res?.data?.result?.reservationConfig){
- that.setData({
- reservationBtn: true
- })
- }
- let earliestReservTime = res?.data?.result?.reservationConfig?.earliestReservTime
- earliestReservTime = earliestReservTime?earliestReservTime:0;
- let advanceReservDays = res?.data?.result?.reservationConfig?.advanceReservDays
- advanceReservDays = advanceReservDays?advanceReservDays:0;
- let minReservTime = res?.data?.result?.reservationConfig?.minReservTime
- minReservTime = minReservTime?minReservTime:0;
- let maxReservTime = res?.data?.result?.reservationConfig?.maxReservTime
- maxReservTime = maxReservTime?maxReservTime:0;
- let maxEarlyExerciseTime = res?.data?.result?.reservationConfig?.maxEarlyExerciseTime
- maxEarlyExerciseTime = maxEarlyExerciseTime?maxEarlyExerciseTime:0;
- let maxReservOvertime = res?.data?.result?.reservationConfig?.maxReservOvertime
- maxReservOvertime = maxReservOvertime?maxReservOvertime:0;
- let breakPunishCount = res?.data?.result?.reservationConfig?.breakPunishCount
- breakPunishCount = breakPunishCount?breakPunishCount:0;
- let nowZero = new Date();
- nowZero.setMilliseconds(0)
- nowZero.setSeconds(0)
- nowZero.setMinutes(0)
- nowZero.setHours(0)
- let currentStart = new Date(nowZero)
- let currentEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
- let secondStart = new Date(currentEnd)
- let secondEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
- let threeStart = new Date(secondEnd)
- let threeEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
- let fourStart = new Date(threeEnd);
- let fourEnd = new Date(nowZero.setDate(nowZero.getDate() + 1 ));
- let current = res?.data?.result?.current;
- current.forEach(series => {
- series.starttime = series.reservChargeStartTime.substr(11,5);
- series.endtime = series.reservChargeEndTime.substr(11,5);
- let reservChargeStartTime = new Date(series.reservChargeStartTime);
- let reservChargeEndTime = new Date(series.reservChargeEndTime);
- if(currentStart > reservChargeStartTime){
- series.starttime = "(前日) " + series.starttime
- }
- if(currentEnd < reservChargeEndTime){
- series.endtime = series.endtime + " (次日)"
- }
- });
- current.sort((a,b)=>{
- return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
- })
- let second = res?.data?.result?.second;
- second.forEach(series => {
- series.starttime = series.reservChargeStartTime.substr(11,5);
- series.endtime = series.reservChargeEndTime.substr(11,5);
- let reservChargeStartTime = new Date(series.reservChargeStartTime);
- let reservChargeEndTime = new Date(series.reservChargeEndTime);
- if(secondStart > reservChargeStartTime){
- series.starttime = "(前日) " + series.starttime
- }
- if(secondEnd < reservChargeEndTime){
- series.endtime = series.endtime + " (次日)"
- }
- });
- second.sort((a,b)=>{
- return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
- })
- let three = res?.data?.result?.three;
- three.forEach(series => {
- series.starttime = series.reservChargeStartTime.substr(11,5);
- series.endtime = series.reservChargeEndTime.substr(11,5);
- let reservChargeStartTime = new Date(series.reservChargeStartTime);
- let reservChargeEndTime = new Date(series.reservChargeEndTime);
- if(threeStart > reservChargeStartTime){
- series.starttime = "(前日) " + series.starttime
- }
- if(threeEnd < reservChargeEndTime){
- series.endtime = series.endtime + " (次日)"
- }
- });
- three.sort((a,b)=>{
- return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
- })
- let four = res?.data?.result?.four;
- four.forEach(series => {
- series.starttime = series.reservChargeStartTime.substr(11,5);
- series.endtime = series.reservChargeEndTime.substr(11,5);
- let reservChargeStartTime = new Date(series.reservChargeStartTime);
- let reservChargeEndTime = new Date(series.reservChargeEndTime);
- if(fourStart > reservChargeStartTime){
- series.starttime = "(前日) " + series.starttime
- }
- if(fourEnd < reservChargeEndTime){
- series.endtime = series.endtime + " (次日)"
- }
- });
- four.sort((a,b)=>{
- return new Date(a.reservChargeStartTime) - new Date(b.reservChargeStartTime)
- })
- let now = new Date();
- let dayFlag1 = (now.getMonth() + 1) + "." + now.getDate()
- now = new Date(now.setDate(now.getDate() + 1));
- let dayFlag2 = (now.getMonth() + 1) + "." + now.getDate()
- now = new Date(now.setDate(now.getDate() + 1));
- let dayFlag3 = (now.getMonth() + 1) + "." + now.getDate()
- now = new Date(now.setDate(now.getDate() + 1));
- let dayFlag4 = (now.getMonth() + 1) + "." + now.getDate()
- that.setData({
- earliestReservTime,
- advanceReservDays,
- minReservTime,
- maxReservTime,
- maxEarlyExerciseTime,
- maxReservOvertime,
- breakPunishCount,
- current,
- second,
- three,
- four,
- timeList: current,
- dayFlag1,
- dayFlag2,
- dayFlag3,
- dayFlag4,
- dayIndex:1
- })
- }
- });
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|