createDevice.php
16.2 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
use yii\helpers\Url;
use app\ht\helpers\CssFiles;
$this->title = '新建序列号';
$this->params['breadcrumbs'][] = '序列号管理';
$this->params['breadcrumbs'][] = ['label' => '序列号列表', 'url' => ['/device/device/index']];
$this->params['breadcrumbs'][] = $this->title;
CssFiles::register($this, 'exts/showimg/css/showimg.css');
?>
<style>
.create-div .form-group{padding:1rem 0}
.create-div .full-width{width:100%;}
.combo-select{max-width:100% !important;}
.source-cls{padding:1rem 0.5rem; box-sizing: border-box;}
.source-cls .add_way,
.source-cls .append_way{margin-left:1rem;}
.source-cls .upload-cls{position: relative;width:100px;display: inline-block;cursor: pointer}
.source-cls .upload-cls-txt{position: absolute;top:0;left:0;width: 100%;display: inline; padding: 0.5rem 0;text-align: center;}
.source-cls .file-upload-cls{background-color:rgba(0,0,0,0);opacity: 0;max-width: 100px;position: absolute;top: 0;left: 0;z-index: 222;padding: 0.5rem;}
</style>
<div class="panel panel-default">
<div class="panel-body form-inline create-div">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#new" aria-controls="new" role="tab" data-toggle="tab">新创建</a></li>
<li role="presentation"><a href="#append" aria-controls="append" role="tab" data-toggle="tab">追加创建</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="new">
<form action="" method="get" id="create-form" class="filter-form">
<div class="form-group col-sm-12">
<label for="manufacture" class="col-sm-4 control-label text-right">厂商:</label>
<div class="col-sm-4 form-inline">
<select class="form-control full-width select-cls" id="manufacture" name="manufacture">
</select>
</div>
<div class="col-sm-4"><a href="<?=Url::toRoute('/manufacturer/manufacturer/create')?>">+创建厂商</a></div>
</div>
<div class="form-group col-sm-12">
<label for="project" class="col-sm-4 control-label text-right">项目名:</label>
<div class="col-sm-4 form-inline">
<select class="form-control full-width select-cls" id="project" name="project">
</select>
</div>
<div class="col-sm-4"><a href="<?=Url::toRoute('/project/project/create')?>">+创建项目</a></div>
</div>
<div class="form-group col-sm-12">
<label for="model" class="col-sm-4 control-label text-right">设备型号:</label>
<div class="col-sm-4 form-inline">
<select class="form-control full-width select-cls" id="model" name="model">
</select>
</div>
<div class="col-sm-4"><a href="<?=Url::toRoute('/model/model/create')?>">+创建型号</a></div>
</div>
<div class="form-group col-sm-12">
<label for="production" class="col-sm-4 control-label text-right">生产日期:</label>
<div class="col-sm-4 form-inline">
<select class="form-control full-width select-cls" id="production" name="production">
</select>
</div>
<div class="col-sm-4"><a href="<?=Url::toRoute('/production/production/create')?>">+生产日期</a></div>
</div>
<div class="form-group col-sm-12">
<label for="batch_no" class="col-sm-4 control-label text-right">编码预览:</label>
<div class="col-sm-4 form-inline">
<span id="preview_batch_no">----</span>
</div>
</div>
<div class="form-group col-sm-12">
<label for="production" class="col-sm-4 control-label text-right">来源:</label>
<div class="col-sm-4 form-inline">
<div class="source-cls" style="padding-top: 0;">
自动生成
<input type="number" class="form-control" style="max-width: 100px;" id="num" name="num" value="" placeholder="例如:20" autocomplete="off">
<input type="radio" class="form-control add_way" name="add_way" value="1" checked/>
</div>
<div class="source-cls">
导入文件
<span class="upload-cls form-control" ><input type="file" style="max-width: 100px;" class="file-upload-cls" id="file_num" name="file" disabled><span class="upload-cls-txt">点击上传</span></span><input type="radio" class="form-control add_way" name="add_way" value="2" />
<input type="hidden" value="" id="upload_path"> <span style="color:#cc0000">(格式是txt,每行一个mac地址,5M以内)</span>
</div>
</div>
</div>
<div class="form-group col-sm-12" style="text-align: center;">
<div><button type="submit" class="btn btn-primary font-1" id="createDeviceBtn">创建</button></div>
</div>
</form>
</div>
<div role="tabpanel" class="tab-pane" id="append">
<form action="" id="append-form" class="filter-form">
<div class="form-group col-sm-12">
<label for="batch_id" class="col-sm-4 control-label text-right">批次编码:</label>
<div class="col-sm-4 form-inline">
<select class="form-control full-width batch-select-cls" id="batch_id" name="batch_id"></select>
</div>
</div>
<div class="form-group col-sm-12">
<label for="append_num" class="col-sm-4 control-label text-right">来源:</label>
<div class="col-sm-4 form-inline">
<div class="source-cls" style="padding-top: 0;">
追加生成
<input type="number" class="form-control" style="max-width: 100px;" id="append_num" name="append_num" value="" placeholder="例如:20" autocomplete="off">
<input type="radio" class="form-control append_way" name="append_way" value="1" checked/>
</div>
<div class="source-cls">
导入文件
<span class="upload-cls form-control" ><input type="file" style="max-width: 100px;" class="file-upload-cls" id="append_file_num" name="file" disabled><span class="upload-cls-txt">点击上传</span></span><input type="radio" class="form-control append_way" name="append_way" value="2" /> <span style="color:#cc0000">(格式是txt,每行一个mac地址,5M以内)</span>
<input type="hidden" value="" id="append_upload_path">
</div>
</div>
</div>
<div class="form-group col-sm-12" style="text-align: center;">
<div><button type="submit" class="btn btn-primary font-1" id="appendDeviceBtn">追加创建</button></div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="<?= Yii::$app->request->baseUrl . "/exts/base/1.0.0/ui/ajaxfileupload/ajaxfileupload-1.0.0.js"?>"></script>
<script src="<?= Yii::$app->request->baseUrl . "/exts/combo-select/js/jquery.combo.select.js"?>"></script>
<link rel="stylesheet" type="text/css" href="<?= Yii::$app->request->baseUrl . "/exts/combo-select/css/combo.select.css"?>" />
<script type="text/javascript">
var searchItemUrl = "<?=Url::toRoute('/device/device/batch-item')?>";
var saveUrl = "<?=Url::toRoute('/device/device/do-create-device')?>";
var getBatchSelectUrl = "<?=Url::toRoute('/device/device/get-batch-select')?>";
var appendSerialUrl = "<?=Url::toRoute('/device/device/append-serial-no')?>";
var upLoadURL = "<?=Url::toRoute('/device/device/upload-mac')?>";
$(function() {
function selectAll(id) {
$.post(searchItemUrl, {type:id}, function(res) {
if(res.list.length > 0) {
var wrapper = '<option value="">请选择</option>';
$.each(res.list, function(i,n){
wrapper = wrapper + '<option value="'+ n.uid+'">'+ n.name+'</option>';
})
$('#'+id).html(wrapper);
$('#'+id).comboSelect();
}
}, 'json')
}
selectAll('manufacture');
selectAll('project');
selectAll('model');
selectAll('production');
// 追加选批次
function getBatchSelectList() {
$.post(getBatchSelectUrl, {type:0}, function(res) {
if(res.list.length > 0) {
var wrapper = '<option value="">请选择</option>';
$.each(res.list, function(i,n){
wrapper = wrapper + '<option value="'+ n.id+'">'+ n.batch_no+' | '+ n.manufacture + '-' + n.project +'-'+ n.model +'</option>';
})
$('#batch_id').html(wrapper);
$('#batch_id').comboSelect();
}
}, 'json')
}
getBatchSelectList();
$('.select-cls').change(function(e){
var manufacture = $('#manufacture').val();
var project = $('#project').val();
var model = $('#model').val();
var production = $('#production').val();
var manufactureArr = manufacture.split('_');
var projectArr = project.split('_');
var modelArr = model.split('_');
var productionArr = production.split('_');
if (undefined !== manufactureArr[1]) {
manufacture = manufactureArr[1];
} else {
manufacture = '-';
}
if (undefined !== projectArr[1]) {
project = projectArr[1];
} else {
project = '-';
}
if (undefined !== modelArr[1]) {
model = modelArr[1];
} else {
model = '-';
}
if (undefined !== productionArr[1]) {
production = productionArr[1];
} else {
production = '-';
}
$('#preview_batch_no').html(manufacture+ project+ model + production +'');
})
$('#createDeviceBtn').click(function(e) {
e.preventDefault();
var manufacture = $('#manufacture').val();
if ('' == manufacture) {
alert('请选择厂商');
return false;
}
//manufacture = manufacture.split('_');
var project = $('#project').val();
if ('' == project) {
alert('请选择项目');
return false;
}
//project = project.split('_');
var model = $('#model').val();
if ('' == model) {
alert('请选择型号');
return false;
}
//model = model.split('_');
var production = $('#production').val();
if ('' == production) {
alert('请选生产日期');
return false;
}
var type = $('.add_way:checked').val();
var num = $('#num').val();
if (1 == type) {
var par = /^[0-9]+$/;
if (par.test(num) && (num > 0)) {
// 合法的
} else {
alert('请录入大于0的整数');
return false;
}
}
var uploadPath = $('#upload_path').val();
if (2 == type) {
if ("" == uploadPath || null == uploadPath) {
alert('请上传文件');
return false;
}
}
var params = {
manufacture: manufacture,
project: project,
model: model,
production: production,
num: num,
type:type,
upload_path:uploadPath
}
$.post(saveUrl, params, function(res) {
if (!res.success) {
alert(res.message);
return false;
}
alert(res.message);
window.location.href = '<?=Url::toRoute('/datas/device/index')?>'
}, 'json')
})
$('#appendDeviceBtn').click(function(e){
var batch_id = $('#batch_id').val();
var append_num = $('#append_num').val();
if ('' == batch_id || 0 == batch_id) {
alert('请选择批次');
return false;
}
var type = $('.append_way:checked').val();
if (1 == type) {
var par = /^[0-9]+$/;
if (par.test(append_num) && (append_num > 0)) {
// 合法的
} else {
alert('请录入大于0的整数');
return false;
}
if (append_num*1 > 3000) {
alert('追加数量不要超过3000');
return false;
}
}
var uploadPath = $('#append_upload_path').val();
if (2 == type) {
if ("" == uploadPath || null == uploadPath) {
alert('请上传文件');
return false;
}
}
$.post(appendSerialUrl,{
batch_id:batch_id,
append_num:append_num,
type:type,
upload_path:uploadPath
}, function(ajaxRes){
if (ajaxRes.success) {
alert(ajaxRes.message);
window.location.href = '<?=Url::toRoute('/datas/device/index')?>'
} else {
alert(ajaxRes.message);
}
}, 'json')
})
$('.add_way').click(function(e){
var type = $(this).val();
if (1 == type) {
$('#num').removeAttr('disabled');
$('#file_num').prop('disabled', true);
} else {
$('#file_num').removeAttr('disabled');
$('#num').prop('disabled', true);
}
})
$('#file_num').change(function(){
$.ajaxFileUpload({
url: upLoadURL,
fileElementId: "file_num",
dataType: "json",
success: function (res) {
if (res.success) {
$('#upload_path').val(res.path);
alert('成功上传');
} else {
$('#upload_path').val('');
alert(res.message);
}
},
});
})
$('.append_way').click(function(e){
var type = $(this).val();
if (1 == type) {
$('#append_num').removeAttr('disabled');
$('#append_file_num').prop('disabled', true);
} else {
$('#append_file_num').removeAttr('disabled');
$('#append_num').prop('disabled', true);
}
})
$('#append_file_num').change(function(){
$.ajaxFileUpload({
url: upLoadURL,
fileElementId: "append_file_num",
dataType: "json",
success: function (res) {
if (res.success) {
$('#append_upload_path').val(res.path);
alert('成功上传');
} else {
$('#append_upload_path').val('');
alert(res.message);
}
},
});
})
})
</script>