combine.php
4.44 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
<?php
use yii\helpers\Url;
$this->title = '合并设备型号';
$this->params['breadcrumbs'][] = '设备管理';
$this->params['breadcrumbs'][] = ['label' => '设备列表', 'url' => ['/device/device/index']];
$this->params['breadcrumbs'][] = ['label' => '型号管理', 'url' => ['/device/model/index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="panel panel-default">
<div id="warning"></div>
<div class="panel-body">
<div class="form-group col-sm-12">
<label for="skillName" class="col-sm-4 control-label text-right">需合并的型号(删除):</label>
<div class="col-sm-4 text-left">
<input type="text" class="form-control" name="needbindmodel" id="needbindmodel"/>
</div>
</div>
<div class="form-group col-sm-12">
<label for="skillName" class="col-sm-4 control-label text-right">合并到的型号(保留):</label>
<div class="col-sm-4 text-left">
<input type="text" class="form-control" name="bindtomodel" id="bindtomodel"/>
</div>
</div>
</div>
<div class="panel-footer text-center">
<button type="button" class="btn btn-primary" id="save">提 交</button>
<a class="btn btn-default" href="<?=Url::toRoute("/device/model/combine")?>">重 置</a>
</div>
</div>
<script type="text/javascript" src="<?=Url::toRoute('/exts/base/1.0.0/ui/typeahead/bootstrap3-typeahead.min.js')?>" ></script>
<script>
var searchItemUrl = "<?=Url::toRoute('/device/model/search-model')?>";
$(document).ready(function(){
$("#save").bind("click",function(){
var needbindmodel = $("#needbindmodel").val();
var bindtomodel = $("#bindtomodel").val();
if (needbindmodel == ""){
alertWaringMsg("请填写需要合并的设备型号");
$("#needbindmodel").focus();
return false;
}
if (bindtomodel == ""){
alertWaringMsg("请填写合并到的设备型号");
$("#bindtomodel").focus();
return false;
}
if (needbindmodel == bindtomodel){
alertWaringMsg("需要合并设备型号和合并到的设备型号不能相同");
$("#bindtomodel").focus();
return false;
}
$.ajax({
type: "post",
url: "<?=Url::toRoute("/device/model/do-combine")?>",
dataType:"json",
data: $.csrf({"needbindmodel":needbindmodel,"bindtomodel":bindtomodel}),
success:function(msg){
alert(msg['msg']);
if (msg['status'] == 1){
location.href="<?php echo Url::toRoute('/device/model/index'); ?>";
}
},
error:function(msg){
}
});
});
$('#needbindmodel,#bindtomodel').typeahead({
minLength: 2,
source: function(query, process) {
var parameter = {query: query};
$.post(searchItemUrl, parameter, function (res) {
var data = [];
var iList = res.list;
for(i in iList){
var tItem = iList[i];
data.push(JSON.stringify(tItem));
}
process(data);
},'json');
},
highlighter: function(item) {
var itemObject = JSON.parse(item);
var title = itemObject.model;
return title ;
},
updater: function(item) {
var itemObject = JSON.parse(item);
var title = itemObject.model;
selectItemInfo(itemObject);
return title;
}
});
function selectItemInfo(item){
$('#deviceParentCat').val(item.model);
}
//显示警告信息
function alertWaringMsg(showmsg){
var htmltext = "<div class='alert alert-warning' style='margin-bottom:0px;display:block" +
"'>" +
" <a href='#' class='close' data-dismiss='alert'>" +
" ×" +
" </a>" +
" <strong>提示!</strong>"+showmsg+"。" +
" </div>";
$("#warning").html(htmltext);
}
});
</script>