Commit f7c1f848c6dbe66ed9eaab779ea5173d6f7a8454

Authored by vking
1 parent a55d33d9

master-rewrite-addnew

// pack-book/components/book/time/add-date.js
import util from '../../../../utils/util'
Component({
/**
* 组件的属性列表
*/
properties: {
nowtime:Number,
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
attached: function () {
this.initView()
},
moved: function () { },
detached: function () { },
},
/**
* 组件的初始数据
*/
data: {
checked:-1,
list:[
{
time:new Date()/1000,
},
{
time:new Date()/1000+86400,
},
{
time:0,
}
],
calendarMaskLoad: false,
calendarMask: false,
},
checked:-1,
/**
* 组件的方法列表
*/
methods: {
initView(){
//console.log('add-date',this.data.nowtime,this.data.today)
setTimeout(() => {
this.setData({
calendarMaskLoad: true,
})
}, 1000);
this.initChecked(this.data.nowtime)
},
initChecked(nowtime){
let nowStr=util.unixtoTime(nowtime,"YYYY-MM-DD");
let list=this.data.list
this.checked=2
this.checkedTime=nowtime
if(nowStr==util.unixtoTime(list[0].time,"YYYY-MM-DD")){
this.checked=0
}else if(nowStr==util.unixtoTime(list[1].time,"YYYY-MM-DD")){
this.checked=1
}
this.setData({
checked:this.checked,
[`list[2].time`]:nowtime,
})
this.trigger()
},
selectedValue(e){
this.checked=util.attr(e,'value')
this.checkedTime=this.data.list[this.checked].time
this.setData({
checked:this.checked,
})
this.trigger()
},
trigger(){
this.triggerEvent('event',{
checked:this.checked,
checkedTime:this.checkedTime,
})
},
calendarShow(e){
this.setData({
calendarMask: true
})
},
calendarClose(){
this.setData({
calendarMask: false,
})
},
dateChange(event){
let cktime = util.timetouUnix(event.detail.date)
this.initChecked(cktime)
this.calendarClose();
},
}
})
... ...
{
"component": true,
"usingComponents": {
"calendar": "plugin://bmCalendar/calendar"
}
}
\ No newline at end of file
... ...
<!--pack-book/components/book/time/add-date.wxml-->
<wxs src="../../../../utils/util.wxs" module="util" />
<view class="tab flex-ll">
<view class="item {{checked==0?'checked':''}}"
bindtap="selectedValue" data-key="date" data-value="0">
{{util.unixtoTime(list[0].time,"MM-DD DAY")}}
</view>
<view class="item {{checked==1?'checked':''}}"
bindtap="selectedValue" data-key="date" data-value="1">
{{util.unixtoTime(list[1].time,"MM-DD DAY")}}
</view>
<view class="item {{checked==2?'checked':''}} flex-lr"
bindtap="calendarShow">
<view style="width: 80%" class="item-text">{{checked==2?util.unixtoTime(list[2].time,"MM-DD"):'其他'}}</view>
<image
src="http://qn.colorcun.com/custom/lite-yd/image/date{{checked==2?'.selected':''}}.png"
style="min-width: 36rpx;width: 36rpx;height: 36rpx; margin-right: 22rpx;"></image>
</view>
</view>
<view class="calendar-mask" bindtap="calendarClose"
style="height:{{calendarMask?'100%':0}};" wx:if="{{calendarMaskLoad}}">
<view style="width: 100%; height:{{calendarMask?'100%':0}};overflow: hidden;position: relative;">
<calendar catchtap="catchtap"
isTodaybtn="{{true}}" todaybtn_txt="回到今天"
custom="{{false}}"
switchover="{{['上一月','下个月']}}"
active-coloro="active-coloro"
active-colort="active-colort"
speciallist="{{speciallist}}"
txt_style="txt-style"
calendar-style="calendar"
header-style="calendar-header"
weektitle-style="weektitle-style"
restcolor-style="restcolor-style"
txt_type="cn-d"
datefont-style="datefont-style"
todaybtn-style="todaybtn-style"
bindnextMonth="nextMonth"
bindprevMonth="prevMonth"
bindselectDate="dateChange"
bindgotoday="gotoday"
prev="{{true||calendar.nextNum>0}}"
circle_show="{{false}}"
closelaststyle="{{true}}"
></calendar>
</view>
</view>
\ No newline at end of file
... ...
/* pack-book/components/book/time/add-date.wxss */
@import "../../../pages/book/common/calendar.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,.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
... ...
// pack-book/components/book/time/add-time-dur-items.js
import util from'../../../../utils/util.js'
import PubSub from '../../../../utils/PubSub';
Component({
/**
* 组件的属性列表
*/
properties: {
},
lifetimes: {
attached: function () {
//console.log('add-time-dur.attached')
PubSub.on('dur-items',(check)=>{
//{ddate_solt: 1, list: Array(9), listIndex: 8}
this.ddate_solt=check.ddate_solt
this.list=check.list
this.listIndex=check.listIndex
console.log('add-time-dur-items',check)
this.setData(check)
this.trigger()
})
},
moved: function () { },
detached: function () {
PubSub.off('du-items')
},
},
/**
* 组件的初始数据
*/
data: {
list:[],
timePickerMask:false,
ddate_solt:-1,
},
/**
* 组件的方法列表
*/
methods: {
calendarShow(){
this.setData({
timePickerMask:true,
})
},
calendarClose(){
this.setData({
timePickerMask:true,
})
},
bindTimePickerChange(e){
console.log('add-time-dur-items',e.detail)
},
trigger(){
this.triggerEvent('event',{
time:this.list[this.listIndex].time,
ddate_solt:this.ddate_solt
})
},
}
})
... ...
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
... ...
<!--pack-book/components/book/time/add-time-dur-items.wxml-->
<view bindtap="calendarShow">
<slot></slot>
</view>
<view class="calendar-mask" bindtap="calendarClose"
style="height:100%;" wx:if="{{timePickerMask}}">
<view class="timePicker">
<view class="flex-rr">
<image class="close" src="http://qn.colorcun.com/custom/lite-yd/image/add-act.png" bindtap="calendarClose"></image>
</view>
<view class="flex-cc" style="margin-bottom: 56rpx; font-size: 30rpx;">
<view bindtap="calendarClose">{{ddate_solt==1?'午市':ddate_solt==2?'晚市':'早市'}}</view>
</view>
<view class="flex-ll" style="flex-wrap:wrap">
<view class="time-item {{item.hasChecked?'checked':''}}"
style="{{(index+1)%3==0?'margin-right:0;':''}}"
wx:for="{{list}}" wx:key="listkey"
bindtap="bindTimePickerChange"
data-index="{{index}}"
data-time="{{item.time}}"
>{{item}}</view>
</view>
</view>
</view>
... ...
/* pack-book/components/book/time/add-time-dur-items.wxss */
@import "../../../app.wxss";
.calendar-mask{
position: fixed;
z-index: 99;
width: 100%;
height: 100%;
left:0;
top:0;
background-color: rgba(0,0,0,.5);
}
.timePicker{
width: 80%;
overflow: hidden;
position: absolute;
bottom: 0;
border-top: 2rpx solid #ccc;
background-color: #FEFEFE;
padding: 20rpx 10% 80rpx;
}
.timePicker .time-item{
width: 150rpx;
height: 60rpx;
line-height: 60rpx;
font-size: 40rpx;
font-weight: bold;
color:#199095;
border: 2rpx solid #199095;
border-radius: 10rpx;
text-align: center;
margin-right: 66rpx;
margin-bottom: 60rpx;
}
.timePicker .time-item.checked{
background-color: #199095;
color:#fefefe;
}
.timePicker .close{
width: 50rpx;
height: 50rpx;
transform:rotate(45deg);
margin-top: -10rpx;
margin-right: -10%;
}
\ No newline at end of file
... ...
// pack-book/components/book/time/add-time-dur.js
var util = require('../../../../utils/util.js')
import util from'../../../../utils/util.js'
import App from '../../../../utils/api';
import PubSub from '../../../../utils/PubSub';
const timeSort=['morning', 'noon', 'night'];
const timeConfig= {
'morning':{
... ... @@ -21,13 +22,9 @@ Component({
* 组件的属性列表
*/
properties: {
solt:{//ddate_solt,时段,修改或从桌位过来使用
type:Number,
value:-1,
},
date:{//0今天,1明天,2其它
type:Number,
value:-1,
date:{//YYYY-MM-DD
type:String,
value:'',
},
ddate:{//到店时间
type:Number,
... ... @@ -42,8 +39,7 @@ Component({
detached: function () { },
},
observers:{
"solt,date":async function(solt,date){
if(solt<0) return;
"date":async function(date){
console.log('add-time-dur.observers',arguments)
this.config=null
this.ddate_solt=-1
... ... @@ -73,15 +69,14 @@ Component({
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")
let datetime=util.unixtoTime(time,"YYYY-MM-DD,HH:II").split(',')
let TODAY=datetime[0]
let HHII=datetime[1]
timeSort.forEach((en_name,ti)=>{
let dur=daily[en_name];
let min='',max='',hasShow=false,hasDisabled=false,hasChecked=false
... ... @@ -94,7 +89,7 @@ Component({
hasChecked=true
this.ddate_solt=ti
}
if(HHII>max && this.data.date==0){
if(HHII>max && this.data.date==TODAY){
hasDisabled=true
}
}
... ... @@ -110,21 +105,12 @@ Component({
});
})
this.config=config;
console.log('add-time-dur.initUserTime',this.config[0].hasDisabled)
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,
})
console.log('add-time-dur.initUserTime',this.data.config[0].hasDisabled)
},
selectedValue(e){
console.log('add-time-dur.selectedValue',e)
... ... @@ -176,10 +162,12 @@ Component({
},
trigger(){
let timeList=this.initTimeSpaceIndex()
this.triggerEvent('event',{
let data={
ddate_solt:this.ddate_solt,
...timeList,
})
}
//this.triggerEvent('event',data)
PubSub.emit('dur-items',data)
}
}
})
... ...
<!--pack-book/components/book/time/add-time-dur.wxml-->
<view class="tab flex-ll">
<block wx:for="{{config}}" wx:key="config-key">
<block wx:for="{{config}}" wx:key="configkey">
<view class="item {{item.hasChecked?'checked':''}} {{item.hasDisabled?'disabled':''}}"
wx:if="{{item.hasShow}}"
bindtap="{{item.hasDisabled?'':'selectedValue'}}" data-value="{{index}}">
... ...
// pages/book/b_addnew.js
import util from '../../../utils/util';
import comm from '../../../utils/bookCommon';
import App from '../../../utils/api';
const {regeneratorRuntime} = global
const formTpl = {
rid: '',
date: 0,
time: 0,
//pnum_str:'1-4',
pnum: 6,
tabid: 0,
rname: '',
phone: '',
sex: 1,
cusdem: '',
tid: [],
}
Page({
/**
* 页面的初始数据
*/
data: {
dateStr: [],
form: JSON.parse(JSON.stringify(formTpl)),
tables: [],
grand: [
{
sex: 1,
grand_title: '先生',
isselect: true
},
{
sex: 2,
grand_title: '女士',
isselect: false
},
{
sex: 3,
grand_title: '公司',
isselect: false
}
],
buttonhide: true,
calendarMaskLoad: false,
calendarMask: false,
dayStyle: [
{month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5'},
{month: 'current', day: new Date().getDate(), color: 'white', background: '#AAD4F5'}
],
timePickerArray: [
[],
[],
[],
],
timePickerIndex: [0, 0, 0],
tablesLength: 0,
timePickerMask: false,
pnumInputFocus: false,
pageMarginBottom: 0,
speciallist: [],
calendar: {
nextNum: 0,
},
defDtime: ['', '12:00', '18:30'],
hasUseDefDtime: true,
CustomRemark:[],
CustomRemarkMoreMask:false,
nowtime:0,//当前时间戳,或修改到店,或桌位预订时间
date:'',//当前选择的日期
},
/**
* 生命周期函数--监听页面加载
*/
reserve_id: '',
checkedTables:{},//已选中的桌子集合
year:util.unixtoTime(new Date() / 1000,'YYYY'),
onLoad: async function (options) {
this.options=options
this.initLoad(options)
this.getCustomRemark();
},
async initLoad(options = {}){
let nt = new Date() / 1000;
let speciallist = [
{date: util.unixtoTime(nt, 'YYYY-MM-DD'), background: '', text: '今 天'},
{date: util.unixtoTime(nt + 86400, 'YYYY-MM-DD'), background: '', text: '明 天'},
{date: util.unixtoTime(nt + 86400 * 2, 'YYYY-MM-DD'), background: '', text: '后 天'},
];
this.reserve_id = options.id || '';
let rev_time=parseInt(nt)
this.sellerid = util.cache('enter_params')['seller_id'];
let timePickerArray = await comm.getDayTimeSpace();
this.setData({
timePickerArray: timePickerArray,
speciallist: speciallist,
//hasUseDefDtime: hasUseDefDtime,
})
if(options.hasQuick==1){
let rdate=options.ddate.split('-')
if(!(rev_time>=rdate[0] && rev_time<=rdate[1])){
rev_time=rdate[0]
}
}
await this.setDateStr(rev_time);
if (this.reserve_id > 0) {
this.initModify(this.reserve_id);
} else if(options.hasQuick==1){
this.initQuick(options);
} else {
this.getTables();
}
},
hasInTimeSpace(hhii,timeIndex){
console.log('hasInTimeSpace',this.data.timePickerArray)
if(this.data.timePickerArray.length<1)return false
let timePickerArray=this.data.timePickerArray[timeIndex];
let tl=timePickerArray.length
if(tl<1) return false
console.log('hasInTimeSpace',hhii,timePickerArray[0],timePickerArray[tl-1],hhii>=timePickerArray[0] && hhii<=timePickerArray[tl-1])
if(hhii>=timePickerArray[0] && hhii<=timePickerArray[tl-1]) return true
return false
},
async setDateStr(d = new Date() / 1000,hasUseDefDtime=false,fouceTime=-1){
fouceTime=fouceTime>-1?fouceTime:this.data.form.time
hasUseDefDtime=this.hasInTimeSpace(this.data.defDtime[fouceTime],fouceTime)
if(hasUseDefDtime){//
let timestr=util.unixtoTime(d,'YYYY-MM-DD '+this.data.defDtime[fouceTime])
d=util.timetouUnix(timestr)
}
console.log('setDateStr',util.unixtoTime(d,'YYYY-MM-DD HH:II'),hasUseDefDtime,fouceTime)
this.year=util.unixtoTime(d,'YYYY');
let ns = new Date() / 1000;
let dateStr = [
util.unixtoTime(ns, 'MM-DD `DAY/周WW`'),
util.unixtoTime(parseInt(ns) + 86400, 'MM-DD `DAY/周WW`'),
];
//let dateStr=this.data.dateStr;
let nowStr = util.unixtoTime(d, 'MM-DD `DAY/周WW`')
let form = this.data.form;
let timeObj = await comm.getTimeSpaceIndexData(d,null,fouceTime);
if(fouceTime!=timeObj.timeIndex && fouceTime>0){
timeObj.timeIndex=fouceTime
}
//form.time=await comm.getTimeSpaceIndex(d);
//如果小于默认时间,使用默认时间
let mmii = util.unixtoTime(d,'HH:II')
console.log('setDateStr-timeObj',timeObj,mmii,this.data.defDtime[timeObj.timeIndex])
if (mmii < this.data.defDtime[timeObj.timeIndex]) {
hasUseDefDtime=this.hasInTimeSpace(this.data.defDtime[timeObj.timeIndex],timeObj.timeIndex)
if(hasUseDefDtime){
let str=util.unixtoTime(d, 'YYYY-MM-DD '+this.data.defDtime[timeObj.timeIndex]+':00')
timeObj = await comm.getTimeSpaceIndexData(util.timetouUnix(str));
}
if(options.id>0){
//修改
return;
}
form.time = timeObj.timeIndex;
let ind = dateStr._indexOf(nowStr);
if (ind > -1) {
form.date = ind
} else {
dateStr.push(nowStr.substr(0, 5));
form.date = 2;
if(options.tid){
//桌位预订
return;
}
let timePickerIndex = this.data.timePickerIndex;
timePickerIndex[timeObj.timeIndex] = timeObj.timeMatchIndex;
let obj = {
dateStr: dateStr,
form: form,
timePickerIndex: timePickerIndex,
timeOpt: timeObj.timeOpt,
hasUseDefDtime:hasUseDefDtime
};
this.setData(obj)
return obj;
this.setData({
nowtime:parseInt(new Date()/1000)
})
},
/**
... ... @@ -194,16 +38,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
//if(!this.reserve_id || util.cache('tableid').length>0){
//if (util.cache('tableid').length > 0) {
this.getTables();
//}
setTimeout(() => {
this.setData({
calendarMaskLoad: true,
})
}, 1000);
this.conditionInfo()
},
/**
... ... @@ -240,680 +75,25 @@ Page({
onShareAppMessage: function () {
},
async selectedValueAsync(e){
console.log(e);
let key = util.attr(e, 'key');
let val;
let sobj = {};
if (key == 'date') {
this.year=util.unixtoTime(new Date() / 1000,'YYYY');
}
if (e.type == 'input' || e.type == 'confirm') {
val = util.val(e);
if (key == 'phone') {
var that = this;
if (e.detail.value != '' && e.detail.value.length >= 3) {
App.Reserve.GetReserveUser(
{
keywords: e.detail.value,
sid: this.sellerid
}
).then(function (json) {
if (json.ret == 200 && json.data.length > 0) {
that.setData({
searchlist: json.data
})
} else {
that.setData({
searchlist: null
})
}
})
} else {
this.setData({
searchlist: null
})
}
}
if (key == 'pnum') {
sobj.pnumInputFocus = true;
}
} else {
val = util.attr(e, 'value');
}
if (key == 'time') {
if (this.data.timeOpt[val]) return;
}
if ((key == 'time' && this.data.form.time == val) || (key == 'date' && this.data.form.date == val)) {
if (util.attr(e, 'display') != 'block') {
return;
}
}
let form = this.data.form;
if (key == 'tid') {
let ts = this.data.tables;
if (ts[val].isselect) {
ts[val].isselect = false;
form.tid.remove(ts[val].id);
delete this.checkedTables[ts[val].id]
} else {
ts[val].isselect = true;
form.tid.push(ts[val].id);
this.checkedTables[ts[val].id]=ts[val].name
}
sobj.tables = ts;
} else {
form[key] = val;
}
console.log('ts', sobj.tables,this.checkedTables);
//console.log(e.type,key,val,form);
sobj.form = form;
sobj.buttonhide = this.data.buttonhide;
if (form.tid.length > 0 && form.rname.length > 0) {
sobj.buttonhide = false;
}else{
sobj.buttonhide = true;
}
let displayTimes = false;
if (key == 'time') {
if (util.attr(e, 'display') == 'block') {
displayTimes = true;
sobj.timePickerMask = true;
}
}
//判断hasUseDefDtime
if ((key == 'time' || key == 'date') && !sobj.timePickerMask) {
sobj.hasUseDefDtime = true
let ntime = parseInt(new Date() / 1000)
let xtime =ntime
if(key == 'time'){
xtime=util.unixtoTime(new Date() / 1000, this.year+'-' + (this.data.dateStr[this.data.form.date].substr(0, 5)) + ' HH:II:SS');
xtime=util.timetouUnix(xtime)
//if 当前时间在区间内 hasUseDefDtime 为 false
let d_rdate = await comm.getTimeSpace(this.data.dateStr[this.data.form.date],
this.data.form.time, null,null,this.year);
d_rdate=d_rdate.split('-');
if(d_rdate[0] <= ntime && ntime<=d_rdate[1]){
sobj.hasUseDefDtime=false
}
}
this.setDateStr(xtime,sobj.hasUseDefDtime,sobj.form.time);
}
if (this.data.form.date == 0) {//
let mmii = util.unixtoTime(new Date() / 1000, 'HH:II');
if (mmii > this.data.defDtime[key == 'time' ? val : this.data.form.time]) {
sobj.hasUseDefDtime = false;
}
}
if ('date,time,pnum,pnum_str,tabid'.indexOf(key) > -1) {
if (!displayTimes) {
//sobj.form.tid = []; //切换日期时间清空桌位
//sobj.buttonhide = true;
this.getTables();
}
if (key == 'date') {
let xtime = util.unixtoTime(new Date() / 1000, this.year+'-' + (this.data.dateStr[val].substr(0, 5)) + ' HH:II:SS');
this.setDateStr(util.timetouUnix(xtime),sobj.hasUseDefDtime);
}
}
this.setData(sobj)
},
selectedValue(e){
console.log(e);
let key = util.attr(e, 'key');
let val;
let sobj = {};
if (key == 'date') {
this.year=util.unixtoTime(new Date() / 1000,'YYYY');
}
if (e.type == 'input' || e.type == 'confirm') {
val = util.val(e);
if (key == 'phone') {
var that = this;
if (e.detail.value != '' && e.detail.value.length >= 3) {
App.Reserve.GetReserveUser(
{
keywords: e.detail.value,
sid: this.sellerid
}
).then(function (json) {
if (json.ret == 200 && json.data.length > 0) {
that.setData({
searchlist: json.data
})
} else {
that.setData({
searchlist: null
})
}
})
} else {
this.setData({
searchlist: null
})
}
}
if (key == 'pnum') {
sobj.pnumInputFocus = true;
}
} else {
val = util.attr(e, 'value');
}
if (key == 'time') {
if (this.data.timeOpt[val]) return;
}
if ((key == 'time' && this.data.form.time == val) || (key == 'date' && this.data.form.date == val)) {
if (util.attr(e, 'display') != 'block') {
return;
}
}
let form = this.data.form;
if (key == 'tid') {
let ts = this.data.tables;
if (ts[val].isselect) {
ts[val].isselect = false;
form.tid.remove(ts[val].id);
delete this.checkedTables[ts[val].id]
} else {
ts[val].isselect = true;
form.tid.push(ts[val].id);
this.checkedTables[ts[val].id]=ts[val].name
}
sobj.tables = ts;
} else {
form[key] = val;
}
console.log('ts', sobj.tables,this.checkedTables);
//console.log(e.type,key,val,form);
sobj.form = form;
sobj.buttonhide = this.data.buttonhide;
if (form.tid.length > 0 && form.rname.length > 0 && this.data.timePickerArray[form.time].length>0){
sobj.buttonhide = false;
}else{
sobj.buttonhide = true;
}
let displayTimes = false;
if (key == 'time') {
if (util.attr(e, 'display') == 'block') {
displayTimes = true;
sobj.timePickerMask = true;
}
}
//判断hasUseDefDtime
if ((key == 'time' || key == 'date') && !sobj.timePickerMask) {
sobj.hasUseDefDtime = true
let ntime = parseInt(new Date() / 1000)
let xtime =ntime
if(key == 'time'){
xtime=util.unixtoTime(new Date() / 1000, this.year+'-' + (this.data.dateStr[this.data.form.date].substr(0, 5)) + ' HH:II:SS');
xtime=util.timetouUnix(xtime)
}
this.setDateStr(xtime,sobj.hasUseDefDtime);
}
if (this.data.form.date == 0) {//
let mmii = util.unixtoTime(new Date() / 1000, 'HH:II');
if (mmii > this.data.defDtime[key == 'time' ? val : this.data.form.time]) {
sobj.hasUseDefDtime = false;
}
}
if ('date,time,pnum,pnum_str,tabid'.indexOf(key) > -1) {
if (!displayTimes) {
//sobj.form.tid = []; //切换日期时间清空桌位
//sobj.buttonhide = true;
this.getTables();
}
if (key == 'date') {
let xtime = util.unixtoTime(new Date() / 1000, this.year+'-' + (this.data.dateStr[val].substr(0, 5)) + ' HH:II:SS');
this.setDateStr(util.timetouUnix(xtime),sobj.hasUseDefDtime);
}
}
this.setData(sobj)
},
async getTables(){
let form = this.data.form;
let tableid = util.cache('tableid');
console.log('getTables-tableid', tableid.length, this.reserve_id);
//if (tableid.length < 1 && this.reserve_id) {
if (tableid.length < 1) {
tableid = this.data.form.tid;
}
console.log('getTables-tableid', tableid, tableid.length);
try {
let rdate = await comm.getTimeSpace(this.data.dateStr[this.data.form.date], this.data.form.time,null,null,this.year);
console.log('rdate', this.data.dateStr[this.data.form.date], rdate);
App.Reserve.GetTableList({
sid: util.cache('enter_params')['seller_id'],
//pnum_str:form.pnum_str,
pnum: form.pnum,
rdate: util.unixtoTime(rdate.substr(0,10),'YYYYMMDD'),
tid: form.tabid,
rid: this.reserve_id,
ddate_solt:parseInt(form.time)+1
}).then(res => {
let tables = [];
let tablesLength = 0;
if (tableid.length > 0) {
let toastTables={...this.checkedTables}
let resData=res.data.slice(1,res.data.length);
console.log('resData',resData)
resData.forEach(p => {
//if(tables.length>=3) return true;
p.list.forEach(t => {
delete toastTables[t.id]
tablesLength++;
if (tables.length >= 3) return true;
if (tableid._indexOf(t.id) > -1) {
t.isselect = true;
tables.push(t);
}
})
})
console.log('toastTables',toastTables,this.data.form.tid,this.checkedTables);
//清理已选中的桌位
let toastTablesInfo=[];
let tid=this.data.form.tid
Object.keys(this.checkedTables).forEach(ckid=>{
if(toastTables[ckid]){
delete this.checkedTables[ckid]
tid.remove(ckid);
toastTablesInfo.push(toastTables[ckid]);
}
})
if(toastTablesInfo.length>0){
this.setData({
[`form.tid`]:tid,
})
util.toast(toastTablesInfo.toString()+'已被占用啦','none');
}
wx.removeStorage({key: 'tableid'})
}
console.log('tables-first',tables);
if(tables.length<1){
tablesLength=0;
let fortids=[];
res.data.forEach((p,ri) => {
p.list.forEach(t => {
if(fortids._indexOf(t.id)<0) {
tablesLength++;
tables.push(t);
fortids.push(t.id);
}
})
})
if (tables.length >= 3) {
tables = tables.slice(0, 3);
}
}
this.tablesLength = tablesLength;
this.setData({
tables: tables,
tablesLength: tablesLength
})
this.conditionInfo();
})
} catch (e) {
this.setData({
tables: []
})
}
},
async formsubmit(){
if (this.data.buttonhide) return;
try {
let d_stimestr = this.data.timePickerArray[this.data.form.time][this.data.timePickerIndex[this.data.form.time]];
let d_rdate = await comm.getTimeSpace(this.data.dateStr[this.data.form.date],
this.data.form.time, d_stimestr,null,this.year);
let stimestr = this.data.timePickerArray[this.data.form.time][this.data.timePickerIndex[0]];
let rdate = await comm.getTimeSpace(this.data.dateStr[this.data.form.date],
this.data.form.time, stimestr,null,this.year);
console.log('stimestr', stimestr, this.data.form.time, this.data.timePickerIndex);
console.log('rdate', rdate);
this.setData({
buttonhide: true,
})
let form = JSON.parse(JSON.stringify(this.data.form));
console.log('typeof form.tid', typeof form.tid);
if (typeof form.tid == 'object') {
let tid = new Set(form.tid);//tid 去重
form.tid = [...tid].toString();
}
if(this.data.timePickerArray[form.time].length<1){
return util.toast('请选择时段', 'none');
}
if (!form.tid) {
return util.toast('请选择桌子', 'none');
}
if (!form.rname) {
return util.toast('请填写预订人', 'none');
}
form.sid = this.sellerid;
form.rdate = rdate
try {
let enter_params = util.cache('enter_params');
let sc = (await App.Reserve.SellerInfo(enter_params)).data
let note_openid = enter_params.seller_openid;
let note_name = sc.seller_user.nick_name || sc.seller_user.nickname;
form.note_openid = note_openid || '';
if (form.rid) {//修改时传递uid
form.note_openid = enter_params.manager_id || '';
}
form.note_name = note_name || '';
} catch (e) {}
form.ddate = d_rdate.substr(0, 10);
if (this.data.hasUseDefDtime && this.data.form.time > 0) {//转为默认时间
let ddateStr = util.unixtoTime(form.ddate, "YYYY-MM-DD " + this.data.defDtime[this.data.form.time] + ":00");
form.ddate = util.timetouUnix(ddateStr);
}
form.ddate_solt=parseInt(form.time)+1
form.is_set_ddate=1
App.Reserve.SetReserveInfo(form).then(res => {
if (res.ret == 200) {
this.getCustomRemark()
let _id = (res.data.id || res.data)
this.setData({
form: JSON.parse(JSON.stringify(formTpl)),
tables: [],
timePickerIndex: [0, 0, 0],
})
this.initLoad();
this.checkedTables={};
App.Reserve.Detail({rid: _id, openid: ''}, 'clear')
wx.navigateTo({
url: util.http_build_query({id:_id,tplid:1},'b_invitation'),
});
} else {
util.toast(res.msg, 'none')
}
})
} catch (e) {
}
},
selectphone: function (e) {
this.data.form.phone = e.detail.phone;
this.data.form.rname = e.detail.rname;
this.data.form.cusdem = e.detail.cusdem;
var form = this.data.form
this.data.form.sex = e.detail.sex;
//日期选择通知
addDateEvent(e){
//console.log('addDateEvent',e.detail)
//{checked: 1, checkedTime: 123456790}
this.setData({
form: this.data.form,
searchlist: null
})
this.conditionInfo();
},
calendarShow(){
this.setData({
calendarMask: true
})
},
dateChange(event){
console.log(event);
//let cktime=util.timetouUnix(event.detail.year+'/'+event.detail.month+'/'+event.detail.day)
let cktime = util.timetouUnix(event.detail.date)
this.year=event.detail.date.substr(0, 4);
console.log('this.year',this.year);
let day0 = parseInt(new Date(new Date().setHours(0, 0, 0, 0)) / 1000);
// if (cktime < day0) {
// util.toast('请选择有效日期', 'none');
// return;
// }
let clickDay = event.detail.date.substr(8, 2);
let changeDay = `dayStyle[1].day`;
let changeBg = `dayStyle[1].background`;
this.setData({
[changeDay]: clickDay,
[changeBg]: "#84e7d0",
//[`form.tid`]: [], //切换日期时间清空桌位
//buttonhide: true,
})
console.log('cktime',cktime,util.unixtoTime(cktime,'YYYY-MM-DD'))
if(cktime == day0){//今天
this.setDateStr( new Date() / 1000 )
}else{
let xtime=util.unixtoTime(new Date() / 1000, event.detail.date + ' HH:II:SS');
xtime=util.timetouUnix(xtime)
this.setDateStr(xtime,true)
}
this.calendarClose();
setTimeout(res=>{
this.getTables();
},10)
},
calendarClose(){
this.setData({
calendarMask: false,
timePickerMask: false,
})
},
async selectdesk(){
let rdate = await comm.getTimeSpace(this.data.dateStr[this.data.form.date], this.data.form.time,null,null,this.year);
console.log(this.data.form)
wx.navigateTo({
url: 'b_desk?rdate=' + rdate + '&tid=' + this.data.form.tabid
//+'&pnum_str='+this.data.form.pnum_str
+ '&pnum=' + this.data.form.pnum
+ '&checked_tids=' + this.data.form.tid
+ '&rid=' + this.reserve_id
+ '&ddate_solt='+(parseInt(this.data.form.time)+1)
})
},
conditionInfo: function () {
var form = this.data.form
if (form.tid.length > 0 && form.rname.length > 0) {
this.data.buttonhide = false;
}
this.setData({
buttonhide: this.data.buttonhide
})
},
/**
* 选中时间区域
*/
bindTimePickerChange(e){
let timeIndex = util.attr(e, 'timeIndex');
if (timeIndex < 0) return;
let timePickerIndex = this.data.timePickerIndex;
//timePickerIndex[timeIndex]=util.val(e);
timePickerIndex[timeIndex] = util.attr(e, 'val');
console.log(e, timeIndex, util.attr(e, 'val'));
this.setData({
timePickerIndex: timePickerIndex,
hasUseDefDtime: false,
})
},
/**
* 修改初始化
*/
async initModify(id){
try {
let res = await App.Reserve.Detail({rid: id, openid: ''});
console.log('initModify', res);
//设置日期
let obj = await this.setDateStr(res.data.ddate,null,res.data.ddate_solt-1);
//设置时间
let nd = util.unixtoTime(res.data.ddate, 'HH:II');
let timePickerIndex = this.data.timePickerIndex
console.log('initModify-', this.data.timePickerArray, obj.form.time, nd)
this.data.timePickerArray[obj.form.time].forEach((dd, ii) => {
console.log('initModify-', nd, dd)
if (nd == dd) {
timePickerIndex[obj.form.time] = ii;
return true;
}
})
console.log('initModify-timePickerIndex', timePickerIndex);
//obj.form.pnum_str=res.data.pnum_str;
obj.form.pnum = res.data.pnum || 6;
obj.form.rname = res.data.rname;
obj.form.phone = res.data.phone || "";
obj.form.sex = res.data.sex;
obj.form.cusdem = res.data.cusdem;
obj.form.rid = id;
obj.form.tid = [];
let tablesed = [];
res.data.tables.forEach((t, ti) => {
obj.form.tid.push(t.id)
if (ti >= 3) return;
t.isselect = true
t["isselected"] = 1
tablesed.push(t);
this.checkedTables[t.id]=t.name;
})
this.setData({
timePickerIndex: timePickerIndex,
form: obj.form,
//tablesed:tablesed,
hasUseDefDtime: false,
})
setTimeout(() => {
this.getTables();
}, 300)
} catch (e) {
console.log('initModify', e)
}
},
pnumInputFocusEvent(e){
console.log(e);
this.setData({
pnumInputFocus: 'focus' == e.type
})
},
inputFocusTime: 0,
blurTime: 0,
inputFocus(e){
console.log(e, this.inputFocusTime);
return;
if (e.timeStamp > this.inputFocusTime) {
this.inputFocusTime = e.timeStamp;
if (e.type == 'focus' && this.data.pageMarginBottom == 0) {
this.setData({
pageMarginBottom: 300
})
setTimeout(res => {
this.pageScrollToBottom();
}, 100)
} else {
if (this.blurTime > 5) {
this.blurTime = 0;
this.setData({
pageMarginBottom: 0
})
} else {
setTimeout(res => {
this.blurTime += 1;
this.inputFocus(e);
}, 300)
}
}
}
},
pageScrollToBottom: function () {
wx.createSelectorQuery().select('#j_page').boundingClientRect(function (rect) {
// 使页面滚动到底部
wx.pageScrollTo({
scrollTop: rect.bottom
})
}).exec()
},
gotoday(e){
this.setData({
[`calendar.nextNum`]: 0
})
},
nextMonth(e){
this.setData({
[`calendar.nextNum`]: this.data.calendar.nextNum + 1
})
},
prevMonth(e){
this.setData({
[`calendar.nextNum`]: this.data.calendar.nextNum - 1
})
},
/**
* 快速预订初始化
* tid
* tname
* ddate
* pnum
*/
async initQuick(options){
try {
console.log('initQuick', options);
this.checkedTables[options.tid]=options.tname
this.year=util.unixtoTime(options.ddate.substr(0,10),'YYYY');
let form=this.data.form
form.tid=[options.tid]
this.setData({
form: form,
})
setTimeout(() => {
this.getTables();
}, 300)
} catch (e) {
console.log('initQuick', e)
}
},
getCustomRemark(){
App.User.GetCustomRemark({
uid:util.cache('enter_params')['manager_id'],
}).then(res=>{
let CustomRemark=[];
res.data.forEach(r=>{
if(r.often_use){
CustomRemark.push(r);
}
})
this.setData({
CustomRemark:CustomRemark,
})
})
},
oftenUse(e){
let id=util.attr(e,'id');
let val=util.attr(e,'value');
let CustomRemark=this.data.CustomRemark;
let form=this.data.form;
CustomRemark.forEach(r=>{
if(id==r.id){
if(r.active){
form.cusdem=form.cusdem.replace(val+'、','')
}
r.active=!r.active
if(r.active){
form.cusdem+=val+'、'
}
}
})
this.setData({
CustomRemark:CustomRemark,
form:form,
})
this.conditionInfo()
},
CustomRemarkMore(){
this.setData({
CustomRemarkMoreMask:!this.data.CustomRemarkMoreMask
date:util.unixtoTime(e.detail.checkedTime,'YYYY-MM-DD')
})
},
//时段选择通知
addTimeDurEvent(e){
console.log('add-time-dur.event',e);
//console.log('addTimeDurEvent',e.detail)
//{ddate_solt: 1, list: Array(9), listIndex: 4}
},
//到店时间选择通知
addTimeDurItemsEvent(e){
//{time: 1577689200, ddate_solt: 1}
//console.log('addTimeDurItemsEvent',e.detail)
this.setData({
[`form.time`]:e.detail.ddate_solt,
...e.detail,
})
},
})
\ No newline at end of file
... ...
... ... @@ -3,13 +3,11 @@
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle":"black",
"usingComponents": {
"nothingBook":"../../components/book/nothing/nothing",
"nav":"/components/nav/nav",
"tabBar":"../../components/book/tabBar/tabBar",
"searchList":"/components/searchlist/searchlist",
"calendar": "plugin://bmCalendar/calendar",
"add-date": "../../components/book/time/add-date",
"board":"../../components/book/board/board",
"formids":"/components/formids/formids",
"add-time-dur":"../../components/book/time/add-time-dur"
"add-time-dur":"../../components/book/time/add-time-dur",
"add-time-dur-items":"../../components/book/time/add-time-dur-items"
}
}
\ No newline at end of file
... ...
<!--pages/book/b_addnew.wxml-->
<wxs src="../../../utils/util.wxs" module="util" />
<nav>录入订座信息</nav>
<view class="page" style="margin-bottom: {{pageMarginBottom}}rpx;" id="j_page">
<view class="base-info">
<!--
<view class="section flex-lr date">
<view class="flex-rr" style="width:100%;">
<item class="date-item {{form.date==0?'checked':''}}"
bindtap="selectedValue" data-key="date" data-value="0">
<view class="date-item-text">{{dateStr[0]}}</view>
</item>
<item class="date-item {{form.date==1?'checked':''}}"
bindtap="selectedValue" data-key="date" data-value="1">
<view class="date-item-text">{{dateStr[1]}}</view>
</item>
</view>
<view class="more flex-ll" bindtap="calendarShow">
<view></view>
<view></view>
<view></view>
</view>
</view>
-->
<view class="section">
<view class="tab flex-ll">
<formids class="item {{form.date==0?'checked':''}}"
bindtap="selectedValue" data-key="date" data-value="0">
{{dateStr[0]}}
</formids>
<formids class="item {{form.date==1?'checked':''}}"
bindtap="selectedValue" data-key="date" data-value="1">
{{dateStr[1]}}
</formids>
<view class="item {{form.date==2?'checked':''}} flex-lr"
bindtap="selectedValue" data-key="date" data-value="2" bindtap="calendarShow">
<view style="width: 80%" class="item-text">{{dateStr[2]||'其他'}}</view>
<image
src="http://qn.colorcun.com/custom/lite-yd/image/date{{dateStr[2]?'.selected':''}}.png"
style="min-width: 36rpx;width: 36rpx;height: 36rpx; margin-right: 22rpx;"></image>
</view>
</view>
</view>
<view class="base-info" wx:if="{{nowtime}}">
<view class="section">
<add-time-dur date="{{form.date}}" solt="{{detail.time.kk}}" bindevent="addTimeDurEvent"></add-time-dur>
<add-date nowtime="{{nowtime}}" bindevent="addDateEvent"></add-date>
</view>
<view class="section ">
<view class="tab flex-ll">
<formids class="item {{form.time==0?'checked':''}} {{timeOpt[0]}}"
wx:if="{{timePickerArray[0].length>0}}"
bindtap="selectedValueAsync" data-key="time" data-value="0">
<view class="picker">早市</view>
</formids>
<formids class="item {{form.time==1?'checked':''}} {{timeOpt[1]}}"
wx:if="{{timePickerArray[1].length>0}}"
bindtap="selectedValueAsync" data-key="time" data-value="1">
<view class="picker">午市</view>
</formids>
<formids class="item {{form.time==2?'checked':''}} {{timeOpt[2]}}"
wx:if="{{timePickerArray[2].length>0}}"
bindtap="selectedValueAsync" data-key="time" data-value="2">
<view class="picker">晚市</view>
</formids>
</view>
<view class="section" wx:if="{{date}}">
<add-time-dur date="{{date}}" ddate="{{detail.ddate||''}}" bindevent="addTimeDurEvent"></add-time-dur>
</view>
<view class="section" style="height: 90rpx;">
<view class="tab flex-lr">
... ... @@ -90,36 +37,6 @@
</view>
</view>
</view>
<!--
<view class="section ">
<view class="tab flex-ll">
<view class="item {{form.pnum_str=='1-4'?'checked':''}}"
bindtap="selectedValue" data-key="pnum_str" data-value="1-4">
4人以下
</view>
<view class="item {{form.pnum_str=='5-9'?'checked':''}}"
bindtap="selectedValue" data-key="pnum_str" data-value="5-9">
5~9人
</view>
<view class="item {{form.pnum_str=='10-99'?'checked':''}}"
bindtap="selectedValue" data-key="pnum_str" data-value="10-99">
10人以上
</view>
</view>
</view>
<view class="section ">
<view class="tab flex-ll">
<view class="item {{form.tabid=='2'?'checked':''}}"
bindtap="selectedValue" data-key="tabid" data-value="2">
包间
</view>
<view class="item {{form.tabid=='1'?'checked':''}}"
bindtap="selectedValue" data-key="tabid" data-value="1">
散台
</view>
</view>
</view>
-->
</view>
<view class="page-full tables">
... ... @@ -154,8 +71,9 @@
data-key="phone"
value="{{form.phone}}" style="color:{{reminder ? '#E14553' : '#353535'}};width:{{reminder ? 400 : 680}}rpx;" cursor-spacing="260"/>
<view bindtap="selectedValue" data-key="time" data-value="{{form.time}}" data-display="block" style="color:#199095">
<view style="font-size: 34rpx;height: 100rpx;line-height: 100rpx;" wx:if="{{hasUseDefDtime && form.time>0}}">{{defDtime[form.time]}}</view>
<view style="font-size: 34rpx;height: 100rpx;line-height: 100rpx;" wx:else="">{{timePickerArray[form.time][timePickerIndex[form.time]]}}</view>
<add-time-dur-items
bindevent="addTimeDurItemsEvent"
style="font-size: 34rpx;height: 100rpx;line-height: 100rpx;">{{util.unixtoTime(time,'YYYY-MM-DD HH:II')}}</add-time-dur-items>
</view>
<block wx:if="{{searchlist}}">
<searchList searchlist="{{searchlist}}" bind:selectphone="selectphone"></searchList>
... ... @@ -209,37 +127,6 @@
</view>
<tabBar></tabBar>
<view class="calendar-mask" bindtap="calendarClose"
style="height:{{calendarMask?'100%':0}};" wx:if="{{calendarMaskLoad}}">
<view style="width: 100%; height:{{calendarMask?'100%':0}};overflow: hidden;position: relative;">
<calendar catchtap="catchtap"
isTodaybtn="{{true}}" todaybtn_txt="回到今天"
custom="{{false}}"
switchover="{{['上一月','下个月']}}"
active-coloro="active-coloro"
active-colort="active-colort"
speciallist="{{speciallist}}"
txt_style="txt-style"
calendar-style="calendar"
header-style="calendar-header"
weektitle-style="weektitle-style"
restcolor-style="restcolor-style"
txt_type="cn-d"
datefont-style="datefont-style"
todaybtn-style="todaybtn-style"
bindnextMonth="nextMonth"
bindprevMonth="prevMonth"
bindselectDate="dateChange"
bindgotoday="gotoday"
prev="{{true||calendar.nextNum>0}}"
circle_show="{{false}}"
closelaststyle="{{true}}"
></calendar>
</view>
</view>
<view class="calendar-mask" bindtap="calendarClose"
style="height:100%;" wx:if="{{timePickerMask}}">
<view class="timePicker">
<view class="flex-rr">
... ...
//时间戳转为时间
function unixtoTime(ns,format="YYYY-MM-DD HH:II:SS") {
if(!ns) return
var result;
var time = getDate(ns*1000);
//result=format || 'YYYY年MM月DD日 HH时II分SS秒 WW';
... ...