taskStatistics.html
8.96 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
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body>
<div id="myTabContent" class="tab-content" style="width:auto;height: auto ">
<div class="tab-pane fade in active" id="tabHeader">
<div class="col-sm-12 select-info">
<form id="task-form">
<div class="select-list">
<ul>
<li class="time" style="height: 30px">
<label>创建时间: </label>
<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="startTime" readonly/>
<span>-</span>
<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime" readonly/>
</li>
<li>
任务类型:<select class="seType" name="type" th:with="type=${@dict.getType('taskType')}">
<option value="">所有</option>
<option th:each="e : ${type}" th:text="${e['dictLabel']}"
th:value="${e['dictValue']}"></option>
</select>
</li>
<li>
<a class="btn btn-primary btn-rounded btn-sm btnQuery"><i class="fa fa-search"></i> 搜索</a>
</li>
</ul>
</div>
</form>
</div>
</div>
</div>
<br><br><br><br>
<div id="inventoryEle" style="width: 105%;height: 90%;"></div>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div th:include="include :: footer"></div>
<script th:src="@{/js/echarts/echarts.js}"></script>
<script type="text/javascript">
/* 数组去掉重复*/
Array.prototype.unique5 = function () {
let x = new Set(this);
return [...x];
}
/*时间差*/
String.prototype.GetDateDiff = function (statr, end) {
if (statr == null || end == null) return "";
var diff = new Date(end).getTime() - new Date(statr).getTime(); //时间差的毫秒数
//计算出相差天数
var days = Math.floor(diff / (24 * 3600 * 1000));
//计算出小时数
var leave1 = diff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
var hours = Math.floor(leave1 / (3600 * 1000));
//计算相差分钟数
var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
var minutes = Math.floor(leave2 / (60 * 1000));
//计算相差秒数
var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
var seconds = Math.round(leave3 / 1000);
var value = "";
if (days != 0) value = days + "天";
if (hours != 0) value += hours + "小时";
if (minutes != 0) value += minutes + "分钟";
if (seconds != 0) value += seconds + "秒";
return value;
}
var prefix = ctx + "inventory/report";
let app = {
data: {
urlInventory: prefix + "/task",
echarts: {
opt: {
inventory: {
legend: {},
tooltip: {},
title: {
text: '任务统计报表'
},
dataset: {
dimensions: ['product'],
source: []
},
xAxis: {
type: 'category',
name : '创建时间'
},
yAxis: {
name: '任务数量'
},
series: []
}
},
ele: {
inventoryEle: document.querySelector("#inventoryEle"),
},
data: {
xAxisData: [],
seriesData: [],
legendTitle: ""
}
},
inventoryEchartsObj: null,
startTimeEle: document.querySelector("#startTime"),
endTimeEle: document.querySelector("#endTime"),
seTypeEle: document.querySelector(".seType"),
dimensionsRel: {
"100": "整盘入库",
"200": "补充入库",
"300": "整盘出库",
"400": "分拣出库",
"500": "空容器入库",
"600": "空容器出库",
"700": "盘点",
"800": "移库",
"900": "出库查看",
}
},
methods: {
getData: function (bodyValue) {
let seType = app.data.seTypeEle.value;
let startTime = app.data.startTimeEle.value;
let endTime = app.data.endTimeEle.value;
let url = "";
if (seType === "") {
url = `${app.data.urlInventory}?startTime=${startTime}&endTime=${endTime}`;
} else {
url = `${app.data.urlInventory}?taskType=${seType}&startTime=${startTime}&endTime=${endTime}`;
}
fetch(url,
{
method: "post",
headers: new Headers({
"Content-Type": "json"
})
}).then(function (res) {
return res.json();
}).then(function (data) {
console.log(data);
app.methods.initValue(data);
app.methods.initEcharts();
}).catch(function (error) {
alert(error);
});
},
initEcharts: function () {
if (app.data.inventoryEchartsObj == null)
app.data.inventoryEchartsObj = echarts.init(app.data.echarts.ele.inventoryEle);
//清空
app.data.inventoryEchartsObj.clear();
app.data.inventoryEchartsObj.setOption(app.data.echarts.opt.inventory);
},
initValue: function (json) {
if (json == null) return;
let source = [];
let dimensions = ['product'];
let seriesLen = 1;
for (let i = 0; i < json.length; i++) {
const created = json[i].created;
let tempSource = []
for (let j = 0; j < json[i].list.length; j++) {
//后台返回的 taskType 值要存在 dimensionsRel
let keys = json[i].list[j].taskType;
let typeName = app.data.dimensionsRel[keys];
dimensions.push(typeName);
var obj = {};
obj.product = created;
let arrIndex = source.findIndex(x => x.product == created);
if (arrIndex !== -1) {
source[arrIndex][typeName] = json[i].list[j].count;
} else {
obj[typeName] = json[i].list[j].count;
source.push(obj);
}
}
seriesLen = json[0].seriesLen;
}
let setType = app.data.seTypeEle.value;
app.data.echarts.opt.inventory.series = [];
if (setType == "") {
app.data.echarts.opt.inventory.series = [{type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}, {type: 'bar'}];
} else {
app.data.echarts.opt.inventory.series.push({type: 'bar'})
}
app.data.echarts.opt.inventory.dataset.dimensions = dimensions.unique5();
app.data.echarts.opt.inventory.dataset.source = source;
}
},
registerEvent: function () {
let btn = document.querySelector('.btnQuery');
btn.addEventListener('click', function () {
let startTime = document.querySelector("#startTime").value;
let endTime = document.querySelector("#endTime").value;
let day = "".GetDateDiff(startTime, endTime).replace("天", "");
if (parseInt(day) > 8) {
alert("日期范围请在一周内!")
return;
}
app.methods.getData();
})
},
init: function () {
setTimeout(() => {
app.methods.getData();
}, 1000)
app.registerEvent();
}
};
app.init();
</script>
</body>
</html>