|
|
|
// pack-book/components/book/time/add-time-dur.js
|
|
|
|
var util = require('../../../../utils/util.js')
|
|
|
|
import App from '../../../../utils/api';
|
|
|
|
const timeSort=['morning', 'noon', 'night'];
|
|
|
|
const timeConfig= {
|
|
|
|
'morning':{
|
|
|
|
name:'早市',
|
|
|
|
defTime:'',
|
|
|
|
},
|
|
|
|
'noon':{
|
|
|
|
name:'午市',
|
|
|
|
defTime:'12:00',
|
|
|
|
},
|
|
|
|
'night': {
|
|
|
|
name: '晚市',
|
|
|
|
defTime: '18:30'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Component({
|
|
|
|
/**
|
|
|
|
* 组件的属性列表
|
|
|
|
*/
|
|
|
|
properties: {
|
|
|
|
solt:{//ddate_solt,时段,修改或从桌位过来使用
|
|
|
|
type:Number,
|
|
|
|
value:-1,
|
|
|
|
},
|
|
|
|
date:{//0今天,1明天,2其它
|
|
|
|
type:Number,
|
|
|
|
value:-1,
|
|
|
|
},
|
|
|
|
ddate:{//到店时间
|
|
|
|
type:Number,
|
|
|
|
value:-1,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
lifetimes: {
|
|
|
|
attached: function () {
|
|
|
|
//console.log('add-time-dur.attached')
|
|
|
|
},
|
|
|
|
moved: function () { },
|
|
|
|
detached: function () { },
|
|
|
|
},
|
|
|
|
observers:{
|
|
|
|
"solt,date":async function(solt,date){
|
|
|
|
if(solt<0) return;
|
|
|
|
console.log('add-time-dur.observers',arguments)
|
|
|
|
this.config=null
|
|
|
|
this.ddate_solt=-1
|
|
|
|
this.initSolt()//初始化solt
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 组件的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
ddate_solt:-1,
|
|
|
|
config:[],
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 组件的方法列表
|
|
|
|
*/
|
|
|
|
methods: {
|
|
|
|
async initSolt(){//初始化solt
|
|
|
|
if(this.initSoltIng) return false
|
|
|
|
this.initSoltIng=true
|
|
|
|
await this.getConfig();//时段配置
|
|
|
|
this.initSoltIng=false
|
|
|
|
},
|
|
|
|
async getConfig(){//时段配置
|
|
|
|
let res = await App.Reserve.SellerInfo(util.cache('enter_params'));
|
|
|
|
let daily = res.data.daily;
|
|
|
|
console.log('add-time-dur.daily',daily)
|
|
|
|
this.initUserTime(daily)
|
|
|
|
if(this.data.solt>-1){
|
|
|
|
this.initSoltTime()
|
|
|
|
}
|
|
|
|
this.trigger();
|
|
|
|
},
|
|
|
|
initUserTime(daily){
|
|
|
|
let config=[]
|
|
|
|
let time=parseInt(new Date()/1000);
|
|
|
|
let HHII=util.unixtoTime(time,"HH:II")
|
|
|
|
timeSort.forEach((en_name,ti)=>{
|
|
|
|
let dur=daily[en_name];
|
|
|
|
let min='',max='',hasShow=false,hasDisabled=false,hasChecked=false
|
|
|
|
if(dur){
|
|
|
|
hasShow=true
|
|
|
|
dur=dur.split('-');
|
|
|
|
min=dur[0];
|
|
|
|
max=dur[1];
|
|
|
|
if(HHII>=min && HHII<=max){
|
|
|
|
hasChecked=true
|
|
|
|
this.ddate_solt=ti
|
|
|
|
}
|
|
|
|
if(HHII>max && this.data.date==0){
|
|
|
|
hasDisabled=true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
config.push({
|
|
|
|
name:timeConfig[en_name].name,
|
|
|
|
en_name:en_name,
|
|
|
|
hasShow:hasShow,
|
|
|
|
min:min,
|
|
|
|
max:max,
|
|
|
|
hasDisabled:hasDisabled,
|
|
|
|
hasChecked:hasChecked,
|
|
|
|
defTime:timeConfig[en_name].defTime
|
|
|
|
});
|
|
|
|
})
|
|
|
|
this.config=config;
|
|
|
|
this.setData({
|
|
|
|
config:this.config,
|
|
|
|
ddate_solt:this.ddate_solt,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
initSoltTime(){//修改或快速预订
|
|
|
|
this.ddate_solt=this.data.solt
|
|
|
|
this.config.forEach((t,ti)=>{
|
|
|
|
t.hasDisabled=false
|
|
|
|
t.hasChecked=ti==this.ddate_solt
|
|
|
|
})
|
|
|
|
this.setData({
|
|
|
|
config:this.config,
|
|
|
|
ddate_solt:this.ddate_solt,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
selectedValue(e){
|
|
|
|
console.log('add-time-dur.selectedValue',e)
|
|
|
|
this.ddate_solt=util.attr(e,'value')
|
|
|
|
this.config.forEach((t,ti)=>{
|
|
|
|
t.hasDisabled=false
|
|
|
|
t.hasChecked=ti==this.ddate_solt
|
|
|
|
})
|
|
|
|
this.setData({
|
|
|
|
config:this.config,
|
|
|
|
ddate_solt:this.ddate_solt,
|
|
|
|
})
|
|
|
|
this.trigger();
|
|
|
|
},
|
|
|
|
initTimeSpaceIndex(){//对选中时段进行展开
|
|
|
|
if(this.ddate_solt<0) return;
|
|
|
|
console.log('add-time-dur.tindex',this.ddate_solt,this.config[this.ddate_solt])
|
|
|
|
let min=this.config[this.ddate_solt].min
|
|
|
|
let max=this.config[this.ddate_solt].max
|
|
|
|
let defTime=this.config[this.ddate_solt].defTime
|
|
|
|
let time
|
|
|
|
if(this.data.ddate>0){
|
|
|
|
time=parseInt(this.data.ddate);
|
|
|
|
}else{
|
|
|
|
time=parseInt(new Date()/1000);
|
|
|
|
}
|
|
|
|
min=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+min+":00"))
|
|
|
|
max=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+max+":00"))
|
|
|
|
if(defTime && !this.data.ddate){//非修改时,优先默认时间
|
|
|
|
defTime=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+defTime+":00"))
|
|
|
|
if(defTime>time){
|
|
|
|
time=defTime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let dur,timeCheckedIndex=0,list=[];
|
|
|
|
for(dur=parseInt(min);dur<=max;dur+=1800){
|
|
|
|
let t={
|
|
|
|
hasChecked:time<=dur,
|
|
|
|
time:dur,
|
|
|
|
//timeStr:util.unixtoTime(dur,"YYYY-MM-DD HH:II:SS")
|
|
|
|
}
|
|
|
|
list.push(t)
|
|
|
|
if(dur<=time){
|
|
|
|
timeCheckedIndex++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('add-time-dur.tindex',timeCheckedIndex,list)
|
|
|
|
return {list:list,listIndex:timeCheckedIndex}
|
|
|
|
},
|
|
|
|
trigger(){
|
|
|
|
let timeList=this.initTimeSpaceIndex()
|
|
|
|
this.triggerEvent('event',{
|
|
|
|
ddate_solt:this.ddate_solt,
|
|
|
|
...timeList,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}) |
...
|
...
|
|