Files
shanxia2.0/miniprogram/pages/db/plans/list.vue
T
2026-07-18 09:14:02 +08:00

120 lines
3.5 KiB
Vue

<script setup>
import { ref, computed } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { listPlans } from '@/api/db'
import { planStatusLabel, dash, formatWeight, filterByKeyword } from '@/utils/dbLabels'
import { PAGE_PATHS } from '@/config/api'
const tabs = [
{ key: 'all', label: '全部' },
{ key: '入库', label: '入库' },
{ key: '出库', 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 !== 'all') {
rows = rows.filter((r) => r.businessType === activeTab.value)
}
return filterByKeyword(rows, keyword.value, [
'planNo',
'product',
'customerName',
'vehicleNo',
'executionStatus'
]).slice(0, 80)
})
const goBack = () => {
uni.navigateBack({
fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
})
}
const goDetail = (row) =>
uni.navigateTo({ url: `${PAGE_PATHS.dbPlansDetail}?id=${row.id}` })
const load = async () => {
loading.value = true
try {
rawList.value = await listPlans()
} catch (e) {
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
const switchTab = (key) => {
activeTab.value = key
}
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.planNo) }}</text>
<text class="mp-card__sub">{{ dash(row.product) }} · {{ dash(row.businessType) }}</text>
</view>
<text class="mp-tag" :class="'mp-tag--' + planStatusLabel(row.executionStatus).tag">
{{ planStatusLabel(row.executionStatus).text }}
</text>
</view>
<view class="mp-card__row">
<text>计划量</text>
<text class="mp-card__row-val">{{ formatWeight(row.plannedQuantity) }}</text>
</view>
<view class="mp-card__row">
<text>已执行</text>
<text class="mp-card__row-val">{{ formatWeight(row.executedQuantity) }}</text>
</view>
<view class="mp-card__row">
<text>客户</text>
<text class="mp-card__row-val">{{ dash(row.customerName) }}</text>
</view>
</view>
</view>
<view v-if="loading" class="mp-list-loading">加载中…</view>
</view>
</view>
</template>