| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <script setup>
- import { ref, computed } from 'vue'
- import { onShow } from '@dcloudio/uni-app'
- import { listInventory } from '@/api/db'
- import {
- inventoryStatusLabel,
- dash,
- formatWeight,
- filterByKeyword,
- todayYmd
- } from '@/utils/dbLabels'
- import { PAGE_PATHS } from '@/config/api'
- const tabs = [
- { key: 'all', label: '全部' },
- { key: '入库', label: '入库' },
- { key: '出库', label: '出库' },
- { key: 'pending', label: '待处理' }
- ]
- const activeTab = ref('all')
- const keyword = ref('')
- const rawList = ref([])
- const loading = ref(false)
- const list = computed(() => {
- let rows = rawList.value
- if (activeTab.value === '入库' || activeTab.value === '出库') {
- rows = rows.filter((r) => r.businessType === activeTab.value)
- } else if (activeTab.value === 'pending') {
- rows = rows.filter((r) => String(r.status || '').includes('待'))
- }
- return filterByKeyword(rows, keyword.value, [
- 'batchNo',
- 'planNo',
- 'vehicleNo',
- 'product',
- 'partnerCompany',
- 'status'
- ]).slice(0, 80)
- })
- const goBack = () => {
- uni.navigateBack({
- fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
- })
- }
- const goDetail = (row) =>
- uni.navigateTo({ url: `${PAGE_PATHS.dbInventoryDetail}?id=${row.id}` })
- const load = async () => {
- loading.value = true
- try {
- // 默认拉今日,减轻全量压力;切「全部」再无日期
- if (activeTab.value === 'all' && !keyword.value) {
- const today = todayYmd()
- rawList.value = await listInventory({ dateFrom: today, dateTo: today })
- if (rawList.value.length < 5) {
- rawList.value = await listInventory()
- }
- } else {
- rawList.value = await listInventory()
- }
- } 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-section" style="padding-bottom: 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.product) }} · {{ dash(row.businessType) }}
- </text>
- </view>
- <text class="mp-tag" :class="'mp-tag--' + inventoryStatusLabel(row.status).tag">
- {{ inventoryStatusLabel(row.status).text }}
- </text>
- </view>
- <view class="mp-card__row">
- <text>数量</text>
- <text class="mp-card__row-val">{{ formatWeight(row.quantity) }}</text>
- </view>
- <view class="mp-card__row">
- <text>往来单位</text>
- <text class="mp-card__row-val">{{ dash(row.partnerCompany) }}</text>
- </view>
- <view class="mp-card__row">
- <text>日期</text>
- <text class="mp-card__row-val">{{ dash(row.date) }}</text>
- </view>
- </view>
- </view>
- <view v-if="loading" class="mp-list-loading">加载中…</view>
- </view>
- </view>
- </template>
|