|
|
|
// pages/book/b_sms.js
|
|
|
|
var util = require('../../utils/util.js')
|
|
|
|
import App from '../../utils/api';
|
|
|
|
import bcm from '../../utils/bookCommon';
|
|
|
|
const {regeneratorRuntime} = global
|
|
|
|
const tpls=[
|
|
|
|
'${guest},您好!${seller_name}已为您预订${date}的桌位:${region_room_name};地址:${seller_addr},电话:${seller_phone}\n客户经理${cusman},期待您的光临!'
|
|
|
|
//+'\n#${code}#复制该短信到微信-发现-小程序-搜索“一键订”,给好友发送尊贵请柬,倍有面子!'
|
|
|
|
];
|
|
|
|
const tpls = {
|
|
|
|
SMS_154587043: '${guest},您好!${seller_name}已为您预订${date}的桌位:${region_room_name};地址:${seller_addr},电话:${seller_phone}\n客户经理${cusman},期待您的光临!',
|
|
|
|
SMS_162733710: '尊敬的贵宾,您好!${reserve_date}的用餐,为您安排在${seller_name_addr_room}房间,${cusman}期待您的光临,预祝就餐愉快!'
|
|
|
|
};
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
tplsIndex:0,
|
|
|
|
tplsIndex: 'SMS_154587043',
|
|
|
|
data: {
|
|
|
|
bookInfo:{},
|
|
|
|
tplMsg:''
|
|
|
|
bookInfo: {},
|
|
|
|
tplMsg: ''
|
|
|
|
},
|
|
|
|
|
|
|
|
seller:{},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.enter_params=util.cache('enter_params');
|
|
|
|
App.Reserve.SellerInfo(this.enter_params).then(res=>{
|
|
|
|
this.seller=res.data;
|
|
|
|
//this.tplsIndex='SMS_162733710'
|
|
|
|
this.getDetail(options.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -51,88 +57,108 @@ Page({ |
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
bookInfo:null,
|
|
|
|
getDetail(id){
|
|
|
|
App.Reserve.Detail({rid:id,openid:''}).then(res=>{
|
|
|
|
res.data.rdateStr=util.unixtoTime(res.data.ddate,"MM月DD日 HH:II")
|
|
|
|
this.bookInfo=res.data;
|
|
|
|
this.setData({
|
|
|
|
bookInfo:res.data,
|
|
|
|
tplMsg:this.getTplMsg()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getTableName(tables){
|
|
|
|
let bao=[],san=[];
|
|
|
|
tables.forEach(t=>{
|
|
|
|
if(t.tid==2){
|
|
|
|
bao.push(t.name);
|
|
|
|
}else{
|
|
|
|
san.push(t.name);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
let str='';
|
|
|
|
if(bao.length>0){
|
|
|
|
str='包厢('+bao.join('、')+')';
|
|
|
|
}
|
|
|
|
if(san.length>0){
|
|
|
|
str+=san.join('、');
|
|
|
|
}
|
|
|
|
str=str.substr(0,20);
|
|
|
|
if(str.indexOf('(')>-1 && str.indexOf(')')<0){
|
|
|
|
str=str.substr(0,19)+')';
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
|
|
|
smsData:{},
|
|
|
|
getTplMsg(){
|
|
|
|
let guest='';
|
|
|
|
if(this.bookInfo.sex==3){
|
|
|
|
guest='贵宾'
|
|
|
|
}else{
|
|
|
|
guest=this.bookInfo.rname.substr(0,1)+(this.bookInfo.sex==1?'先生':'女士')
|
|
|
|
bookInfo: null,
|
|
|
|
async getDetail(id){
|
|
|
|
let res=await App.Reserve.Detail({rid: id, openid: ''});
|
|
|
|
res.data.rdateStr = util.unixtoTime(res.data.ddate, "MM月DD日 HH:II")
|
|
|
|
this.bookInfo = res.data;
|
|
|
|
let tplMsg= await this.getTplMsg()
|
|
|
|
this.setData({
|
|
|
|
bookInfo: res.data,
|
|
|
|
tplMsg: tplMsg
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getTableName(tables){
|
|
|
|
let bao = [], san = [];
|
|
|
|
tables.forEach(t => {
|
|
|
|
if (t.tid == 2) {
|
|
|
|
bao.push(t.name);
|
|
|
|
} else {
|
|
|
|
san.push(t.name);
|
|
|
|
}
|
|
|
|
let smsData={
|
|
|
|
guest:guest,
|
|
|
|
seller_name:this.bookInfo.seller.sellername.substr(0,20),
|
|
|
|
date:this.bookInfo.rdateStr,
|
|
|
|
region_room_name:this.getTableName(this.bookInfo.tables),
|
|
|
|
reserve_pnum:(this.bookInfo.pnum || this.bookInfo.pnum_str)+'人',
|
|
|
|
seller_addr:(this.bookInfo.seller.real_address || this.bookInfo.seller.map_address).substr(0,20),
|
|
|
|
seller_phone:this.bookInfo.seller.phone.substr(0,20),
|
|
|
|
cusman:(this.bookInfo.cusman||this.bookInfo.seller.sellername).substr(0,20),
|
|
|
|
cusman_phone:(this.bookInfo.cusman_phone||this.bookInfo.seller.phone).substr(0,20),
|
|
|
|
code:this.bookInfo.code,
|
|
|
|
})
|
|
|
|
let str = '';
|
|
|
|
if (bao.length > 0) {
|
|
|
|
str = '包厢(' + bao.join('、') + ')';
|
|
|
|
}
|
|
|
|
if (san.length > 0) {
|
|
|
|
str += san.join('、');
|
|
|
|
}
|
|
|
|
str = str.substr(0, 20);
|
|
|
|
if (str.indexOf('(') > -1 && str.indexOf(')') < 0) {
|
|
|
|
str = str.substr(0, 19) + ')';
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
|
|
|
getTableNameShort(tables){//短桌位
|
|
|
|
let str=tables[0].name;
|
|
|
|
return str+(tables.length>1?'等':'');
|
|
|
|
},
|
|
|
|
smsData: {},
|
|
|
|
async getTplMsg(){
|
|
|
|
let smsData = {}
|
|
|
|
switch (this.tplsIndex) {
|
|
|
|
//尊敬的贵宾,您好!(4月6日)(中午)的用餐,为您安排在(好又多复兴路店)(202)房间,(王丽娜)期待您的光临,预祝就餐愉快!
|
|
|
|
case 'SMS_162733710':
|
|
|
|
let txa=['早上','中午','晚上']
|
|
|
|
let tx=await bcm.getTimeSpaceIndexData(this.bookInfo.rdate);
|
|
|
|
console.log(tx);
|
|
|
|
smsData = {
|
|
|
|
reserve_date: util.unixtoTime(this.bookInfo.rdate,'MM月DD日')+' '+txa[tx.timeIndex],
|
|
|
|
seller_name_addr_room: this.getTableNameShort(this.bookInfo.tables).substr(0, 20),
|
|
|
|
cusman: (this.bookInfo.cusman || this.bookInfo.seller.sellername).substr(0, 20),
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
let guest = '';
|
|
|
|
if (this.bookInfo.sex == 3) {
|
|
|
|
guest = '贵宾'
|
|
|
|
} else {
|
|
|
|
guest = this.bookInfo.rname.substr(0, 1) + (this.bookInfo.sex == 1 ? '先生' : '女士')
|
|
|
|
}
|
|
|
|
smsData = {
|
|
|
|
guest: guest,
|
|
|
|
seller_name: this.bookInfo.seller.sellername.substr(0, 20),
|
|
|
|
date: this.bookInfo.rdateStr,
|
|
|
|
region_room_name: this.getTableName(this.bookInfo.tables),
|
|
|
|
reserve_pnum: (this.bookInfo.pnum || this.bookInfo.pnum_str) + '人',
|
|
|
|
seller_addr: (this.bookInfo.seller.real_address || this.bookInfo.seller.map_address).substr(0, 20),
|
|
|
|
seller_phone: this.bookInfo.seller.phone.substr(0, 20),
|
|
|
|
cusman: (this.bookInfo.cusman || this.bookInfo.seller.sellername).substr(0, 20),
|
|
|
|
cusman_phone: (this.bookInfo.cusman_phone || this.bookInfo.seller.phone).substr(0, 20),
|
|
|
|
code: this.bookInfo.code,
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
let tpl = tpls[this.tplsIndex];
|
|
|
|
this.smsData = smsData;
|
|
|
|
tpl = tpl.replace(/\${([^}]+)}/ig, function ($0, $1) {
|
|
|
|
//console.log($0, $1);
|
|
|
|
return smsData[$1];
|
|
|
|
})
|
|
|
|
return tpl
|
|
|
|
},
|
|
|
|
sendsms(){
|
|
|
|
App.SendSMS.Message({
|
|
|
|
phone: this.bookInfo.phone,
|
|
|
|
sign_name: '一键订',
|
|
|
|
template_code: this.tplsIndex,
|
|
|
|
template_param: JSON.stringify(this.smsData),
|
|
|
|
rid: this.bookInfo.id
|
|
|
|
}).then((res) => {
|
|
|
|
if (res.ret != 200) {
|
|
|
|
return util.toast(res.msg, 'none');
|
|
|
|
}
|
|
|
|
let tpl=tpls[this.tplsIndex];
|
|
|
|
this.smsData=smsData;
|
|
|
|
tpl=tpl.replace(/\${([^}]+)}/ig,function($0,$1){
|
|
|
|
console.log($0,$1);
|
|
|
|
return smsData[$1];
|
|
|
|
util.toast('短信已发送');
|
|
|
|
this.setData({
|
|
|
|
hideSendsms: true,
|
|
|
|
})
|
|
|
|
return tpl
|
|
|
|
},
|
|
|
|
sendsms(){
|
|
|
|
App.SendSMS.Message({
|
|
|
|
phone:this.bookInfo.phone,
|
|
|
|
sign_name:'一键订',
|
|
|
|
template_code:'SMS_154587043',
|
|
|
|
template_param:JSON.stringify(this.smsData),
|
|
|
|
rid:this.bookInfo.id
|
|
|
|
}).then((res)=>{
|
|
|
|
if(res.ret!=200){
|
|
|
|
return util.toast(res.msg,'none');
|
|
|
|
}
|
|
|
|
util.toast('短信已发送');
|
|
|
|
this.setData({
|
|
|
|
hideSendsms:true,
|
|
|
|
})
|
|
|
|
App.Reserve.SmsInfo({seller_id:this.bookInfo.seller.id},'clear')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
copysms(){
|
|
|
|
wx.setClipboardData({
|
|
|
|
data:this.data.tplMsg
|
|
|
|
})
|
|
|
|
},
|
|
|
|
App.Reserve.SmsInfo({seller_id: this.bookInfo.seller.id}, 'clear')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
copysms(){
|
|
|
|
wx.setClipboardData({
|
|
|
|
data: this.data.tplMsg
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|