create.php
5.78 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
<?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;
?>
<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"?>" />
<form action="<?php echo Url::toRoute(['/device/brand/do-add']); ?>" 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 text-left form-inline">
<select class="form-control" id="deviceParentCat" name="deviceParentCat"></select>
<select class="form-control" id="deviceChildCat" name="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="">--请选择品牌--</option>
<?php foreach ($brandList as $brand) : ?>
<option value="<?=$brand['id'] ?>" <?php if ($brand_id == $brand['id']){ echo "selected=\"selected\""; } ?> ><?=$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-4 text-left">
<input class="form-control" name="model" id="model">
</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/create")?>">重 置</a>
</div>
</div>
</form>
<script>
$(document).ready(function(){
$("#save").bind("click",function(){
var deviceChildCat = $("#deviceChildCat").val();
var brand_id = $("#brand").val();
var model = $("#model").val();
if (deviceChildCat == null || deviceChildCat == ""){
alert("请选择二级分类");
return false;
}
if (brand_id == null || brand_id == ""){
alert("请选择品牌");
return false;
}
if (model == null || model == ""){
alert("请输入类型");
return false;
}
$.ajax({
type: "post",
url: "do-add",
dataType:"json",
data: $.csrf({"brand_id":brand_id,"cat_id":deviceChildCat,"model":model}),
success:function(msg){
alert(msg['msg']);
if (msg['status'] == 1){
location.href = "<?=Url::toRoute("/device/model/index")?>";
}else{
}
},
error:function(msg){
}
});
});
function loadDeviceParentCat(){
$.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){
}
});
}
loadDeviceParentCat();
//获取子级分类
$("#deviceParentCat").bind("change",function(){
var pid = $(this).val();
$.ajax({
type: "post",
url: "<?=Url::toRoute("/device/model/get-device-cat-list")?>",
dataType:"json",
data: $.csrf({"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{
}
},
error:function(msg){
}
});
});
$('#brand').comboSelect();
});
</script>