修复生产统计与维修记录用户数据

This commit is contained in:
2026-09-06 21:06:36 +08:00
parent 02c8fb7021
commit 5ca6ef2d5a
41 changed files with 1838 additions and 205 deletions
+426 -125
View File
@@ -27,7 +27,7 @@
<view class="metric-card">
<view class="section-header">
<text class="section-title">核心指标</text>
<text class="section-subtitle">近 30 天累计</text>
<text class="section-subtitle">本月累计</text>
</view>
<view class="metric-grid">
<view v-for="item in metrics" :key="item.label" class="metric-item">
@@ -37,6 +37,20 @@
</view>
</view>
<view class="process-card">
<view class="section-header">
<text class="section-title">工序步骤统计</text>
<text class="section-subtitle">本月 Top 10</text>
</view>
<view v-if="processBreakdown.length" class="process-list">
<view v-for="item in processBreakdown" :key="item.key" class="process-row">
<text class="process-name">{{ item.name }}</text>
<text class="process-count">{{ item.quantity }}</text>
</view>
</view>
<text v-else class="empty-text">本月暂无工序步骤记录</text>
</view>
<view class="trend-card">
<view class="section-header">
<text class="section-title">个人趋势</text>
@@ -52,6 +66,32 @@
</view>
</view>
<view class="calendar-card">
<view class="calendar-title-row">
<view class="calendar-title"><u-icon name="list-dot" color="#1677ff" size="34" /><text>月度总表({{ calendarMonthLabel }})</text></view>
<view class="month-actions"><text @tap="changeMonth(-1)">‹</text><text @tap="changeMonth(1)">›</text></view>
</view>
<text class="calendar-hint">日历仅显示是否有数据,点击日期查看当天统计</text>
<view class="weekday-row"><text v-for="day in weekdays" :key="day">{{ day }}</text></view>
<view v-for="(week, index) in calendarWeeks" :key="index" class="calendar-week">
<view v-for="cell in week" :key="cell.date" class="calendar-cell" :class="{ muted: !cell.currentMonth, selected: cell.date === selectedDate, today: cell.isToday, hasData: cell.hasData }" @tap="selectCalendarDate(cell)">
<text>{{ cell.day }}</text><view v-if="cell.hasData" class="data-dot"></view>
</view>
</view>
<view class="day-detail">
<view class="day-detail-header"><text>当天明细</text><text>{{ selectedDate }}</text></view>
<view class="day-metrics">
<view><text>订单扫码</text><strong>{{ selectedDaySummary.order }}</strong></view>
<view><text>整机数量</text><strong>{{ selectedDaySummary.product }}</strong></view>
<view><text>总计</text><strong>{{ selectedDaySummary.total }}</strong></view>
</view>
<view v-if="selectedDaySummary.steps.length" class="day-step-list">
<view v-for="step in selectedDaySummary.steps" :key="step.key" class="day-step-row"><text>{{ step.name }}</text><strong>{{ step.quantity }}</strong></view>
</view>
<text v-else class="day-empty">当天暂无工序数据</text>
</view>
</view>
<view class="record-card">
<view class="section-header">
<text class="section-title">最近明细</text>
@@ -72,43 +112,12 @@
</view>
</view>
<view class="split-card">
<view class="split-section">
<view class="section-header compact">
<text class="section-title">扫码类型占比</text>
</view>
<view v-for="item in typeRate" :key="item.label" class="progress-row">
<view class="progress-info">
<text class="progress-label">{{ item.label }}</text>
<text class="progress-value">{{ item.value }}%</text>
</view>
<view class="progress-track">
<view class="progress-fill" :style="{ width: item.value + '%', backgroundColor: item.color }"></view>
</view>
</view>
</view>
<view class="split-section">
<view class="section-header compact">
<text class="section-title">异常统计</text>
</view>
<view v-for="item in exceptionData" :key="item.label" class="progress-row">
<view class="progress-info">
<text class="progress-label">{{ item.label }}</text>
<text class="progress-value">{{ item.value }}%</text>
</view>
<view class="progress-track">
<view class="progress-fill" :style="{ width: item.value + '%', backgroundColor: item.color }"></view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import { getUserInfo } from '@/api/member.js'
import { getOrderRecentRecords, getOrderStatistics, getProductRecentRecords, getProductStatistics } from '@/api/produce/data-entry.js'
import { getExceptionStatistics, getOrderRecentRecords, getOrderStatistics, getProductRecentRecords, getProductStatistics, getRepairStatistics, getTodayDashboard } from '@/api/produce/data-entry.js'
export default {
data() {
@@ -122,23 +131,24 @@ export default {
level: '-'
},
metrics: [
{ label: '今日扫码', value: '0', type: 'primary' },
{ label: '本月累计', value: '0', type: 'success' },
{ label: '成功率', value: '0%', type: 'success' },
{ label: '异常数', value: '0', type: 'danger' }
{ label: '订单数', value: '0', type: 'primary' }, { label: '整机数', value: '0', type: 'success' },
{ label: '本月总计', value: '0', type: 'primary' }, { label: '异常提报', value: '0', type: 'warning' },
{ label: '维修量', value: '0', type: 'warning' }, { label: '责任订单', value: '0', type: 'danger' }
],
trendData: [],
processBreakdown: [],
recentRecords: [],
typeRate: [
{ label: '订单模式', value: 0, color: '#2f6cf6' },
{ label: '整机模式', value: 0, color: '#35bfa3' },
{ label: '异常记录', value: 0, color: '#f7b733' }
],
exceptionData: [
{ label: '已处理', value: 0, color: '#19be6b' },
{ label: '待复核', value: 0, color: '#f7b733' },
{ label: '待处理', value: 0, color: '#e91f3f' }
]
weekdays: ['一', '二', '三', '四', '五', '六', '日'],
calendarMonth: new Date(),
selectedDate: '',
calendarWeeks: [],
calendarData: {},
selectedDaySummary: { order: 0, product: 0, quantity: 0, total: 0, steps: [] },
}
},
computed: {
calendarMonthLabel() {
return `${this.calendarMonth.getFullYear()}-${String(this.calendarMonth.getMonth() + 1).padStart(2, '0')}`
}
},
onLoad() {
@@ -151,13 +161,25 @@ export default {
},
async loadPageData() {
const userCode = this.getCurrentUserCode()
const today = new Date()
const dateText = (date) => date.toISOString().slice(0, 10)
const todayDate = dateText(today)
this.selectedDate = todayDate
this.buildCalendar()
const monthDate = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-01`
try {
const [profile, orderStats, productStats, orderRecent, productRecent] = await Promise.all([
const [profile, orderStats, productStats, repairStats, exceptionStats, dashboard, todayOrderStats, todayProductStats, todayRepairStats, orderRecent, productRecent] = await Promise.all([
getUserInfo(),
getOrderStatistics({ user_code: userCode }),
getProductStatistics({ user_code: userCode }),
getOrderRecentRecords({ user_code: userCode, limit: 3 }),
getProductRecentRecords({ user_code: userCode, limit: 3 })
getOrderStatistics({ user_code: userCode, start_date: monthDate, end_date: todayDate }),
getProductStatistics({ user_code: userCode, start_date: monthDate, end_date: todayDate }),
getRepairStatistics({ user_code: userCode, start_date: monthDate, end_date: todayDate }),
getExceptionStatistics({ user_code: userCode, start_date: monthDate, end_date: todayDate }),
getTodayDashboard(),
getOrderStatistics({ user_code: userCode, start_date: todayDate, end_date: todayDate }),
getProductStatistics({ user_code: userCode, start_date: todayDate, end_date: todayDate }),
getRepairStatistics({ user_code: userCode, start_date: todayDate, end_date: todayDate }),
getOrderRecentRecords({ user_code: userCode, start_date: monthDate, end_date: todayDate, limit: 3 }),
getProductRecentRecords({ user_code: userCode, start_date: monthDate, end_date: todayDate, limit: 3 })
])
this.profile = {
@@ -169,16 +191,42 @@ export default {
level: Number(profile.enabled) === 0 ? '已停用' : '稳定输出'
}
const todayTotal = Number(orderStats?.today_total || 0) + Number(productStats?.today_total || 0)
const successTotal = Number(orderStats?.success_total || 0) + Number(productStats?.success_total || 0)
const failedTotal = Number(orderStats?.failed_total || 0) + Number(productStats?.failed_total || 0)
const successRate = todayTotal > 0 ? ((successTotal / todayTotal) * 100).toFixed(1) : '0.0'
const repairTotal = Number(repairStats?.completed_today || 0)
const exceptionTotal = Number(exceptionStats?.pending || 0) + Number(exceptionStats?.review || 0) + Number(exceptionStats?.done || 0)
const monthScanTotal = Number(orderStats?.today_total || 0) + Number(productStats?.today_total || 0)
const todayTotal = Number(todayOrderStats?.today_total || 0) + Number(todayProductStats?.today_total || 0)
this.selectedDaySummary = this.makeDaySummary(todayOrderStats, todayProductStats, todayRepairStats)
const responsibilityTotal = Number(dashboard?.responsibility_order_total || 0)
this.metrics = [
{ label: '今日扫码', value: String(todayTotal), type: 'primary' },
{ label: '本月累计', value: String(todayTotal), type: 'success' },
{ label: '成功率', value: `${successRate}%`, type: 'success' },
{ label: '异常数', value: String(failedTotal), type: 'danger' }
{ label: '订单数', value: String(orderStats?.today_total || 0), type: 'primary' },
{ label: '整机数', value: String(productStats?.today_total || 0), type: 'success' },
{ label: '本月总计', value: String(monthScanTotal), type: 'primary' },
{ label: '异常提报', value: String(exceptionTotal), type: 'warning' },
{ label: '维修量', value: String(repairTotal), type: 'warning' },
{ label: '责任订单', value: String(responsibilityTotal), type: 'danger' }
]
const breakdown = [...(orderStats?.process_breakdown || []), ...(productStats?.process_breakdown || []), ...(repairStats?.process_breakdown || [])]
const grouped = {}
breakdown.forEach((item) => {
const key = `${item.process_id || 'none'}-${item.step_id || 'none'}`
if (!grouped[key]) grouped[key] = { key, name: `${item.process_name || '未记录工序'} / ${item.step_name || '未记录步骤'}`, quantity: 0 }
grouped[key].quantity += Number(item.quantity || 0)
})
this.processBreakdown = Object.values(grouped).sort((a, b) => b.quantity - a.quantity).slice(0, 10)
const trendMap = {}
;[...(orderStats?.daily_trend || []), ...(productStats?.daily_trend || [])].forEach((item) => {
trendMap[item.date] = (trendMap[item.date] || 0) + Number(item.quantity || 0)
})
const trendDates = Object.keys(trendMap).sort().slice(-7)
const maxTrend = Math.max(1, ...trendDates.map((date) => trendMap[date]))
this.trendData = trendDates.map((date, index) => ({
label: date.slice(5),
value: trendMap[date],
percent: Math.round(trendMap[date] / maxTrend * 100),
color: index % 2 ? '#35bfa3' : '#2f6cf6'
}))
this.calendarData = trendMap
this.buildCalendar()
const orderItems = Array.isArray(orderRecent?.items) ? orderRecent.items : []
const productItems = Array.isArray(productRecent?.items) ? productRecent.items : []
@@ -192,20 +240,70 @@ export default {
count: item.quantity ? `+${item.quantity}` : '1'
}))
this.typeRate = [
{ label: '订单模式', value: orderItems.length, color: '#2f6cf6' },
{ label: '整机模式', value: productItems.length, color: '#35bfa3' },
{ label: '异常记录', value: failedTotal, color: '#f7b733' }
]
this.exceptionData = [
{ label: '已处理', value: successTotal, color: '#19be6b' },
{ label: '待复核', value: failedTotal > 0 ? Math.min(failedTotal, 18) : 0, color: '#f7b733' },
{ label: '待处理', value: failedTotal > 18 ? failedTotal - 18 : 0, color: '#e91f3f' }
]
} catch (error) {
console.error('[scanapp] 统计页数据加载失败', error)
}
},
formatDate(date) {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
},
buildCalendar() {
const year = this.calendarMonth.getFullYear()
const month = this.calendarMonth.getMonth()
const firstDay = (new Date(year, month, 1).getDay() + 6) % 7
const cells = []
for (let index = 0; index < 42; index++) {
const date = new Date(year, month, index - firstDay + 1)
const value = this.formatDate(date)
cells.push({ date: value, day: date.getDate(), currentMonth: date.getMonth() === month, isToday: value === this.formatDate(new Date()), hasData: Boolean(this.calendarData[value]) })
}
this.calendarWeeks = Array.from({ length: 6 }, (_, index) => cells.slice(index * 7, index * 7 + 7))
},
async changeMonth(offset) {
this.calendarMonth = new Date(this.calendarMonth.getFullYear(), this.calendarMonth.getMonth() + offset, 1)
const year = this.calendarMonth.getFullYear()
const month = this.calendarMonth.getMonth() + 1
const startDate = `${year}-${String(month).padStart(2, '0')}-01`
const endDate = this.formatDate(new Date(year, month, 0))
try {
const [order, product] = await Promise.all([
getOrderStatistics({ user_code: this.getCurrentUserCode(), start_date: startDate, end_date: endDate }),
getProductStatistics({ user_code: this.getCurrentUserCode(), start_date: startDate, end_date: endDate })
])
this.calendarData = [...(order?.daily_trend || []), ...(product?.daily_trend || [])].reduce((map, item) => ({ ...map, [item.date]: true }), {})
} catch (error) {
this.calendarData = {}
}
this.buildCalendar()
const firstCell = this.calendarWeeks.flat().find((cell) => cell.currentMonth)
if (firstCell) this.selectCalendarDate(firstCell)
},
async selectCalendarDate(cell) {
if (!cell.currentMonth) return
this.selectedDate = cell.date
try {
const [order, product, repair] = await Promise.all([
getOrderStatistics({ user_code: this.getCurrentUserCode(), start_date: cell.date, end_date: cell.date }),
getProductStatistics({ user_code: this.getCurrentUserCode(), start_date: cell.date, end_date: cell.date }),
getRepairStatistics({ user_code: this.getCurrentUserCode(), start_date: cell.date, end_date: cell.date })
])
this.selectedDaySummary = this.makeDaySummary(order, product, repair)
} catch (error) {
console.error('[scanapp] 日期统计加载失败', error)
}
},
makeDaySummary(order, product, repair) {
const orderTotal = Number(order?.today_total || 0)
const productTotal = Number(product?.today_total || 0)
const repairTotal = Number(repair?.completed_today || 0)
const rows = [...(order?.process_breakdown || []), ...(product?.process_breakdown || []), ...(repair?.process_breakdown || [])]
const grouped = {}
rows.forEach((item) => {
const key = `${item.process_id || 'none'}-${item.step_id || 'none'}`
if (!grouped[key]) grouped[key] = { key, name: `${item.process_name || '未记录工序'} / ${item.step_name || '未记录步骤'}`, quantity: 0 }
grouped[key].quantity += Number(item.quantity || 0)
})
return { order: orderTotal, product: productTotal, quantity: productTotal, total: orderTotal + productTotal + repairTotal, steps: Object.values(grouped).sort((a, b) => b.quantity - a.quantity) }
}
}
}
@@ -221,10 +319,11 @@ export default {
.hero-card,
.profile-card,
.calendar-card,
.metric-card,
.trend-card,
.record-card,
.split-card {
.process-card {
margin-top: 18rpx;
padding: 24rpx;
border-radius: 22rpx;
@@ -232,6 +331,179 @@ export default {
box-shadow: 0 10rpx 26rpx rgba(23, 35, 61, 0.05);
}
.calendar-title-row,
.calendar-title,
.month-actions,
.weekday-row,
.calendar-week,
.day-detail-header,
.day-metrics {
display: flex;
align-items: center;
}
.calendar-title-row,
.day-detail-header {
justify-content: space-between;
}
.calendar-title {
gap: 12rpx;
color: #17233d;
font-size: 28rpx;
font-weight: 700;
}
.month-actions text {
padding: 4rpx 14rpx;
color: #1677ff;
font-size: 36rpx;
}
.calendar-hint {
display: block;
margin-top: 16rpx;
padding: 16rpx;
border-radius: 12rpx;
background: #f5f8fd;
color: #7d8798;
font-size: 20rpx;
}
.weekday-row,
.calendar-week {
justify-content: space-between;
}
.weekday-row {
margin-top: 18rpx;
color: #9aa4b4;
font-size: 20rpx;
text-align: center;
}
.weekday-row text,
.calendar-cell {
width: 13.2%;
text-align: center;
}
.calendar-week {
margin-top: 10rpx;
}
.calendar-cell {
position: relative;
padding: 18rpx 0;
border-radius: 16rpx;
color: #303949;
font-size: 26rpx;
}
.calendar-cell.muted {
color: #c4cad5;
}
.calendar-cell.hasData::after {
content: '';
position: absolute;
bottom: 8rpx;
left: 50%;
width: 6rpx;
height: 6rpx;
border-radius: 50%;
background: #19be6b;
transform: translateX(-50%);
}
.calendar-cell.selected {
background: #2f80ed;
color: #ffffff;
box-shadow: 0 6rpx 14rpx rgba(47, 128, 237, 0.25);
}
.calendar-cell.selected.hasData::after {
background: #ffffff;
}
.day-detail {
margin-top: 18rpx;
padding: 18rpx;
border: 1rpx solid #dceafd;
border-radius: 16rpx;
background: #fbfdff;
}
.day-detail-header text:first-child {
color: #17233d;
font-size: 28rpx;
font-weight: 700;
}
.day-detail-header text:last-child {
color: #7d8798;
font-size: 20rpx;
}
.day-metrics {
gap: 12rpx;
margin-top: 16rpx;
}
.day-metrics view {
flex: 1;
padding: 14rpx 6rpx;
border-radius: 12rpx;
background: #f0f6ff;
text-align: center;
}
.day-metrics view:nth-child(2) { background: #f2fbea; }
.day-metrics view:nth-child(3) { background: #fff7e6; }
.day-metrics text,
.day-metrics strong {
display: block;
}
.day-metrics text {
color: #7d8798;
font-size: 18rpx;
}
.day-metrics strong {
margin-top: 6rpx;
color: #303949;
font-size: 28rpx;
}
.day-empty {
display: block;
margin-top: 16rpx;
color: #9aa4b4;
font-size: 20rpx;
text-align: center;
}
.day-step-list {
margin-top: 14rpx;
border-top: 1rpx solid #e7edf6;
}
.day-step-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12rpx 4rpx;
border-bottom: 1rpx solid #e7edf6;
color: #526078;
font-size: 20rpx;
}
.day-step-row strong {
color: #2f6cf6;
font-size: 22rpx;
}
.hero-card {
display: flex;
align-items: center;
@@ -370,7 +642,7 @@ export default {
.metric-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14rpx;
}
@@ -399,6 +671,10 @@ export default {
color: #e91f3f;
}
.metric-value.warning {
color: #f7a928;
}
.metric-label {
margin-top: 6rpx;
color: #7d8798;
@@ -450,6 +726,37 @@ export default {
border-bottom: 1rpx solid #eef1f6;
}
.process-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14rpx 0;
border-bottom: 1rpx solid #eef1f6;
}
.process-row:last-child {
border-bottom: 0;
}
.process-name {
color: #4d5b70;
font-size: 22rpx;
}
.process-count {
color: #2f6cf6;
font-size: 24rpx;
font-weight: 700;
}
.empty-text {
display: block;
padding: 20rpx 0 6rpx;
color: #9aa4b4;
font-size: 20rpx;
text-align: center;
}
.record-item:last-child {
padding-bottom: 0;
border-bottom: 0;
@@ -504,74 +811,29 @@ export default {
line-height: 1.35;
}
.split-card {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 18rpx;
}
.split-section {
padding: 20rpx;
border-radius: 18rpx;
background: #f8fbff;
}
.progress-row {
margin-top: 14rpx;
}
.progress-info {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8rpx;
}
.progress-label,
.progress-value {
color: #7d8798;
font-size: 20rpx;
line-height: 1.35;
}
.progress-value {
color: #17233d;
font-weight: 700;
}
.progress-track {
height: 14rpx;
border-radius: 999rpx;
background: #e9edf4;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 999rpx;
}
.theme-dark.statistics-page {
background: #151923;
}
.theme-dark .hero-card,
.theme-dark .profile-card,
.theme-dark .calendar-card,
.theme-dark .metric-card,
.theme-dark .trend-card,
.theme-dark .record-card,
.theme-dark .split-card {
.theme-dark .process-card {
border-color: #364152;
background: #222936;
box-shadow: none;
}
.theme-dark .metric-item,
.theme-dark .split-section,
.theme-dark .profile-chip {
background: #1c2431;
}
.theme-dark .profile-name,
.theme-dark .calendar-title,
.theme-dark .section-title,
.theme-dark .metric-value,
.theme-dark .record-main,
@@ -580,6 +842,7 @@ export default {
}
.theme-dark .profile-desc,
.theme-dark .calendar-hint,
.theme-dark .section-subtitle,
.theme-dark .metric-label,
.theme-dark .bar-label,
@@ -590,16 +853,54 @@ export default {
color: #aeb9ca;
}
.theme-dark .record-item,
.theme-dark .progress-track {
.theme-dark .process-name,
.theme-dark .empty-text {
color: #aeb9ca;
}
.theme-dark .process-row {
border-color: #364152;
}
.theme-dark .bar-track,
.theme-dark .progress-track {
.theme-dark .record-item {
border-color: #364152;
}
.theme-dark .bar-track {
background: #1c2431;
}
.theme-dark .calendar-hint,
.theme-dark .day-detail {
background: #1c2431;
border-color: #364152;
}
.theme-dark .calendar-cell {
color: #f2f5fa;
}
.theme-dark .calendar-cell.muted,
.theme-dark .day-detail-header text:last-child,
.theme-dark .day-metrics text,
.theme-dark .day-empty {
color: #aeb9ca;
}
.theme-dark .day-detail-header text:first-child,
.theme-dark .day-metrics strong {
color: #f2f5fa;
}
.theme-dark .day-step-list,
.theme-dark .day-step-row {
border-color: #364152;
}
.theme-dark .day-step-row {
color: #aeb9ca;
}
.theme-dark .profile-badge {
background: rgba(47, 108, 246, 0.2);
}