create.php
6.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
<?php
use yii\helpers\Url;
$this->title = '添加故障';
$this->params['breadcrumbs'][] = '设备管理';
$this->params['breadcrumbs'][] = ['label' => '故障管理', 'url' => ['/device/fault/index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<form action="" name="brandForm" id="brandForm" method="post" enctype="multipart/form-data">
<div class="panel panel-default">
<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 form-inline">
<select class="form-control" id="deviceParentCat"></select>
<select class="form-control" id="deviceChildCat"></select>
</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">
<select class="form-control" id="brand" name="brand">
<option value="0">--请选择品牌--</option>
<?php /*foreach ($brandList as $brand) : */?>
<option value="<?/*=$brand['id'] */?>"><?/*=$brand['chinese_name'] */?></option>
<?php /*endforeach; */?>
</select>
</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-5">
<input type="text" class="form-control" id="faultName">
</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 form-inline">
<label class="checkbox-inline">
<input type="checkbox" id="isCommon" name="isCommon" value="1">常见
</label>
</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">
<input type="text" class="form-control" id="sortOrder">
</div>
</div>
</div>
<div class="panel-footer text-center">
<button type="button" class="btn btn-primary ladda-button" data-style="slide-up" id="save">提 交</button>
<a class="btn btn-default" href="<?=Url::toRoute("/device/fault/create")?>">重 置</a>
</div>
</div>
</form>
<script>
$(document).ready(function(){
function loadParentCat(){
$.ajax({
type: "post",
url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
dataType:"json",
data: $.csrf({"parentId":0}),
success:function(msg){
if (msg['status'] == 1){
var data = eval(msg['modelList']);
var html = "";
for(var s in data){
html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
}
$("#deviceParentCat").html(html);
$("#deviceParentCat").trigger("change");
}else{
$("#deviceParentCat").html("<option value='0'>--无一级类型--</option>");
$("#deviceChildCat").html("<option value='0'>--无二级类型--</option>");
}
},
error:function(msg){
//提示确认失败
showToast("加载异常");
}
});
}
loadParentCat();
//获取子级分类
$("#deviceParentCat").bind("change",function(){
var pid = $(this).val();
var brandId = $("#brand").val();
$.ajax({
type: "post",
url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
dataType:"json",
data: $.csrf({"brandId":brandId,"parentId":pid}),
success:function(msg){
if (msg['status'] == 1){
var data = eval(msg['modelList']);
var html = "";
for(var s in data){
html = html +"<option value='"+data[s]['id']+"'>"+data[s]['name']+"</option>";
}
$("#deviceChildCat").html(html);
}else{
showToast("加载失败");
}
},
error:function(msg){
//提示确认失败
showToast("加载异常");
}
});
});
$("#save").bind("click",function(){
var deviceParentCat = $("#deviceParentCat").val();
var deviceChildCat = $("#deviceChildCat").val();
var faultName = $("#faultName").val();
var isCommon = $("#isCommon").val();
var sortOrder = $("#sortOrder").val();
if (deviceChildCat == null || deviceChildCat == "" || deviceChildCat == 0){
alert("无法添加故障信息,请选择设备类型");
return false;
}
var l = $.ladda(this);
$.ajax({
type: "post",
url: "do-add",
dataType:"json",
data: $.csrf({"parentId":deviceParentCat,"childId":deviceChildCat,"faultName":faultName,"isCommon":isCommon,"sortOrder":sortOrder}),
success:function(msg){
alert(msg['msg']);
if (msg['status'] == 1){
location.href = "<?=Url::toRoute("/device/fault/index")?>";
}else{
}
},
beforeSend: function () {
// 开始显示
l.start();
},
complete: function () {
// 取消加载提示
l.stop();
},
error:function(msg){
//提示确认失败
}
});
});
});
</script>