瑞利声电固定资产管理系统
ycq
2026-10-16 dbbadb021c2fc171466cc82bd9a7a82cc47165f5
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<%@ page language="java" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>资产统计分析</title>
    <link href="static/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="static/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="static/plugins/echarts/echarts.min.js"></script>
    <style>
        .viz-root {
            --surface-1: #fcfcfb;
            --page: #f9f9f7;
            --text-primary: #0b0b0b;
            --text-secondary: #52514e;
            --text-muted: #898781;
            --grid: #e1e0d9;
            --axis: #c3c2b7;
            --border: rgba(11, 11, 11, 0.10);
            --critical: #d03b3b;
            --warning: #fab219;
            --series-1: #2a78d6;
        }
        html, body { margin: 0; background: #f9f9f7; }
        .viz-root { font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; color: var(--text-primary); padding: 16px; box-sizing: border-box; }
        .head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
        .head h1 { font-size: 18px; margin: 0; font-weight: 600; }
        .head .scope { color: var(--text-secondary); font-size: 13px; }
        .head label { font-size: 13px; color: var(--text-secondary); cursor: pointer; }
        .btn { font-size: 13px; padding: 4px 12px; border: 1px solid var(--axis); border-radius: 4px; background: var(--surface-1); cursor: pointer; color: var(--text-primary); }
        .btn:hover { border-color: var(--series-1); color: var(--series-1); }
        .tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
        .tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
        .tile .label { font-size: 12px; color: var(--text-secondary); }
        .tile .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
        .tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
        .tile .status { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
        .tile .status i { font-size: 13px; }
        .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
        .card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; min-width: 0; }
        .card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
        .card h2 { font-size: 14px; margin: 0; font-weight: 600; }
        .card .desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
        .toggle { font-size: 12px; color: var(--series-1); cursor: pointer; white-space: nowrap; }
        .chart { height: 300px; }
        .table-view { display: none; max-height: 300px; overflow: auto; }
        table { width: 100%; border-collapse: collapse; font-size: 13px; }
        th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; }
        th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }
        td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
        .empty { color: var(--text-muted); font-size: 13px; padding: 40px 0; text-align: center; }
        @media (max-width: 520px) { .grid { grid-template-columns: 1fr; } }
    </style>
