b_sms.js
5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// 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 = {
SMS_154587043: '${guest},您好!${seller_name}已为您预订${date}的桌位:${region_room_name};地址:${seller_addr},电话:${seller_phone}\n客户经理${cusman},期待您的光临!',
SMS_162733710: '尊敬的贵宾,您好!${reserve_date}的用餐,为您安排在${seller_name_addr_room}房间,${cusman}期待您的光临,预祝就餐愉快!',
SMS_163050401: '尊敬的贵宾,您好!\n ${seller_name}已为您安排${date}的用餐,房间:${region_room_name}; \n地址:${seller_addr}; \n电话:${seller_phone} \n预祝用餐愉快,${cusman}期待您的光临!',
};
Page({
/**
* 页面的初始数据
*/
tplsIndex: 'SMS_163050401',
data: {
bookInfo: {},
tplMsg: ''
},
sc:{},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.enter_params=util.cache('enter_params');
App.Reserve.SellerInfo(this.enter_params).then(res=>{
this.sc=res.data;
try{
this.tplsIndex=res.data.setting.template_code
}catch(e){}
this.getDetail(options.id);
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
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 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;
},
getTableNameOne(tables){
let bao = [];
tables.forEach(t => {
bao.push(t.name);
})
return bao.join('、');
},
getTableNameShort(tables){//短桌位
let str=tables[0].name;
if(tables.length>1){
str+='等'+tables.length+'个';
}
return str;
},
smsData: {},
async getTplMsg(){
let smsData = {}
let txa=['早上','中午','晚上']
let tx=await bcm.getTimeSpaceIndexData(this.bookInfo.rdate);
switch (this.tplsIndex) {
//尊敬的贵宾,您好!(4月6日)(中午)的用餐,为您安排在(好又多复兴路店)(202)房间,(王丽娜)期待您的光临,预祝就餐愉快!
case 'SMS_162733710':
smsData = {
reserve_date: util.unixtoTime(this.bookInfo.rdate,'MM月DD日')
.replace(/0(\d)/g,function($0,$1){
return $1;
})+' '+txa[tx.timeIndex],
seller_name_addr_room: this.sc.seller.selleralias+this.getTableNameShort(this.bookInfo.tables).substr(0, 20),
cusman: (this.bookInfo.cusman || this.bookInfo.seller.sellername).substr(0, 20),
}
break;
case 'SMS_163050401':
smsData = {
seller_name: this.bookInfo.seller.sellername.substr(0, 20),
date: this.bookInfo.rdateStr.replace('日','日'+txa[tx.timeIndex]),
region_room_name: this.getTableNameOne(this.bookInfo.tables).substr(0, 20),
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||'').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,
len:this.data.tplMsg.length
}).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
})
},
})