list.jsp
14.3 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<%@include file="/common/CHeader.jsp" %>
<%@page pageEncoding="UTF-8" %>
<body>
<div class="container-fluid">
<div class="row-fluid">
<!-- block -->
<div id="app" class="block">
<div class="block-content collapse in">
<%--------%>
<div class="span6 pull-right" style="margin: 2px 0px 2px 0px">
<button class="btn btn-primary btn-sm pull-right" data-toggle="modal" data-target="#myModal">
选择列
</button>
<button class="btn btn-primary btn-sm pull-right" data-toggle="collapse" data-target="#demo"
style="margin-right: 5px">
搜索列
</button>
</div>
<!--搜索条件,选择搜索字段-->
<div class="col-md-12 collapse in" id="demo" style="padding-left: 3px;padding-right: 0px">
<%--<ul class="list-inline">--%>
<%--<template v-for="(value,key) in singelModel">--%>
<%--<li class="">--%>
<%--<div class="checkbox"><label><input type="checkbox" v-bind:value="key"--%>
<%--v-model="searchProperty" class="checkbox">{{il8message[key]}}</label>--%>
<%--</div>--%>
<%--</li>--%>
<%--</template>--%>
<%--</ul>--%>
<div class="col-md-12" style="padding-right: 0;padding-left: 0;">
<div class="" id="example2_filter">
<template v-for="item in searchProperty">
<div class="col-md-3" style="padding-left: 0;padding-right: 5px;margin-bottom: 10px">
<input class="form-control" v-model="singelModel[item]" type="text"
v-bind:placeholder="il8message[item]"></div>
</template>
<button v-on:click="clickpage('search',$event)" class="btn btn-primary btn-sm pull-right"
style="margin-right: 5px;margin-bottom: 5px">搜索
</button>
</div>
</div>
</div>
<%--------%>
<div class="span12">
<div class="dataTables_wrapper form-inline" role="grid">
<table cellpadding="0" cellspacing="0" border="0"
class="table table-striped table-bordered dataTable" id="example2"
aria-describedby="example2_info">
<thead>
<tr>
<th></th>
<%--取已选择的要显示的字段--%>
<template v-for="keyname in selectedProperty">
<th>{{il8message[keyname]}}</th>
</template>
</tr>
</thead>
<tbody>
<tr v-for="(model,index) in listModel">
<td>{{index+1}}</td>
<template v-for="keyname in selectedProperty">
<td>{{model[keyname]}}</td>
</template>
</tr>
</tbody>
</table>
<%--分页--%>
<div>
<div class="span6 pull-left">
<div class="dataTables_length">
<label>
<select v-model="pageLength" @change="clickpage('select',$event)"
name="pagelength" class="form-control selectpicker">
<option v-for="option in pageOptions" v-bind:value="option.value">
{{option.text}}
</option>
</select>
</label>
<span class="label label-primary" style="height: 20px;line-height: 20px">共{{vpages.count}}条运单记录</span>
<span class="label label-primary" style="height: 20px;line-height: 20px">总重量:{{weightTotal}}</span>
<span class="label label-primary" style="height: 20px;line-height: 20px">总体积:{{volTotal}}</span>
<span class="label label-primary" style="height: 20px;line-height: 20px">总件数:{{pcsTotal}}</span>
<span class="label label-primary" style="height: 20px;line-height: 20px">总分单数:{{hbillqty}}</span>
</div>
</div>
<div class="span6 pull-right">
<div class="dataTables_paginate paging_bootstrap pagination"
style="margin:0px;display: block">
<ul class="pagination pagination-sm pull-right" style="margin:0px" >
<li v-show="currentPage != 1" @click="currentPage-- && clickpage('change',currentPage)" ><a href="#">上一页</a></li>
<li v-for="index in pages" @click="clickpage('change',index)" :class="{'active':currentPage == index}" :key="index">
<a href="javascript:void(0);" >{{index}}</a>
</li>
<li v-show="vpages.total != currentPage && vpages.total != 0 " @click="currentPage++ && clickpage('change',currentPage++)"><a href="#" >下一页</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 模态框(Modal) -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true" style="vertical-align: middle">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
选择列(Column)选项
</h4>
</div>
<div class="modal-body">
<ul class="list-inline">
<template v-for="(value,key) in singelModel">
<li class="">
<div class="checkbox"><label><input type="checkbox" v-bind:value="key"
v-model="selectedProperty"
class="checkbox">{{il8message[key]}}</label>
</div>
</li>
</template>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">
选择完毕
</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
</div>
<!-- /block -->
</div>
</div>
<script>
var vm = new Vue({
el: '#app',
//需要注入的模板的父元素
data: {
listModel: [], //对象列表
singelModel: [], //对象
vpages: [],
currentPage: [],
pageLength: '10', //默认每页显示几条数据
showItem:5, //分页显示几页
pageOptions: [
{text: '每页2条', value: '2'},
{text: '每页4条', value: '4'},
{text: '每页10条', value: '10'},
{text: '每页50条', value: '50'},
{text: '每页100条', value: '100'}
],
//字段中英文对照表
il8message: il8message.kpi,
//存储已选择的要显示表格里面的列名
selectedProperty: ["domint","airline1","waybilltype","agentid","carrycost","carryrate"],
//存储已选择的要作为搜索条件的字段名,可预置
searchProperty: ["waybilltype","waybillpre","domint","airline1","agentid","operdepartid","shprname","productid","productname","curyear","curmonth","curweek","endyear","endmonth","endweek"],
weightTotal:0, //总重量
volTotal:0, //总体积
pcsTotal:0, //总件数
hbillqty:0, //分单总数
}, //end data
created: function () {
var initPara = {begin: 0, length: this.pageLength};
$.ajax({
type: 'POST',
url: "list.json",
data: initPara,
// dataType: 'json',
// contentType: "application/json",
success: function (data) {
vm.vpages = data.page; //总页码
vm.listModel = data.model;//循环内容
vm.weightTotal = data.totals.weight;
vm.volTotal = data.totals.vol;
vm.pcsTotal = data.totals.pcs;
vm.hbillqty =data.totals.hbillqty;
vm.singelModel = data.model[0]; //取出一个对象
vm.currentPage = data.page.current;//当前页(添加高亮样式)
},
});
this.singelModel = setObjProp2Null(this.singelModel);
}, //created
computed:{
pages:function(){
var pag = [];
if( this.currentPage < this.showItem ){ //如果当前的激活的项 小于要显示的条数
//总页数和要显示的条数那个大就显示多少条
var i = Math.min(this.showItem,this.vpages.total);
while(i){
pag.unshift(i--);
}
}else{ //当前页数大于等于显示页数了
var middle = this.currentPage - Math.floor(this.showItem / 2 ),//从哪里开始
i = this.showItem;
if( middle > (this.vpages.total - this.showItem) ){
middle = (this.vpages.total - this.showItem) + 1
}
while(i--){
pag.push( middle++ );//填充页数
}
}
return pag
}
},
methods: {
/**
*
* @param type 点击绑定的类型,(前一页,后一页,被选择的页数,搜索)
* @param event 绑定事件
*/
clickpage: function (type,index) {
var currentPage, begin, page, lenth;
currentPage = parseInt(vm.currentPage); //取当前页
lenth = parseInt(vm.pageLength);
//前一页 后一页 搜索,前一页取默认就行 所以不判断
switch (type) {
case "search":
currentPage = 0; //搜索归零起始页面
begin = currentPage * lenth; //计算数据开始位置,
break;
case "change"://选择页面判断
currentPage = index;
begin = (parseInt(currentPage) - 1) * lenth;
break;
case "select": //更换页面数量
begin = vm.vpages.begin;
break;
}
page = {
begin: begin,
length: lenth
};
var para = page;
var gettype = Object.prototype.toString;
//搜索条件
vm.searchProperty.forEach(function (val, index) {
para[val] = vm.singelModel[val];
});
$.ajax({
type: 'POST',
url: "list.json",
data: para,
// dataType: 'json',
// contentType: "application/json",
success: function (data) {
vm.listModel = data.model;
vm.vpages = data.page;
vm.currentPage = data.page.current;
vm.weightTotal = data.totals.weight;
vm.volTotal = data.totals.vol;
vm.pcsTotal = data.totals.pcs;
vm.hbillqty =data.totals.hbillqty;
console.log(data);
},
});
},
/**
* 计算总重量,体积,件数
*/
count:function () {
for(var i=0;i<vm.listModel.length;i++){
vm.weightTotal += checkNum(Number(vm.listModel[i].weight));
vm.volTotal += checkNum(Number(vm.listModel[i].vol));
vm.pcsTotal += checkNum(Number(vm.listModel[i].pcs));
}
},
}
}); //end vue
</script>
</body>
</html>