更新 pages/views/renliziyuan/renyuanxinxi/qttongji.vue

This commit is contained in:
ldeyun 2025-02-13 14:29:56 +00:00
parent ebf06cffaa
commit 8050b65ea8

View File

@ -22,9 +22,9 @@
</view> </view>
<!-- 翻页按钮 --> <!-- 翻页按钮 -->
<view style="display: flex; justify-content: center; margin-top: 20px"> <view style="display: flex; justify-content: center; margin-top: 10px">
<button @click="prevPage" :disabled="currentPage === 1">上一页</button> <button @click="prevPage" :disabled="currentPage === 1" size="mini">上一页</button>
<button @click="nextPage" :disabled="currentPage * pageSize >= chartDataCount.value">下一页</button> <button @click="nextPage" :disabled="currentPage * pageSize >= chartDataCount.value" size="mini">下一页</button>
</view> </view>
<!-- 数据表格 --> <!-- 数据表格 -->
@ -37,7 +37,7 @@
<view class="titleStyle">姓名</view> <view class="titleStyle">姓名</view>
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
<view class="titleStyle">性别</view> <view class="titleStyle">基层单位</view>
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
<view class="titleStyle">年龄</view> <view class="titleStyle">年龄</view>
@ -62,7 +62,7 @@
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
<view class="dataStyle"> <view class="dataStyle">
{{ item.xb_dictText }} {{ item.jcxd }}
</view> </view>
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
@ -85,6 +85,8 @@
import { ref, reactive, onMounted, computed } from 'vue'; import { ref, reactive, onMounted, computed } from 'vue';
import * as echarts from 'echarts'; import * as echarts from 'echarts';
import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js'; import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js';
import { initDictOption } from '@/api/common.js';
// tableData // tableData
const bottomHeight = ref(0); const bottomHeight = ref(0);
// //
@ -93,17 +95,27 @@ const chartDataCount = ref(0);
const fieldList = ref([ const fieldList = ref([
{ {
text: '性别', text: '性别',
value: 'xb' value: 'xb',
isDict: true,
dictCode: 'sex'
}, },
{ {
text: '年龄', text: '政治面貌',
value: 'nl' value: 'zzmm',
isDict: true,
dictCode: 'zzmm'
}, },
{ {
text: '学历', text: '民族',
value: 'rylb1' value: 'mz',
isDict: true,
dictCode: 'mz'
} }
]); // ]); //
const dictCode = ref('');
const fieldisDict = ref(true);
const selectedOrgCode = ref(''); // orgCode const selectedOrgCode = ref(''); // orgCode
const selectedOrgCodeLabel = ref('请选择单位'); // const selectedOrgCodeLabel = ref('请选择单位'); //
const selectedField = ref(''); // const selectedField = ref(''); //
@ -111,7 +123,8 @@ const selectedFieldLabel = ref('请选择字段'); // 当前选择的字段名
const orgCodeGroupData = ref([]); //orgcode const orgCodeGroupData = ref([]); //orgcode
const chartData = ref({}); // const chartData = ref({}); //
const personnelList = ref([]); // initChart const personnelList = ref([]); // initChart
const fieldValues = ref([]); const fieldValues = ref([]); //
const fieldTexts = ref([]); //
const chartOption = ref({}); const chartOption = ref({});
const chartTitle = computed(() => { const chartTitle = computed(() => {
@ -165,56 +178,69 @@ const initChart = () => {
}, 300); }, 300);
}; };
// const prevPage = () => {
const updateChart = (tempchartData) => { if (currentPage.value > 1) {
// currentPage.value--;
setTimeout(async () => { }
if (!chart.value) return; updateChart(chartData.value);
const myChart = await chart.value.init(echarts); };
console.log(tempchartData);
let temp = JSON.parse(JSON.stringify(tempchartData[0].children)); const nextPage = () => {
chartDataCount.value = temp.length; if (currentPage.value * pageSize.value < chartDataCount.value) {
currentPage.value++;
// //
const startIndex = (currentPage.value - 1) * pageSize.value; const startIndex = (currentPage.value - 1) * pageSize.value;
const endIndex = startIndex + pageSize.value; const endIndex = startIndex + pageSize.value;
// updateChart(chartData.value);
const pageData = temp.slice(startIndex, endIndex); // 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 xData = [];
let seriesData = []; let seriesData = [];
// console.log(1, temp); console.log(1, tempChartData);
// transformDataForEcharts // transformDataForEcharts
pageData.forEach((item) => { let legendData = [];
for (let i = 0; i < fieldValues.value.length; i++) {
legendData.push(fieldValues.value[i].filedText);
}
tempChartData.forEach((item) => {
xData.push(item.name); xData.push(item.name);
}); });
for (let i = 0; i < fieldValues.value.length; i++) { for (let i = 0; i < fieldValues.value.length; i++) {
let tempData = []; let tempData = [];
pageData.forEach((item) => { tempChartData.forEach((item) => {
console.log(item);
if (item.data[i]) { if (item.data[i]) {
tempData.push(item.data[i]); tempData.push(item.data[i]);
} else { } else {
tempData.push(0); tempData.push(0);
} }
}); });
seriesData.push({ name: fieldValues.value[i], type: 'bar', data: tempData }); seriesData.push({
name: fieldValues.value[i].filedText,
type: 'bar',
label: {
show: true, //
position: 'top' //
},
data: tempData
});
} }
console.log(2, legendData, xData, seriesData);
function prevPage() { let tempOption = {
if (currentPage.value > 1) {
currentPage.value--;
updateChart(chartData.value);
}
}
function nextPage() {
if (currentPage.value * pageSize.value < chartDataCount) {
currentPage.value++;
updateChart(chartData.value);
}
}
console.log(xData, seriesData, fieldValues.value);
myChart.setOption({
title: { title: {
text: chartTitle.value, text: chartTitle.value,
padding: [0, 0, 0, 30] padding: [0, 0, 0, 30]
@ -280,7 +306,7 @@ const updateChart = (tempchartData) => {
series: seriesData, series: seriesData,
legend: { legend: {
data: fieldValues.value, data: legendData,
itemGap: 5, itemGap: 5,
padding: [0, 15, 0, 15], padding: [0, 15, 0, 15],
y: 'bottom', y: 'bottom',
@ -288,16 +314,32 @@ const updateChart = (tempchartData) => {
itemWidth: 18, // itemWidth: 18, //
type: 'scroll' type: 'scroll'
} }
}); };
return tempOption;
} catch (error) {
console.log(error);
}
};
//
const updateChart = (tempchartData) => {
//
setTimeout(async () => {
if (!chart.value) return;
const myChart = await chart.value.init(echarts);
console.log(tempchartData);
let tempOption = getChartOption(tempchartData);
myChart.setOption(tempOption);
// //
myChart.on('click', (params) => { myChart.on('click', (params) => {
console.log(params.name, params.seriesIndex, params.dataIndex); console.log(params.name, params.seriesIndex, params.dataIndex);
console.log(orgCodeGroupData.value); console.log(orgCodeGroupData.value);
let updateData = findRyByOrgCode(orgCodeGroupData.value.children, params.name);
// console.log(updateData);
const ldhth = updateData.fieldValues[params.dataIndex].ldhth; let updateData = findRyByOrgCode(orgCodeGroupData.value.children, params.name);
console.log(updateData);
const ldhth = updateData.fieldValues[params.seriesIndex].ldhth;
console.log(ldhth); console.log(ldhth);
@ -314,7 +356,7 @@ function findRyByOrgCode(treeData, targetOrgCode) {
// console.log(treeData, targetOrgCode); // console.log(treeData, targetOrgCode);
for (const node of treeData) { for (const node of treeData) {
// //
if (node.orgCode === targetOrgCode) { if (node.orgText === targetOrgCode) {
return node; return node;
} }
// //
@ -349,21 +391,41 @@ function findNodeByOrgCode(treeData, targetOrgCode) {
} }
//fieldValue //fieldValue
function collectUniqueKeyValues(tree, key) { function collectUniqueKeyFieldValues(tree) {
const uniqueValues = new Set(); // 使Set const uniqueMap = new Map();
tree.forEach((item) => {
const { fieldValue, filedText } = item;
const key = `${fieldValue}-${filedText}`;
function traverse(node) { if (!uniqueMap.has(key)) {
if (node[key] !== undefined) { uniqueMap.set(key, {
uniqueValues.add(node[key]); fieldValue,
filedText
});
} }
if (node.children && Array.isArray(node.children)) { });
node.children.forEach((child) => traverse(child));
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;
} }
} }
tree.forEach((node) => traverse(node)); // tree // orgCode orgText
findOrgText(orgCode) {
return Array.from(uniqueValues); // Set return this.orgCodeToOrgTextMap[orgCode];
}
} }
// //
@ -380,7 +442,10 @@ function collectUniqueKeyValues(tree, key) {
function transformData(selectOrgCode, data) { function transformData(selectOrgCode, data) {
const nodes = new Map(); const nodes = new Map();
//fieldValue data[] fieldValue //fieldValue data[] fieldValue
fieldValues.value = collectUniqueKeyValues(data, 'fieldValue'); fieldValues.value = collectUniqueKeyFieldValues(data);
// console.log(fieldValues.value);
const orgMapper = new OrgCodeMapper(data); //orgtext
// console.log(orgMapper.findOrgText('A01A01A01A01'));
// orgCode // orgCode
function getHierarchy(orgCode) { function getHierarchy(orgCode) {
const hierarchy = []; const hierarchy = [];
@ -400,25 +465,30 @@ function transformData(selectOrgCode, data) {
// //
data.forEach((entry) => { data.forEach((entry) => {
const hierarchy = getHierarchy(entry.orgCode); const hierarchy = getHierarchy(entry.orgCode);
// console.log(entry);
hierarchy.forEach((code) => { hierarchy.forEach((code) => {
// console.log(code);
let tempOrgText = orgMapper.findOrgText(code) === undefined ? '' : orgMapper.findOrgText(code);
// console.log(tempOrgText);
if (!nodes.has(code)) { if (!nodes.has(code)) {
nodes.set(code, { nodes.set(code, {
orgCode: code, orgCode: code,
name: tempOrgText,
type: 'bar', type: 'bar',
data: JSON.parse(JSON.stringify(tempArrayValue)), // data[0, 0] data: JSON.parse(JSON.stringify(tempArrayValue)), // data[0, 0]
children: [] children: []
}); });
} }
}); });
// console.log(nodes);
// console.log('fieldValues', fieldValues.value, fieldValues.value.length, hierarchy); // console.log('fieldValues', fieldValues.value, fieldValues.value.length, hierarchy);
// data // data
const node = nodes.get(entry.orgCode); const node = nodes.get(entry.orgCode);
const fieldValue = parseInt(entry.fieldValue, 10); const fieldValue = entry.fieldValue;
for (let i = 0; i < fieldValues.value.length; i++) { for (let i = 0; i < fieldValues.value.length; i++) {
if (fieldValue === parseInt(fieldValues.value[i], 10)) { if (fieldValue === fieldValues.value[i].fieldValue) {
// console.log(555, i, fieldValue, fieldValues.value[i], entry.number); // console.log(555, i, fieldValue, fieldValues.value[i], entry.number);
node.data[i] += entry.number; node.data[i] += entry.number;
} }
@ -463,18 +533,24 @@ function transformData(selectOrgCode, data) {
// data // data
rootNodes.forEach((root) => computeData(root)); rootNodes.forEach((root) => computeData(root));
return rootNodes;
// console.log('rootNodes', rootNodes); // console.log('rootNodes', rootNodes);
// // //
function formatTree(node) { // function formatTree(node) {
return { // // console.log(node);
name: node.orgCode, // return {
type: 'bar', // orgCode: node.orgCode,
data: node.data, // name: node.name,
children: node.children.map((child) => formatTree(child)) // type: 'bar',
}; // data: node.data,
} // children: node.children.map((child) => formatTree(child))
// };
// }
return rootNodes.map((root) => formatTree(root)); // return rootNodes.map((root) => {
// console.log(root);
// formatTree(root);
// });
} }
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
@ -483,36 +559,56 @@ function transformData(selectOrgCode, data) {
const groupByOrgCode = (orgCode, data) => { 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 // null
if (filteredData.length === 0) { if (filteredData.length === 0) {
uni.showToast({
title: '过滤后数据为空',
duration: 1000
});
return null; return null;
} }
// console.log(0, filteredData);
// fieldValue // fieldValue
const groupedByFieldValue = {}; const groupedByFieldValue = {};
filteredData.forEach((item) => { try {
// console.log(item.orgCode, 11, groupedByFieldValue[item.fieldValue]); filteredData.forEach((item) => {
if (!groupedByFieldValue[item.fieldValue]) { // console.log(item);
groupedByFieldValue[item.fieldValue] = { if (!groupedByFieldValue[item.fieldValue]) {
number: 0, groupedByFieldValue[item.fieldValue] = {
ldhth: [] orgCode: item.orgCode,
}; orgText: item.orgText,
} filedText: item.filedText,
// console.log(item.orgCode, 22, groupedByFieldValue[item.fieldValue]); number: 0,
groupedByFieldValue[item.fieldValue].number += item.number; ldhth: []
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(',')); };
}); }
// 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 = { const result = {
orgCode: orgCode, orgCode: orgCode,
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => ({ orgText: orgMapper.findOrgText(orgCode),
fieldValue: fieldValue, fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => {
number: groupedByFieldValue[fieldValue].number, const { filedText, orgCode, orgText } = groupedByFieldValue[fieldValue] || {};
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] // return {
})), fieldValue: fieldValue,
filedText: filedText,
orgCode: orgCode,
orgText: orgText,
number: groupedByFieldValue[fieldValue].number,
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] //
};
}),
children: [] children: []
}; };
@ -520,38 +616,68 @@ const groupByOrgCode = (orgCode, data) => {
// orgCode // orgCode
const nextLevelOrgCodes = new Set(); const nextLevelOrgCodes = new Set();
filteredData.forEach((item) => { try {
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) { filteredData.forEach((item) => {
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3); if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
nextLevelOrgCodes.add(nextLevelOrgCode); const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
} nextLevelOrgCodes.add(nextLevelOrgCode);
}); }
});
} catch (error) {
console.log(error);
}
// //
nextLevelOrgCodes.forEach((nextLevelOrgCode) => { try {
const child = groupByOrgCode(nextLevelOrgCode, data); nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
if (child) { const child = groupByOrgCode(nextLevelOrgCode, data);
result.children.push(child); if (child) {
} result.children.push(child);
}); }
});
} catch (error) {
console.log(error);
}
// console.log('', result); // console.log('', result);
return result; return result;
}; };
// then // then filter
const fetchStatisticsData = async () => { const fetchStatisticsData = async () => {
if (!selectedOrgCode.value || !selectedField.value) return; if (!selectedOrgCode.value || !selectedField.value) return;
let res = [];
chartData.value = [];
try { try {
const res = await cxcRyDatAstatistics({ res = await cxcRyDatAstatistics({
orgCode: selectedOrgCode.value, orgCode: selectedOrgCode.value,
field: selectedField.value field: selectedField.value,
dictCode: dictCode.value,
fieldisDict: fieldisDict.value
}); });
// console.log(res); //deepseek // console.log(res); //deepseek
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res); if (res.success) {
chartData.value = transformData(selectedOrgCode.value, res); // console.log(selectedOrgCode.value, res);
// console.log(chartData.value); if (res.result.length < 1) {
updateChart(chartData.value); 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) { } catch (error) {
console.error('获取统计数据失败:', error); console.error('获取统计数据失败:', error);
} }
@ -559,12 +685,15 @@ const fetchStatisticsData = async () => {
// delimiter // delimiter
const fetchPersonnelList = async (ldhthList) => { const fetchPersonnelList = async (ldhthList) => {
personnelList.value = [];
try { try {
const res = await cxcRyDatAstatisticsDetails({ const res = await cxcRyDatAstatisticsDetails({
ldhth: ldhthList ldhth: ldhthList
}); });
console.log(res); console.log(res);
personnelList.value = res.data; if (res.success) {
personnelList.value = res.result;
}
} catch (error) { } catch (error) {
console.error('获取人员列表失败:', error); console.error('获取人员列表失败:', error);
} }
@ -573,24 +702,24 @@ const fetchPersonnelList = async (ldhthList) => {
// //
const onOrgCodeChange = (e, data) => { const onOrgCodeChange = (e, data) => {
selectedOrgCode.value = e; selectedOrgCode.value = e;
console.log(data.value.title); // console.log(data.value.title);
selectedOrgCodeLabel.value = data.value.title; selectedOrgCodeLabel.value = data.value.title;
fetchStatisticsData(); fetchStatisticsData();
}; };
const onFieldChange = (e) => { const onFieldChange = (e) => {
console.log(e); // console.log(e);
try { try {
selectedField.value = e; selectedField.value = e;
for (var index = 0; index < fieldList.value.length; index++) { for (var index = 0; index < fieldList.value.length; index++) {
var element = fieldList.value[index]; var element = fieldList.value[index];
console.log(element); // console.log(element);
if (element.value === e) { if (element.value === e) {
selectedFieldLabel.value = element.text; selectedFieldLabel.value = element.text;
dictCode.value = element.dictCode;
fieldisDict.value = element.isDict;
} }
} }
console.log(selectedFieldLabel);
fetchStatisticsData(); fetchStatisticsData();
} catch (error) { } catch (error) {
//TODO handle the exception //TODO handle the exception
@ -628,7 +757,7 @@ const onChartClick = (e) => {
/* 图表容器 */ /* 图表容器 */
.chart-container { .chart-container {
height: 50vh; height: 200px;
margin: 20rpx 0; margin: 20rpx 0;
border-radius: 24rpx; border-radius: 24rpx;
overflow: hidden; overflow: hidden;
@ -638,47 +767,35 @@ const onChartClick = (e) => {
} }
/* 表格标题行 */ /* 表格标题行 */
.titleStyle { .titleStyle {
font-size: 28rpx; font-size: 12px;
font-weight: 600; color: #747474;
color: #ffffff; line-height: 30px;
background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end)); height: 30px;
padding: 28rpx 0; background: #f2f9fc;
border-radius: 16rpx 16rpx 0 0; text-align: center;
box-shadow: 0 4rpx 12rpx rgba(67, 100, 247, 0.2); vertical-align: middle;
letter-spacing: 1rpx; border-left: 1px solid #919191;
border-bottom: 1px solid #919191;
} }
/* 数据行 */ /* 内容样式 */
.dataStyle { .dataStyle {
font-size: 28rpx; max-font-size: 14px;
color: #3a466b; /* 最大字体限制 */
padding: 32rpx 0; min-font-size: 10px;
background: #ffffff; /* 最小字体限制 */
border-bottom: 2rpx solid #f0f6ff; font-size: 12px;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); color: #00007f;
} line-height: 30px;
height: 30px;
.dataStyle:hover { font-weight: 500;
background: #f8fbff; text-align: center;
transform: translateY(-2rpx); vertical-align: middle;
} border-bottom: 1px solid #919191;
border-left: 1px solid #919191;
/* 操作按钮 */ text-overflow: ellipsis;
button[type='primary'] {
background: linear-gradient(135deg, var(--primary-blue), var(--deep-blue));
border: none;
border-radius: 12rpx;
padding: 12rpx 32rpx;
font-size: 26rpx;
box-shadow: 0 6rpx 16rpx rgba(64, 158, 255, 0.3);
transition: all 0.25s ease;
}
button[type='primary']:active {
transform: scale(0.96);
box-shadow: 0 4rpx 8rpx rgba(64, 158, 255, 0.3);
background: linear-gradient(135deg, var(--deep-blue), var(--primary-blue));
} }
/* 滚动区域 */ /* 滚动区域 */
@ -700,6 +817,7 @@ scroll-view {
opacity: 0; opacity: 0;
transform: translateY(20rpx); transform: translateY(20rpx);
} }
to { to {
opacity: 1; opacity: 1;
transform: translateY(0); transform: translateY(0);
@ -732,7 +850,7 @@ scroll-view {
/* 响应式调整优化 */ /* 响应式调整优化 */
@media (max-width: 768px) { @media (max-width: 768px) {
.chart-container { .chart-container {
height: 55vh; height: 200px;
border-radius: 20rpx; border-radius: 20rpx;
} }
@ -740,11 +858,6 @@ scroll-view {
font-size: 26rpx; font-size: 26rpx;
padding: 24rpx 0; padding: 24rpx 0;
} }
button[type='primary'] {
padding: 10rpx 24rpx;
font-size: 24rpx;
}
} }
/* 数据行高亮效果 */ /* 数据行高亮效果 */