Files
shanxia2.0/miniprogram/pages/pl/freight/approval.vue
T
2026-07-18 09:14:02 +08:00

140 lines
4.1 KiB
Vue

<script setup>
import { ref, computed } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { listFreight } from '@/api/pl'
import { dash, formatMoney, settlementStatusLabel } from '@/utils/plLabels'
import { PAGE_PATHS } from '@/config/api'
const tabs = [
{ key: 'approval_pending', label: '待我审批' },
{ key: 'approval_done', label: '已审批' }
]
const activeTab = ref('approval_pending')
const keyword = ref('')
const rows = ref([])
const loading = ref(false)
const page = ref(1)
const finished = ref(false)
const list = computed(() => {
const kw = String(keyword.value || '')
.trim()
.toLowerCase()
if (!kw) return rows.value
return rows.value.filter((row) => {
const blob = [row.settlementNo, row.licensePlateSummary, row.submitterName]
.join(' ')
.toLowerCase()
return blob.includes(kw)
})
})
const goBack = () => {
uni.navigateBack({
fail: () => uni.switchTab({ url: PAGE_PATHS.workbench })
})
}
const goDetail = (row) =>
uni.navigateTo({ url: `${PAGE_PATHS.plFreightDetail}?id=${row.id}` })
const load = async (reset = true) => {
if (loading.value) return
if (reset) {
page.value = 1
finished.value = false
rows.value = []
}
if (finished.value) return
loading.value = true
try {
const res = await listFreight({
tab: activeTab.value,
q: keyword.value.trim() || undefined,
page: page.value,
pageSize: 20
})
const next = res.rows || []
rows.value = reset ? next : rows.value.concat(next)
if (!next.length || rows.value.length >= (res.total || 0)) finished.value = true
else page.value += 1
} catch (e) {
uni.showToast({ title: e.message || '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
const switchTab = (key) => {
activeTab.value = key
load(true)
}
onShow(() => load(true))
</script>
<template>
<view class="mp-page mp-page--sub">
<view class="mp-header mp-header--pl">
<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="结算号 / 车牌"
confirm-type="search"
@confirm="load(true)"
/>
</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.settlementNo) }}</text>
<text class="mp-card__sub">
{{ dash(row.licensePlateSummary) }} · {{ dash(row.submitterName) }}
</text>
</view>
<text class="mp-tag" :class="'mp-tag--' + settlementStatusLabel(row.settlementStatus).tag">
{{ settlementStatusLabel(row.settlementStatus).text }}
</text>
</view>
<view class="mp-card__row">
<text>运费合计</text>
<text class="mp-card__amount">{{ formatMoney(row.totalFreight) }}</text>
</view>
<view class="mp-card__foot">
<button class="mp-btn mp-btn--primary" @click.stop="goDetail(row)">
{{ row.canApprove ? '去审批' : '详情' }}
</button>
</view>
</view>
</view>
<view v-if="!finished && rows.length" class="mp-load-more" @click="load(false)">
{{ loading ? '加载中…' : '加载更多' }}
</view>
</view>
</view>
</template>