✨ feat: 增加智慧库房,完善项目盈亏
This commit is contained in:
102
pages/workbench/smartWM/components/InOutCompare.vue
Normal file
102
pages/workbench/smartWM/components/InOutCompare.vue
Normal file
@@ -0,0 +1,102 @@
|
||||
<template>
|
||||
<view class="charts-box">
|
||||
<qiun-data-charts
|
||||
type="column"
|
||||
: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>
|
||||
142
pages/workbench/smartWM/components/InventoryTrend.vue
Normal file
142
pages/workbench/smartWM/components/InventoryTrend.vue
Normal file
@@ -0,0 +1,142 @@
|
||||
<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 {
|
||||
name: 'InventoryTrend',
|
||||
// 接收父组件传入的日期参数(YYYY-mm格式)
|
||||
props: {
|
||||
date: {
|
||||
type: String,
|
||||
required: true,
|
||||
validator: function(value) {
|
||||
// 验证格式是否为YYYY-mm
|
||||
const reg = /^\d{4}-\d{2}$/;
|
||||
return reg.test(value);
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
// 图表数据
|
||||
chartData: {
|
||||
categories: [], // 日期(1日-当前日或当月总天数)
|
||||
series: [] // 库存趋势数据
|
||||
},
|
||||
// 图表配置
|
||||
chartOpts: {
|
||||
legend: false,
|
||||
dataLabel: false,
|
||||
line: {
|
||||
smooth: true,
|
||||
type: "straight"
|
||||
},
|
||||
xAxis: {
|
||||
fontColor: "#666",
|
||||
fontSize: 12,
|
||||
rotateLabel: true
|
||||
},
|
||||
yAxis: {
|
||||
fontColor: "#666",
|
||||
fontSize: 12,
|
||||
gridColor: "#eee"
|
||||
},
|
||||
color: ["#00cc66"],
|
||||
padding: [15, 15, 30, 15]
|
||||
}
|
||||
};
|
||||
},
|
||||
// 监听日期变化,重新加载数据
|
||||
watch: {
|
||||
date: {
|
||||
immediate: true, // 初始化时立即执行
|
||||
handler(newVal) {
|
||||
this.getData(newVal);
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getData(selectedDate) {
|
||||
// 显示加载提示
|
||||
uni.showLoading({
|
||||
title: '加载数据中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
// 从选中日期中提取年份(根据接口需求调整参数)
|
||||
const year = selectedDate;
|
||||
|
||||
monthDataAnalysis({ month: year }).then(res => {
|
||||
// 隐藏加载提示
|
||||
uni.hideLoading();
|
||||
|
||||
// 解析选中的年月
|
||||
const [year, month] = selectedDate.split('-').map(Number);
|
||||
|
||||
// 计算当月总天数
|
||||
const daysInMonth = new Date(year, month, 0).getDate();
|
||||
|
||||
// 计算当前日期是否在选中月份内
|
||||
const today = new Date();
|
||||
const currentYear = today.getFullYear();
|
||||
const currentMonth = today.getMonth() + 1;
|
||||
|
||||
// 确定需要显示的天数(如果是当前月则显示到今天,否则显示整月)
|
||||
const daysToShow = (year === currentYear && month === currentMonth)
|
||||
? today.getDate()
|
||||
: daysInMonth;
|
||||
|
||||
// 生成日期类别
|
||||
const dayCategories = Array.from(
|
||||
{ length: daysToShow },
|
||||
(_, i) => `${i + 1}日`
|
||||
);
|
||||
|
||||
// 格式化数据
|
||||
this.chartData = {
|
||||
categories: dayCategories,
|
||||
series: [
|
||||
{
|
||||
name: "库存趋势",
|
||||
data: res.data.dataMap["日"] || []
|
||||
}
|
||||
]
|
||||
};
|
||||
}).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>
|
||||
179
pages/workbench/smartWM/components/RecentRecords.vue
Normal file
179
pages/workbench/smartWM/components/RecentRecords.vue
Normal 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>
|
||||
119
pages/workbench/smartWM/components/SummaryCards.vue
Normal file
119
pages/workbench/smartWM/components/SummaryCards.vue
Normal file
@@ -0,0 +1,119 @@
|
||||
<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">{{ formatNumber(card.value) }}</view>
|
||||
<view
|
||||
class="card-trend"
|
||||
:class="{ 'trend-up': card.trend > 0, 'trend-down': card.trend < 0, 'trend-flat': card.trend === 0 }"
|
||||
>
|
||||
<text v-if="card.trend !== 0">
|
||||
<uni-icons
|
||||
:type="card.trend > 0 ? 'arrowup' : 'arrowdown'"
|
||||
size="16"
|
||||
></uni-icons>
|
||||
{{ Math.abs(card.trend) }}%
|
||||
{{ card.trend > 0 ? '环比上月' : '环比昨日' }}
|
||||
</text>
|
||||
<text v-else>持平</text>
|
||||
</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>
|
||||
Reference in New Issue
Block a user