用户中心和采购计划完善

This commit is contained in:
砂糖
2025-10-13 17:51:27 +08:00
parent 8db5eb7707
commit d0520e7872
48 changed files with 4833 additions and 713 deletions

View File

@@ -0,0 +1,48 @@
<template>
<view class="charts-box">
<qiun-data-charts
type="column"
:chartData="chartData"
:opts="chartOpts"
/>
</view>
</template>
<script>
export default {
name: 'InventoryTrend',
// 接收父组件传入的日期参数YYYY-mm格式
props: {
chartData: {
type: Object,
default: {
categories: [], // 日期1日-当前日或当月总天数)
series: [] // 库存趋势数据
}
}
},
data() {
return {
// 图表配置
chartOpts: {
title: { text:'月度收支', left:'center' },
tooltip:{ trigger:'axis' },
legend:{ data:['支出','收入(CNY)','收入(USD)'], bottom:0 },
}
};
},
};
</script>
<style scoped>
.charts-box {
width: 100%;
height: 300px;
padding: 16rpx;
box-sizing: border-box;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
margin-bottom: 20rpx;
}
</style>

View File

@@ -0,0 +1,102 @@
<template>
<view class="charts-box">
<qiun-data-charts
type="line"
:chartData="chartData"
:opts="chartOpts"
/>
</view>
</template>
<script>
import { monthDataAnalysis } from "@/api/oa/wms/oaWarehouse";
export default {
data() {
return {
// 图表数据符合uCharts格式
chartData: {
categories: [], // 月份
series: [] // 入库量、出库量数据
},
// 图表配置项
chartOpts: {
legend: true, // 显示图例
dataLabel: false, // 不显示数据标签
column: {
type: "group" // 分组柱状图
},
xAxis: {
fontColor: "#666",
fontSize: 12
},
yAxis: {
fontColor: "#666",
fontSize: 12,
gridColor: "#eee"
},
color: ["#007aff", "#ff9500"] // 入库、出库颜色
}
};
},
mounted() {
// 页面就绪后获取数据
this.getServerData();
},
methods: {
getServerData() {
// 显示加载提示
uni.showLoading({
title: '加载数据中...',
mask: true
});
// 调用接口获取数据(当前年份作为参数)
const currentYear = new Date().getFullYear() + '-01';
monthDataAnalysis({ month: currentYear }).then(res => {
// 隐藏加载提示
uni.hideLoading();
// 格式化接口数据为uCharts所需格式
this.chartData = {
categories: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
series: [
{
name: "入库量",
data: res.data.inData["月"] || [] // 从接口取入库数据
},
{
name: "出库量",
data: res.data.outData["月"] || [] // 从接口取出库数据
}
]
};
}).catch(err => {
// 隐藏加载提示
uni.hideLoading();
// 错误处理
uni.showToast({
title: '数据加载失败',
icon: 'none',
duration: 2000
});
console.error('获取出入库数据失败:', err);
});
}
}
};
</script>
<style scoped>
.charts-box {
width: 100%;
height: 300px; /* 固定图表高度,适配手机屏幕 */
padding: 16rpx;
box-sizing: border-box;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
margin-bottom: 20rpx;
}
</style>

View File

@@ -0,0 +1,59 @@
<template>
<view class="charts-box">
<qiun-data-charts type="pie" :chartData="chartData" :opts="chartOpts" />
</view>
</template>
<script>
export default {
props: {
projectList: {
required: true,
type: Array
}
},
data() {
return {
chartData: {},
chartOpts: {
color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
padding: [5, 5, 5, 5],
enableScroll: false,
extra: {
pie: {
activeOpacity: 0.5,
activeRadius: 10,
offsetAngle: 0,
labelWidth: 15,
border: false,
borderWidth: 3,
borderColor: "#FFFFFF"
}
}
}
}
},
watch: {
projectList: {
handler(newVal) {
const pieData = this.projectList
// .filter(p => p.totalPrice > 0)
.map(p => ({
name: p.projectName,
value: p.totalPrice,
}));
this.chartData = {
series: [{
data: pieData
}]
}
},
immediate: true,
},
}
}
</script>
<style>
</style>

View File

