|
|
|
// 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 |
...
|
...
|
|