135 lines
4.4 KiB
Vue
135 lines
4.4 KiB
Vue
<script setup>
|
||
import { ref } from 'vue'
|
||
import { onShow } from '@dcloudio/uni-app'
|
||
import {
|
||
getDashboardStats,
|
||
listWeighing,
|
||
getInboundByCargo,
|
||
getOutboundByCargo
|
||
} from '@/api/db'
|
||
import { weighingPhase, todayYmd, dash, formatWeight } from '@/utils/dbLabels'
|
||
import { PAGE_PATHS } from '@/config/api'
|
||
|
||
const stats = ref({
|
||
todayInbound: 0,
|
||
todayOutbound: 0,
|
||
todayWeighing: 0,
|
||
needSecond: 0
|
||
})
|
||
const topCargo = ref([])
|
||
const loading = ref(false)
|
||
|
||
const goBack = () => {
|
||
uni.navigateBack({
|
||
fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
|
||
})
|
||
}
|
||
|
||
const goWeighing = () => uni.navigateTo({ url: PAGE_PATHS.dbWeighingList })
|
||
const goPlans = () => uni.navigateTo({ url: PAGE_PATHS.dbPlansList })
|
||
const goInventory = () => uni.navigateTo({ url: PAGE_PATHS.dbInventoryList })
|
||
|
||
const load = async () => {
|
||
loading.value = true
|
||
try {
|
||
const [s, weighings, inCargo, outCargo] = await Promise.all([
|
||
getDashboardStats(),
|
||
listWeighing({ dateFrom: todayYmd(), dateTo: todayYmd() }),
|
||
getInboundByCargo(),
|
||
getOutboundByCargo()
|
||
])
|
||
const todayList = weighings || []
|
||
const needSecond = todayList.filter((w) => {
|
||
const p = weighingPhase(w)
|
||
return p.text === '一次过磅'
|
||
}).length
|
||
stats.value = {
|
||
todayInbound: s.todayInbound ?? s.today_inbound ?? 0,
|
||
todayOutbound: s.todayOutbound ?? s.today_outbound ?? 0,
|
||
todayWeighing: todayList.filter((w) => Number(w.isVoided) !== 1).length,
|
||
needSecond
|
||
}
|
||
const merged = []
|
||
.concat(inCargo || [])
|
||
.concat(outCargo || [])
|
||
.slice(0, 6)
|
||
topCargo.value = merged
|
||
} catch (e) {
|
||
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
onShow(() => load())
|
||
</script>
|
||
|
||
<template>
|
||
<view class="mp-page mp-page--sub">
|
||
<view class="mp-header mp-header--db">
|
||
<text class="mp-subpage-back" @click="goBack">← 工作台</text>
|
||
<text class="mp-header__title" style="margin-top: 16rpx">地磅仪表盘</text>
|
||
<text class="mp-header__meta">今日出入库与过磅概况</text>
|
||
</view>
|
||
|
||
<view class="mp-stats mp-stats--4">
|
||
<view class="mp-stat">
|
||
<text class="mp-stat__num">{{ stats.todayWeighing }}</text>
|
||
<text class="mp-stat__label">今日过磅</text>
|
||
</view>
|
||
<view class="mp-stat">
|
||
<text class="mp-stat__num">{{ stats.needSecond }}</text>
|
||
<text class="mp-stat__label">待二次过磅</text>
|
||
</view>
|
||
<view class="mp-stat">
|
||
<text class="mp-stat__num">{{ Number(stats.todayInbound).toFixed(0) }}</text>
|
||
<text class="mp-stat__label">今日入库</text>
|
||
</view>
|
||
<view class="mp-stat">
|
||
<text class="mp-stat__num">{{ Number(stats.todayOutbound).toFixed(0) }}</text>
|
||
<text class="mp-stat__label">今日出库</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="mp-section">
|
||
<view class="mp-list">
|
||
<view class="mp-card" @click="goWeighing">
|
||
<view class="mp-card__head">
|
||
<text class="mp-card__title">地磅单管理</text>
|
||
<text class="mp-tag mp-tag--warning">现场</text>
|
||
</view>
|
||
<text class="mp-card__sub">查看过磅记录,办理二次过磅</text>
|
||
</view>
|
||
<view class="mp-card" @click="goPlans">
|
||
<view class="mp-card__head">
|
||
<text class="mp-card__title">地磅计划</text>
|
||
<text class="mp-tag mp-tag--info">计划</text>
|
||
</view>
|
||
<text class="mp-card__sub">查看入/出库计划执行进度</text>
|
||
</view>
|
||
<view class="mp-card" @click="goInventory">
|
||
<view class="mp-card__head">
|
||
<text class="mp-card__title">出入库单</text>
|
||
<text class="mp-tag mp-tag--success">单据</text>
|
||
</view>
|
||
<text class="mp-card__sub">查看出入库及关联过磅</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view v-if="topCargo.length" class="mp-block">
|
||
<text class="mp-block__title">货品计划 vs 实绩(节选)</text>
|
||
<view class="mp-block__panel">
|
||
<view v-for="(c, i) in topCargo" :key="i" class="mp-kv">
|
||
<text class="mp-kv__label">{{ dash(c.label) }}</text>
|
||
<text class="mp-kv__value">
|
||
计划 {{ formatWeight(c.planned, '') }} / 实绩 {{ formatWeight(c.actual, '') }}
|
||
</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view v-if="loading" class="mp-list-loading">加载中…</view>
|
||
</view>
|
||
</template>
|