| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <script setup>
- import { ref, computed } from 'vue'
- import { onShow } from '@dcloudio/uni-app'
- import { listWeighing } from '@/api/db'
- import {
- weighingPhase,
- dash,
- formatWeight,
- filterByKeyword,
- todayYmd
- } from '@/utils/dbLabels'
- import { PAGE_PATHS } from '@/config/api'
- const tabs = [
- { key: 'today', label: '今日' },
- { key: 'second', label: '待二次' },
- { key: 'all', label: '全部' }
- ]
- const activeTab = ref('today')
- const keyword = ref('')
- const rawList = ref([])
- const loading = ref(false)
- const stats = computed(() => {
- const today = todayYmd()
- const todayRows = rawList.value.filter((w) => {
- const t = String(w.grossWeightTime || w.createdAt || '')
- return t.startsWith(today) && Number(w.isVoided) !== 1
- })
- const needSecond = todayRows.filter((w) => weighingPhase(w).text === '一次过磅').length
- return {
- today: todayRows.length,
- needSecond
- }
- })
- const list = computed(() => {
- let rows = rawList.value
- const today = todayYmd()
- if (activeTab.value === 'today') {
- rows = rows.filter((w) => String(w.grossWeightTime || w.createdAt || '').startsWith(today))
- } else if (activeTab.value === 'second') {
- rows = rows.filter((w) => weighingPhase(w).text === '一次过磅')
- }
- return filterByKeyword(rows, keyword.value, [
- 'vehicleNo',
- 'cargoName',
- 'planNo',
- 'batchNo',
- 'supplier',
- 'consignee'
- ]).slice(0, 80)
- })
- const goBack = () => {
- uni.navigateBack({
- fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
- })
- }
- const goDetail = (row) =>
- uni.navigateTo({ url: `${PAGE_PATHS.dbWeighingDetail}?id=${row.id}` })
- const load = async () => {
- loading.value = true
- try {
- // 今日优先带日期参数;全部再拉全量(数据量大时可能慢)
- if (activeTab.value === 'all') {
- rawList.value = await listWeighing()
- } else {
- const today = todayYmd()
- rawList.value = await listWeighing({ dateFrom: today, dateTo: today })
- // 待二次若今日无,再尝试不带日期限制的一次过磅(限制体验:仅今日+已加载)
- if (activeTab.value === 'second' && !rawList.value.some((w) => weighingPhase(w).text === '一次过磅')) {
- const all = await listWeighing()
- rawList.value = all
- }
- }
- } catch (e) {
- uni.showToast({ title: e.message || '加载失败', icon: 'none' })
- } finally {
- loading.value = false
- }
- }
- const switchTab = (key) => {
- activeTab.value = key
- load()
- }
- 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>
- <view class="mp-header__search">
- <view class="mp-header__search-dot" />
- <input
- v-model="keyword"
- class="mp-header__search-input"
- placeholder="车牌 / 货物 / 计划号"
- />
- </view>
- </view>
- <view class="mp-stats">
- <view class="mp-stat">
- <text class="mp-stat__num">{{ stats.today }}</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">{{ list.length }}</text>
- <text class="mp-stat__label">当前列表</text>
- </view>
- </view>
- <view class="mp-section" style="padding-bottom: 0; padding-top: 0">
- <scroll-view scroll-x class="mp-tabs">
- <view
- v-for="t in tabs"
- :key="t.key"
- class="mp-tab"
- :class="{ 'mp-tab--active': activeTab === t.key }"
- @click="switchTab(t.key)"
- >
- {{ t.label }}
- </view>
- </scroll-view>
- </view>
- <view class="mp-section">
- <mp-empty v-if="!list.length && !loading" title="暂无地磅单" />
- <view v-else class="mp-list">
- <view v-for="row in list" :key="row.id" class="mp-card" @click="goDetail(row)">
- <view class="mp-card__head">
- <view>
- <text class="mp-card__title">{{ dash(row.batchNo || row.id) }}</text>
- <text class="mp-card__sub">{{ dash(row.vehicleNo) }} · {{ dash(row.cargoName) }}</text>
- </view>
- <text class="mp-tag" :class="'mp-tag--' + weighingPhase(row).tag">
- {{ weighingPhase(row).text }}
- </text>
- </view>
- <view class="mp-card__row">
- <text>净重</text>
- <text class="mp-card__row-val">{{ formatWeight(row.netWeight) }}</text>
- </view>
- <view class="mp-card__row">
- <text>过磅时间</text>
- <text class="mp-card__row-val">{{ dash(row.grossWeightTime) }}</text>
- </view>
- <view v-if="weighingPhase(row).text === '一次过磅'" class="mp-card__foot">
- <view class="mp-btn mp-btn--primary mp-btn--sm">二次过磅</view>
- </view>
- </view>
- </view>
- <view v-if="loading" class="mp-list-loading">加载中…</view>
- </view>
- </view>
- </template>
|