Compare commits
5 Commits
8050b65ea8
...
8cf96126fe
Author | SHA1 | Date | |
---|---|---|---|
8cf96126fe | |||
9808821b70 | |||
d3878d3358 | |||
2a746146f0 | |||
![]() |
cedff04447 |
@ -1,4 +1,4 @@
|
||||
# 开发环境
|
||||
# 请求接口地址
|
||||
VITE_REQUEST_BASE_URL = https://36.112.48.190
|
||||
#VITE_REQUEST_BASE_URL = http://10.75.15.247:8080
|
||||
#VITE_REQUEST_BASE_URL = http://10.75.15.247:8080
|
||||
|
16
api/common.js
Normal file
16
api/common.js
Normal file
@ -0,0 +1,16 @@
|
||||
import {
|
||||
https
|
||||
} from '@/utils/http.js';
|
||||
/*
|
||||
这是后端系统通用的系统类的基础性的api路径,后续的大家分类建js存放
|
||||
*/
|
||||
|
||||
|
||||
|
||||
export function initDictOption(dictCode) { // 获取部门所有人员信息
|
||||
return https({
|
||||
url: ' /sys/dict/getDictItems',
|
||||
method: 'get',
|
||||
data: dictCode
|
||||
})
|
||||
}
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -19,7 +19,7 @@
|
||||
},
|
||||
"node_modules/base-64": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/base-64/-/base-64-1.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz",
|
||||
"integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg=="
|
||||
},
|
||||
"node_modules/dayjs": {
|
||||
@ -61,7 +61,7 @@
|
||||
},
|
||||
"base-64": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/base-64/-/base-64-1.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/base-64/-/base-64-1.0.0.tgz",
|
||||
"integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg=="
|
||||
},
|
||||
"dayjs": {
|
||||
|
@ -12,33 +12,31 @@
|
||||
</uni-card>
|
||||
|
||||
<uni-card :is-shadow="false">
|
||||
<button type="primary" @click="toQtTongji">其他统计</button>
|
||||
<button type="primary" @click="toQtTongji">通用字段统计</button>
|
||||
</uni-card>
|
||||
</uni-section>
|
||||
</uni-card>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
function toTaizhang() {
|
||||
uni.navigateTo({
|
||||
url: "/pages/views/renliziyuan/renyuanxinxi/taizhang"
|
||||
})
|
||||
url: '/pages/views/renliziyuan/renyuanxinxi/taizhang'
|
||||
});
|
||||
}
|
||||
|
||||
function toTongji() {
|
||||
uni.navigateTo({
|
||||
url: "/pages/views/renliziyuan/renyuanxinxi/tongji"
|
||||
})
|
||||
url: '/pages/views/renliziyuan/renyuanxinxi/tongji'
|
||||
});
|
||||
}
|
||||
|
||||
function toQtTongji() {
|
||||
uni.navigateTo({
|
||||
url: "/pages/views/renliziyuan/renyuanxinxi/qttongji"
|
||||
})
|
||||
url: '/pages/views/renliziyuan/renyuanxinxi/qttongji'
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
<style></style>
|
@ -1,352 +0,0 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="container" id="top1">
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
|
||||
</uni-row>
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode" @change="onOrgCodeChange"></trq-depart-select>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
|
||||
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
|
||||
</picker>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
</view>
|
||||
<!-- ECharts图表 -->
|
||||
<view class="chart-container">
|
||||
<l-echart ref="chart" @finished="initChart" />
|
||||
</view>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
|
||||
<uni-row style="margin-top: 10px; margin-left: 30rpx; margin-right: 30rpx" v-if="personnelList.length > 0">
|
||||
<uni-col :span="3">
|
||||
<view class="titleStyle">序号</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">姓名</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">性别</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">年龄</view>
|
||||
</uni-col>
|
||||
<uni-col :span="6">
|
||||
<view class="titleStyle">操作</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
|
||||
<scroll-view scroll-y :style="{ height: bottomHeight + 'px' }">
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<view v-for="(item, index) in personnelList">
|
||||
<uni-col :span="3">
|
||||
<view class="dataStyle">
|
||||
{{ index + 1 }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.xm }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.xb_dictText }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.nl }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="6">
|
||||
<view class="dataStyle">
|
||||
<button size="mini" type="primary" @click="detail(item)">详情</button>
|
||||
</view>
|
||||
</uni-col>
|
||||
</view>
|
||||
</uni-row>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import * as echarts from 'echarts';
|
||||
import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js';
|
||||
// 存储下方组件的高度 tableData
|
||||
const bottomHeight = ref(0);
|
||||
// 新增加载状态
|
||||
const chart = ref(null);
|
||||
const fieldList = ref([
|
||||
{
|
||||
label: '性别',
|
||||
value: 'xb'
|
||||
},
|
||||
{
|
||||
label: '年龄',
|
||||
value: 'nl'
|
||||
},
|
||||
{
|
||||
label: '学历',
|
||||
value: 'rylb1'
|
||||
}
|
||||
]); // 字段列表
|
||||
const selectedOrgCode = ref(''); // 当前选择的单位 orgCode
|
||||
const selectedOrgCodeLabel = ref('请选择单位'); // 当前选择的单位名称
|
||||
const selectedField = ref(''); // 当前选择的字段
|
||||
const selectedFieldLabel = ref('请选择字段'); // 当前选择的字段名称
|
||||
const orgCodeGroupData = ref([]); //按照orgcode进行分组的数据
|
||||
const chartData = ref({}); // 图表数据
|
||||
const personnelList = ref([]); // 人员列表 initChart
|
||||
|
||||
const chartOption = ref({});
|
||||
|
||||
function detail(record) {
|
||||
// console.log(record)
|
||||
uni.navigateTo({
|
||||
url: '/pages/views/renliziyuan/renyuanxinxi/detail?data=' + encodeURIComponent(JSON.stringify(record))
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// #ifdef APP
|
||||
getHeight();
|
||||
// #endif
|
||||
});
|
||||
// #ifdef APP
|
||||
|
||||
const getHeight = () => {
|
||||
// 获取屏幕高度
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const screenHeight = systemInfo.screenHeight;
|
||||
// 创建选择器查询对象
|
||||
const query = uni.createSelectorQuery();
|
||||
// 获取上方组件的高度
|
||||
query
|
||||
.select('#top1')
|
||||
.boundingClientRect((rect1) => {
|
||||
// 计算上方组件高度总和
|
||||
const topComponentsHeight = rect1.height;
|
||||
// 计算下方组件的高度
|
||||
bottomHeight.value = screenHeight - topComponentsHeight - 415;
|
||||
})
|
||||
.exec();
|
||||
};
|
||||
|
||||
// #endif
|
||||
// 初始化 ECharts length departChange
|
||||
// 初始化图表
|
||||
const initChart = () => {
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return;
|
||||
const myChart = await chart.value.init(echarts);
|
||||
myChart.setOption(chartOption.value);
|
||||
}, 300);
|
||||
};
|
||||
|
||||
// 更新图表
|
||||
const updateChart = () => {};
|
||||
|
||||
//根据 orgCode 的分级格式,递归地汇总本级及其所有下级的数据,并将下级数据放在本级的 children 属性中。
|
||||
|
||||
const groupByOrgCode = (orgCode, data) => {
|
||||
// 过滤出本级和所有下级的数据
|
||||
const filteredData = data.filter((item) => item.orgCode.startsWith(orgCode));
|
||||
|
||||
// 如果过滤后的数据为空,返回 null
|
||||
if (filteredData.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 按照 fieldValue 分组
|
||||
const groupedByFieldValue = {};
|
||||
filteredData.forEach((item) => {
|
||||
if (!groupedByFieldValue[item.fieldValue]) {
|
||||
groupedByFieldValue[item.fieldValue] = {
|
||||
number: 0,
|
||||
ldhth: []
|
||||
};
|
||||
}
|
||||
groupedByFieldValue[item.fieldValue].number += item.number;
|
||||
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
|
||||
});
|
||||
|
||||
// 构建本级结果
|
||||
const result = {
|
||||
orgCode: orgCode,
|
||||
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => ({
|
||||
fieldValue: fieldValue,
|
||||
number: groupedByFieldValue[fieldValue].number,
|
||||
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] // 去重
|
||||
})),
|
||||
children: []
|
||||
};
|
||||
|
||||
// 获取所有下一级的 orgCode
|
||||
const nextLevelOrgCodes = new Set();
|
||||
filteredData.forEach((item) => {
|
||||
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
|
||||
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
|
||||
nextLevelOrgCodes.add(nextLevelOrgCode);
|
||||
}
|
||||
});
|
||||
|
||||
// 递归处理下一级数据
|
||||
nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
|
||||
const child = groupByOrgCode(nextLevelOrgCode, data);
|
||||
if (child) {
|
||||
result.children.push(child);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// 获取统计数据
|
||||
const fetchStatisticsData = async () => {
|
||||
if (!selectedOrgCode.value || !selectedField.value) return;
|
||||
try {
|
||||
const res = await cxcRyDatAstatistics({
|
||||
orgCode: selectedOrgCode.value,
|
||||
field: selectedField.value
|
||||
});
|
||||
console.log(res);
|
||||
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res);
|
||||
console.log(orgCodeGroupData.value);
|
||||
chartData.value = orgCodeGroupData.value;
|
||||
// updateChart();
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取人员列表 delimiter
|
||||
const fetchPersonnelList = async (ldhthList) => {
|
||||
try {
|
||||
const res = await cxcRyDatAstatisticsDetails({
|
||||
ldhth: ldhthList
|
||||
});
|
||||
console.log(res);
|
||||
personnelList.value = res.data;
|
||||
} catch (error) {
|
||||
console.error('获取人员列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 事件处理
|
||||
const onOrgCodeChange = (e, data) => {
|
||||
selectedOrgCode.value = e;
|
||||
console.log(data.value.title);
|
||||
selectedOrgCodeLabel.value = data.value.title;
|
||||
fetchStatisticsData();
|
||||
};
|
||||
|
||||
const onFieldChange = (e) => {
|
||||
const index = e.detail.value;
|
||||
selectedField.value = fieldList.value[index].value;
|
||||
selectedFieldLabel.value = fieldList.value[index].label;
|
||||
fetchStatisticsData();
|
||||
};
|
||||
|
||||
const onChartClick = (e) => {
|
||||
const { ldhth } = chartData.value;
|
||||
if (ldhth && ldhth.length > 0) {
|
||||
fetchPersonnelList(ldhth);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
margin: 20, 20, 20, 20rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
border: 1rpx solid #ddd;
|
||||
padding: 15rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.query-btn {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
padding: 0 40rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.stats-box {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin: 30rpx 0;
|
||||
padding: 20rpx;
|
||||
background: #f8f8f8;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #0000ff;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 800rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.titleStyle {
|
||||
font-size: 12px;
|
||||
color: #747474;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
background: #f2f9fc;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-left: 1px solid #919191;
|
||||
border-bottom: 1px solid #919191;
|
||||
}
|
||||
|
||||
/* 内容样式 */
|
||||
.dataStyle {
|
||||
max-font-size: 14px;
|
||||
/* 最大字体限制 */
|
||||
min-font-size: 10px;
|
||||
/* 最小字体限制 */
|
||||
font-size: 12px;
|
||||
color: #00007f;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-bottom: 1px solid #919191;
|
||||
border-left: 1px solid #919191;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
@ -1,730 +0,0 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="container" id="top1">
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
|
||||
</uni-row>
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode" @change="onOrgCodeChange"></trq-depart-select>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
|
||||
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
|
||||
</picker>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
</view>
|
||||
<!-- ECharts图表 -->
|
||||
<view class="chart-container">
|
||||
<l-echart ref="chart" @finished="initChart" />
|
||||
</view>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
|
||||
<uni-row style="margin-top: 10px; margin-left: 30rpx; margin-right: 30rpx" v-if="personnelList.length > 0">
|
||||
<uni-col :span="3">
|
||||
<view class="titleStyle">序号</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">姓名</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">性别</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">年龄</view>
|
||||
</uni-col>
|
||||
<uni-col :span="6">
|
||||
<view class="titleStyle">操作</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
|
||||
<scroll-view scroll-y :style="{ height: bottomHeight + 'px' }">
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<view v-for="(item, index) in personnelList">
|
||||
<uni-col :span="3">
|
||||
<view class="dataStyle">
|
||||
{{ index + 1 }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.xm }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.xb_dictText }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.nl }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="6">
|
||||
<view class="dataStyle">
|
||||
<button size="mini" type="primary" @click="detail(item)">详情</button>
|
||||
</view>
|
||||
</uni-col>
|
||||
</view>
|
||||
</uni-row>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import * as echarts from 'echarts';
|
||||
import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js';
|
||||
// 存储下方组件的高度 tableData
|
||||
const bottomHeight = ref(0);
|
||||
// 新增加载状态
|
||||
const chart = ref(null);
|
||||
const fieldList = ref([
|
||||
{
|
||||
label: '性别',
|
||||
value: 'xb'
|
||||
},
|
||||
{
|
||||
label: '年龄',
|
||||
value: 'nl'
|
||||
},
|
||||
{
|
||||
label: '学历',
|
||||
value: 'rylb1'
|
||||
}
|
||||
]); // 字段列表
|
||||
const selectedOrgCode = ref(''); // 当前选择的单位 orgCode
|
||||
const selectedOrgCodeLabel = ref('请选择单位'); // 当前选择的单位名称
|
||||
const selectedField = ref(''); // 当前选择的字段
|
||||
const selectedFieldLabel = ref('请选择字段'); // 当前选择的字段名称
|
||||
const orgCodeGroupData = ref([]); //按照orgcode进行分组的数据
|
||||
const chartData = ref({}); // 图表数据
|
||||
const personnelList = ref([]); // 人员列表 initChart
|
||||
|
||||
const chartOption = ref({});
|
||||
|
||||
function detail(record) {
|
||||
// console.log(record)
|
||||
uni.navigateTo({
|
||||
url: '/pages/views/renliziyuan/renyuanxinxi/detail?data=' + encodeURIComponent(JSON.stringify(record))
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// #ifdef APP
|
||||
getHeight();
|
||||
// #endif
|
||||
});
|
||||
// #ifdef APP
|
||||
|
||||
const getHeight = () => {
|
||||
// 获取屏幕高度
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const screenHeight = systemInfo.screenHeight;
|
||||
// 创建选择器查询对象
|
||||
const query = uni.createSelectorQuery();
|
||||
// 获取上方组件的高度
|
||||
query
|
||||
.select('#top1')
|
||||
.boundingClientRect((rect1) => {
|
||||
// 计算上方组件高度总和
|
||||
const topComponentsHeight = rect1.height;
|
||||
// 计算下方组件的高度
|
||||
bottomHeight.value = screenHeight - topComponentsHeight - 415;
|
||||
})
|
||||
.exec();
|
||||
};
|
||||
|
||||
// #endif
|
||||
// 初始化 ECharts length departChange
|
||||
// 初始化图表
|
||||
const initChart = () => {
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return;
|
||||
const myChart = await chart.value.init(echarts);
|
||||
myChart.setOption(chartOption.value);
|
||||
}, 300);
|
||||
};
|
||||
|
||||
// 更新图表
|
||||
const updateChart = () => {
|
||||
if (!chart) return;
|
||||
chartOption.value = transformToEChartsFormat(chartData.value);
|
||||
// 初始化图表
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return;
|
||||
const myChart = await chart.value.init(echarts);
|
||||
myChart.setOption(chartOption.value);
|
||||
myChart.on('click', (params) => {
|
||||
try {
|
||||
console.log(JSON.stringify(params.seriesIndex));
|
||||
} catch (error) {
|
||||
console.error('Error stringifying params:', error);
|
||||
}
|
||||
personnelList.value = fetchPersonnelList(params.seriesName);
|
||||
});
|
||||
}, 300);
|
||||
};
|
||||
|
||||
//根据 orgCode 的分级格式,递归地汇总本级及其所有下级的数据,并将下级数据放在本级的 children 属性中。
|
||||
|
||||
const groupByOrgCode = (orgCode, data) => {
|
||||
// 过滤出本级和所有下级的数据
|
||||
const filteredData = data.filter((item) => item.orgCode.startsWith(orgCode));
|
||||
|
||||
// 如果过滤后的数据为空,返回 null
|
||||
if (filteredData.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 按照 fieldValue 分组
|
||||
const groupedByFieldValue = {};
|
||||
filteredData.forEach((item) => {
|
||||
if (!groupedByFieldValue[item.fieldValue]) {
|
||||
groupedByFieldValue[item.fieldValue] = {
|
||||
number: 0,
|
||||
ldhth: []
|
||||
};
|
||||
}
|
||||
groupedByFieldValue[item.fieldValue].number += item.number;
|
||||
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
|
||||
});
|
||||
|
||||
// 构建本级结果
|
||||
const result = {
|
||||
orgCode: orgCode,
|
||||
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => ({
|
||||
fieldValue: fieldValue,
|
||||
number: groupedByFieldValue[fieldValue].number,
|
||||
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] // 去重
|
||||
})),
|
||||
children: []
|
||||
};
|
||||
|
||||
// 获取所有下一级的 orgCode
|
||||
const nextLevelOrgCodes = new Set();
|
||||
filteredData.forEach((item) => {
|
||||
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
|
||||
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
|
||||
nextLevelOrgCodes.add(nextLevelOrgCode);
|
||||
}
|
||||
});
|
||||
|
||||
// 递归处理下一级数据
|
||||
nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
|
||||
const child = groupByOrgCode(nextLevelOrgCode, data);
|
||||
if (child) {
|
||||
result.children.push(child);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
//转换分组数据 本级汇总及下一级的合集
|
||||
const transformData = (selectOrgCode, inputData) => {
|
||||
try {
|
||||
// 存储本级数据
|
||||
const currentLevelData = {};
|
||||
// 存储下一级数据,按 orgCode 分组
|
||||
const childrenData = {};
|
||||
|
||||
// 遍历输入数据
|
||||
inputData.forEach((item) => {
|
||||
const { orgCode, fieldValue, number, ldhth } = item;
|
||||
// 提取本级 orgCode
|
||||
const currentOrgCode = selectOrgCode;
|
||||
// 检查是否为下一级 orgCode
|
||||
if (orgCode.startsWith(currentOrgCode) && orgCode.length > currentOrgCode.length) {
|
||||
// 提取下一级 orgCode
|
||||
const childOrgCode = orgCode.slice(0, currentOrgCode.length + 3);
|
||||
if (!childrenData[childOrgCode]) {
|
||||
childrenData[childOrgCode] = {};
|
||||
}
|
||||
if (!childrenData[childOrgCode][fieldValue]) {
|
||||
childrenData[childOrgCode][fieldValue] = { number: 0, ldhth: [] };
|
||||
}
|
||||
childrenData[childOrgCode][fieldValue].number += number;
|
||||
childrenData[childOrgCode][fieldValue].ldhth.push(ldhth);
|
||||
}
|
||||
|
||||
// 汇总本级数据
|
||||
if (!currentLevelData[fieldValue]) {
|
||||
currentLevelData[fieldValue] = { number: 0, ldhth: [] };
|
||||
}
|
||||
currentLevelData[fieldValue].number += number;
|
||||
currentLevelData[fieldValue].ldhth.push(ldhth);
|
||||
});
|
||||
|
||||
// 转换本级数据格式
|
||||
const formattedCurrentLevelData = Object.keys(currentLevelData).map((fieldValue) => ({
|
||||
fieldValue,
|
||||
number: currentLevelData[fieldValue].number,
|
||||
ldhth: currentLevelData[fieldValue].ldhth.join(',')
|
||||
}));
|
||||
|
||||
// 转换下一级数据格式
|
||||
const formattedChildrenData = Object.keys(childrenData).map((childOrgCode) => ({
|
||||
orgCode: childOrgCode,
|
||||
data: Object.keys(childrenData[childOrgCode]).map((fieldValue) => ({
|
||||
fieldValue,
|
||||
number: childrenData[childOrgCode][fieldValue].number,
|
||||
ldhth: childrenData[childOrgCode][fieldValue].ldhth.join(',')
|
||||
}))
|
||||
}));
|
||||
console.log({
|
||||
orgCode: selectOrgCode,
|
||||
data: formattedCurrentLevelData,
|
||||
children: formattedChildrenData
|
||||
});
|
||||
// 组合最终结果
|
||||
return {
|
||||
orgCode: selectOrgCode,
|
||||
data: formattedCurrentLevelData,
|
||||
children: formattedChildrenData
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
//TODO handle the exception
|
||||
}
|
||||
};
|
||||
|
||||
const transformToEChartsFormat = (data) => {
|
||||
const result = {
|
||||
xAxis: { data: [] },
|
||||
legend: { data: [] },
|
||||
series: []
|
||||
};
|
||||
|
||||
// 用于存储不同orgCode的series数据
|
||||
const seriesMap = {};
|
||||
try {
|
||||
data.forEach((item) => {
|
||||
const orgCode = item.orgCode;
|
||||
|
||||
// 初始化当前orgCode对应的series数据
|
||||
if (!seriesMap[orgCode]) {
|
||||
seriesMap[orgCode] = { name: orgCode, type: 'bar', data: [] };
|
||||
result.xAxis.data.push(orgCode);
|
||||
}
|
||||
|
||||
item.data.forEach((field) => {
|
||||
const fieldValue = field.fieldValue;
|
||||
|
||||
// 确保图例中包含当前fieldValue
|
||||
if (!result.legend.data.includes(fieldValue)) {
|
||||
result.legend.data.push(fieldValue);
|
||||
}
|
||||
|
||||
// 确保seriesMap中的每个series都有对应fieldValue的位置
|
||||
seriesMap[orgCode].data[fieldValue] = seriesMap[orgCode].data[fieldValue] || 0;
|
||||
|
||||
// 添加number到对应位置
|
||||
seriesMap[orgCode].data[fieldValue] += field.number;
|
||||
});
|
||||
});
|
||||
|
||||
// 将seriesMap中的数据转换为正确的格式并添加到result.series中
|
||||
for (let orgCode in seriesMap) {
|
||||
// 转换seriesMap中的data为数组格式
|
||||
seriesMap[orgCode].data = result.legend.data.map((value) => seriesMap[orgCode].data[value] || 0);
|
||||
result.series.push(seriesMap[orgCode]);
|
||||
}
|
||||
} catch (error) {
|
||||
//TODO handle the exception
|
||||
}
|
||||
|
||||
const Option = {
|
||||
title: {
|
||||
text: '人员年龄分组统计',
|
||||
padding: [0, 0, 0, 30]
|
||||
},
|
||||
toolbox: {
|
||||
padding: [0, 30, 0, 0],
|
||||
show: true,
|
||||
feature: {
|
||||
//工具配置项
|
||||
|
||||
restore: {
|
||||
show: true //是否显示该工具
|
||||
},
|
||||
saveAsImage: {
|
||||
show: true //是否显示该工具
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: result.legend,
|
||||
itemGap: 5,
|
||||
padding: [0, 15, 0, 15],
|
||||
y: 'bottom',
|
||||
itemHeight: 8, //高
|
||||
itemWidth: 8, //宽
|
||||
type: 'scroll'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: result.xAxis,
|
||||
axisLabel: {
|
||||
color: '#7F84B5',
|
||||
fontWeight: 300,
|
||||
interval: 0,
|
||||
rotate: 0
|
||||
},
|
||||
padding: [0, 10, 0, 10],
|
||||
axisTick: {
|
||||
show: false //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
show: true,
|
||||
boundaryGap: false, //解决数据与线不对应问题
|
||||
type: 'value',
|
||||
// name: 'Budget (million USD)',
|
||||
// data: this.yList,
|
||||
minInterval: 1,
|
||||
axisLabel: {
|
||||
interval: 0
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
//背景网格线
|
||||
type: 'dashed'
|
||||
}
|
||||
},
|
||||
|
||||
axisTick: {
|
||||
show: true //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
}
|
||||
],
|
||||
series: result.series
|
||||
};
|
||||
return Option;
|
||||
};
|
||||
|
||||
// 统计后台获取数据中单位的个数
|
||||
const countUniqueOrgCodes = (data) => {
|
||||
// 创建一个 Set 来存储唯一的 orgCode
|
||||
const orgCodeSet = new Set();
|
||||
// 遍历数据数组
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
// 将每个数据项的 orgCode 添加到 Set 中
|
||||
orgCodeSet.add(data[i].orgCode);
|
||||
}
|
||||
// 返回 Set 的大小,即不同 orgCode 的个数
|
||||
return orgCodeSet.size;
|
||||
};
|
||||
|
||||
// 生成随机颜色的辅助函数
|
||||
function getRandomColor() {
|
||||
const letters = '0123456789ABCDEF';
|
||||
let color = '#';
|
||||
for (let i = 0; i < 6; i++) {
|
||||
color += letters[Math.floor(Math.random() * 16)];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
//根据数据生成echart需要的option 一个单位的情况
|
||||
const convertToEChartsOption = (data) => {
|
||||
// 用于存储按 orgCode 和 fieldValue 分组的数据
|
||||
const groupedData = {};
|
||||
// 遍历原始数据
|
||||
data.forEach((item) => {
|
||||
const { orgCode, fieldValue, number } = item;
|
||||
if (!groupedData[orgCode]) {
|
||||
groupedData[orgCode] = {};
|
||||
}
|
||||
groupedData[orgCode][fieldValue] = number;
|
||||
});
|
||||
// 获取所有不同的 orgCode
|
||||
const orgCodes = Object.keys(groupedData);
|
||||
console.log(orgCodes, groupedData);
|
||||
let labels = [];
|
||||
let datasets = [];
|
||||
let xDatas = [];
|
||||
// 如果只有一个 orgCode,生成单柱状图数据
|
||||
if (orgCodes.length === 1) {
|
||||
const singleOrgCode = orgCodes[0];
|
||||
const singleOrgData = groupedData[singleOrgCode];
|
||||
|
||||
console.log('单个', singleOrgCode, singleOrgData);
|
||||
labels = Object.keys(singleOrgData);
|
||||
console.log('单个labels', labels);
|
||||
xDatas = labels;
|
||||
datasets = [
|
||||
{
|
||||
type: 'bar',
|
||||
data: labels.map((label, index) => {
|
||||
return {
|
||||
value: singleOrgData[label],
|
||||
itemStyle: {
|
||||
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
|
||||
}
|
||||
};
|
||||
})
|
||||
}
|
||||
];
|
||||
console.log('单个的数据', xDatas, labels, datasets);
|
||||
} else {
|
||||
// 如果有多个 orgCode,生成多柱状图数据
|
||||
const allFieldValues = new Set();
|
||||
orgCodes.forEach((orgCode) => {
|
||||
const fieldValues = Object.keys(groupedData[orgCode]);
|
||||
fieldValues.forEach((fieldValue) => allFieldValues.add(fieldValue));
|
||||
});
|
||||
const sortedFieldValues = Array.from(allFieldValues).sort();
|
||||
console.log('多个数据', sortedFieldValues);
|
||||
labels = sortedFieldValues;
|
||||
xDatas = orgCodes;
|
||||
datasets = orgCodes.map((orgCode) => {
|
||||
const dataPoints = sortedFieldValues.map((fieldValue, index) => {
|
||||
return {
|
||||
value: groupedData[orgCode][fieldValue] || 0,
|
||||
itemStyle: {
|
||||
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
name: orgCode,
|
||||
type: 'bar',
|
||||
data: dataPoints
|
||||
};
|
||||
});
|
||||
}
|
||||
console.log(labels, orgCodes, datasets);
|
||||
|
||||
// 构建 ECharts option 对象
|
||||
const option = {
|
||||
title: {
|
||||
text: '人员年龄分组统计',
|
||||
padding: [0, 0, 0, 30]
|
||||
},
|
||||
toolbox: {
|
||||
padding: [0, 30, 0, 0],
|
||||
show: true,
|
||||
feature: {
|
||||
//工具配置项
|
||||
|
||||
restore: {
|
||||
show: true //是否显示该工具
|
||||
},
|
||||
saveAsImage: {
|
||||
show: true //是否显示该工具
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: labels,
|
||||
itemGap: 5,
|
||||
padding: [0, 15, 0, 15],
|
||||
y: 'bottom',
|
||||
itemHeight: 8, //高
|
||||
itemWidth: 8, //宽
|
||||
type: 'scroll'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: xDatas,
|
||||
axisLabel: {
|
||||
color: '#7F84B5',
|
||||
fontWeight: 300,
|
||||
interval: 0,
|
||||
rotate: 0
|
||||
},
|
||||
padding: [0, 10, 0, 10],
|
||||
axisTick: {
|
||||
show: false //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
show: true,
|
||||
boundaryGap: false, //解决数据与线不对应问题
|
||||
type: 'value',
|
||||
// name: 'Budget (million USD)',
|
||||
// data: this.yList,
|
||||
minInterval: 1,
|
||||
axisLabel: {
|
||||
interval: 0
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
//背景网格线
|
||||
type: 'dashed'
|
||||
}
|
||||
},
|
||||
|
||||
axisTick: {
|
||||
show: true //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
}
|
||||
],
|
||||
series: datasets
|
||||
};
|
||||
return option;
|
||||
};
|
||||
|
||||
// 获取统计数据
|
||||
const fetchStatisticsData = async () => {
|
||||
if (!selectedOrgCode.value || !selectedField.value) return;
|
||||
try {
|
||||
const res = await cxcRyDatAstatistics({
|
||||
orgCode: selectedOrgCode.value,
|
||||
field: selectedField.value
|
||||
});
|
||||
console.log(res);
|
||||
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res);
|
||||
console.log(orgCodeGroupData.value);
|
||||
chartData.value = orgCodeGroupData.value.children;
|
||||
// updateChart();
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取人员列表 delimiter
|
||||
const fetchPersonnelList = async (ldhthList) => {
|
||||
try {
|
||||
const res = await cxcRyDatAstatisticsDetails({
|
||||
ldhth: ldhthList
|
||||
});
|
||||
console.log(res);
|
||||
personnelList.value = res.data;
|
||||
} catch (error) {
|
||||
console.error('获取人员列表失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 事件处理
|
||||
const onOrgCodeChange = (e, data) => {
|
||||
selectedOrgCode.value = e;
|
||||
console.log(data.value.title);
|
||||
selectedOrgCodeLabel.value = data.value.title;
|
||||
fetchStatisticsData();
|
||||
};
|
||||
|
||||
const onFieldChange = (e) => {
|
||||
const index = e.detail.value;
|
||||
selectedField.value = fieldList.value[index].value;
|
||||
selectedFieldLabel.value = fieldList.value[index].label;
|
||||
fetchStatisticsData();
|
||||
};
|
||||
|
||||
const onChartClick = (e) => {
|
||||
const { ldhth } = chartData.value;
|
||||
if (ldhth && ldhth.length > 0) {
|
||||
fetchPersonnelList(ldhth);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
margin: 20, 20, 20, 20rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
border: 1rpx solid #ddd;
|
||||
padding: 15rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.query-btn {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
padding: 0 40rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.stats-box {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin: 30rpx 0;
|
||||
padding: 20rpx;
|
||||
background: #f8f8f8;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #0000ff;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 800rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.titleStyle {
|
||||
font-size: 12px;
|
||||
color: #747474;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
background: #f2f9fc;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-left: 1px solid #919191;
|
||||
border-bottom: 1px solid #919191;
|
||||
}
|
||||
|
||||
/* 内容样式 */
|
||||
.dataStyle {
|
||||
max-font-size: 14px;
|
||||
/* 最大字体限制 */
|
||||
min-font-size: 10px;
|
||||
/* 最小字体限制 */
|
||||
font-size: 12px;
|
||||
color: #00007f;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-bottom: 1px solid #919191;
|
||||
border-left: 1px solid #919191;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
@ -2,19 +2,17 @@
|
||||
<view>
|
||||
<view class="container" id="top1">
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
|
||||
</uni-row>
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<uni-col :span="5"><uni-title :title="'选择单位'" align="left" type="h4"></uni-title></uni-col>
|
||||
|
||||
<uni-col :span="19">
|
||||
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode" @change="onOrgCodeChange"></trq-depart-select>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
|
||||
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
|
||||
</picker>
|
||||
<uni-col :span="5"><uni-title :title="'选择字段'" align="left" type="h4"></uni-title></uni-col>
|
||||
<uni-col :span="19">
|
||||
<uni-data-select v-model="selectedField" :localdata="fieldList" @change="onFieldChange"></uni-data-select>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
</view>
|
||||
@ -23,6 +21,12 @@
|
||||
<l-echart ref="chart" @finished="initChart" />
|
||||
</view>
|
||||
|
||||
<!-- 翻页按钮 -->
|
||||
<view style="display: flex; justify-content: center; margin-top: 10px">
|
||||
<button @click="prevPage" :disabled="currentPage === 1" size="mini">上一页</button>
|
||||
<button @click="nextPage" :disabled="currentPage * pageSize >= chartDataCount.value" size="mini">下一页</button>
|
||||
</view>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
|
||||
<uni-row style="margin-top: 10px; margin-left: 30rpx; margin-right: 30rpx" v-if="personnelList.length > 0">
|
||||
@ -33,7 +37,7 @@
|
||||
<view class="titleStyle">姓名</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">性别</view>
|
||||
<view class="titleStyle">基层单位</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">年龄</view>
|
||||
@ -58,7 +62,7 @@
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{ item.xb_dictText }}
|
||||
{{ item.jcxd }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
@ -78,37 +82,58 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { ref, reactive, onMounted, computed } from 'vue';
|
||||
import * as echarts from 'echarts';
|
||||
import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js';
|
||||
|
||||
// 存储下方组件的高度 tableData
|
||||
const bottomHeight = ref(0);
|
||||
// 新增加载状态
|
||||
const chart = ref(null);
|
||||
const chartDataCount = ref(0);
|
||||
const fieldList = ref([
|
||||
{
|
||||
label: '性别',
|
||||
value: 'xb'
|
||||
text: '性别',
|
||||
value: 'xb',
|
||||
isDict: true,
|
||||
dictCode: 'sex'
|
||||
},
|
||||
{
|
||||
label: '年龄',
|
||||
value: 'nl'
|
||||
text: '政治面貌',
|
||||
value: 'zzmm',
|
||||
isDict: true,
|
||||
dictCode: 'zzmm'
|
||||
},
|
||||
{
|
||||
label: '学历',
|
||||
value: 'rylb1'
|
||||
text: '民族',
|
||||
value: 'mz',
|
||||
isDict: true,
|
||||
dictCode: 'mz'
|
||||
}
|
||||
]); // 字段列表
|
||||
|
||||
const dictCode = ref('');
|
||||
const fieldisDict = ref(true);
|
||||
|
||||
const selectedOrgCode = ref(''); // 当前选择的单位 orgCode
|
||||
const selectedOrgCodeLabel = ref('请选择单位'); // 当前选择的单位名称
|
||||
const selectedField = ref(''); // 当前选择的字段
|
||||
const selectedFieldLabel = ref('请选择字段'); // 当前选择的字段名称
|
||||
const orgCodeGroupData = ref([]); //按照orgcode进行分组的数据
|
||||
const orgCodeGroupData = ref([]); //按照orgcode进行分组的数据 含劳动合同号
|
||||
const chartData = ref({}); // 图表数据
|
||||
const personnelList = ref([]); // 人员列表 initChart
|
||||
|
||||
const fieldValues = ref([]); //字段值
|
||||
const fieldTexts = ref([]); //字段值
|
||||
const chartOption = ref({});
|
||||
|
||||
const chartTitle = computed(() => {
|
||||
return selectedOrgCodeLabel.value + '人员(' + selectedFieldLabel.value + ')分组统计';
|
||||
});
|
||||
|
||||
//图标翻页
|
||||
const pageSize = ref(3); // 每页显示的项目数量
|
||||
const currentPage = ref(1); // 当前页码
|
||||
|
||||
function detail(record) {
|
||||
// console.log(record)
|
||||
uni.navigateTo({
|
||||
@ -152,163 +177,506 @@ const initChart = () => {
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const prevPage = () => {
|
||||
if (currentPage.value > 1) {
|
||||
currentPage.value--;
|
||||
}
|
||||
updateChart(chartData.value);
|
||||
};
|
||||
|
||||
const nextPage = () => {
|
||||
if (currentPage.value * pageSize.value < chartDataCount.value) {
|
||||
currentPage.value++;
|
||||
// 计算当前页数据的起始和结束索引
|
||||
const startIndex = (currentPage.value - 1) * pageSize.value;
|
||||
const endIndex = startIndex + pageSize.value;
|
||||
updateChart(chartData.value);
|
||||
// const tempChartData = temp.slice(startIndex, endIndex);
|
||||
}
|
||||
};
|
||||
// 更具数据生成图标的option
|
||||
const getChartOption = (ChartData) => {
|
||||
// let temp = JSON.parse(JSON.stringify(tempchartData[0].children));
|
||||
// chartDataCount.value = temp.length;
|
||||
// 计算当前页数据的起始和结束索引
|
||||
const startIndex = (currentPage.value - 1) * pageSize.value;
|
||||
const endIndex = startIndex + pageSize.value;
|
||||
// 截取当前页的数据
|
||||
const tempChartData = ChartData.slice(startIndex, endIndex);
|
||||
try {
|
||||
let xData = [];
|
||||
let seriesData = [];
|
||||
console.log(1, tempChartData);
|
||||
//当前机构下的数据 transformDataForEcharts
|
||||
|
||||
let legendData = [];
|
||||
for (let i = 0; i < fieldValues.value.length; i++) {
|
||||
legendData.push(fieldValues.value[i].filedText);
|
||||
}
|
||||
|
||||
tempChartData.forEach((item) => {
|
||||
xData.push(item.name);
|
||||
});
|
||||
|
||||
for (let i = 0; i < fieldValues.value.length; i++) {
|
||||
let tempData = [];
|
||||
tempChartData.forEach((item) => {
|
||||
console.log(item);
|
||||
if (item.data[i]) {
|
||||
tempData.push(item.data[i]);
|
||||
} else {
|
||||
tempData.push(0);
|
||||
}
|
||||
});
|
||||
seriesData.push({
|
||||
name: fieldValues.value[i].filedText,
|
||||
type: 'bar',
|
||||
label: {
|
||||
show: true, // 显示数值标签
|
||||
position: 'top' // 数值标签位置
|
||||
},
|
||||
data: tempData
|
||||
});
|
||||
}
|
||||
console.log(2, legendData, xData, seriesData);
|
||||
let tempOption = {
|
||||
title: {
|
||||
text: chartTitle.value,
|
||||
padding: [0, 0, 0, 30]
|
||||
},
|
||||
toolbox: {
|
||||
padding: [0, 30, 0, 0],
|
||||
show: true,
|
||||
feature: {
|
||||
//工具配置项
|
||||
|
||||
restore: {
|
||||
show: true //是否显示该工具
|
||||
},
|
||||
saveAsImage: {
|
||||
show: true //是否显示该工具
|
||||
}
|
||||
}
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: xData,
|
||||
axisLabel: {
|
||||
color: '#7F84B5',
|
||||
fontWeight: 300,
|
||||
interval: 0,
|
||||
rotate: 0
|
||||
},
|
||||
padding: [0, 10, 0, 10],
|
||||
axisTick: {
|
||||
show: false //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
show: true,
|
||||
boundaryGap: false, //解决数据与线不对应问题
|
||||
type: 'value',
|
||||
// name: 'Budget (million USD)',
|
||||
// data: this.yList,
|
||||
minInterval: 1,
|
||||
axisLabel: {
|
||||
interval: 0
|
||||
},
|
||||
splitLine: {
|
||||
show: true,
|
||||
lineStyle: {
|
||||
//背景网格线
|
||||
type: 'dashed'
|
||||
}
|
||||
},
|
||||
|
||||
axisTick: {
|
||||
show: true //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
}
|
||||
],
|
||||
series: seriesData,
|
||||
|
||||
legend: {
|
||||
data: legendData,
|
||||
itemGap: 5,
|
||||
padding: [0, 15, 0, 15],
|
||||
y: 'bottom',
|
||||
itemHeight: 8, //高
|
||||
itemWidth: 18, //宽
|
||||
type: 'scroll'
|
||||
}
|
||||
};
|
||||
return tempOption;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
// 更新图表
|
||||
const updateChart = () => {
|
||||
const updateChart = (tempchartData) => {
|
||||
// 初始化图表
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return;
|
||||
const myChart = await chart.value.init(echarts);
|
||||
chartOption.value = transformDataForEcharts(chartData.value, selectedOrgCode.value);
|
||||
myChart.setOption({
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: chartOption.value.categories.map((code) => `${code}${chartOption.value.children ? ' ▶' : ''}`)
|
||||
},
|
||||
yAxis: { type: 'value' },
|
||||
series: chartOption.value.series,
|
||||
tooltip: { trigger: 'axis' },
|
||||
legend: { data: chartOption.value.series.map((s) => s.name) }
|
||||
});
|
||||
console.log(tempchartData);
|
||||
let tempOption = getChartOption(tempchartData);
|
||||
|
||||
myChart.setOption(tempOption);
|
||||
// 点击钻取事件
|
||||
myChart.on('click', (params) => {
|
||||
const clickedCode = params.name.split(' ')[0];
|
||||
const nextData = transformDataForEcharts(originalData, clickedCode);
|
||||
console.log(params.name, params.seriesIndex, params.dataIndex);
|
||||
console.log(orgCodeGroupData.value);
|
||||
|
||||
if (nextData.categories.length > 0) {
|
||||
historyStack.push(currentLevel);
|
||||
currentLevel = clickedCode;
|
||||
renderChart(nextData);
|
||||
} else if (nextData.children) {
|
||||
historyStack.push(currentLevel);
|
||||
currentLevel = clickedCode;
|
||||
chartData = transformDataForEcharts(originalData, currentLevel);
|
||||
renderChart(chartData);
|
||||
} else {
|
||||
console.log('已是最末级节点');
|
||||
let updateData = findRyByOrgCode(orgCodeGroupData.value.children, params.name);
|
||||
console.log(updateData);
|
||||
|
||||
const ldhth = updateData.fieldValues[params.seriesIndex].ldhth;
|
||||
|
||||
console.log(ldhth);
|
||||
|
||||
if (ldhth && ldhth.length > 0) {
|
||||
fetchPersonnelList(ldhth);
|
||||
}
|
||||
// updateChart(updateData);
|
||||
});
|
||||
}, 300);
|
||||
};
|
||||
//根据一个键值查找数据
|
||||
//查找人员劳动合同号
|
||||
function findRyByOrgCode(treeData, targetOrgCode) {
|
||||
// console.log(treeData, targetOrgCode);
|
||||
for (const node of treeData) {
|
||||
// 如果当前节点匹配,直接返回该节点及其子节点
|
||||
if (node.orgText === targetOrgCode) {
|
||||
return node;
|
||||
}
|
||||
// 递归检查子节点
|
||||
if (node.children && node.children.length > 0) {
|
||||
const found = findNodeByOrgCode(node.children, targetOrgCode);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从echart图标的树状数据中根据 orgCode 获取节点及其子节点数据
|
||||
* @param {Array} treeData 树状数据
|
||||
* @param {string} targetOrgCode 目标 orgCode
|
||||
* @returns {Object|null} 匹配的节点及其子节点数据,未找到返回 null
|
||||
*/
|
||||
function findNodeByOrgCode(treeData, targetOrgCode) {
|
||||
// console.log(treeData, targetOrgCode);
|
||||
for (const node of treeData) {
|
||||
// 如果当前节点匹配,直接返回该节点及其子节点
|
||||
if (node.name === targetOrgCode) {
|
||||
return node;
|
||||
}
|
||||
// 递归检查子节点
|
||||
if (node.children && node.children.length > 0) {
|
||||
const found = findNodeByOrgCode(node.children, targetOrgCode);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//获取所有的fieldValue
|
||||
function collectUniqueKeyFieldValues(tree) {
|
||||
const uniqueMap = new Map();
|
||||
tree.forEach((item) => {
|
||||
const { fieldValue, filedText } = item;
|
||||
const key = `${fieldValue}-${filedText}`;
|
||||
|
||||
if (!uniqueMap.has(key)) {
|
||||
uniqueMap.set(key, {
|
||||
fieldValue,
|
||||
filedText
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const result = Array.from(uniqueMap.values());
|
||||
return result;
|
||||
}
|
||||
|
||||
// 封装一个类来管理组织代码和组织名称的映射
|
||||
class OrgCodeMapper {
|
||||
constructor(data) {
|
||||
// 初始化一个空对象用于存储映射关系
|
||||
this.orgCodeToOrgTextMap = {};
|
||||
// 遍历传入的数据数组
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const item = data[i];
|
||||
// 将 orgCode 作为键,orgText 作为值存入映射对象
|
||||
this.orgCodeToOrgTextMap[item.orgCode] = item.orgText;
|
||||
}
|
||||
}
|
||||
|
||||
// 查找指定 orgCode 对应的 orgText 的方法
|
||||
findOrgText(orgCode) {
|
||||
return this.orgCodeToOrgTextMap[orgCode];
|
||||
}
|
||||
}
|
||||
|
||||
// 示例用法
|
||||
// const result = findNodeByOrgCode(echartData, "A01A01A01A01");
|
||||
// console.log(result);
|
||||
/**
|
||||
* 转换数据为支持钻取的ECharts格式
|
||||
* @param {Array} data 原始数据
|
||||
* @param {string} currentOrgCode 当前组织编码
|
||||
* @returns {Object} 包含当前层级数据和子节点信息的对象
|
||||
* @param {string} selectOrgCode 当前选择的组织编码
|
||||
* @returns {Object} 包含当前层级数据和子节点信息的对象 符合echart的格式
|
||||
*/
|
||||
function transformDataForEcharts(data, currentOrgCode = '') {
|
||||
// 计算当前层级的长度(每级+3)
|
||||
const currentLevel = currentOrgCode.length;
|
||||
const nextLevel = currentLevel + 3;
|
||||
console.log(currentLevel, nextLevel, currentOrgCode, data);
|
||||
// 过滤当前层级数据
|
||||
const currentLevelData = data.filter((item) => item.orgCode.length === currentLevel && (currentLevel === 0 || item.orgCode === currentOrgCode));
|
||||
console.log(1);
|
||||
console.log(currentLevelData);
|
||||
|
||||
// 过滤直接子节点(严格前缀匹配)
|
||||
const children = data
|
||||
.filter(
|
||||
(item) => item.orgCode.startsWith(currentOrgCode) && item.orgCode.length === nextLevel && (currentLevel === 0 || item.orgCode.slice(0, currentLevel) === currentOrgCode)
|
||||
)
|
||||
.map((item) => ({
|
||||
orgCode: item.orgCode,
|
||||
hasChildren: data.some((d) => d.orgCode.startsWith(item.orgCode) && d.orgCode.length === nextLevel + 3)
|
||||
}));
|
||||
console.log(2, children);
|
||||
// 按fieldValue分组统计
|
||||
const fieldGroups = currentLevelData.reduce((acc, curr) => {
|
||||
const key = curr.fieldValue;
|
||||
if (!acc[key]) {
|
||||
acc[key] = {
|
||||
name: key,
|
||||
data: []
|
||||
};
|
||||
//-----------------------------------------------------------------------------------------
|
||||
function transformData(selectOrgCode, data) {
|
||||
const nodes = new Map();
|
||||
//获取所有的fieldValue 用于图例和钻取和data[]中的数据顺序保持一致 动态建立fieldValue的数据
|
||||
fieldValues.value = collectUniqueKeyFieldValues(data);
|
||||
// console.log(fieldValues.value);
|
||||
const orgMapper = new OrgCodeMapper(data); //用于快速查找orgtext
|
||||
// console.log(orgMapper.findOrgText('A01A01A01A01'));
|
||||
// 获取orgCode的所有层级
|
||||
function getHierarchy(orgCode) {
|
||||
const hierarchy = [];
|
||||
for (let i = selectOrgCode.length; i <= orgCode.length; i += 3) {
|
||||
hierarchy.push(orgCode.substring(0, i));
|
||||
}
|
||||
acc[key].data.push(curr.number);
|
||||
return acc;
|
||||
}, {});
|
||||
// console.log('hierarchy', hierarchy);
|
||||
return hierarchy;
|
||||
}
|
||||
// 获取父级orgCode
|
||||
function getParentCode(code) {
|
||||
if (code.length <= 3) return null;
|
||||
return code.substring(0, code.length - 3);
|
||||
}
|
||||
// 动态赋值series的数据长度
|
||||
let tempArrayValue = new Array(fieldValues.value.length).fill(0);
|
||||
// 创建所有节点并建立父子关系
|
||||
data.forEach((entry) => {
|
||||
const hierarchy = getHierarchy(entry.orgCode);
|
||||
// console.log(entry);
|
||||
hierarchy.forEach((code) => {
|
||||
// console.log(code);
|
||||
let tempOrgText = orgMapper.findOrgText(code) === undefined ? '' : orgMapper.findOrgText(code);
|
||||
// console.log(tempOrgText);
|
||||
if (!nodes.has(code)) {
|
||||
nodes.set(code, {
|
||||
orgCode: code,
|
||||
name: tempOrgText,
|
||||
type: 'bar',
|
||||
data: JSON.parse(JSON.stringify(tempArrayValue)), // 初始化data为[0, 0] 动态
|
||||
children: []
|
||||
});
|
||||
}
|
||||
});
|
||||
// console.log(nodes);
|
||||
// console.log('fieldValues', fieldValues.value, fieldValues.value.length, hierarchy);
|
||||
|
||||
return {
|
||||
categories: currentLevelData.map((d) => d.orgCode),
|
||||
series: Object.values(fieldGroups),
|
||||
children: children.length > 0 ? children : null
|
||||
};
|
||||
// 更新当前节点的data
|
||||
const node = nodes.get(entry.orgCode);
|
||||
const fieldValue = entry.fieldValue;
|
||||
|
||||
for (let i = 0; i < fieldValues.value.length; i++) {
|
||||
if (fieldValue === fieldValues.value[i].fieldValue) {
|
||||
// console.log(555, i, fieldValue, fieldValues.value[i], entry.number);
|
||||
node.data[i] += entry.number;
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(11, node);
|
||||
|
||||
// 建立父子关系
|
||||
for (let i = 0; i < hierarchy.length - 1; i++) {
|
||||
const parentCode = hierarchy[i];
|
||||
const childCode = hierarchy[i + 1];
|
||||
const parentNode = nodes.get(parentCode);
|
||||
const childNode = nodes.get(childCode);
|
||||
if (!parentNode.children.some((c) => c.orgCode === childCode)) {
|
||||
parentNode.children.push(childNode);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 计算非叶子节点的data(子节点之和)
|
||||
function computeData(node) {
|
||||
if (node.children.length === 0) return;
|
||||
node.data = JSON.parse(JSON.stringify(tempArrayValue));
|
||||
node.children.forEach((child) => {
|
||||
computeData(child);
|
||||
for (let i = 0; i < fieldValues.value.length; i++) {
|
||||
// console.log(666, i, node.data[i], child.data[i]);
|
||||
node.data[i] += child.data[i];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取所有根节点(没有父节点或父节点不存在)
|
||||
const rootNodes = [];
|
||||
nodes.forEach((node, code) => {
|
||||
const parentCode = getParentCode(code);
|
||||
// console.log(parentCode);
|
||||
if (!parentCode || !nodes.has(parentCode)) {
|
||||
rootNodes.push(node);
|
||||
}
|
||||
});
|
||||
|
||||
// 递归计算每个根节点的data
|
||||
rootNodes.forEach((root) => computeData(root));
|
||||
return rootNodes;
|
||||
// console.log('rootNodes', rootNodes);
|
||||
// // 转换为目标格式
|
||||
// function formatTree(node) {
|
||||
// // console.log(node);
|
||||
// return {
|
||||
// orgCode: node.orgCode,
|
||||
// name: node.name,
|
||||
// type: 'bar',
|
||||
// data: node.data,
|
||||
// children: node.children.map((child) => formatTree(child))
|
||||
// };
|
||||
// }
|
||||
|
||||
// return rootNodes.map((root) => {
|
||||
// console.log(root);
|
||||
// formatTree(root);
|
||||
// });
|
||||
}
|
||||
|
||||
// 使用示例
|
||||
// let currentLevel = 'A01A01'; // 初始层级
|
||||
// let chartData = transformDataForEcharts(originalData, currentLevel);
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
//根据 orgCode 的分级格式,递归地汇总本级及其所有下级的数据,并将下级数据放在本级的 children 属性中。 deepseek
|
||||
|
||||
const groupByOrgCode = (orgCode, data) => {
|
||||
// 过滤出本级和所有下级的数据
|
||||
const filteredData = data.filter((item) => item.orgCode.startsWith(orgCode));
|
||||
|
||||
const filteredData = data.filter((item) => item.orgCode.startsWith(orgCode));
|
||||
const orgMapper = new OrgCodeMapper(data);
|
||||
// 如果过滤后的数据为空,返回 null
|
||||
if (filteredData.length === 0) {
|
||||
uni.showToast({
|
||||
title: '过滤后数据为空',
|
||||
duration: 1000
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
// console.log(0, filteredData);
|
||||
// 按照 fieldValue 分组
|
||||
const groupedByFieldValue = {};
|
||||
filteredData.forEach((item) => {
|
||||
if (!groupedByFieldValue[item.fieldValue]) {
|
||||
groupedByFieldValue[item.fieldValue] = {
|
||||
number: 0,
|
||||
ldhth: []
|
||||
};
|
||||
}
|
||||
groupedByFieldValue[item.fieldValue].number += item.number;
|
||||
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
|
||||
});
|
||||
|
||||
try {
|
||||
filteredData.forEach((item) => {
|
||||
// console.log(item);
|
||||
if (!groupedByFieldValue[item.fieldValue]) {
|
||||
groupedByFieldValue[item.fieldValue] = {
|
||||
orgCode: item.orgCode,
|
||||
orgText: item.orgText,
|
||||
filedText: item.filedText,
|
||||
number: 0,
|
||||
ldhth: []
|
||||
};
|
||||
}
|
||||
// console.log(item.orgCode, 22, groupedByFieldValue[item.fieldValue]);
|
||||
groupedByFieldValue[item.fieldValue].number += item.number;
|
||||
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
console.log(1, orgMapper.findOrgText(orgCode));
|
||||
// 构建本级结果
|
||||
|
||||
const result = {
|
||||
orgCode: orgCode,
|
||||
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => ({
|
||||
fieldValue: fieldValue,
|
||||
number: groupedByFieldValue[fieldValue].number,
|
||||
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] // 去重
|
||||
})),
|
||||
orgText: orgMapper.findOrgText(orgCode),
|
||||
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => {
|
||||
const { filedText, orgCode, orgText } = groupedByFieldValue[fieldValue] || {};
|
||||
return {
|
||||
fieldValue: fieldValue,
|
||||
filedText: filedText,
|
||||
orgCode: orgCode,
|
||||
orgText: orgText,
|
||||
number: groupedByFieldValue[fieldValue].number,
|
||||
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] // 去重
|
||||
};
|
||||
}),
|
||||
children: []
|
||||
};
|
||||
|
||||
// console.log('本级', result);
|
||||
|
||||
// 获取所有下一级的 orgCode
|
||||
const nextLevelOrgCodes = new Set();
|
||||
filteredData.forEach((item) => {
|
||||
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
|
||||
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
|
||||
nextLevelOrgCodes.add(nextLevelOrgCode);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
filteredData.forEach((item) => {
|
||||
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
|
||||
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
|
||||
nextLevelOrgCodes.add(nextLevelOrgCode);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
// 递归处理下一级数据
|
||||
nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
|
||||
const child = groupByOrgCode(nextLevelOrgCode, data);
|
||||
if (child) {
|
||||
result.children.push(child);
|
||||
}
|
||||
});
|
||||
try {
|
||||
nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
|
||||
const child = groupByOrgCode(nextLevelOrgCode, data);
|
||||
if (child) {
|
||||
result.children.push(child);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
// console.log('全部', result);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
// 获取统计数据 then
|
||||
// 获取统计数据 then filter
|
||||
const fetchStatisticsData = async () => {
|
||||
if (!selectedOrgCode.value || !selectedField.value) return;
|
||||
let res = [];
|
||||
chartData.value = [];
|
||||
try {
|
||||
const res = await cxcRyDatAstatistics({
|
||||
res = await cxcRyDatAstatistics({
|
||||
orgCode: selectedOrgCode.value,
|
||||
field: selectedField.value
|
||||
field: selectedField.value,
|
||||
dictCode: dictCode.value,
|
||||
fieldisDict: fieldisDict.value
|
||||
});
|
||||
// console.log(res); //deepseek
|
||||
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res);
|
||||
console.log(orgCodeGroupData.value);
|
||||
chartData.value = orgCodeGroupData.value.children;
|
||||
updateChart();
|
||||
// console.log(res); //deepseek
|
||||
if (res.success) {
|
||||
// console.log(selectedOrgCode.value, res);
|
||||
if (res.result.length < 1) {
|
||||
uni.showToast({
|
||||
title: '查询数据为空'
|
||||
});
|
||||
return;
|
||||
}
|
||||
//按单位进行分组
|
||||
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res.result);
|
||||
// console.log(orgCodeGroupData.value);
|
||||
//将数据转换成echart格式
|
||||
const temp = transformData(selectedOrgCode.value, res.result);
|
||||
|
||||
if (temp[0].children.length > 0) {
|
||||
chartData.value = JSON.parse(JSON.stringify(temp[0].children));
|
||||
} else {
|
||||
chartData.value = temp[0];
|
||||
}
|
||||
chartDataCount.value = chartData.value.length;
|
||||
// console.log(chartData.value);
|
||||
updateChart(chartData.value);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error);
|
||||
}
|
||||
@ -316,12 +684,15 @@ const fetchStatisticsData = async () => {
|
||||
|
||||
// 获取人员列表 delimiter
|
||||
const fetchPersonnelList = async (ldhthList) => {
|
||||
personnelList.value = [];
|
||||
try {
|
||||
const res = await cxcRyDatAstatisticsDetails({
|
||||
ldhth: ldhthList
|
||||
});
|
||||
console.log(res);
|
||||
personnelList.value = res.data;
|
||||
if (res.success) {
|
||||
personnelList.value = res.result;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取人员列表失败:', error);
|
||||
}
|
||||
@ -330,16 +701,29 @@ const fetchPersonnelList = async (ldhthList) => {
|
||||
// 事件处理
|
||||
const onOrgCodeChange = (e, data) => {
|
||||
selectedOrgCode.value = e;
|
||||
console.log(data.value.title);
|
||||
// console.log(data.value.title);
|
||||
selectedOrgCodeLabel.value = data.value.title;
|
||||
fetchStatisticsData();
|
||||
};
|
||||
|
||||
const onFieldChange = (e) => {
|
||||
const index = e.detail.value;
|
||||
selectedField.value = fieldList.value[index].value;
|
||||
selectedFieldLabel.value = fieldList.value[index].label;
|
||||
fetchStatisticsData();
|
||||
// console.log(e);
|
||||
try {
|
||||
selectedField.value = e;
|
||||
for (var index = 0; index < fieldList.value.length; index++) {
|
||||
var element = fieldList.value[index];
|
||||
// console.log(element);
|
||||
if (element.value === e) {
|
||||
selectedFieldLabel.value = element.text;
|
||||
dictCode.value = element.dictCode;
|
||||
fieldisDict.value = element.isDict;
|
||||
}
|
||||
}
|
||||
fetchStatisticsData();
|
||||
} catch (error) {
|
||||
//TODO handle the exception
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const onChartClick = (e) => {
|
||||
@ -349,63 +733,40 @@ const onChartClick = (e) => {
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 颜色变量 */
|
||||
:root {
|
||||
--primary-blue: #409eff;
|
||||
--deep-blue: #2c7be5;
|
||||
--light-blue: #ecf5ff;
|
||||
--gradient-start: #6b8cff;
|
||||
--gradient-end: #4364f7;
|
||||
--hover-blue: #66b1ff;
|
||||
}
|
||||
|
||||
/* 全局容器 */
|
||||
.container {
|
||||
margin: 20, 20, 20, 20rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
border: 1rpx solid #ddd;
|
||||
padding: 15rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.query-btn {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
padding: 0 40rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.stats-box {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin: 30rpx 0;
|
||||
padding: 20rpx;
|
||||
background: #f8f8f8;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #0000ff;
|
||||
margin: 10rpx 10rpx;
|
||||
padding: 10rpx;
|
||||
background: linear-gradient(145deg, #f5f9ff, var(--light-blue));
|
||||
border-radius: 24rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(64, 158, 255, 0.15);
|
||||
border: 2rpx solid rgba(64, 158, 255, 0.1);
|
||||
}
|
||||
|
||||
/* 图表容器 */
|
||||
.chart-container {
|
||||
height: 800rpx;
|
||||
margin-top: 20rpx;
|
||||
height: 250px;
|
||||
margin: 20rpx 0;
|
||||
border-radius: 24rpx;
|
||||
overflow: hidden;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 8rpx 32rpx rgba(64, 158, 255, 0.12);
|
||||
border: 2rpx solid rgba(64, 158, 255, 0.08);
|
||||
}
|
||||
|
||||
/* 表格标题行 */
|
||||
|
||||
.titleStyle {
|
||||
font-size: 12px;
|
||||
color: #747474;
|
||||
@ -435,4 +796,70 @@ const onChartClick = (e) => {
|
||||
border-left: 1px solid #919191;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* 滚动区域 */
|
||||
scroll-view {
|
||||
background: #ffffff;
|
||||
border-radius: 0 0 16rpx 16rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 35, 111, 0.08);
|
||||
}
|
||||
|
||||
/* 输入框聚焦效果 */
|
||||
.trq-depart-select:focus-within {
|
||||
box-shadow: 0 0 0 4rpx rgba(64, 158, 255, 0.2);
|
||||
border-color: var(--primary-blue);
|
||||
}
|
||||
|
||||
/* 加载动画优化 */
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20rpx);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.container > * {
|
||||
animation: fadeIn 0.6s cubic-bezier(0.23, 1, 0.32, 1);
|
||||
}
|
||||
|
||||
/* 自定义滚动条美化 */
|
||||
::-webkit-scrollbar {
|
||||
width: 8rpx;
|
||||
background: rgba(64, 158, 255, 0.05);
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: linear-gradient(45deg, var(--primary-blue), var(--deep-blue));
|
||||
border-radius: 12rpx;
|
||||
border: 2rpx solid white;
|
||||
}
|
||||
|
||||
/* 筛选行间距优化 */
|
||||
.filter-row {
|
||||
margin: 30rpx 0;
|
||||
padding: 20rpx 0;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
/* 响应式调整优化 */
|
||||
@media (max-width: 768px) {
|
||||
.chart-container {
|
||||
height: 250px;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
/* 数据行高亮效果 */
|
||||
.data-row:nth-child(even) {
|
||||
background: rgba(236, 245, 255, 0.3);
|
||||
}
|
||||
|
||||
.data-row:hover {
|
||||
box-shadow: 0 4rpx 12rpx rgba(64, 158, 255, 0.1);
|
||||
}
|
||||
</style>
|
||||
|
@ -1,18 +1,17 @@
|
||||
<template>
|
||||
<view>
|
||||
<view class="container" id="top1">
|
||||
<uni-row style="margin-bottom: 10rpx;margin-left: 30rpx;margin-right: 30rpx;">
|
||||
<uni-col :span="24"><uni-title :title="'所选单位ID:'+orgCode" align="left" type="h4"></uni-title></uni-col>
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24"><uni-title :title="'所选单位'" align="left" type="h4"></uni-title></uni-col>
|
||||
</uni-row>
|
||||
<uni-row style="margin-bottom: 20rpx;margin-left: 30rpx;margin-right: 30rpx;">
|
||||
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<uni-col :span="24">
|
||||
<trq-depart-select v-model="orgCode" returnCodeOrID="orgCode"
|
||||
@change="departChange"></trq-depart-select>
|
||||
<trq-depart-select v-model="orgCode" returnCodeOrID="orgCode" @change="departChange"></trq-depart-select>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
<!-- 概览统计 -->
|
||||
<view class="stats-box" v-if="summary.total">
|
||||
<view class=" stat-item">
|
||||
<view class="stat-item">
|
||||
<text class="label">总人数</text>
|
||||
<text class="value">{{ summary.total }}</text>
|
||||
</view>
|
||||
@ -27,56 +26,47 @@
|
||||
<l-echart ref="chart" @finished="initChart" />
|
||||
</view>
|
||||
|
||||
|
||||
<!-- 数据表格 -->
|
||||
|
||||
<uni-row style="margin-top: 10px; margin-left: 30rpx;margin-right: 30rpx;" v-if="tableData.length>0">
|
||||
<uni-row style="margin-top: 10px; margin-left: 30rpx; margin-right: 30rpx" v-if="tableData.length > 0">
|
||||
<uni-col :span="3">
|
||||
<view class="titleStyle">
|
||||
序号
|
||||
</view>
|
||||
<view class="titleStyle">序号</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">
|
||||
姓名
|
||||
</view>
|
||||
<view class="titleStyle">姓名</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">
|
||||
性别
|
||||
</view>
|
||||
<view class="titleStyle">性别</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="titleStyle">
|
||||
年龄
|
||||
</view>
|
||||
<view class="titleStyle">年龄</view>
|
||||
</uni-col>
|
||||
<uni-col :span="6">
|
||||
<view class="titleStyle">
|
||||
操作
|
||||
</view>
|
||||
<view class="titleStyle">操作</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
|
||||
<scroll-view scroll-y :style="{height: bottomHeight + 'px' }">
|
||||
<uni-row style="margin-bottom: 10rpx;margin-left: 30rpx;margin-right: 30rpx;">
|
||||
<view v-for="(item,index) in tableData">
|
||||
<scroll-view scroll-y :style="{ height: bottomHeight + 'px' }">
|
||||
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
|
||||
<view v-for="(item, index) in tableData">
|
||||
<uni-col :span="3">
|
||||
<view class="dataStyle">
|
||||
{{index+1}}
|
||||
{{ index + 1 }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{item.xm}}
|
||||
{{ item.xm }}
|
||||
</view>
|
||||
</uni-col><uni-col :span="5">
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{item.xb_dictText}}
|
||||
{{ item.xb_dictText }}
|
||||
</view>
|
||||
</uni-col><uni-col :span="5">
|
||||
</uni-col>
|
||||
<uni-col :span="5">
|
||||
<view class="dataStyle">
|
||||
{{item.nl}}
|
||||
{{ item.nl }}
|
||||
</view>
|
||||
</uni-col>
|
||||
<uni-col :span="6">
|
||||
@ -84,310 +74,297 @@
|
||||
<button size="mini" type="primary" @click="detail(item)">详情</button>
|
||||
</view>
|
||||
</uni-col>
|
||||
|
||||
</view>
|
||||
|
||||
</uni-row>
|
||||
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
ref,
|
||||
reactive,
|
||||
onMounted
|
||||
} from 'vue';
|
||||
import * as echarts from 'echarts'
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import * as echarts from 'echarts';
|
||||
|
||||
import {
|
||||
queryRenyuanByDepartID
|
||||
} from '@/api/renyuan.js'
|
||||
import { queryRenyuanByDepartID } from '@/api/renyuan.js';
|
||||
|
||||
// 存储下方组件的高度
|
||||
const bottomHeight = ref(0);
|
||||
// 新增加载状态
|
||||
const isLoading = ref(false);
|
||||
const orgCode = ref('');
|
||||
const rawData = ref([]);
|
||||
const tableData = ref([]);
|
||||
const summary = reactive({
|
||||
total: 0,
|
||||
avgAge: 0
|
||||
// 存储下方组件的高度
|
||||
const bottomHeight = ref(0);
|
||||
// 新增加载状态
|
||||
const isLoading = ref(false);
|
||||
const orgCode = ref('');
|
||||
const rawData = ref([]);
|
||||
const tableData = ref([]);
|
||||
const summary = reactive({
|
||||
total: 0,
|
||||
avgAge: 0
|
||||
});
|
||||
const chart = ref(null);
|
||||
const chartOption = ref({});
|
||||
const drillPopup = ref(null);
|
||||
const drillList = ref([]);
|
||||
const drillTitle = ref('');
|
||||
|
||||
function detail(record) {
|
||||
// console.log(record)
|
||||
uni.navigateTo({
|
||||
url: '/pages/views/renliziyuan/renyuanxinxi/detail?data=' + encodeURIComponent(JSON.stringify(record))
|
||||
});
|
||||
const chart = ref(null);
|
||||
const chartOption = ref({});
|
||||
const drillPopup = ref(null);
|
||||
const drillList = ref([]);
|
||||
const drillTitle = ref('');
|
||||
|
||||
function detail(record) {
|
||||
// console.log(record)
|
||||
uni.navigateTo({
|
||||
url: "/pages/views/renliziyuan/renyuanxinxi/detail?data=" + encodeURIComponent(JSON.stringify(record))
|
||||
})
|
||||
}
|
||||
// 计算年龄initChart
|
||||
const calculateAge = (birthDate) => {
|
||||
const today = new Date();
|
||||
const birth = new Date(birthDate);
|
||||
let age = today.getFullYear() - birth.getFullYear();
|
||||
const monthDiff = today.getMonth() - birth.getMonth();
|
||||
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
|
||||
age--;
|
||||
}
|
||||
// 计算年龄initChart
|
||||
const calculateAge = (birthDate) => {
|
||||
const today = new Date();
|
||||
const birth = new Date(birthDate);
|
||||
let age = today.getFullYear() - birth.getFullYear();
|
||||
const monthDiff = today.getMonth() - birth.getMonth();
|
||||
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
|
||||
age--;
|
||||
return age;
|
||||
};
|
||||
// 加载数据
|
||||
const departChange = async (e, data) => {
|
||||
tableData.value = [];
|
||||
console.log(e);
|
||||
orgCode.value = e;
|
||||
try {
|
||||
// 显示加载状态
|
||||
|
||||
isLoading.value = true;
|
||||
if (orgCode.value.length <= 6) {
|
||||
console.log(123242353);
|
||||
uni.showToast({
|
||||
title: '全厂数据较多,请选 下一层级...',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
});
|
||||
isLoading.value = false;
|
||||
return;
|
||||
} else {
|
||||
uni.showLoading({
|
||||
title: '数据加载中...',
|
||||
mask: true
|
||||
});
|
||||
}
|
||||
return age;
|
||||
};
|
||||
// 加载数据
|
||||
const departChange = async (e, data) => {
|
||||
|
||||
tableData.value = []
|
||||
console.log(e)
|
||||
orgCode.value = e;
|
||||
try {
|
||||
// 显示加载状态
|
||||
|
||||
isLoading.value = true;
|
||||
if (orgCode.value.length <= 6) {
|
||||
|
||||
console.log(123242353)
|
||||
uni.showLoading({
|
||||
title: '全厂数据较多,耐心等待数据加载中...',
|
||||
mask: true
|
||||
});
|
||||
} else {
|
||||
uni.showLoading({
|
||||
title: '数据加载中...',
|
||||
mask: true
|
||||
});
|
||||
}
|
||||
|
||||
let params = {
|
||||
pageSize: 3000,
|
||||
fields: ['xm', 'nl', 'xb', 'xb_dictText', 'orgCode', 'jcdw', 'jcxd', 'jcxdCode']
|
||||
};
|
||||
if (orgCode.value.length <= 9) {
|
||||
params.orgCode = orgCode.value
|
||||
} else {
|
||||
params.jcxd_code = orgCode.value
|
||||
|
||||
}
|
||||
queryRenyuanByDepartID(params).then((res) => {
|
||||
let params = {
|
||||
pageSize: 3000,
|
||||
fields: ['xm', 'nl', 'xb', 'xb_dictText', 'orgCode', 'jcdw', 'jcxd', 'jcxdCode']
|
||||
};
|
||||
if (orgCode.value.length <= 9) {
|
||||
params.orgCode = orgCode.value;
|
||||
} else {
|
||||
params.jcxd_code = orgCode.value;
|
||||
}
|
||||
queryRenyuanByDepartID(params)
|
||||
.then((res) => {
|
||||
if (res.success) {
|
||||
processData(res.result.records);
|
||||
|
||||
// 隐藏加载状态
|
||||
isLoading.value = false;
|
||||
uni.hideLoading();
|
||||
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
uni.showToast({
|
||||
title: '数据加载失败',
|
||||
icon: 'none'
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
uni.showToast({
|
||||
title: '数据加载失败',
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
// 隐藏加载状态
|
||||
isLoading.value = false;
|
||||
uni.hideLoading();
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
uni.showToast({
|
||||
title: '数据加载失败',
|
||||
icon: 'none',
|
||||
duration: 1000
|
||||
});
|
||||
} finally {
|
||||
// 隐藏加载状态
|
||||
isLoading.value = false;
|
||||
uni.hideLoading();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 数据处理
|
||||
const processData = (data) => {
|
||||
|
||||
// 添加年龄字段并过滤有效数据
|
||||
const validData = data.map(item => ({
|
||||
// 数据处理
|
||||
const processData = (data) => {
|
||||
// 添加年龄字段并过滤有效数据
|
||||
const validData = data
|
||||
.map((item) => ({
|
||||
...item,
|
||||
nl: calculateAge(item.cssj)
|
||||
})).filter(item => item.nl >= 21 && item.nl <= 64);
|
||||
// 计算概览数据
|
||||
summary.total = validData.length;
|
||||
summary.avgAge = validData.reduce((sum, cur) => sum + cur.nl, 0) / summary.total || 0;
|
||||
// 生成表格数据
|
||||
// tableData.value = validData;
|
||||
|
||||
groupsData(validData);
|
||||
// 生成图表数据
|
||||
generateChartData(validData);
|
||||
|
||||
};
|
||||
|
||||
// 计算统计信息...
|
||||
const subOrgStaffs = ref({}); // 按下级单位存储所有人员
|
||||
const ageGroupStaffs = ref({}); // 按年龄段存储所有人员
|
||||
|
||||
|
||||
const groupsData = (data) => {
|
||||
// 清空旧数据
|
||||
subOrgStaffs.value = {};
|
||||
ageGroupStaffs.value = {};
|
||||
data.reduce((acc, cur) => {
|
||||
// console.log(cur)
|
||||
let subOrg = "";
|
||||
let ageRange = getAgeRange(cur.nl);
|
||||
// console.log(cur.orgCode, cur.jcxdCode)
|
||||
if (cur.orgCode <= 6) {
|
||||
subOrg = cur.orgCode
|
||||
} else {
|
||||
subOrg = cur.jcxdCode
|
||||
}
|
||||
|
||||
// 存储到subOrgStaffs
|
||||
if (!subOrgStaffs.value[subOrg]) {
|
||||
subOrgStaffs.value[subOrg] = [];
|
||||
}
|
||||
subOrgStaffs.value[subOrg].push(cur);
|
||||
|
||||
// 存储到ageGroupStaffs
|
||||
if (!ageGroupStaffs.value[ageRange]) {
|
||||
ageGroupStaffs.value[ageRange] = [];
|
||||
}
|
||||
ageGroupStaffs.value[ageRange].push(cur);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 新增年龄范围计算方法
|
||||
const getAgeRange = (age) => {
|
||||
const ranges = ['21-30岁', '31-40岁', '41-50岁', '51-60岁', '61-64岁'];
|
||||
const index = Math.floor((age - 21) / 10);
|
||||
return ranges[index] || '其他';
|
||||
};
|
||||
|
||||
// 修改后的显示人员列表方法
|
||||
const showStaffList = (subOrg, ageRange) => {
|
||||
// 从结构化数据中直接获取
|
||||
const targetStaffs = subOrgStaffs.value[subOrg].filter(staff =>
|
||||
getAgeRange(staff.nl) === ageRange
|
||||
);
|
||||
|
||||
staffList.value = targetStaffs;
|
||||
popupTitle.value = `${subOrg} ${ageRange}人员列表(共${targetStaffs.length}人)`;
|
||||
popup.value.open();
|
||||
};
|
||||
|
||||
// 新增获取指定单位人员的方法
|
||||
const getSubOrgStaffs = (subOrgCode) => {
|
||||
return subOrgStaffs.value[subOrgCode] || [];
|
||||
};
|
||||
|
||||
// 新增获取指定年龄段人员的方法
|
||||
const getAgeGroupStaffs = (ageRange) => {
|
||||
return ageGroupStaffs.value[ageRange] || [];
|
||||
};
|
||||
|
||||
// 生成图表数据(修改部分)
|
||||
const generateChartData = (data) => {
|
||||
// 按基层单位分组
|
||||
const ageRanges = ['21-30岁', '31-40岁', '41-50岁', '51-60岁', '61-64岁'];
|
||||
const jcdwGroups = data.reduce((acc, cur) => {
|
||||
if (!acc[cur.jcdw]) {
|
||||
acc[cur.jcdw] = {
|
||||
ageGroups: [0, 0, 0, 0, 0] // 21-30,31-40,41-50,51-60,61-64
|
||||
};
|
||||
}
|
||||
const ageGroup = Math.floor((cur.nl - 21) / 10);
|
||||
// console.log(ageGroup, cur.jcdw)
|
||||
if (ageGroup >= 0 && ageGroup <= 4) {
|
||||
acc[cur.jcdw].ageGroups[ageGroup]++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
|
||||
// 生成分组柱状图配置
|
||||
const xData = Object.keys(jcdwGroups);
|
||||
|
||||
const seriesData = ageRanges.map((range, index) => ({
|
||||
name: range,
|
||||
type: 'bar',
|
||||
data: xData.map(jcdw => jcdwGroups[jcdw].ageGroups[index] || 0),
|
||||
itemStyle: {
|
||||
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
|
||||
},
|
||||
// 显示数值标签
|
||||
label: {
|
||||
show: true,
|
||||
position: 'top'
|
||||
},
|
||||
// 设置柱宽为 20 像素
|
||||
// barWidth: 20
|
||||
}))
|
||||
chartOption.value = {
|
||||
title: {
|
||||
text: '人员年龄分组统计',
|
||||
padding: [0, 0, 0, 30],
|
||||
},
|
||||
toolbox: {
|
||||
padding: [0, 30, 0, 0],
|
||||
show: true,
|
||||
feature: {
|
||||
//工具配置项
|
||||
.filter((item) => item.nl >= 21 && item.nl <= 64);
|
||||
// 计算概览数据
|
||||
summary.total = validData.length;
|
||||
summary.avgAge = validData.reduce((sum, cur) => sum + cur.nl, 0) / summary.total || 0;
|
||||
// 生成表格数据
|
||||
// tableData.value = validData;
|
||||
|
||||
restore: {
|
||||
show: true //是否显示该工具
|
||||
},
|
||||
saveAsImage: {
|
||||
show: true //是否显示该工具
|
||||
}
|
||||
}
|
||||
},
|
||||
// tooltip: {
|
||||
// trigger: 'axis',
|
||||
// axisPointer: {
|
||||
// type: 'shadow',
|
||||
// label: {
|
||||
// show: false
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
grid: {
|
||||
top: '15%',
|
||||
left: '4%',
|
||||
right: '4%',
|
||||
bottom: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
legend: {
|
||||
data: ageRanges,
|
||||
itemGap: 5,
|
||||
padding: [0, 15, 0, 15],
|
||||
y: 'bottom',
|
||||
itemHeight: 8, //高
|
||||
itemWidth: 8, //宽
|
||||
type: 'scroll'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: xData,
|
||||
axisLabel: {
|
||||
color: '#7F84B5',
|
||||
fontWeight: 300,
|
||||
interval: 0,
|
||||
rotate: 0,
|
||||
groupsData(validData);
|
||||
// 生成图表数据
|
||||
generateChartData(validData);
|
||||
};
|
||||
|
||||
// 计算统计信息...
|
||||
const subOrgStaffs = ref({}); // 按下级单位存储所有人员
|
||||
const ageGroupStaffs = ref({}); // 按年龄段存储所有人员
|
||||
|
||||
const groupsData = (data) => {
|
||||
// 清空旧数据
|
||||
subOrgStaffs.value = {};
|
||||
ageGroupStaffs.value = {};
|
||||
data.reduce((acc, cur) => {
|
||||
// console.log(cur)
|
||||
let subOrg = '';
|
||||
let ageRange = getAgeRange(cur.nl);
|
||||
// console.log(cur.orgCode, cur.jcxdCode)
|
||||
if (cur.orgCode <= 6) {
|
||||
subOrg = cur.orgCode;
|
||||
} else {
|
||||
subOrg = cur.jcxdCode;
|
||||
}
|
||||
|
||||
// 存储到subOrgStaffs
|
||||
if (!subOrgStaffs.value[subOrg]) {
|
||||
subOrgStaffs.value[subOrg] = [];
|
||||
}
|
||||
subOrgStaffs.value[subOrg].push(cur);
|
||||
|
||||
// 存储到ageGroupStaffs
|
||||
if (!ageGroupStaffs.value[ageRange]) {
|
||||
ageGroupStaffs.value[ageRange] = [];
|
||||
}
|
||||
ageGroupStaffs.value[ageRange].push(cur);
|
||||
});
|
||||
};
|
||||
|
||||
// 新增年龄范围计算方法
|
||||
const getAgeRange = (age) => {
|
||||
const ranges = ['21-30岁', '31-40岁', '41-50岁', '51-60岁', '61-64岁'];
|
||||
const index = Math.floor((age - 21) / 10);
|
||||
return ranges[index] || '其他';
|
||||
};
|
||||
|
||||
// 修改后的显示人员列表方法
|
||||
const showStaffList = (subOrg, ageRange) => {
|
||||
// 从结构化数据中直接获取
|
||||
const targetStaffs = subOrgStaffs.value[subOrg].filter((staff) => getAgeRange(staff.nl) === ageRange);
|
||||
|
||||
staffList.value = targetStaffs;
|
||||
popupTitle.value = `${subOrg} ${ageRange}人员列表(共${targetStaffs.length}人)`;
|
||||
popup.value.open();
|
||||
};
|
||||
|
||||
// 新增获取指定单位人员的方法
|
||||
const getSubOrgStaffs = (subOrgCode) => {
|
||||
return subOrgStaffs.value[subOrgCode] || [];
|
||||
};
|
||||
|
||||
// 新增获取指定年龄段人员的方法
|
||||
const getAgeGroupStaffs = (ageRange) => {
|
||||
return ageGroupStaffs.value[ageRange] || [];
|
||||
};
|
||||
|
||||
// 生成图表数据(修改部分)
|
||||
const generateChartData = (data) => {
|
||||
// 按基层单位分组
|
||||
const ageRanges = ['21-30岁', '31-40岁', '41-50岁', '51-60岁', '61-64岁'];
|
||||
const jcdwGroups = data.reduce((acc, cur) => {
|
||||
if (!acc[cur.jcdw]) {
|
||||
acc[cur.jcdw] = {
|
||||
ageGroups: [0, 0, 0, 0, 0] // 21-30,31-40,41-50,51-60,61-64
|
||||
};
|
||||
}
|
||||
const ageGroup = Math.floor((cur.nl - 21) / 10);
|
||||
// console.log(ageGroup, cur.jcdw)
|
||||
if (ageGroup >= 0 && ageGroup <= 4) {
|
||||
acc[cur.jcdw].ageGroups[ageGroup]++;
|
||||
}
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// 生成分组柱状图配置
|
||||
const xData = Object.keys(jcdwGroups);
|
||||
|
||||
const seriesData = ageRanges.map((range, index) => ({
|
||||
name: range,
|
||||
type: 'bar',
|
||||
data: xData.map((jcdw) => jcdwGroups[jcdw].ageGroups[index] || 0),
|
||||
itemStyle: {
|
||||
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
|
||||
},
|
||||
// 显示数值标签
|
||||
label: {
|
||||
show: true,
|
||||
position: 'top'
|
||||
}
|
||||
// 设置柱宽为 20 像素
|
||||
// barWidth: 20
|
||||
}));
|
||||
chartOption.value = {
|
||||
title: {
|
||||
text: '人员年龄分组统计',
|
||||
padding: [0, 0, 0, 30]
|
||||
},
|
||||
toolbox: {
|
||||
padding: [0, 30, 0, 0],
|
||||
show: true,
|
||||
feature: {
|
||||
//工具配置项
|
||||
|
||||
restore: {
|
||||
show: true //是否显示该工具
|
||||
},
|
||||
padding: [0, 10, 0, 10],
|
||||
axisTick: {
|
||||
show: false //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
saveAsImage: {
|
||||
show: true //是否显示该工具
|
||||
}
|
||||
}
|
||||
},
|
||||
// tooltip: {
|
||||
// trigger: 'axis',
|
||||
// axisPointer: {
|
||||
// type: 'shadow',
|
||||
// label: {
|
||||
// show: false
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
grid: {
|
||||
top: '15%',
|
||||
left: '4%',
|
||||
right: '4%',
|
||||
bottom: '10%',
|
||||
containLabel: true
|
||||
},
|
||||
legend: {
|
||||
data: ageRanges,
|
||||
itemGap: 5,
|
||||
padding: [0, 15, 0, 15],
|
||||
y: 'bottom',
|
||||
itemHeight: 8, //高
|
||||
itemWidth: 8, //宽
|
||||
type: 'scroll'
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: xData,
|
||||
axisLabel: {
|
||||
color: '#7F84B5',
|
||||
fontWeight: 300,
|
||||
interval: 0,
|
||||
rotate: 0
|
||||
},
|
||||
yAxis: [{
|
||||
padding: [0, 10, 0, 10],
|
||||
axisTick: {
|
||||
show: false //刻度线
|
||||
},
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
show: true,
|
||||
boundaryGap: false, //解决数据与线不对应问题
|
||||
type: 'value',
|
||||
@ -411,153 +388,147 @@
|
||||
axisLine: {
|
||||
show: false //不显示坐标轴线
|
||||
}
|
||||
}],
|
||||
|
||||
series: seriesData,
|
||||
|
||||
};
|
||||
|
||||
// 初始化图表
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return
|
||||
const myChart = await chart.value.init(echarts)
|
||||
myChart.setOption(chartOption.value)
|
||||
myChart.on('click', (params) => {
|
||||
console.log(params.seriesName)
|
||||
tableData.value = getAgeGroupStaffs(params.seriesName)
|
||||
|
||||
})
|
||||
}, 300)
|
||||
|
||||
|
||||
// #ifdef APP
|
||||
getHeight();
|
||||
// #endif
|
||||
}
|
||||
],
|
||||
|
||||
series: seriesData
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
// #ifdef APP
|
||||
getHeight();
|
||||
// #endif
|
||||
})
|
||||
// #ifdef APP
|
||||
|
||||
const getHeight = () => {
|
||||
// 获取屏幕高度
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const screenHeight = systemInfo.screenHeight;
|
||||
// 创建选择器查询对象
|
||||
const query = uni.createSelectorQuery();
|
||||
// 获取上方组件的高度
|
||||
query
|
||||
.select('#top1')
|
||||
.boundingClientRect((rect1) => {
|
||||
// 计算上方组件高度总和
|
||||
const topComponentsHeight = rect1.height
|
||||
// 计算下方组件的高度
|
||||
bottomHeight.value = screenHeight - topComponentsHeight - 415;
|
||||
})
|
||||
.exec();
|
||||
};
|
||||
|
||||
// #endif
|
||||
// 初始化图表
|
||||
const initChart = () => {
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return
|
||||
const myChart = await chart.value.init(echarts)
|
||||
myChart.setOption(chartOption.value)
|
||||
}, 300)
|
||||
};
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return;
|
||||
const myChart = await chart.value.init(echarts);
|
||||
myChart.setOption(chartOption.value);
|
||||
myChart.on('click', (params) => {
|
||||
console.log(params.seriesName);
|
||||
tableData.value = getAgeGroupStaffs(params.seriesName);
|
||||
});
|
||||
}, 300);
|
||||
|
||||
// #ifdef APP
|
||||
getHeight();
|
||||
// #endif
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
// #ifdef APP
|
||||
getHeight();
|
||||
// #endif
|
||||
});
|
||||
// #ifdef APP
|
||||
|
||||
const getHeight = () => {
|
||||
// 获取屏幕高度
|
||||
const systemInfo = uni.getSystemInfoSync();
|
||||
const screenHeight = systemInfo.screenHeight;
|
||||
// 创建选择器查询对象
|
||||
const query = uni.createSelectorQuery();
|
||||
// 获取上方组件的高度
|
||||
query
|
||||
.select('#top1')
|
||||
.boundingClientRect((rect1) => {
|
||||
// 计算上方组件高度总和
|
||||
const topComponentsHeight = rect1.height;
|
||||
// 计算下方组件的高度
|
||||
bottomHeight.value = screenHeight - topComponentsHeight - 415;
|
||||
})
|
||||
.exec();
|
||||
};
|
||||
|
||||
// #endif
|
||||
// 初始化图表
|
||||
const initChart = () => {
|
||||
setTimeout(async () => {
|
||||
if (!chart.value) return;
|
||||
const myChart = await chart.value.init(echarts);
|
||||
myChart.setOption(chartOption.value);
|
||||
}, 300);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
margin: 20, 20, 20, 20rpx;
|
||||
}
|
||||
.container {
|
||||
margin: 20, 20, 20, 20rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
.input-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
border: 1rpx solid #ddd;
|
||||
padding: 15rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.input {
|
||||
flex: 1;
|
||||
border: 1rpx solid #ddd;
|
||||
padding: 15rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.query-btn {
|
||||
background: #007AFF;
|
||||
color: white;
|
||||
padding: 0 40rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.query-btn {
|
||||
background: #007aff;
|
||||
color: white;
|
||||
padding: 0 40rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.stats-box {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin: 30rpx 0;
|
||||
padding: 20rpx;
|
||||
background: #f8f8f8;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
.stats-box {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin: 30rpx 0;
|
||||
padding: 20rpx;
|
||||
background: #f8f8f8;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
.label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #0000ff;
|
||||
}
|
||||
.value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #0000ff;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 400rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
.chart-container {
|
||||
height: 400rpx;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.titleStyle {
|
||||
font-size: 12px;
|
||||
color: #747474;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
background: #F2F9FC;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-left: 1px solid #919191;
|
||||
border-bottom: 1px solid #919191;
|
||||
;
|
||||
}
|
||||
.titleStyle {
|
||||
font-size: 12px;
|
||||
color: #747474;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
background: #f2f9fc;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-left: 1px solid #919191;
|
||||
border-bottom: 1px solid #919191;
|
||||
}
|
||||
|
||||
/* 内容样式 */
|
||||
.dataStyle {
|
||||
max-font-size: 14px;
|
||||
/* 最大字体限制 */
|
||||
min-font-size: 10px;
|
||||
/* 最小字体限制 */
|
||||
font-size: 12px;
|
||||
color: #00007f;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-bottom: 1px solid #919191;
|
||||
border-left: 1px solid #919191;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
}
|
||||
</style>
|
||||
/* 内容样式 */
|
||||
.dataStyle {
|
||||
max-font-size: 14px;
|
||||
/* 最大字体限制 */
|
||||
min-font-size: 10px;
|
||||
/* 最小字体限制 */
|
||||
font-size: 12px;
|
||||
color: #00007f;
|
||||
line-height: 30px;
|
||||
height: 30px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
border-bottom: 1px solid #919191;
|
||||
border-left: 1px solid #919191;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user