@@ -0,0 +1,179 @@
<template>
<view class="recent-records-container">
<view class="table-header">
<text class="title">最近记录</text>
</view>
<scroll-view
scroll-x="true"
class="table-scroll"
show-scrollbar="false"
>
<view class="table-wrapper">
<!-- 表头 -->
<view class="table-row header-row">
<view class="table-cell">物料名称</view>
<view class="table-cell">型号</view>
<view class="table-cell">当前库存</view>
<view class="table-cell">安全库存</view>
<view class="table-cell">在途数量</view>
<view class="table-cell">库存状态</view>
</view>
<!-- 表体 -->
<view
class="table-row"
v-for="(item, index) in tableData"
:key="index"
:class="{ 'odd-row': index % 2 === 1 }"
>
<view class="table-cell">{{ item.name }}</view>
<view class="table-cell">{{ item.model }}</view>
<view class="table-cell">{{ item.inventory }}</view>
<view class="table-cell">{{ item.threshold }}</view>
<view class="table-cell">{{ item.taskInventory }}</view>
<view class="table-cell">
<view
class="status-tag"
:class="calcInventoryStatus(item.inventory, item.taskInventory, item.threshold).type"
>
{{ calcInventoryStatus(item.inventory, item.taskInventory, item.threshold).status }}
</view>
</view>
</view>
<!-- 空状态 -->
<view v-if="tableData.length === 0" class="empty-state">
<uni-icons type="empty" size="60" color="#cccccc"></uni-icons>
<text class="empty-text">暂无记录</text>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
name: 'RecentRecords',
props: {
// 接收表格数据
tableData: {
type: Array,
default: () => []
}
},
methods: {
// 计算库存状态
calcInventoryStatus(inventory, inTransit, threshold) {
const total = inventory + inTransit;
if (total > threshold + 10) {
return { status: '库存积压', type: 'warning' };
} else if (total > threshold) {
return { status: '正常', type: 'success' };
} else if (total <= threshold && total > threshold - 2) {
return { status: '库存预警', type: 'danger' };
} else {
return { status: '库存不足', type: 'info' };
}
}
}
};
</script>
<style scoped>
.recent-records-container {
width: 100%;
background-color: #ffffff;
border-radius: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
overflow: hidden;
}
.table-header {
padding: 20rpx 16rpx;
border-bottom: 1px solid #f5f5f5;
}
.title {
font-size: 28rpx;
font-weight: bold;
color: #333333;
}
.table-scroll {
width: 100%;
}
.table-wrapper {
width: 100%;
min-width: 900rpx; /* 确保表格有足够宽度展示内容 */
}
.table-row {
display: flex;
width: 100%;
border-bottom: 1px solid #f5f5f5;
}
.table-row:last-child {
border-bottom: none;
}
.header-row {
background-color: #f9f9f9;
}
.odd-row {
background-color: #fafafa;
}
.table-cell {
flex: 1;
padding: 20rpx 10rpx;
font-size: 24rpx;
color: #666666;
text-align: center;
word-break: break-all;
display: flex;
align-items: center;
justify-content: center;
}
.status-tag {
padding: 4rpx 12rpx;
border-radius: 14rpx;
font-size: 22rpx;
color: #ffffff;
}
.status-tag.success {
background-color: #00b42a;
}
.status-tag.warning {
background-color: #ff7d00;
}
.status-tag.danger {
background-color: #f53f3f;
}
.status-tag.info {
background-color: #86909c;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 80rpx 0;
}
.empty-text {
font-size: 26rpx;
color: #999999;
margin-top: 20rpx;
}
</style>

View File

@@ -0,0 +1,106 @@
<template>
<view class="summary-cards-container">
<scroll-view
scroll-x="true"
class="cards-scroll"
show-scrollbar="false"
>
<view class="cards-wrapper">
<view
class="summary-card"
v-for="(card, index) in cardsData"
:key="index"
>
<view class="card-title">{{ card.title }}</view>
<view class="card-value">人民币{{ card.valueCNY }}</view>
<view class="card-value">美元{{ card.valueUSD }}</view>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
name: 'SummaryCards',
props: {
// 接收卡片数据,格式为数组对象
cardsData: {
type: Array,
default: () => [
{ title: '当前总库存量', value: 0, trend: 0 },
{ title: '在途物料数量', value: 0, trend: 0 },
{ title: '今日入库量', value: 0, trend: 0 },
{ title: '今日出库量', value: 0, trend: 0 },
{ title: '预警信息', value: 0, trend: 0 }
]
}
},
methods: {
// 格式化数字,添加千位分隔符
formatNumber(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
}
};
</script>
<style scoped>
.summary-cards-container {
width: 100%;
margin-bottom: 20rpx;
}
.cards-scroll {
width: 100%;
white-space: nowrap;
padding: 10rpx 0;
}
.cards-wrapper {
display: inline-flex;
gap: 16rpx;
padding: 0 16rpx;
}
.summary-card {
min-width: 240rpx;
background-color: #ffffff;
border-radius: 12rpx;
padding: 20rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}
.card-title {
font-size: 26rpx;
color: #666666;
margin-bottom: 10rpx;
}
.card-value {
font-size: 34rpx;
font-weight: bold;
color: #333333;
margin-bottom: 8rpx;
}
.card-trend {
font-size: 22rpx;
display: flex;
align-items: center;
justify-content: center;
gap: 4rpx;
}
.trend-up {
color: #00b42a;
}
.trend-down {
color: #f53f3f;
}
.trend-flat {
color: #888888;
}
</style>

