Commit a55d33d9d81b933035b77a8e8ecf219b3658f83b

Authored by vking
1 parent d5fff0b7

master-rewrite-addnew

// 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,
})
}
}
})
... ...
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
... ...
<!--pack-book/components/book/time/add-time-dur.wxml-->
<view class="tab flex-ll">
<block wx:for="{{config}}" wx:key="config-key">
<view class="item {{item.hasChecked?'checked':''}} {{item.hasDisabled?'disabled':''}}"
wx:if="{{item.hasShow}}"
bindtap="{{item.hasDisabled?'':'selectedValue'}}" data-value="{{index}}">
<view class="picker">{{item.name}}</view>
</view>
</block>
</view>
... ...
/* pack-book/components/book/time/add-time-dur.wxss */
@import "../../../app.wxss";
.tab{
font-size: 34rpx;
color: #199095;
}
.tab .item{
height: 50rpx;
line-height: 49rpx;
width: 210rpx !important;
min-width: 210rpx !important;
border-radius: 10rpx;
border: 2rpx solid #199095;
margin-right: 20rpx;
text-align: center;
}
.tab .item .item-text,.section .tab .item .picker{
height: 46rpx;
line-height: 46rpx;
}
.tab .item .picker{
width:210rpx;
text-align: center;
}
.tab .item-pnum{
height: 50rpx;
line-height: 50rpx;
width: 60rpx !important;
min-width: 60rpx !important;
border-radius: 10rpx;
border: 2rpx solid #199095;
margin-right: 32rpx;
text-align: center;
}
.tab .item-pnum .pnum,.tab .item .pnum input{
height: 46rpx;
line-height: 46rpx;
font-size: 34rpx;
}
.tab .item:last-child{
margin-right: 0;
}
.tab .item-pnum:last-child{
margin-right: 0;
}
.tab .checked{
background-color:#199095;
color: #FEFEFE;
border: 2rpx solid #199095;
}
.tab .disabled{
background-color:#999999;
color: #efefef;
border: 2rpx solid #999999;
}
\ No newline at end of file
... ...
... ... @@ -909,5 +909,11 @@ Page({
this.setData({
CustomRemarkMoreMask:!this.data.CustomRemarkMoreMask
})
}
},
addTimeDurEvent(e){
console.log('add-time-dur.event',e);
this.setData({
[`form.time`]:e.detail.ddate_solt,
})
},
})
\ No newline at end of file
... ...
... ... @@ -9,6 +9,7 @@
"searchList":"/components/searchlist/searchlist",
"calendar": "plugin://bmCalendar/calendar",
"board":"../../components/book/board/board",
"formids":"/components/formids/formids"
"formids":"/components/formids/formids",
"add-time-dur":"../../components/book/time/add-time-dur"
}
}
\ No newline at end of file
... ...
... ... @@ -40,6 +40,9 @@
</view>
</view>
</view>
<view class="section">
<add-time-dur date="{{form.date}}" solt="{{detail.time.kk}}" bindevent="addTimeDurEvent"></add-time-dur>
</view>
<view class="section ">
<view class="tab flex-ll">
<formids class="item {{form.time==0?'checked':''}} {{timeOpt[0]}}"
... ...
... ... @@ -5,11 +5,14 @@
"es6": true,
"enhance": true,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": true,
"coverView": true,
"nodeModules": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
... ... @@ -527,7 +530,7 @@
"id": 64,
"name": "pack-book/pages/book/b_addnew 桌位进入",
"pathName": "pack-book/pages/book/b_addnew",
"query": "id=43844",
"query": "",
"scene": null
},
{
... ...