update.php
5.46 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
<?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-5">
<input type="text" class="form-control" id="faultName" value="<?=$fault['name'] ?>">
<input type="hidden" value="<?=$fault['id'] ?>" id="faultId">
</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">
<select class="form-control" id="deviceParentCat">
<?php foreach ($deviceCatParentList as $deviceCatParent) : ?>
<option value="<?=$deviceCatParent['id'] ?>" <?php if ($catPid == $deviceCatParent['id']){ echo "selected"; } ?>><?=$deviceCatParent['name'] ?></option>
<?php endforeach; ?>
</select>
<select class="form-control" id="deviceChildCat">
<?php foreach ($deviceCatChildList as $deviceCatChild) : ?>
<option value="<?=$deviceCatChild['id'] ?>" <?php if ($catId == $deviceCatChild['id']){ echo "selected"; } ?>><?=$deviceCatChild['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-4 form-inline">
<select class="form-control" id="isCommon" name="isCommon">
<option value="1" <?php if ($fault['is_common'] == 1){ echo "selected"; } ?>>是</option>
<option value="0" <?php if ($fault['is_common'] == 0){ echo "selected"; } ?>>否</option>
</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">
<input type="text" class="form-control" id="sortOrder" value="<?=$fault['sort_order'] ?>" />
</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/fault/create")?>">重 置</a>
</div>
</div>
</form>
<script>
$(document).ready(function(){
//获取子级分类
$("#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 faultId = $("#faultId").val();
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;
}
$.ajax({
type: "post",
url: "do-update",
dataType:"json",
data: $.csrf({"faultId":faultId,"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{
}
},
error:function(msg){
//提示确认失败
}
});
});
});
</script>