View File

@@ -0,0 +1,289 @@
<template>
<view class="container">
<!-- 加载状态 -->
<view v-if="loading" class="loading-view">
<uni-loading-icon size="24" color="#007aff"></uni-loading-icon>
<text class="loading-text">加载中...</text>
</view>
<!-- 内容区域加载完成后显示 -->
<view v-else>
<!-- 月份选择 -->
<view class="date-picker-container">
<picker mode="date" @change="onDateChange" fields="month" :value="currentDate" class="date-picker">
<view class="picker-view">
<text>{{ formattedDate }}</text>
</view>
</picker>
</view>
<fad-collapse title="指标汇总">
<SummaryCardsVue :cardsData="cardData"/>
</fad-collapse>
<fad-collapse title="月度收支">
<!-- <BarVue :chart-data="barChartData"></BarVue> -->
</fad-collapse>
<fad-collapse title="近六月趋势">
</fad-collapse>
<fad-collapse title="项目支出占比">
<PieVue :project-list="projectList"></PieVue>
</fad-collapse>
<fad-collapse title="明细表格">
</fad-collapse>
</view>
</view>
</template>
<script>
import {
barData,
findFinanceList2
} from '@/api/oa/finance/finance';
import {
getExchangeRate
} from '@/api/oa/finance/exchangeRate';
import {
projectData2
} from '@/api/oa/project';
import SummaryCardsVue from './components/SummaryCards.vue';
import PieVue from './components/Pie.vue'
import BarVue from './components/Bar.vue';
export default {
data() {
return {
loading: true,
currentDate: '',
cardData: [], // 改为数组,存储汇总卡片数据(核心)
monthlyDataMap: {}, // 初始化月度数据映射(用于图表/卡片)
currentList: [], // barData接口返回的列表
projectList: [], // projectData2接口返回的列表
financeList: [], // findFinanceList2接口返回的列表
queryFinanceParams: {}, // 接口请求参数(需确保已定义)
dateForProject: '' ,// 项目接口日期参数(需确保已定义)
barChartData: {},
exchangeRate: 7,
};
},
computed: {
formattedDate() {
const [year, month] = this.currentDate.split('-');
return `${year}${month}`;
}
},
components: {
SummaryCardsVue,
PieVue,
BarVue
},
onLoad() {
// 初始化日期为当前月份
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
this.currentDate = `${year}-${month.toString().padStart(2, '0')}-01`;
this.loadAllData()
},
methods: {
async loadAllExchangeRates(months) {
for (const m of months) {
if (!this.monthlyDataMap[m]) this.monthlyDataMap[m] = {};
if (this.monthlyDataMap[m].exchangeRate) continue;
this.monthlyDataMap[m].exchangeRate = this.exchangeRate;
}
},
onDateChange(e) {
const value = e.detail.value;
this.currentDate = value + '-01';
this.loadAllData()
},
async loadAllData() {
this.loading = true;
this.exchangeRate = await getExchangeRate()
barData(this.queryFinanceParams)
.then(res => {
this.currentList = res.data;
})
.then(async () => {
const months = this.currentList.map(i => i.month);
await this.loadAllExchangeRates(months);
return Promise.all([
projectData2(this.currentDate),
findFinanceList2({
date: this.currentDate
})
]);
})
.then(([projRes, finRes]) => {
this.projectList = projRes.data;
this.financeList = finRes.data;
this.computeSummaries();
})
.finally(() => {
this.loading = false;
console.log('loadAllData done', this.monthlyDataMap);
this.$nextTick(this.initCharts);
});
},
computeSummaries() {
// 1. 获取当前选中月份格式YYYY-MM从currentDate提取
const currentMonth = this.currentDate.slice(0, 7);
// 2. 初始化月度数据映射(确保每个月份的基础结构存在)
this.currentList.forEach(item => {
const month = item.month;
if (!this.monthlyDataMap[month]) {
this.monthlyDataMap[month] = {
outTotal: 0,
inCNY: 0,
inUSD: 0,
exchangeRate: this.monthlyDataMap[month]?.exchangeRate || 0 // 保留已有汇率
};
}
// 赋值出库总额从barData接口获取
this.monthlyDataMap[month].outTotal = item.totalOut;
});
// 3. 初始化统计变量(月度/项目收支)
const initStats = {
monthlyOutCNY: 0, // 月度总支出(人民币)
monthlyOutUSD: 0, // 月度总支出(美元)
monthlyInCNY: 0, // 月度总收入(人民币)
monthlyInUSD: 0, // 月度总收入(美元)
projectOutCNY: 0, // 项目支出(人民币)
projectOutUSD: 0, // 项目支出(美元)
projectInCNY: 0, // 项目收入(人民币)
projectInUSD: 0 // 项目收入(美元)
};
Object.assign(this, initStats);
// 4. 遍历财务明细,计算收支数据
this.financeList.forEach(finItem => {
const itemMonth = finItem.date.slice(0, 7); // 明细所属月份
const amount = Number(finItem.amount) || 0; // 金额转数字避免NaN
const isOut = finItem.type === '0'; // 0=支出1=收入(按业务定义)
const currency = finItem.currency === 'USD' ? 'USD' : 'CNY'; // 货币类型
// 4.1 更新月度收入数据存入monthlyDataMap
const monthData = this.monthlyDataMap[itemMonth];
if (monthData && !isOut) {
monthData[`in${currency}`] += amount;
}
// 4.2 计算「当前选中月份」的统计数据
if (itemMonth === currentMonth) {
if (isOut) {
// 支出:更新月度总支出 + 项目支出有projectId才统计项目
this[`monthlyOut${currency}`] += amount;
if (finItem.projectId) {
this[`projectOut${currency}`] += amount;
}
} else {
// 收入:更新月度总收入 + 项目收入有projectId才统计项目
this[`monthlyIn${currency}`] += amount;
if (finItem.projectId) {
this[`projectIn${currency}`] += amount;
}
}
}
});
// 5. 构建汇总卡片数据核心适配SummaryCards组件
console.log(this.monthlyDataMap, '月度数据')
this.cardData = [
{
title: '月度总支出',
valueCNY: Number(this.monthlyOutCNY.toFixed(2)), // 保留2位小数转数字
valueUSD: Number(this.monthlyOutUSD.toFixed(2))
},
{
title: '月度总收入',
valueCNY: Number(this.monthlyInCNY.toFixed(2)),
valueUSD: Number(this.monthlyInUSD.toFixed(2))
},
{
title: '项目支出',
valueCNY: Number(this.projectOutCNY.toFixed(2)),
valueUSD: Number(this.projectOutUSD.toFixed(2))
},
{
title: '项目收入',
valueCNY: Number(this.projectInCNY.toFixed(2)),
valueUSD: Number(this.projectInUSD.toFixed(2))
}
];
},
}
};
</script>
<style scoped>
.container {
padding: 16rpx;
background-color: #f5f5f5;
min-height: 100vh;
}
/* 日期选择器在折叠卡片额外内容中的样式 */
.picker-view {
display: flex;
align-items: center;
color: #666;
font-size: 24rpx;
padding: 4rpx 8rpx;
}
.icon-margin {
margin-right: 8rpx;
}
/* 图表样式调整 */
.chart-item {
width: 100%;
}
/* 加载状态样式 */
.loading-view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
.loading-text {
margin-top: 20rpx;
font-size: 28rpx;
color: #666;
}
/* 折叠卡片间距 */
.fad-collapse {
margin-bottom: 16rpx;
}
.date-picker-container {
background-color: #fff;
border-radius: 8rpx;
padding: 16rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}
.date-picker {
width: 100%;
}
.picker-view {
text-align: center;
font-size: 28rpx;
color: #007aff;
padding: 8rpx 0;
}
</style>