robotMobile.ejs
10.6 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE html>
<html>
<head>
<title> 小爱外呼机器人</title>
<meta http-equiv="X-UA-Compatible" content="IE=10">
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="/js/jquery-1.9.1.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdn.bootcss.com/moment.js/2.22.1/moment.min.js"></script>
<style type="text/css">
.bootStrapShadow{
padding: 16px;
}
.row_wrap{
margin: 8px 0;
}
.verticalAlign{
vertical-align:top;
}
</style>
</head>
<body class="bootStrapShadow">
<h2>
呼出历史
</h2>
<div class="text-right row_wrap">
<button class="btn btn-primary" data-toggle="modal" data-target="#addMobileModal">添加外呼号码</button>
<button class="btn btn-primary" data-toggle="modal" data-target="#myModal">新建呼出</button>
</div>
<div class="table-responsive" id="grid">
<table class="table table-bordered">
<thead>
<tr>
<th>呼出手机号</th>
<th>呼出时间</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody id="grid-body">
<tr>
<td>15510382586</td>
<td>2015-08-30 01:02:00</td>
<td>呼出完成</td>
<td>
<button type="button" class="btn btn-link">回放</button>
<button type="button" class="btn btn-link" data-toggle="modal" data-target="#viewModal">查看</button>
</td>
</tr>
</tbody>
</table>
</div>
<!--新建呼出-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">新建呼出</h4>
</div>
<div class="modal-body">
<form>
<div class="form-group" id="mobile-select">
<label for="mobile">手机号</label>
<input type="mobile" class="form-control" name="call_out_number" id="call_out_number" placeholder="手机号">
</div>
<div class="form-group">
<label for="scene">场景</label>
<select class="form-control">
<option>外呼场景</option>
</select>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" id="myModalOk">确认</button>
</div>
</div>
</div>
</div>
<!--查看呼出-->
<div class="modal fade" id="viewModal" tabindex="-1" role="dialog" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="viewModalLabel">查看</h4>
</div>
<div class="modal-body" id="viewModal-body">
<address>
<strong>机器人:</strong> 1355 Market Street, Suite 900
<br>
</address>
<address>
<strong>机器人:</strong> 1355 Market Street, Suite 900
<br>
</address>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
<!--添加外呼手机号-->
<div class="modal fade" id="addMobileModal" tabindex="-1" role="dialog" >
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="addMobileModalLabel">添加外呼号码</h4>
</div>
<div class="modal-body" id="addMobileModal-body">
<form>
<div class="form-group">
<label for="mobile">姓名</label>
<input type="mobile" class="form-control" name="call_name" id="call_name" placeholder="姓名">
</div>
<div class="form-group">
<label for="mobile">手机号</label>
<input type="mobile" class="form-control" name="add_call_out_number" id="add_call_out_number" placeholder="手机号">
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" id="addMobileModalOk">提交</button>
</div>
</div>
</div>
</div>
<script>
//刷新列表
function loadGrid(){
$.ajax({
type: "GET",
url: "/demo/api/call_tasks?limit=10000&offset=0",
dataType: "json",
contentType :'application/json',
data: JSON.stringify({}),
success: function(data){
var items = data.items||[],temp=[];
var status ={
'0':'未呼出',
'1':'正在通话',
'2':'通话失败',
'3':'通话完成'
}
for(i=0;i<items.length;i++){
var item= items[i];
temp.push('<tr>');
temp.push('<td>'+item.call_out_number+'</td>');
temp.push('<td>'+(item.call_out_time>0?moment(item.call_out_time*1000).format('YYYY-MM-DD HH:mm'):'')+'</td>');
temp.push('<td>'+(status[item.status]?status[item.status]:' ')+'</td>');
temp.push('<td>');
if(item.record_url){
temp.push('<audio src="'+item.record_url+'" controls="controls">');
temp.push('你的游览器不支持播放格式');
temp.push('</audio>');
}
temp.push('<a class="btn btn-link verticalAlign show-detail" data-id="'+item.id+'" >查看</a> ');
temp.push('</td>');
temp.push('</tr>');
}
$('#grid-body').html(temp.join(""));
}
});
}
//获取外呼号码列表
function loadMobiles(){
$.ajax({
type: "GET",
url: "/demo/api/contact?limit=10000&offset=0",
dataType: "json",
contentType :'application/json',
data: JSON.stringify({}),
success: function(data){
var items = data.items||[],temp=[];
temp.push('<label for="scene">手机号</label>');
temp.push('<select class="form-control" name="call_out_number" id="call_out_number">');
for(i=0;i<items.length;i++){
var item= items[i];
temp.push('<option value="'+item.tel+'">'+item.tel+'</option> ');
}
temp.push('</select>');
$('#mobile-select').html(temp.join(""));
}
});
}
//新建外呼
$('#myModalOk').click(function () {
var mobile =$('#call_out_number').val();
if(mobile&&/^(19[0-9]|16[0-9]|17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(mobile)){
$.ajax({
type: "POST",
url: "/demo/api/call_tasks",
dataType: "json",
contentType :'application/json',
data: JSON.stringify({
"call_out_number":mobile,
"scene":"呼叫场景DEMO"
}),
success: function(data){
if(data.id){
$('#myModal').modal('hide');
loadGrid();
}else{
alert(data.message)
}
}
});
}else{
alert('请输入正确的手机号!')
}
});
//查看详情
$(document).on('click','.show-detail',function () {
var id=$(this).data("id");
$.ajax({
type: "GET",
url: "/demo/api/call_tasks/"+id+"/record_texts",
dataType: "json",
contentType :'application/json',
data: '',
success: function(data){
var temp=[];
var items = data.items||[];
for(i=0;i<items.length;i++){
var item= items[i];
temp.push('<address>');
temp.push('<strong>'+(item.speaker?item.speaker=='robot'?'机器人':'接听者':'')+'</strong>');
temp.push( item.speaked_at>0?'<small style="margin-left: 8px;color: #999;">'+moment(item.speaked_at*1000).format('YYYY-MM-DD HH:mm')+'</small>':'' );
temp.push('<br>');
temp.push( item.content?item.content:'' );
temp.push('<br>');
temp.push('</address>');
}
$('#viewModal-body').html(temp.join(""));
$('#viewModal').modal('show');
}
});
});
//添加手机号码
$('#addMobileModalOk').click(function(){
var mobile =$('#add_call_out_number').val();
var name =$('#call_name').val();
if(mobile&&/^(19[0-9]|16[0-9]|17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(mobile)){
$.ajax({
type: "POST",
url: "/demo/api/contact",
dataType: "json",
contentType :'application/json',
data: JSON.stringify({
"tel":mobile,
"name": name
}),
success: function(data){
if(data.id){
$('#addMobileModal').modal('hide');
loadMobiles();
}else{
alert(data.message)
}
}
});
}else{
alert('请输入正确的手机号!')
}
});
//
loadGrid();
loadMobiles();
</script>
</body>
</html>