|
1
|
// pages/book/b_sms.js
|
1
|
// pages/book/b_sms.js
|
|
2
|
var util = require('../../utils/util.js')
|
2
|
var util = require('../../utils/util.js')
|
|
3
|
import App from '../../utils/api';
|
3
|
import App from '../../utils/api';
|
|
|
|
4
|
+import bcm from '../../utils/bookCommon';
|
|
4
|
const {regeneratorRuntime} = global
|
5
|
const {regeneratorRuntime} = global
|
|
5
|
-const tpls=[
|
|
|
|
6
|
- '${guest},您好!${seller_name}已为您预订${date}的桌位:${region_room_name};地址:${seller_addr},电话:${seller_phone}\n客户经理${cusman},期待您的光临!'
|
|
|
|
7
|
- //+'\n#${code}#复制该短信到微信-发现-小程序-搜索“一键订”,给好友发送尊贵请柬,倍有面子!'
|
|
|
|
8
|
-];
|
6
|
+const tpls = {
|
|
|
|
7
|
+ SMS_154587043: '${guest},您好!${seller_name}已为您预订${date}的桌位:${region_room_name};地址:${seller_addr},电话:${seller_phone}\n客户经理${cusman},期待您的光临!',
|
|
|
|
8
|
+ SMS_162733710: '尊敬的贵宾,您好!${reserve_date}的用餐,为您安排在${seller_name_addr_room}房间,${cusman}期待您的光临,预祝就餐愉快!'
|
|
|
|
9
|
+};
|
|
9
|
Page({
|
10
|
Page({
|
|
10
|
|
11
|
|
|
11
|
/**
|
12
|
/**
|
|
12
|
* 页面的初始数据
|
13
|
* 页面的初始数据
|
|
13
|
*/
|
14
|
*/
|
|
14
|
- tplsIndex:0,
|
15
|
+ tplsIndex: 'SMS_154587043',
|
|
15
|
data: {
|
16
|
data: {
|
|
16
|
- bookInfo:{},
|
|
|
|
17
|
- tplMsg:''
|
17
|
+ bookInfo: {},
|
|
|
|
18
|
+ tplMsg: ''
|
|
18
|
},
|
19
|
},
|
|
19
|
-
|
20
|
+ seller:{},
|
|
20
|
/**
|
21
|
/**
|
|
21
|
* 生命周期函数--监听页面加载
|
22
|
* 生命周期函数--监听页面加载
|
|
22
|
*/
|
23
|
*/
|
|
23
|
onLoad: function (options) {
|
24
|
onLoad: function (options) {
|
|
|
|
25
|
+ this.enter_params=util.cache('enter_params');
|
|
|
|
26
|
+ App.Reserve.SellerInfo(this.enter_params).then(res=>{
|
|
|
|
27
|
+ this.seller=res.data;
|
|
|
|
28
|
+ //this.tplsIndex='SMS_162733710'
|
|
24
|
this.getDetail(options.id);
|
29
|
this.getDetail(options.id);
|
|
|
|
30
|
+ });
|
|
25
|
},
|
31
|
},
|
|
26
|
|
32
|
|
|
27
|
/**
|
33
|
/**
|
|
@@ -51,88 +57,108 @@ Page({ |
|
@@ -51,88 +57,108 @@ Page({ |
|
51
|
onUnload: function () {
|
57
|
onUnload: function () {
|
|
52
|
|
58
|
|
|
53
|
},
|
59
|
},
|
|
54
|
- bookInfo:null,
|
|
|
|
55
|
- getDetail(id){
|
|
|
|
56
|
- App.Reserve.Detail({rid:id,openid:''}).then(res=>{
|
|
|
|
57
|
- res.data.rdateStr=util.unixtoTime(res.data.ddate,"MM月DD日 HH:II")
|
|
|
|
58
|
- this.bookInfo=res.data;
|
|
|
|
59
|
- this.setData({
|
|
|
|
60
|
- bookInfo:res.data,
|
|
|
|
61
|
- tplMsg:this.getTplMsg()
|
|
|
|
62
|
- })
|
|
|
|
63
|
- })
|
|
|
|
64
|
- },
|
|
|
|
65
|
- getTableName(tables){
|
|
|
|
66
|
- let bao=[],san=[];
|
|
|
|
67
|
- tables.forEach(t=>{
|
|
|
|
68
|
- if(t.tid==2){
|
|
|
|
69
|
- bao.push(t.name);
|
|
|
|
70
|
- }else{
|
|
|
|
71
|
- san.push(t.name);
|
|
|
|
72
|
- }
|
|
|
|
73
|
- })
|
|
|
|
74
|
- let str='';
|
|
|
|
75
|
- if(bao.length>0){
|
|
|
|
76
|
- str='包厢('+bao.join('、')+')';
|
|
|
|
77
|
- }
|
|
|
|
78
|
- if(san.length>0){
|
|
|
|
79
|
- str+=san.join('、');
|
|
|
|
80
|
- }
|
|
|
|
81
|
- str=str.substr(0,20);
|
|
|
|
82
|
- if(str.indexOf('(')>-1 && str.indexOf(')')<0){
|
|
|
|
83
|
- str=str.substr(0,19)+')';
|
|
|
|
84
|
- }
|
|
|
|
85
|
- return str;
|
|
|
|
86
|
- },
|
|
|
|
87
|
- smsData:{},
|
|
|
|
88
|
- getTplMsg(){
|
|
|
|
89
|
- let guest='';
|
|
|
|
90
|
- if(this.bookInfo.sex==3){
|
|
|
|
91
|
- guest='贵宾'
|
|
|
|
92
|
- }else{
|
|
|
|
93
|
- guest=this.bookInfo.rname.substr(0,1)+(this.bookInfo.sex==1?'先生':'女士')
|
60
|
+ bookInfo: null,
|
|
|
|
61
|
+ async getDetail(id){
|
|
|
|
62
|
+ let res=await App.Reserve.Detail({rid: id, openid: ''});
|
|
|
|
63
|
+ res.data.rdateStr = util.unixtoTime(res.data.ddate, "MM月DD日 HH:II")
|
|
|
|
64
|
+ this.bookInfo = res.data;
|
|
|
|
65
|
+ let tplMsg= await this.getTplMsg()
|
|
|
|
66
|
+ this.setData({
|
|
|
|
67
|
+ bookInfo: res.data,
|
|
|
|
68
|
+ tplMsg: tplMsg
|
|
|
|
69
|
+ })
|
|
|
|
70
|
+ },
|
|
|
|
71
|
+ getTableName(tables){
|
|
|
|
72
|
+ let bao = [], san = [];
|
|
|
|
73
|
+ tables.forEach(t => {
|
|
|
|
74
|
+ if (t.tid == 2) {
|
|
|
|
75
|
+ bao.push(t.name);
|
|
|
|
76
|
+ } else {
|
|
|
|
77
|
+ san.push(t.name);
|
|
94
|
}
|
78
|
}
|
|
95
|
- let smsData={
|
|
|
|
96
|
- guest:guest,
|
|
|
|
97
|
- seller_name:this.bookInfo.seller.sellername.substr(0,20),
|
|
|
|
98
|
- date:this.bookInfo.rdateStr,
|
|
|
|
99
|
- region_room_name:this.getTableName(this.bookInfo.tables),
|
|
|
|
100
|
- reserve_pnum:(this.bookInfo.pnum || this.bookInfo.pnum_str)+'人',
|
|
|
|
101
|
- seller_addr:(this.bookInfo.seller.real_address || this.bookInfo.seller.map_address).substr(0,20),
|
|
|
|
102
|
- seller_phone:this.bookInfo.seller.phone.substr(0,20),
|
|
|
|
103
|
- cusman:(this.bookInfo.cusman||this.bookInfo.seller.sellername).substr(0,20),
|
|
|
|
104
|
- cusman_phone:(this.bookInfo.cusman_phone||this.bookInfo.seller.phone).substr(0,20),
|
|
|
|
105
|
- code:this.bookInfo.code,
|
79
|
+ })
|
|
|
|
80
|
+ let str = '';
|
|
|
|
81
|
+ if (bao.length > 0) {
|
|
|
|
82
|
+ str = '包厢(' + bao.join('、') + ')';
|
|
|
|
83
|
+ }
|
|
|
|
84
|
+ if (san.length > 0) {
|
|
|
|
85
|
+ str += san.join('、');
|
|
|
|
86
|
+ }
|
|
|
|
87
|
+ str = str.substr(0, 20);
|
|
|
|
88
|
+ if (str.indexOf('(') > -1 && str.indexOf(')') < 0) {
|
|
|
|
89
|
+ str = str.substr(0, 19) + ')';
|
|
|
|
90
|
+ }
|
|
|
|
91
|
+ return str;
|
|
|
|
92
|
+ },
|
|
|
|
93
|
+ getTableNameShort(tables){//短桌位
|
|
|
|
94
|
+ let str=tables[0].name;
|
|
|
|
95
|
+ return str+(tables.length>1?'等':'');
|
|
|
|
96
|
+ },
|
|
|
|
97
|
+ smsData: {},
|
|
|
|
98
|
+ async getTplMsg(){
|
|
|
|
99
|
+ let smsData = {}
|
|
|
|
100
|
+ switch (this.tplsIndex) {
|
|
|
|
101
|
+ //尊敬的贵宾,您好!(4月6日)(中午)的用餐,为您安排在(好又多复兴路店)(202)房间,(王丽娜)期待您的光临,预祝就餐愉快!
|
|
|
|
102
|
+ case 'SMS_162733710':
|
|
|
|
103
|
+ let txa=['早上','中午','晚上']
|
|
|
|
104
|
+ let tx=await bcm.getTimeSpaceIndexData(this.bookInfo.rdate);
|
|
|
|
105
|
+ console.log(tx);
|
|
|
|
106
|
+ smsData = {
|
|
|
|
107
|
+ reserve_date: util.unixtoTime(this.bookInfo.rdate,'MM月DD日')+' '+txa[tx.timeIndex],
|
|
|
|
108
|
+ seller_name_addr_room: this.getTableNameShort(this.bookInfo.tables).substr(0, 20),
|
|
|
|
109
|
+ cusman: (this.bookInfo.cusman || this.bookInfo.seller.sellername).substr(0, 20),
|
|
|
|
110
|
+ }
|
|
|
|
111
|
+ break;
|
|
|
|
112
|
+ default:
|
|
|
|
113
|
+ let guest = '';
|
|
|
|
114
|
+ if (this.bookInfo.sex == 3) {
|
|
|
|
115
|
+ guest = '贵宾'
|
|
|
|
116
|
+ } else {
|
|
|
|
117
|
+ guest = this.bookInfo.rname.substr(0, 1) + (this.bookInfo.sex == 1 ? '先生' : '女士')
|
|
|
|
118
|
+ }
|
|
|
|
119
|
+ smsData = {
|
|
|
|
120
|
+ guest: guest,
|
|
|
|
121
|
+ seller_name: this.bookInfo.seller.sellername.substr(0, 20),
|
|
|
|
122
|
+ date: this.bookInfo.rdateStr,
|
|
|
|
123
|
+ region_room_name: this.getTableName(this.bookInfo.tables),
|
|
|
|
124
|
+ reserve_pnum: (this.bookInfo.pnum || this.bookInfo.pnum_str) + '人',
|
|
|
|
125
|
+ seller_addr: (this.bookInfo.seller.real_address || this.bookInfo.seller.map_address).substr(0, 20),
|
|
|
|
126
|
+ seller_phone: this.bookInfo.seller.phone.substr(0, 20),
|
|
|
|
127
|
+ cusman: (this.bookInfo.cusman || this.bookInfo.seller.sellername).substr(0, 20),
|
|
|
|
128
|
+ cusman_phone: (this.bookInfo.cusman_phone || this.bookInfo.seller.phone).substr(0, 20),
|
|
|
|
129
|
+ code: this.bookInfo.code,
|
|
|
|
130
|
+ }
|
|
|
|
131
|
+ break;
|
|
|
|
132
|
+ }
|
|
|
|
133
|
+ let tpl = tpls[this.tplsIndex];
|
|
|
|
134
|
+ this.smsData = smsData;
|
|
|
|
135
|
+ tpl = tpl.replace(/\${([^}]+)}/ig, function ($0, $1) {
|
|
|
|
136
|
+ //console.log($0, $1);
|
|
|
|
137
|
+ return smsData[$1];
|
|
|
|
138
|
+ })
|
|
|
|
139
|
+ return tpl
|
|
|
|
140
|
+ },
|
|
|
|
141
|
+ sendsms(){
|
|
|
|
142
|
+ App.SendSMS.Message({
|
|
|
|
143
|
+ phone: this.bookInfo.phone,
|
|
|
|
144
|
+ sign_name: '一键订',
|
|
|
|
145
|
+ template_code: this.tplsIndex,
|
|
|
|
146
|
+ template_param: JSON.stringify(this.smsData),
|
|
|
|
147
|
+ rid: this.bookInfo.id
|
|
|
|
148
|
+ }).then((res) => {
|
|
|
|
149
|
+ if (res.ret != 200) {
|
|
|
|
150
|
+ return util.toast(res.msg, 'none');
|
|
106
|
}
|
151
|
}
|
|
107
|
- let tpl=tpls[this.tplsIndex];
|
|
|
|
108
|
- this.smsData=smsData;
|
|
|
|
109
|
- tpl=tpl.replace(/\${([^}]+)}/ig,function($0,$1){
|
|
|
|
110
|
- console.log($0,$1);
|
|
|
|
111
|
- return smsData[$1];
|
152
|
+ util.toast('短信已发送');
|
|
|
|
153
|
+ this.setData({
|
|
|
|
154
|
+ hideSendsms: true,
|
|
112
|
})
|
155
|
})
|
|
113
|
- return tpl
|
|
|
|
114
|
- },
|
|
|
|
115
|
- sendsms(){
|
|
|
|
116
|
- App.SendSMS.Message({
|
|
|
|
117
|
- phone:this.bookInfo.phone,
|
|
|
|
118
|
- sign_name:'一键订',
|
|
|
|
119
|
- template_code:'SMS_154587043',
|
|
|
|
120
|
- template_param:JSON.stringify(this.smsData),
|
|
|
|
121
|
- rid:this.bookInfo.id
|
|
|
|
122
|
- }).then((res)=>{
|
|
|
|
123
|
- if(res.ret!=200){
|
|
|
|
124
|
- return util.toast(res.msg,'none');
|
|
|
|
125
|
- }
|
|
|
|
126
|
- util.toast('短信已发送');
|
|
|
|
127
|
- this.setData({
|
|
|
|
128
|
- hideSendsms:true,
|
|
|
|
129
|
- })
|
|
|
|
130
|
- App.Reserve.SmsInfo({seller_id:this.bookInfo.seller.id},'clear')
|
|
|
|
131
|
- })
|
|
|
|
132
|
- },
|
|
|
|
133
|
- copysms(){
|
|
|
|
134
|
- wx.setClipboardData({
|
|
|
|
135
|
- data:this.data.tplMsg
|
|
|
|
136
|
- })
|
|
|
|
137
|
- },
|
156
|
+ App.Reserve.SmsInfo({seller_id: this.bookInfo.seller.id}, 'clear')
|
|
|
|
157
|
+ })
|
|
|
|
158
|
+ },
|
|
|
|
159
|
+ copysms(){
|
|
|
|
160
|
+ wx.setClipboardData({
|
|
|
|
161
|
+ data: this.data.tplMsg
|
|
|
|
162
|
+ })
|
|
|
|
163
|
+ },
|
|
138
|
}) |
164
|
}) |