Commit 6db64e0eb870dcffcc2980ea04a65a83962014d4

Authored by vking
1 parent f7c1f848

master-rewrite-addnew

// pack-book/components/book/time/add-date.js
import util from '../../../../utils/util'
import PubSub from '../../../../utils/PubSub';
Component({
/**
* 组件的属性列表
*/
properties: {
nowtime:Number,
type:Number,
time:Number,
},
lifetimes: {
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
... ... @@ -47,8 +49,11 @@ Component({
calendarMaskLoad: true,
})
}, 1000);
this.initChecked(this.data.nowtime)
this.HHIISS=util.unixtoTime(this.data.time,'HH:II:SS')
this.initChecked(this.data.time)
setTimeout(() => {
this.trigger()
}, 800);
},
initChecked(nowtime){
let nowStr=util.unixtoTime(nowtime,"YYYY-MM-DD");
... ... @@ -64,7 +69,7 @@ Component({
checked:this.checked,
[`list[2].time`]:nowtime,
})
this.trigger()
},
selectedValue(e){
this.checked=util.attr(e,'value')
... ... @@ -75,10 +80,20 @@ Component({
this.trigger()
},
trigger(){
this.triggerEvent('event',{
checked:this.checked,
checkedTime:this.checkedTime,
})
let date=util.unixtoTime(this.checkedTime,"YYYY-MM-DD")
let dur_time=util.timetouUnix(date+' '+this.HHIISS);
let data={
type:this.data.type,
date:date,
dur_time:dur_time,
dateIndex:this.checked,
}
console.log('add-date.trigger',data)
// this.triggerEvent('event',{
// checked:this.checked,
// checkedTime:this.checkedTime,
// })
PubSub.emit('add-time-dur',data)
},
calendarShow(e){
this.setData({
... ... @@ -93,6 +108,7 @@ Component({
dateChange(event){
let cktime = util.timetouUnix(event.detail.date)
this.initChecked(cktime)
this.trigger()
this.calendarClose();
},
}
... ...
... ... @@ -10,13 +10,12 @@ Component({
},
lifetimes: {
attached: function () {
//console.log('add-time-dur.attached')
PubSub.on('dur-items',(check)=>{
//{ddate_solt: 1, list: Array(9), listIndex: 8}
console.log('dur-items.PubSub',check)
this.ddate_solt=check.ddate_solt
this.list=check.list
this.listIndex=check.listIndex
console.log('add-time-dur-items',check)
this.dur_list=check.dur_list
this.dur_list_checked=check.dur_list_checked
this.setData(check)
this.trigger()
})
... ... @@ -30,7 +29,7 @@ Component({
* 组件的初始数据
*/
data: {
list:[],
dur_list:[],
timePickerMask:false,
ddate_solt:-1,
},
... ... @@ -46,16 +45,22 @@ Component({
},
calendarClose(){
this.setData({
timePickerMask:true,
timePickerMask:false,
})
},
bindTimePickerChange(e){
console.log('add-time-dur-items',e.detail)
this.dur_list_checked=util.attr(e,'index')
this.setData({
dur_list_checked:this.dur_list_checked,
})
this.trigger()
this.calendarClose()
},
trigger(){
this.triggerEvent('event',{
time:this.list[this.listIndex].time,
ddate_solt:this.ddate_solt
time:this.dur_list[this.dur_list_checked].time,
ddate_solt:this.ddate_solt,
timeDur:this.dur_list[0].time+'-'+this.dur_list[this.dur_list.length-1].time
})
},
}
... ...
<!--pack-book/components/book/time/add-time-dur-items.wxml-->
<wxs src="../../../../utils/util.wxs" module="util" />
<view bindtap="calendarShow">
<slot></slot>
</view>
... ... @@ -12,13 +13,12 @@
<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':''}}"
<view class="time-item {{index==dur_list_checked?'checked':''}}"
style="{{(index+1)%3==0?'margin-right:0;':''}}"
wx:for="{{list}}" wx:key="listkey"
bindtap="bindTimePickerChange"
wx:for="{{dur_list}}" wx:key="listkey"
catchtap="bindTimePickerChange"
data-index="{{index}}"
data-time="{{item.time}}"
>{{item}}</view>
>{{util.unixtoTime(item.time,"HH:II")}}</view>
</view>
</view>
</view>
... ...
... ... @@ -22,30 +22,28 @@ Component({
* 组件的属性列表
*/
properties: {
date:{//YYYY-MM-DD
type:String,
value:'',
},
ddate:{//到店时间
type:Number,
value:-1,
}
},
lifetimes: {
attached: function () {
//console.log('add-time-dur.attached')
//event {type: 1, date: "2019-12-31", dur_time: "NaN", dateIndex: 0}
PubSub.on('add-time-dur',(event)=>{
console.log('add-time-dur.PubSub',event)
this.config=null
this.ddate_solt=-1
this.date=event.date
this.dateIndex=event.dateIndex
this.dur_time=event.dur_time
this.type=this.type
this.initSolt()//初始化solt
})
},
moved: function () { },
detached: function () { },
},
observers:{
"date":async function(date){
console.log('add-time-dur.observers',arguments)
this.config=null
this.ddate_solt=-1
this.initSolt()//初始化solt
}
detached: function () {
PubSub.off('add-time-dur')
},
},
observers:{},
/**
* 组件的初始数据
*/
... ... @@ -69,14 +67,16 @@ Component({
let daily = res.data.daily;
console.log('add-time-dur.daily',daily)
this.initUserTime(daily)
this.trigger();
setTimeout(()=>{
this.trigger();
},0)
},
initUserTime(daily){
let config=[]
let time=parseInt(new Date()/1000);
let datetime=util.unixtoTime(time,"YYYY-MM-DD,HH:II").split(',')
let datetime=util.unixtoTime(this.dur_time,"YYYY-MM-DD,HH:II").split(',')
let TODAY=datetime[0]
let HHII=datetime[1]
this.ddate_solt=-1
timeSort.forEach((en_name,ti)=>{
let dur=daily[en_name];
let min='',max='',hasShow=false,hasDisabled=false,hasChecked=false
... ... @@ -85,11 +85,11 @@ Component({
dur=dur.split('-');
min=dur[0];
max=dur[1];
if(HHII>=min && HHII<=max){
if(HHII<=max && this.ddate_solt==-1){
hasChecked=true
this.ddate_solt=ti
}
if(HHII>max && this.data.date==TODAY){
if(HHII>max && this.dateIndex==0){//灰掉今天过期时间
hasDisabled=true
}
}
... ... @@ -105,12 +105,11 @@ Component({
});
})
this.config=config;
console.log('add-time-dur.initUserTime',this.config[0].hasDisabled)
console.log('add-time-dur.initUserTime',this.ddate_solt,this.config)
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)
... ... @@ -127,46 +126,43 @@ Component({
},
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);
}
let time=this.dur_time
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){//非修改时,优先默认时间
if(defTime && this.type!=1){//非修改时,优先默认时间
defTime=util.timetouUnix(util.unixtoTime(time,"YYYY-MM-DD "+defTime+":00"))
if(defTime>time){
if(defTime>time || this.dateIndex>0){
time=defTime
}
}
let dur,timeCheckedIndex=0,list=[];
let dur,timeCheckedIndex=-1,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")
disabled:this.dateIndex==0,//disabled 今天过期时间?
}
list.push(t)
if(dur<=time){
timeCheckedIndex++
}
}
console.log('add-time-dur.tindex',timeCheckedIndex,list)
console.log('add-time-dur.tindex',list,timeCheckedIndex)
return {list:list,listIndex:timeCheckedIndex}
},
trigger(){
let timeList=this.initTimeSpaceIndex()
let data={
ddate_solt:this.ddate_solt,
...timeList,
dur_list:timeList.list,
dur_list_checked:timeList.listIndex,
}
//this.triggerEvent('event',data)
console.log('dur-items.trigger',data)
PubSub.emit('dur-items',data)
}
}
... ...
// pages/book/b_addnew.js
import util from '../../../utils/util';
import App from '../../../utils/api';
const formTpl = {
rid: '',
pnum: 6,
tabid: 0,
rname: '',
phone: '',
sex: 1,
cusdem: '',
tid: [],
}
Page({
/**
* 页面的初始数据
*/
data: {
nowtime:0,//当前时间戳,或修改到店,或桌位预订时间
date:'',//当前选择的日期
type:1, // type 1/2/3 新增/修改/桌位
time:0,//当前时间戳,或修改到店,或桌位预订时间
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,
tablesLength: 0,
pnumInputFocus: false,
pageMarginBottom: 0,
speciallist: [],
CustomRemark:[],
CustomRemarkMoreMask:false,
},
reserve_id: '',
checkedTables:{},//已选中的桌子集合
/**
* 生命周期函数--监听页面加载
*/
onLoad: async function (options) {
this.options=options
this.sellerid = util.cache('enter_params')['seller_id'];
this.getCustomRemark();
if(options.id>0){
//修改
return;
... ... @@ -23,7 +66,8 @@ Page({
return;
}
this.setData({
nowtime:parseInt(new Date()/1000)
time:parseInt(new Date()/1000),
type:1
})
},
... ... @@ -75,25 +119,314 @@ Page({
onShareAppMessage: function () {
},
//日期选择通知
addDateEvent(e){
//console.log('addDateEvent',e.detail)
//{checked: 1, checkedTime: 123456790}
//到店时间选择通知
addTimeDurItemsEvent(e){
//{time: 1577788200, ddate_solt: 2, timeDur: "1577786400-1577804400"}
console.log('addTimeDurItemsEvent',e.detail,util.unixtoTime(e.detail.time))
this.time=e.detail.time
this.ddate_solt=e.detail.ddate_solt
this.timeDur=e.detail.timeDur//预订所在时段区间时间戳
this.setData({
date:util.unixtoTime(e.detail.checkedTime,'YYYY-MM-DD')
...e.detail,
})
this.getTables();
},
//时段选择通知
addTimeDurEvent(e){
//console.log('addTimeDurEvent',e.detail)
//{ddate_solt: 1, list: Array(9), listIndex: 4}
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,
})
})
},
//到店时间选择通知
addTimeDurItemsEvent(e){
//{time: 1577689200, ddate_solt: 1}
//console.log('addTimeDurItemsEvent',e.detail)
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({
...e.detail,
CustomRemark:CustomRemark,
form:form,
})
this.conditionInfo()
},
CustomRemarkMore(){
this.setData({
CustomRemarkMoreMask:!this.data.CustomRemarkMoreMask
})
},
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
})
},
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 {
App.Reserve.GetTableList({
sid: util.cache('enter_params')['seller_id'],
//pnum_str:form.pnum_str,
pnum: form.pnum,
rdate: util.unixtoTime(this.time,'YYYYMMDD'),
tid: form.tabid,
rid: this.reserve_id,
ddate_solt:this.ddate_solt
}).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: []
})
}
},
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;
this.setData({
form: this.data.form,
searchlist: null
})
this.conditionInfo();
},
selectdesk(){
wx.navigateTo({
url: 'b_desk?rdate=' + this.time + '&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='+this.ddate_solt
})
},
selectedValue(e){
console.log(e);
let key = util.attr(e, 'key');
let val;
let sobj = {};
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');
}
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 ('pnum,pnum_str,tabid'.indexOf(key) > -1) {
if (!displayTimes) {
this.getTables();
}
}
this.setData(sobj)
},
async formsubmit(){
if (this.data.buttonhide) return;
try {
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.ddate_solt<0){
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 = this.time;
form.ddate_solt=this.ddate_solt
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) {
}
},
})
\ No newline at end of file
... ...
... ... @@ -5,8 +5,9 @@
"usingComponents": {
"nav":"/components/nav/nav",
"tabBar":"../../components/book/tabBar/tabBar",
"add-date": "../../components/book/time/add-date",
"board":"../../components/book/board/board",
"searchList":"/components/searchlist/searchlist",
"add-date": "../../components/book/time/add-date",
"add-time-dur":"../../components/book/time/add-time-dur",
"add-time-dur-items":"../../components/book/time/add-time-dur-items"
}
... ...
... ... @@ -2,12 +2,12 @@
<wxs src="../../../utils/util.wxs" module="util" />
<nav>录入订座信息</nav>
<view class="page" style="margin-bottom: {{pageMarginBottom}}rpx;" id="j_page">
<view class="base-info" wx:if="{{nowtime}}">
<view class="base-info" wx:if="{{time}}">
<view class="section">
<add-date nowtime="{{nowtime}}" bindevent="addDateEvent"></add-date>
<add-date time="{{time}}" type="{{type}}"></add-date>
</view>
<view class="section" wx:if="{{date}}">
<add-time-dur date="{{date}}" ddate="{{detail.ddate||''}}" bindevent="addTimeDurEvent"></add-time-dur>
<view class="section">
<add-time-dur></add-time-dur>
</view>
<view class="section" style="height: 90rpx;">
<view class="tab flex-lr">
... ... @@ -73,7 +73,9 @@
<view bindtap="selectedValue" data-key="time" data-value="{{form.time}}" data-display="block" style="color:#199095">
<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>
style="font-size: 34rpx;height: 100rpx;line-height: 100rpx;">
{{util.unixtoTime(time,'HH:II')}}
</add-time-dur-items>
</view>
<block wx:if="{{searchlist}}">
<searchList searchlist="{{searchlist}}" bind:selectphone="selectphone"></searchList>
... ...
... ... @@ -26,11 +26,11 @@ function formatNumber(n) {
return n[1] ? n : '0' + n
}
//时间戳转为时间
function unixtoTime(ns,format) {
function unixtoTime(ns,format='') {
var result;
var time = new Date(ns*1000);
//result=format || 'YYYY年MM月DD日 HH时II分SS秒 WW';
result=format || 'YYYY年MM月DD日';
result=format || 'YYYY年MM月DD日 HH时II分SS秒';
//console.log(format);
result=result.toUpperCase();
result=result.replace('YYYY',time.getFullYear());
... ...