142 lines
4.1 KiB
Vue
142 lines
4.1 KiB
Vue
<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>
|