batch_create.php
6.41 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
<?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;
?>
<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 class="control-label text-right col-sm-2">品牌:</label>
<div class="text-left col-sm-2">
<select class="form-control " id="brand" name="brand">
<option value="">--请选择品牌--</option>
<?php foreach ($brandList as $brand) : ?>
<option value="<?=$brand['id'] ?>" ><?=$brand['chinese_name'] ?></option>
<?php endforeach; ?>
</select>
</div>
<label class="control-label text-right col-sm-2">品牌:</label>
<div class="text-left col-sm-6 form-inline">
<select class="form-control" id="deviceParentCat" name="deviceParentCat"></select>
<select class="form-control" id="deviceChildCat" name="deviceChildCat"></select>
</div>
</div>
</div>
<div class="panel-body col-sm-12 text-center">
<div class="form-group col-sm-12">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<table class="table no-border" id="table_model">
<tr><th class="text-center">型号</th></tr>
<tr><td><input type="text" class="form-control" name="model"></td></tr>
<tr><td><input type="text" class="form-control" name="model"></td></tr>
<tr><td><input type="text" class="form-control" name="model"></td></tr>
</table>
</div>
<div class="col-sm-3"></div>
</div>
<div class="form-group col-sm-12 text-center">
<button type="button" class="btn btn-success" id="batch_add">继续添加</button>
</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/batch-create")?>">重 置</a>
</div>
</div>
</form>
<script>
$(document).ready(function(){
$("#batch_add").bind("click",function(){
var html = "<tr><td><input type=\"text\" class=\"form-control\" name=\"model\"></td></tr>";
$("#table_model").append(html);
});
$("#save").bind("click",function(){
var modelList=new Array();
$("input[name='model']").each(function(){
var model = $.trim($(this).val());
if (model != null && model != ""){
modelList.push(model);
}
});
if (modelList.length == 0){
alert("请添加型号");
return false;
}
var deviceChildCat = $("#deviceChildCat").val();
var brand_id = $("#brand").val();
if (deviceChildCat == null || deviceChildCat == ""){
alert("请选择二级分类");
return false;
}
if (brand_id == null || brand_id == ""){
alert("请选择品牌");
return false;
}
$.ajax({
type: "post",
url: "do-add-batch",
dataType:"json",
data: $.csrf({"brand_id":brand_id,"cat_id":deviceChildCat,"model":modelList}),
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){
}
});
});
});
</script>