</head>
<body>
<div class="viz-root">
    <div class="head">
        <h1>资产统计分析</h1>
        <span class="scope" id="scope"></span>
        <label><input type="checkbox" id="includeScrapped"> 分布统计包含报废资产</label>
        <button class="btn" id="refresh"><i class="fa fa-refresh"></i> 刷新</button>
    </div>
 
    <div class="tiles" id="tiles"></div>
 
    <div class="grid">
        <div class="card" data-chart="state">
            <div class="card-head"><div><h2>资产状态分布</h2><div class="desc">各状态资产数量(含报废)</div></div><span class="toggle">查看表格</span></div>
            <div class="chart"></div><div class="table-view"></div>
        </div>
        <div class="card" data-chart="categoryCount">
            <div class="card-head"><div><h2>一级类别 · 资产数量</h2><div class="desc">按一级类别汇总的资产件数</div></div><span class="toggle">查看表格</span></div>
            <div class="chart"></div><div class="table-view"></div>
        </div>
        <div class="card" data-chart="categoryValue">
            <div class="card-head"><div><h2>一级类别 · 资产原值</h2><div class="desc">按一级类别汇总的原值(元)</div></div><span class="toggle">查看表格</span></div>
            <div class="chart"></div><div class="table-view"></div>
        </div>
        <div class="card" data-chart="dept">
            <div class="card-head"><div><h2>使用部门 · 资产数量 TOP 10</h2><div class="desc">资产最多的十个部门</div></div><span class="toggle">查看表格</span></div>
            <div class="chart"></div><div class="table-view"></div>
        </div>
        <div class="card" data-chart="monthly">
            <div class="card-head"><div><h2>近 12 个月资产流转</h2><div class="desc">每月流转记录条数,按业务类型堆叠</div></div><span class="toggle">查看表格</span></div>
            <div class="chart"></div><div class="table-view"></div>
        </div>
        <div class="card" data-chart="receipts">
            <div class="card-head"><div><h2>近 12 个月采购入库金额</h2><div class="desc">已确认入库的金额(元)</div></div><span class="toggle">查看表格</span></div>
            <div class="chart"></div><div class="table-view"></div>
        </div>
        <div class="card" data-chart="expire">
            <div class="card-head"><div><h2>到期统计</h2><div class="desc" id="expireDesc"></div></div></div>
            <div class="table-view" style="display:block;"></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    // 分类色按固定顺序取用(经 dataviz 校验器验证的参考调色板前 6 槽,浅色模式)
    var SERIES = ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300'];
    var INK = {primary: '#0b0b0b', secondary: '#52514e', muted: '#898781', grid: '#e1e0d9', axis: '#c3c2b7', surface: '#fcfcfb'};
    var charts = {};
 
    $(function () {
        $('#refresh').on('click', load);
        $('#includeScrapped').on('change', load);
        $('.card').on('click', '.toggle', function () {
            var $card = $(this).closest('.card');
            var showTable = $card.find('.table-view').is(':hidden');
            $card.find('.table-view').toggle(showTable);
            $card.find('.chart').toggle(!showTable);
            $(this).text(showTable ? '查看图表' : '查看表格');
            if (!showTable) {
                charts[$card.data('chart')] && charts[$card.data('chart')].resize();
            }
        });
        $(window).on('resize', function () {
            $.each(charts, function (k, c) { c.resize(); });
        });
        load();
    });
 
    function num(v) {
        var n = Number(v);
        return isNaN(n) ? 0 : n;
    }
 
    function money(v) {
        return num(v).toLocaleString('zh-CN', {minimumFractionDigits: 2, maximumFractionDigits: 2});
    }
 
    function count(v) {
        return num(v).toLocaleString('zh-CN');
    }
 
    function load() {
        $.get('fams/stat/data', {includeScrapped: $('#includeScrapped').prop('checked')}, function (res) {
            if (!res || !res.success) {
                $('#tiles').text((res && res.error && res.error.message) || '统计数据加载失败');
                return;
            }
            render(res.result);
        });
    }
 
    function render(d) {
        $('#scope').text(d.includeScrapped ? '口径:含报废资产' : '口径:不含报废资产(状态分布除外)');
        renderTiles(d.kpi, num(d.daysAhead));
        var states = d.byState;
        hbar('state', states, 'count', '件', count);
        table('state', ['资产状态', '数量', '原值(元)'], $.map(states, function (r) { return [[r.name, count(r.count), money(r.amount)]]; }), [1, 2]);
        hbar('categoryCount', d.byCategory, 'count', '件', count);
        hbar('categoryValue', d.byCategory, 'amount', '元', money);
        var catRows = $.map(d.byCategory, function (r) { return [[r.name, count(r.count), money(r.amount)]]; });
        table('categoryCount', ['一级类别', '数量', '原值(元)'], catRows, [1, 2]);
        table('categoryValue', ['一级类别', '数量', '原值(元)'], catRows, [1, 2]);
        hbar('dept', d.byDept, 'count', '件', count);
        table('dept', ['使用部门', '数量', '原值(元)'], $.map(d.byDept, function (r) { return [[r.name, count(r.count), money(r.amount)]]; }), [1, 2]);
        monthly(d.monthly);
        receipts(d.receipts);
        expire(d.expire, num(d.daysAhead));
    }
 
    function renderTiles(k, days) {
        var $t = $('#tiles').empty();
        tile($t, '资产总数', count(k.total), '件');
        tile($t, '原值合计', money(k.value), '元');
        tile($t, '在用', count(k.inUse), '件');
        tile($t, '闲置', count(k.idle), '件');
        tile($t, '借用 / 封存 / 维修', count(k.borrowed) + ' / ' + count(k.sealed) + ' / ' + count(k.repair), '件');
        statusTile($t, '已过期', count(k.overdue), 'fa-exclamation-circle', '#d03b3b', '需尽快处理');
        statusTile($t, days + ' 天内到期', count(k.dueSoon), 'fa-clock-o', '#fab219', '即将到期');
    }
 
    function tile($t, label, value, unit) {
        var $tile = $('<div class="tile"></div>');
        $tile.append($('<div class="label"></div>').text(label));
        $tile.append($('<div class="value"></div>').text(value));
        $tile.append($('<div class="sub"></div>').text(unit));
        $t.append($tile);
    }
 
    // 状态色只用于图标,并且总配文字标签,不单靠颜色表达
    function statusTile($t, label, value, icon, iconColor, statusText) {
        var $tile = $('<div class="tile"></div>');
        $tile.append($('<div class="label"></div>').text(label));
        $tile.append($('<div class="value"></div>').text(value));
        var $status = $('<div class="sub status"></div>');
        $status.append($('<i class="fa"></i>').addClass(icon).css('color', iconColor));
        $status.append($('<span></span>').text(statusText));
        $tile.append($status);
        $t.append($tile);
    }
 
    function chartOf(key) {
        var el = $('.card[data-chart=' + key + '] .chart')[0];
        if (!charts[key]) {
            charts[key] = echarts.init(el);
        }
        return charts[key];
    }
 
    function emptyChart(key, text) {
        var c = chartOf(key);
        c.clear();
        c.setOption({title: {text: text, left: 'center', top: 'middle', textStyle: {color: INK.muted, fontSize: 13, fontWeight: 'normal'}}});
    }
 
    function axisStyle() {
        return {
            axisLine: {lineStyle: {color: INK.axis}},
            axisTick: {show: false},
            axisLabel: {color: INK.muted},
            splitLine: {lineStyle: {color: INK.grid}}
        };
    }
 
    // 单系列横向条形图:最大的在上,数值标在条末端,悬停显示详情
    function hbar(key, rows, field, unit, fmt) {
        if (!rows || !rows.length) {
            emptyChart(key, '暂无数据');
            return;
        }
        var names = $.map(rows, function (r) { return r.name; });
        var values = $.map(rows, function (r) { return num(r[field]); });
        var c = chartOf(key);
        c.clear();
        c.setOption({
            grid: {left: 8, right: 64, top: 8, bottom: 8, containLabel: true},
            tooltip: {trigger: 'item', formatter: function (p) { return p.name + ':' + fmt(p.value) + ' ' + unit; }},
            xAxis: $.extend({type: 'value'}, axisStyle(), {axisLabel: {color: INK.muted, formatter: function (v) { return fmt(v).replace('.00', ''); }}}),
            yAxis: $.extend({type: 'category', data: names, inverse: true}, axisStyle(), {splitLine: {show: false}, axisLabel: {color: INK.secondary}}),
            series: [{
                type: 'bar', data: values, barMaxWidth: 18,
                itemStyle: {color: SERIES[0], barBorderRadius: [0, 4, 4, 0]},
                label: {show: true, position: 'right', color: INK.secondary, formatter: function (p) { return fmt(p.value); }},
                emphasis: {itemStyle: {color: '#256abf'}}
            }]
        });
    }
 
    function monthly(m) {
        var key = 'monthly';
        var total = 0;
        $.each(m.series, function (i, s) { $.each(s.data, function (j, v) { total += num(v); }); });
        if (!total) {
            emptyChart(key, '近 12 个月暂无流转记录');
        } else {
            var c = chartOf(key);
            c.clear();
            c.setOption({
                color: SERIES,
                legend: {top: 0, left: 0, itemWidth: 10, itemHeight: 10, icon: 'roundRect', textStyle: {color: INK.secondary}},
                grid: {left: 8, right: 8, top: 34, bottom: 8, containLabel: true},
                tooltip: {trigger: 'axis', axisPointer: {type: 'shadow', shadowStyle: {color: 'rgba(11,11,11,0.04)'}}},
                xAxis: $.extend({type: 'category', data: m.months}, axisStyle(), {splitLine: {show: false}}),
                yAxis: $.extend({type: 'value', minInterval: 1}, axisStyle()),
                series: $.map(m.series, function (s) {
                    // 1px 描边叠加形成段间 2px 表面色间隙
                    return {name: s.name, type: 'bar', stack: 'total', barMaxWidth: 22, data: $.map(s.data, num),
                        itemStyle: {borderColor: INK.surface, borderWidth: 1}};
                })
            });
        }
        var header = ['月份'].concat($.map(m.series, function (s) { return s.name; }));
        var rows = $.map(m.months, function (month, i) {
            return [[month].concat($.map(m.series, function (s) { return count(s.data[i]); }))];
        });
        var numCols = [];
        for (var i = 1; i < header.length; i++) { numCols.push(i); }
        table(key, header, rows, numCols);
    }
 
    function receipts(r) {
        var key = 'receipts';
        var amounts = $.map(r.amounts, num);
        var total = 0;
        $.each(amounts, function (i, v) { total += v; });
        if (!total) {
            emptyChart(key, '近 12 个月暂无采购入库');
        } else {
            var c = chartOf(key);
            c.clear();
            c.setOption({
                grid: {left: 8, right: 8, top: 16, bottom: 8, containLabel: true},
                tooltip: {trigger: 'axis', axisPointer: {type: 'shadow', shadowStyle: {color: 'rgba(11,11,11,0.04)'}},
                    formatter: function (ps) { var i = ps[0].dataIndex; return r.months[i] + '<br>入库金额:' + money(amounts[i]) + ' 元<br>入库资产:' + count(r.counts[i]) + ' 件'; }},
                xAxis: $.extend({type: 'category', data: r.months}, axisStyle(), {splitLine: {show: false}}),
                yAxis: $.extend({type: 'value'}, axisStyle()),
                series: [{type: 'bar', data: amounts, barMaxWidth: 22, itemStyle: {color: SERIES[0], barBorderRadius: [4, 4, 0, 0]}}]
            });
        }
        table(key, ['月份', '入库资产(件)', '入库金额(元)'], $.map(r.months, function (m, i) { return [[m, count(r.counts[i]), money(r.amounts[i])]]; }), [1, 2]);
    }
 
    function expire(rows, days) {
        $('#expireDesc').text('已过期与 ' + days + ' 天内到期的资产件数(不含报废);明细见「到期提醒」菜单');
        table('expire', ['到期类型', '已过期', days + ' 天内到期'], $.map(rows, function (r) { return [[r.type, count(r.overdue), count(r.soon)]]; }), [1, 2]);
    }
 
    function table(key, header, rows, numCols) {
        var $box = $('.card[data-chart=' + key + '] .table-view').empty();
        if (!rows.length) {
            $box.append($('<div class="empty"></div>').text('暂无数据'));
            return;
        }
        var $table = $('<table></table>');
        var $tr = $('<tr></tr>');
        $.each(header, function (i, h) { $tr.append($('<th></th>').text(h).toggleClass('num', numCols.indexOf(i) >= 0)); });
        $table.append($('<thead></thead>').append($tr));
        var $body = $('<tbody></tbody>');
        $.each(rows, function (r, row) {
            var $row = $('<tr></tr>');
            $.each(row, function (i, cell) { $row.append($('<td></td>').text(cell).toggleClass('num', numCols.indexOf(i) >= 0)); });
            $body.append($row);
        });
        $box.append($table.append($body));
    }
</script>
</body>
</html>