Commit 0b62f5e1 by zhangzhen

订单功能优化

parent 333a1d6a
......@@ -547,7 +547,7 @@
onChangePackage(index){
if(this.modeIndex == index) return;
let startDateTime = this.modeIndex >=0 ? this.formatAllData.startDateTime: null
let startDateTime = this.orderType ==2? this.orderInfo.startDate: ''
this.modeIndex = index
this.modeIndex2 = -1
......@@ -556,7 +556,6 @@
startDateTime,
duration: this.roomLabelList[this.modeIndex].labelDuration,
});
console.log(this.formatAllData,"this.formatAllData")
},
onPackageCheck(){
this.onCancleTip();
......@@ -580,7 +579,6 @@
let orderEndDate = moment(endDate).valueOf()
if(start >= orderStartDate && start<=orderEndDate && item.status ==1){
startDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00");
console.log(startDate,"重置的开始时间")
}
})
......@@ -591,64 +589,202 @@
duration,
durationType:2
});
console.log(this.formatAllData,9999992222)
},
// 套餐切换
onChangePackage2(index){
if(this.modeIndex2 == index) return;
this.tempPackageIndex = index;
let startStr = `${this.dateList[this.dateIndex].readDate} ${this.packageMode[this.tempPackageIndex].packaStartPeriod}:00:00`
let startDate = moment(moment().format(startStr)).format("YYYY-MM-DD HH:00:00");
let endStr = `${this.dateList[this.dateIndex].readDate} ${this.packageMode[this.tempPackageIndex].packaEndPeriod}:00:00`
let endDate = moment(moment().format(endStr)).format("YYYY-MM-DD HH:00:00");
if(this.dateIndex === 0 && (moment().valueOf() > moment(endDate).valueOf())){
startDate = moment(startDate).add(1,'d').format("YYYY-MM-DD HH:00:00")
endDate = moment(endDate).add(1,'d').format("YYYY-MM-DD HH:00:00")
}
console.log(startDate,endDate,"此套餐的开始时间和结束时间")
//原始时长,结束时间-原开始时间
let originDate = moment(endDate).valueOf() - moment(startDate).valueOf();
console.log(originDate/1000/60, "originDate原始时长")
this.dateIntervalList.forEach(item=>{
let start = moment(moment(item.timeHour).format("YYYY-MM-DD HH::mm:ss")).valueOf()
let orderStartDate = moment(startDate).valueOf()
let orderEndDate = moment(endDate).valueOf()
if(start >= orderStartDate && start<=orderEndDate && item.status ==1){
startDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00");
console.log(startDate,"重置的开始时间")
}
})
// 如果此套餐的结束时间在11点前,则为通宵套餐,会在当天及明天进行找合适的时间段,否则则没有合适的套餐时段
let pointDateForm = moment(this.dateList[this.dateIndex].readDate).format("YYYY-MM-DD 11:00:00");
let dateTimeObj = {};
console.log(pointDateForm,9999)
if(moment(endDate).valueOf() < moment(pointDateForm).valueOf()){
dateTimeObj = this.onComputeStartDateAndEndDate(startDate,endDate);
console.log(dateTimeObj,"计算后的时间");
//实际时长,结束时间-实际开始时间
let actualDate = moment(endDate).valueOf() - moment(startDate).valueOf();
console.log(actualDate/1000/60, "actualDate实际时长")
// 实际时长小于原时长的50%则选择明天的时间
if( actualDate >= originDate*0.6 && actualDate <= originDate*0.8 ){
this.$refs.popupDialog.open();
return
} else if (actualDate < originDate*0.6){
this.$refs.popupMessage2.open();
// 原时间
let originTime = moment(endDate).valueOf() - moment(startDate).valueOf()
// 实际时间
let actualTime = moment(dateTimeObj.tempEndDate).valueOf() - moment(dateTimeObj.tempStartDate).valueOf()
if( actualTime< originTime*0.6){
console.log("实际时长小于原时长的50%则选择明天的时间");
// 加一天时间重新计算
dateTimeObj = this.onComputeStartDateAndEndDate(moment(startDate).add(1,"d").format("YYYY-MM-DD HH:00:00"),moment(endDate).add(1,"d").format("YYYY-MM-DD HH:00:00"));
console.log(dateTimeObj,"计算后的时间2");
// 实际时间
actualTime = moment(dateTimeObj.tempEndDate).valueOf() - moment(dateTimeObj.tempStartDate).valueOf()
if( actualTime < originTime*0.6){
uni.showToast({
icon:"none",
title:'可使用时长不足,请选择其他日期'
})
return
}else if(actualTime < originTime*0.8 && actualTime >= originTime*0.6){
this.$refs.popupDialog.open();
return
}
} else if( actualTime < originTime*0.8 && actualTime >= originTime*0.6){
this.$refs.popupDialog.open();
return
}else{
this.modeIndex = -1
this.modeIndex2 = index
let duration = (moment(endDate).valueOf()-moment(startDate).valueOf())/1000/60;
let duration = (moment(dateTimeObj.tempEndDate).valueOf()-moment(dateTimeObj.tempStartDate).valueOf())/1000/60;
this.formatAllData = this.onTransiteForDate({
list: JSON.parse(JSON.stringify(this.dateIntervalList)),
startDateTime: startDate,
startDateTime: dateTimeObj.tempStartDate,
endDateTime: dateTimeObj.tempEndDate,
duration,
durationType:2
});
console.log(this.formatAllData,9999992222)
}
}
// 如果此套餐的结束时间在12点后,则为闲时套餐,仅查看今日日否有合适的套餐
},
// 通过指定时间在当前时间段内查询合适的时间段
onComputeStartDateAndEndDate(startDate,endDate){
//重新设置开始时间和结束时间
let tempStartDate = startDate;
let tempEndDate = endDate;
let startNeedChange = false;
let endNeedChange = false;
this.dateIntervalList.forEach(item=>{
// 检查时段在开始时间和结束时间内
let start = moment(moment(item.timeHour).format("YYYY-MM-DD HH:00:00")).valueOf()
let end = moment(moment(item.timeHour).format("YYYY-MM-DD HH:59:59")).valueOf()
if( start < moment(endDate).valueOf() && start >= moment(startDate).valueOf()){
// 当前小时被完全占用
if(item.status ==1 && this.onCheckHourUse(item.startHoldTime,item.endHoldTime)){
startNeedChange = true;
tempStartDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00")
}
if(item.status ==1 && !this.onCheckHourUse(item.startHoldTime,item.endHoldTime)){
tempStartDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00")
startNeedChange = false;
}
if(item.status == 0 && startNeedChange){
tempStartDate = moment(item.timeHour).format("YYYY-MM-DD HH:00:00")
startNeedChange = false;
}
if(start > moment(tempStartDate).valueOf() && endNeedChange){
endNeedChange = true;
tempEndDate = moment(item.startHoldTime).format("YYYY-MM-DD HH:mm:00")
}
if(start > moment(tempStartDate).valueOf() && !endNeedChange && item.status == 1){
endNeedChange = false;
tempEndDate = moment(item.startHoldTime).format("YYYY-MM-DD HH:mm:00")
}
}
})
console.log(tempStartDate,tempEndDate,9999);
return {
tempStartDate,
tempEndDate
}
},
// 通过指定时长在当前时间段内查询合适的时间段
onComputeByDuration(duration,durationType=1){
console.log(duration,durationType,8888)
//重新设置开始时间和结束时间
let m = Number(duration)*60;
if (durationType === 2) {
m = Number(duration)
}
// 把时长计算成毫秒数
let timeStampLong = m*60*1000;
let tempStartDate = '';
let tempEndDate = '';
let startNeedChange = true;
let endNeedChange = true;
console.log(this.dateIntervalList,9999,"原列表")
this.dateIntervalList.forEach((item,k) => {
if(k<24){
if(item.status == 1 && startNeedChange && this.onCheckHourUse(item.startHoldTime,item.endHoldTime)){
tempStartDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00")
startNeedChange = true
endNeedChange = true;
}
if(item.status == 1 && startNeedChange && !this.onCheckHourUse(item.startHoldTime,item.endHoldTime)){
tempStartDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00")
startNeedChange = false
endNeedChange = true;
}
if(item.status == 0 && startNeedChange){
tempStartDate = moment(item.timeHour).format("YYYY-MM-DD HH:00:00")
startNeedChange = false
endNeedChange = true;
}
}
if(item.status == 1 && endNeedChange && tempStartDate){
let endDate = moment(item.startHoldTime).format("YYYY-MM-DD HH:mm:00")
if( moment(endDate).valueOf() >= moment(tempStartDate).valueOf()){
tempEndDate = endDate
if( moment(tempEndDate).valueOf() - moment(tempStartDate).valueOf() >= timeStampLong){
startNeedChange = false;
endNeedChange = false;
}else{
if(k <24 ){
tempStartDate = moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00")
startNeedChange = true;
}else{
startNeedChange = false;
}
endNeedChange = false;
}
}
}else if(item.status == 0 && endNeedChange && tempStartDate){
console.log(k)
let endDate = moment(item.timeHour).format("YYYY-MM-DD HH:59:00")
if( moment(endDate).valueOf() - moment(tempStartDate).valueOf() >= timeStampLong){
endNeedChange = false;
tempEndDate = moment(moment(tempStartDate).valueOf()+timeStampLong).format("YYYY-MM-DD HH:mm:00")
}else{
endNeedChange = true;
}
}
})
let params = {
startDateTime:tempStartDate,
endDateTime: tempEndDate,
useStatus: moment(tempEndDate).valueOf() - moment(tempStartDate).valueOf() < timeStampLong
}
console.log(params,"通过时长找合适时间段1213")
return params
},
onInitDateList() {
......@@ -708,7 +844,6 @@
},
onGetOrderInfo() {
getOrderInfoByNo(this.preOrderNo).then(res => {
console.log(res, "订单信息")
if (res.data.code == 200) {
this.orderInfo = res.data.data;
this.id = this.orderInfo.roomId;
......@@ -766,7 +901,6 @@
list: JSON.parse(JSON.stringify(this.dateIntervalList)),
duration: this.roomLabelList[this.modeIndex].labelDuration
});
console.log(this.formatAllData, "transiteForDate2222")
})
},
// 获取可用优惠券
......@@ -930,15 +1064,11 @@
this.checkedDateList = this.checkedIndex.length ? this.checkedIndex.map(item => Number(item)) : [0, 0];
let startTime = `${this.hourList[this.checkedDateList[0]]}:${this.minuteList[this.checkedDateList[1]]}`;
this.formatAllData.startTime = startTime;
console.log(startTime,"开始时间,888")
this.formatAllData = this.onTransiteForDate({
...this.formatAllData,
list: JSON.parse(JSON.stringify(this.dateIntervalList)),
startDateTime: `${this.dateList[this.dateIndex].readDate} ${startTime}:00`,
endDateTime: '',
endTime:''
duration: this.roomLabelList[this.modeIndex].labelDuration
});
console.log(this.formatAllData,9911199)
this.$forceUpdate();
this.onHideModal();
},
......@@ -985,7 +1115,6 @@
},
complete: (res) => {
console.log(res, 909090)
// this.$refs.confirmPop.open();
this.onOrderConfirm();
}
......@@ -1067,7 +1196,6 @@
},
complete: (res) => {
console.log(res, 909090)
// this.$refs.confirmPop.open();
this.onOrderCreate();
}
......@@ -1123,7 +1251,6 @@
})
},
"fail": (resp) => {
console.log(resp, "支付失败")
// 取消支付或支付失败
uni.showToast({
title: "取消支付"
......@@ -1131,11 +1258,10 @@
orderCancelPay({
orderNo: res.data.data.orderNo
}).then(res => {
console.log(res)
})
},
"complete": (resp) => {
console.log(resp, "支付完成")
// 接口调用结束的回调函数(调用成功、失败都会执行)
}
});
......@@ -1198,9 +1324,7 @@
})
return
}
console.log(val,9999)
let startDate = val.endHoldTime? moment(val.endHoldTime).format("YYYY-MM-DD HH:mm:00") : moment(val.timeHour).format("YYYY-MM-DD HH:00:00")
let startDate = val.endHoldTime? moment(val.endHoldTime).add(1,'m').format("YYYY-MM-DD HH:mm:00") : moment(val.timeHour).format("YYYY-MM-DD HH:00:00")
this.formatAllData = this.onTransiteForDate({
list: JSON.parse(JSON.stringify(this.dateIntervalList)),
startDateTime: startDate,
......@@ -1208,13 +1332,42 @@
durationType:2
});
this.$forceUpdate();
console.log(this.formatAllData,"处理后的数据")
},
// 通过开始时间和时长计算时段有无占用
onUseByStartAndDuration(startDate,duration,durationType=1){
let useStatus = false;
let m = Number(duration)*60;
if (durationType === 2) {
m = Number(duration)
}
let stempLong = m*60000;
let nextStatus = false;
this.dateIntervalList.forEach((item,k) =>{
if(nextStatus) return;
let start = moment(item.timeHour+':00:00').valueOf();
let end = moment(item.timeHour+':59:59').valueOf();
if( end > moment(startDate).valueOf() && start < moment(startDate).valueOf()+stempLong){
if(item.status ==1){
if(moment(item.endHoldTime).valueOf() > moment(startDate).valueOf() ){
useStatus = true;
nextStatus = true;
}
if(moment(item.startHoldTime).valueOf()< moment(startDate).valueOf() + stempLong){
useStatus = true
nextStatus = true;
}
}
}
})
return useStatus
},
//list(Array):当前日期的时间占用情况
//startDateTime(YYYY-MM-DD HH:mm:ss): 开始时间
//endDateTime(YYYY-MM-DD HH:mm:ss): 开始时间
//endDateTime(YYYY-MM-DD HH:mm:ss): 结束时间
//duration(Number||String): 时长,小时或分钟
//durationType(Number) : 时长类型,1:小时,2:分钟
// 返回值
......@@ -1236,73 +1389,57 @@
if (params.durationType === 2) {
m = Number(params.duration)
}
// 开始时间的毫秒数
let startStamp = this.dateIndex > 0 && !params.startDateTime ? moment(params.list[0].timeHour).valueOf() : !params.startDateTime || params.startDateTime == null ? moment(moment().add(1,'m').format("YYYY-MM-DD HH:mm:00")).valueOf() : moment(params.startDateTime).valueOf();
let endStamp = startStamp + m * 60 * 1000;
console.log(moment(endStamp).format("YYYY-MM-DD HH:mm:ss"),"结束时间戳")
// 记录可开始的时间点
let startPoint = startStamp;
let endPoint = endStamp
let useStatus = false;
let startStamp = moment().valueOf();
let endStamp = moment().valueOf() + m*60000;
let dateObj = {
useStatus: false
};
if(params.startDateTime){
// 开始和结束时间的毫秒数
startStamp = moment(params.startDateTime).valueOf();
endStamp = startStamp + m*60000;
dateObj.useStatus = this.onUseByStartAndDuration(params.startDateTime,m,2)
console.log(dateObj.useStatus,9999334)
} else if(params.duration){
dateObj = this.onComputeByDuration(m,2);
startStamp = moment(dateObj.startDateTime).valueOf();
endStamp = moment(dateObj.endDateTime).valueOf();
}
// 获取开始时间的当前小时
let startPointDate = moment(moment(startStamp).format("YYYY-MM-DD HH:00:00")).valueOf();
// 截取可预定时间段状态,true表示也筛选到
let interceptDateStatus = false;
let list = params.list.map((item, index) => {
console.log(interceptDateStatus,"interceptDateStatus")
if (interceptDateStatus) {
return item
}
if(item.status == 0){
let s = moment(moment(item.timeHour).format("YYYY-MM-DD HH:59:59")).valueOf();
if(s>endStamp){
interceptDateStatus = true;
}
}else if(item.status == 1){
let startH = moment(moment(item.timeHour).format("YYYY-MM-DD HH:00:00")).valueOf();
let endH = moment(moment(item.timeHour).format("YYYY-MM-DD HH:59:59")).valueOf();
let end = moment(moment(item.endHoldTime).format("YYYY-MM-DD HH:mm:00")).valueOf();
if( startStamp >= startH && startStamp < endH && startStamp < end && endStamp > endH){
useStatus = true;
}
let start = moment(item.startHoldTime).valueOf();
if(endStamp >= startH && endStamp < endH && endStamp > start && startStamp < startH ){
useStatus = true;
interceptDateStatus = true;
if( endH >= startStamp && endH < endStamp){
item.status = 2
}
if((start > startStamp && start < endPoint) || (end > startStamp && end < endPoint)) {
useStatus = true;
interceptDateStatus = true;
}
return item
})
if(dateObj.useStatus){
this.$refs.popupMessage.open();
}
let point = moment(moment(item.timeHour).format("YYYY-MM-DD HH:00:00")).valueOf();
if (point >= startPointDate && point < endStamp) {
item.status = 2;
}
return item
})
let paramsData = {
list: useStatus? JSON.parse(JSON.stringify(this.dateIntervalList)) : list ,
startDateTime: moment(startPoint).format("YYYY-MM-DD HH:mm:ss"),
startTime: moment(startPoint).format("HH:mm"),
endDateTime: moment(endPoint).format("YYYY-MM-DD HH:mm:ss"),
endTime: moment(endPoint).format("HH:mm"),
list: dateObj.useStatus? JSON.parse(JSON.stringify(this.dateIntervalList)) : list,
startDateTime: moment(startStamp).format("YYYY-MM-DD HH:mm:ss"),
startTime: moment(startStamp).format("HH:mm"),
endDateTime: moment(endStamp).format("YYYY-MM-DD HH:mm:ss"),
endTime: moment(endStamp).format("HH:mm"),
duration: m,
useStatus,
useStatus:dateObj.useStatus,
durationType: 2,
interceptDateStatus
}
// 获取用户可用优化券
this.onGetUseCoupon(paramsData)
if(paramsData.useStatus){
this.$refs.popupMessage.open();
}
console.log(paramsData,"返回结果")
return paramsData
},
onCancleTip(){
......@@ -1310,7 +1447,11 @@
this.$refs.popupMessage2.close();
this.$refs.popupDialog.close();
},
onCheckDate() {}
// 检查当前小时段是否被全部占用
onCheckHourUse(startDate,endDate) {
let timeStamp = moment(endDate).valueOf()-moment(startDate).valueOf();
return timeStamp >= 3599000
}
}
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment