统计查询修改

This commit is contained in:
廖德云 2025-02-13 23:03:49 +08:00
parent 9808821b70
commit 8cf96126fe
2 changed files with 410 additions and 445 deletions

View File

@ -85,7 +85,6 @@
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);
@ -757,7 +756,7 @@ const onChartClick = (e) => {
/* 图表容器 */ /* 图表容器 */
.chart-container { .chart-container {
height: 200px; height: 250px;
margin: 20rpx 0; margin: 20rpx 0;
border-radius: 24rpx; border-radius: 24rpx;
overflow: hidden; overflow: hidden;
@ -850,14 +849,9 @@ scroll-view {
/* 响应式调整优化 */ /* 响应式调整优化 */
@media (max-width: 768px) { @media (max-width: 768px) {
.chart-container { .chart-container {
height: 200px; height: 250px;
border-radius: 20rpx; border-radius: 20rpx;
} }
.titleStyle {
font-size: 26rpx;
padding: 24rpx 0;
}
} }
/* 数据行高亮效果 */ /* 数据行高亮效果 */

View File

@ -1,13 +1,12 @@
<template> <template>
<view> <view>
<view class="container" id="top1"> <view class="container" id="top1">
<uni-row style="margin-bottom: 10rpx;margin-left: 30rpx;margin-right: 30rpx;"> <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-col :span="24"><uni-title :title="'所选单位'" align="left" type="h4"></uni-title></uni-col>
</uni-row> </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"> <uni-col :span="24">
<trq-depart-select v-model="orgCode" returnCodeOrID="orgCode" <trq-depart-select v-model="orgCode" returnCodeOrID="orgCode" @change="departChange"></trq-depart-select>
@change="departChange"></trq-depart-select>
</uni-col> </uni-col>
</uni-row> </uni-row>
<!-- 概览统计 --> <!-- 概览统计 -->
@ -27,39 +26,28 @@
<l-echart ref="chart" @finished="initChart" /> <l-echart ref="chart" @finished="initChart" />
</view> </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"> <uni-col :span="3">
<view class="titleStyle"> <view class="titleStyle">序号</view>
序号
</view>
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
<view class="titleStyle"> <view class="titleStyle">姓名</view>
姓名
</view>
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
<view class="titleStyle"> <view class="titleStyle">性别</view>
性别
</view>
</uni-col> </uni-col>
<uni-col :span="5"> <uni-col :span="5">
<view class="titleStyle"> <view class="titleStyle">年龄</view>
年龄
</view>
</uni-col> </uni-col>
<uni-col :span="6"> <uni-col :span="6">
<view class="titleStyle"> <view class="titleStyle">操作</view>
操作
</view>
</uni-col> </uni-col>
</uni-row> </uni-row>
<scroll-view scroll-y :style="{ height: bottomHeight + 'px' }"> <scroll-view scroll-y :style="{ height: bottomHeight + 'px' }">
<uni-row style="margin-bottom: 10rpx;margin-left: 30rpx;margin-right: 30rpx;"> <uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
<view v-for="(item, index) in tableData"> <view v-for="(item, index) in tableData">
<uni-col :span="3"> <uni-col :span="3">
<view class="dataStyle"> <view class="dataStyle">
@ -70,11 +58,13 @@
<view class="dataStyle"> <view class="dataStyle">
{{ item.xm }} {{ item.xm }}
</view> </view>
</uni-col><uni-col :span="5"> </uni-col>
<uni-col :span="5">
<view class="dataStyle"> <view class="dataStyle">
{{ item.xb_dictText }} {{ item.xb_dictText }}
</view> </view>
</uni-col><uni-col :span="5"> </uni-col>
<uni-col :span="5">
<view class="dataStyle"> <view class="dataStyle">
{{ item.nl }} {{ item.nl }}
</view> </view>
@ -84,26 +74,17 @@
<button size="mini" type="primary" @click="detail(item)">详情</button> <button size="mini" type="primary" @click="detail(item)">详情</button>
</view> </view>
</uni-col> </uni-col>
</view> </view>
</uni-row> </uni-row>
</scroll-view> </scroll-view>
</view> </view>
</template> </template>
<script setup> <script setup>
import { import { ref, reactive, onMounted } from 'vue';
ref, import * as echarts from 'echarts';
reactive,
onMounted
} from 'vue';
import * as echarts from 'echarts'
import { import { queryRenyuanByDepartID } from '@/api/renyuan.js';
queryRenyuanByDepartID
} from '@/api/renyuan.js'
// //
const bottomHeight = ref(0); const bottomHeight = ref(0);
@ -125,8 +106,8 @@
function detail(record) { function detail(record) {
// console.log(record) // console.log(record)
uni.navigateTo({ uni.navigateTo({
url: "/pages/views/renliziyuan/renyuanxinxi/detail?data=" + encodeURIComponent(JSON.stringify(record)) url: '/pages/views/renliziyuan/renyuanxinxi/detail?data=' + encodeURIComponent(JSON.stringify(record))
}) });
} }
// initChart // initChart
const calculateAge = (birthDate) => { const calculateAge = (birthDate) => {
@ -141,21 +122,22 @@
}; };
// //
const departChange = async (e, data) => { const departChange = async (e, data) => {
tableData.value = [];
tableData.value = [] console.log(e);
console.log(e)
orgCode.value = e; orgCode.value = e;
try { try {
// //
isLoading.value = true; isLoading.value = true;
if (orgCode.value.length <= 6) { if (orgCode.value.length <= 6) {
console.log(123242353);
console.log(123242353) uni.showToast({
uni.showLoading({ title: '全厂数据较多,请选 下一层级...',
title: '全厂数据较多,耐心等待数据加载中...', icon: 'none',
mask: true duration: 1000
}); });
isLoading.value = false;
return;
} else { } else {
uni.showLoading({ uni.showLoading({
title: '数据加载中...', title: '数据加载中...',
@ -168,34 +150,34 @@
fields: ['xm', 'nl', 'xb', 'xb_dictText', 'orgCode', 'jcdw', 'jcxd', 'jcxdCode'] fields: ['xm', 'nl', 'xb', 'xb_dictText', 'orgCode', 'jcdw', 'jcxd', 'jcxdCode']
}; };
if (orgCode.value.length <= 9) { if (orgCode.value.length <= 9) {
params.orgCode = orgCode.value params.orgCode = orgCode.value;
} else { } else {
params.jcxd_code = orgCode.value params.jcxd_code = orgCode.value;
} }
queryRenyuanByDepartID(params).then((res) => { queryRenyuanByDepartID(params)
.then((res) => {
if (res.success) { if (res.success) {
processData(res.result.records); processData(res.result.records);
// //
isLoading.value = false; isLoading.value = false;
uni.hideLoading(); uni.hideLoading();
} }
}).catch((err) => {
console.log(err)
uni.showToast({
title: '数据加载失败',
icon: 'none'
});
}) })
.catch((err) => {
console.log(err);
} catch (error) {
console.log(error)
uni.showToast({ uni.showToast({
title: '数据加载失败', title: '数据加载失败',
icon: 'none' icon: 'none',
duration: 1000
});
});
} catch (error) {
console.log(error);
uni.showToast({
title: '数据加载失败',
icon: 'none',
duration: 1000
}); });
} finally { } finally {
// //
@ -204,15 +186,15 @@
} }
}; };
// //
const processData = (data) => { const processData = (data) => {
// //
const validData = data.map(item => ({ const validData = data
.map((item) => ({
...item, ...item,
nl: calculateAge(item.cssj) nl: calculateAge(item.cssj)
})).filter(item => item.nl >= 21 && item.nl <= 64); }))
.filter((item) => item.nl >= 21 && item.nl <= 64);
// //
summary.total = validData.length; summary.total = validData.length;
summary.avgAge = validData.reduce((sum, cur) => sum + cur.nl, 0) / summary.total || 0; summary.avgAge = validData.reduce((sum, cur) => sum + cur.nl, 0) / summary.total || 0;
@ -222,27 +204,25 @@
groupsData(validData); groupsData(validData);
// //
generateChartData(validData); generateChartData(validData);
}; };
// ... // ...
const subOrgStaffs = ref({}); // const subOrgStaffs = ref({}); //
const ageGroupStaffs = ref({}); // const ageGroupStaffs = ref({}); //
const groupsData = (data) => { const groupsData = (data) => {
// //
subOrgStaffs.value = {}; subOrgStaffs.value = {};
ageGroupStaffs.value = {}; ageGroupStaffs.value = {};
data.reduce((acc, cur) => { data.reduce((acc, cur) => {
// console.log(cur) // console.log(cur)
let subOrg = ""; let subOrg = '';
let ageRange = getAgeRange(cur.nl); let ageRange = getAgeRange(cur.nl);
// console.log(cur.orgCode, cur.jcxdCode) // console.log(cur.orgCode, cur.jcxdCode)
if (cur.orgCode <= 6) { if (cur.orgCode <= 6) {
subOrg = cur.orgCode subOrg = cur.orgCode;
} else { } else {
subOrg = cur.jcxdCode subOrg = cur.jcxdCode;
} }
// subOrgStaffs // subOrgStaffs
@ -256,9 +236,8 @@
ageGroupStaffs.value[ageRange] = []; ageGroupStaffs.value[ageRange] = [];
} }
ageGroupStaffs.value[ageRange].push(cur); ageGroupStaffs.value[ageRange].push(cur);
}) });
} };
// //
const getAgeRange = (age) => { const getAgeRange = (age) => {
@ -270,9 +249,7 @@
// //
const showStaffList = (subOrg, ageRange) => { const showStaffList = (subOrg, ageRange) => {
// //
const targetStaffs = subOrgStaffs.value[subOrg].filter(staff => const targetStaffs = subOrgStaffs.value[subOrg].filter((staff) => getAgeRange(staff.nl) === ageRange);
getAgeRange(staff.nl) === ageRange
);
staffList.value = targetStaffs; staffList.value = targetStaffs;
popupTitle.value = `${subOrg} ${ageRange}人员列表(共${targetStaffs.length}人)`; popupTitle.value = `${subOrg} ${ageRange}人员列表(共${targetStaffs.length}人)`;
@ -307,14 +284,13 @@
return acc; return acc;
}, {}); }, {});
// //
const xData = Object.keys(jcdwGroups); const xData = Object.keys(jcdwGroups);
const seriesData = ageRanges.map((range, index) => ({ const seriesData = ageRanges.map((range, index) => ({
name: range, name: range,
type: 'bar', type: 'bar',
data: xData.map(jcdw => jcdwGroups[jcdw].ageGroups[index] || 0), data: xData.map((jcdw) => jcdwGroups[jcdw].ageGroups[index] || 0),
itemStyle: { itemStyle: {
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index] color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
}, },
@ -322,14 +298,14 @@
label: { label: {
show: true, show: true,
position: 'top' position: 'top'
}, }
// 20 // 20
// barWidth: 20 // barWidth: 20
})) }));
chartOption.value = { chartOption.value = {
title: { title: {
text: '人员年龄分组统计', text: '人员年龄分组统计',
padding: [0, 0, 0, 30], padding: [0, 0, 0, 30]
}, },
toolbox: { toolbox: {
padding: [0, 30, 0, 0], padding: [0, 30, 0, 0],
@ -377,7 +353,7 @@
color: '#7F84B5', color: '#7F84B5',
fontWeight: 300, fontWeight: 300,
interval: 0, interval: 0,
rotate: 0, rotate: 0
}, },
padding: [0, 10, 0, 10], padding: [0, 10, 0, 10],
axisTick: { axisTick: {
@ -387,7 +363,8 @@
show: false //线 show: false //线
} }
}, },
yAxis: [{ yAxis: [
{
show: true, show: true,
boundaryGap: false, //线 boundaryGap: false, //线
type: 'value', type: 'value',
@ -411,37 +388,33 @@
axisLine: { axisLine: {
show: false //线 show: false //线
} }
}], }
],
series: seriesData,
series: seriesData
}; };
// //
setTimeout(async () => { setTimeout(async () => {
if (!chart.value) return if (!chart.value) return;
const myChart = await chart.value.init(echarts) const myChart = await chart.value.init(echarts);
myChart.setOption(chartOption.value) myChart.setOption(chartOption.value);
myChart.on('click', (params) => { myChart.on('click', (params) => {
console.log(params.seriesName) console.log(params.seriesName);
tableData.value = getAgeGroupStaffs(params.seriesName) tableData.value = getAgeGroupStaffs(params.seriesName);
});
}) }, 300);
}, 300)
// #ifdef APP // #ifdef APP
getHeight(); getHeight();
// #endif // #endif
}; };
onMounted(() => { onMounted(() => {
// #ifdef APP // #ifdef APP
getHeight(); getHeight();
// #endif // #endif
}) });
// #ifdef APP // #ifdef APP
const getHeight = () => { const getHeight = () => {
@ -455,7 +428,7 @@
.select('#top1') .select('#top1')
.boundingClientRect((rect1) => { .boundingClientRect((rect1) => {
// //
const topComponentsHeight = rect1.height const topComponentsHeight = rect1.height;
// //
bottomHeight.value = screenHeight - topComponentsHeight - 415; bottomHeight.value = screenHeight - topComponentsHeight - 415;
}) })
@ -466,10 +439,10 @@
// //
const initChart = () => { const initChart = () => {
setTimeout(async () => { setTimeout(async () => {
if (!chart.value) return if (!chart.value) return;
const myChart = await chart.value.init(echarts) const myChart = await chart.value.init(echarts);
myChart.setOption(chartOption.value) myChart.setOption(chartOption.value);
}, 300) }, 300);
}; };
</script> </script>
@ -492,7 +465,7 @@
} }
.query-btn { .query-btn {
background: #007AFF; background: #007aff;
color: white; color: white;
padding: 0 40rpx; padding: 0 40rpx;
border-radius: 8rpx; border-radius: 8rpx;
@ -534,12 +507,11 @@
color: #747474; color: #747474;
line-height: 30px; line-height: 30px;
height: 30px; height: 30px;
background: #F2F9FC; background: #f2f9fc;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
border-left: 1px solid #919191; border-left: 1px solid #919191;
border-bottom: 1px solid #919191; border-bottom: 1px solid #919191;
;
} }
/* 内容样式 */ /* 内容样式 */
@ -558,6 +530,5 @@
border-bottom: 1px solid #919191; border-bottom: 1px solid #919191;
border-left: 1px solid #919191; border-left: 1px solid #919191;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
</style> </style>