Files
shanxia2.0/miniprogram/pages/pl/transport-plan/list.vue
T
2026-09-26 11:59:39 +08:00

248 lines
7.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="bx-page pl-site-plan-page">
<view class="topbar" :style="safeAreaStyle">
<view class="topbar-left">
<text class="topbar-back" @click="goBack">←</text>
<text class="topbar-title">现场运输计划单</text>
</view>
<view class="topbar-right" />
</view>
<view class="filters">
<uni-calendar
:insert="true"
:date="selectedDate"
:selected="calendarSelected"
:showMonth="false"
@change="onCalendarChange"
@monthSwitch="onMonthSwitch"
/>
<input
class="search-input"
v-model="keyword"
placeholder="车牌号/产品名称"
confirm-type="search"
@confirm="loadList"
/>
</view>
<view class="list-body">
<view v-if="loading" class="page-loading">加载中...</view>
<view v-else-if="!records.length" class="empty-hint">暂无现场记录</view>
<view
v-for="(row, index) in records"
:key="row.planId || index"
class="record-card"
@click="openRecord(row)"
>
<text class="index-tag">{{ index + 1 }}</text>
<view class="record-top">
<text class="card-title">{{ cardTitle(row) }}</text>
<text class="tag" :class="tagClass(row)">{{ row.statusLabel || '进行中' }}</text>
</view>
<view class="meta">
车牌:<text class="plate-hl">{{ row.licensePlate || '—' }}</text>
</view>
<template v-if="(row.stops || []).length">
<view
v-for="(stop, sIndex) in row.stops"
:key="`${stop.stopType}-${stop.seq ?? sIndex}`"
class="stop-block"
>
<view class="stop-block__title"
>{{ stop.label }} · {{ stop.customerName || '—' }}</view
>
<view class="meta">时间:{{ formatDay(stop.stopTime) }}</view>
<view class="meta">地址:{{ stop.address || '—' }}</view>
<template v-if="!(stop.products || []).length">
<view class="meta">产品:—</view>
</template>
<template v-for="(prod, pIndex) in stop.products || []" :key="pIndex">
<view class="meta">产品:{{ prod.productName || '—' }}</view>
<view class="meta">规格型号:{{ prod.model || '—' }}</view>
<view class="meta">包装规格:{{ prod.packageSpec || '—' }}</view>
<view class="meta"
>数量:{{ formatQty(prod.quantity) }} · 单位:{{ prod.unit || '—' }}</view
>
</template>
</view>
</template>
<view class="meta">运输计划号:{{ row.planNo || '—' }}</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, watch } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { PAGE_PATHS } from '@/config/api'
import { sitePlanApi } from '@/api/pl'
import { getSafeAreaStyle } from '@/utils/safeArea'
const safeAreaStyle = getSafeAreaStyle()
function todayStr() {
const d = new Date()
const m = `${d.getMonth() + 1}`.padStart(2, '0')
const day = `${d.getDate()}`.padStart(2, '0')
return `${d.getFullYear()}-${m}-${day}`
}
const selectedDate = ref(todayStr())
const keyword = ref('')
const records = ref([])
const loading = ref(false)
const calendarSelected = ref([])
let calendarMonth = selectedDate.value.slice(0, 7)
let keywordTimer = null
function formatDay(value) {
if (!value) return '—'
const normalized = String(value).replace('T', ' ')
return normalized.length >= 10 ? normalized.slice(0, 10) : normalized
}
function formatQty(value) {
if (value == null || value === '') return '—'
return String(value)
}
function cardTitleDate(row) {
const stopTimes = (row.stops || [])
.map((stop) => formatDay(stop.stopTime))
.filter((value) => value !== '—')
if (stopTimes.length) return stopTimes[0]
const fromPickup = formatDay(row.pickupTime)
if (fromPickup !== '—') return fromPickup
const fromDelivery = formatDay(row.deliveryTime)
if (fromDelivery !== '—') return fromDelivery
return selectedDate.value
}
function cardTitle(row) {
const names = (row.stops || [])
.flatMap((stop) => (stop.products || []).map((p) => (p.productName || '').trim()))
.filter(Boolean)
const uniqueNames = [...new Set(names)]
const productLabel = uniqueNames.length ? uniqueNames.join('、') : '—'
return `${cardTitleDate(row)} ${productLabel}`
}
function tagClass(row) {
if (row.planVoided || row.statusLabel === '已作废') return 'tag--danger'
if (row.planArchived || row.statusLabel === '已归档') return 'tag--muted'
return 'tag--success'
}
async function loadList() {
loading.value = true
try {
const res = await sitePlanApi.history({
date: selectedDate.value,
q: keyword.value.trim() || undefined
})
records.value = res.records || []
} catch (e) {
records.value = []
} finally {
loading.value = false
}
}
async function loadCalendarCounts(month) {
const m = String(month || '').slice(0, 7)
if (!/^\d{4}-\d{2}$/.test(m)) return
calendarMonth = m
const today = todayStr()
try {
const counts = await sitePlanApi.calendarCounts(m)
calendarSelected.value = Object.keys(counts || {})
.filter((date) => Number(counts[date]) > 0 && date >= today)
.map((date) => ({ date, info: String(counts[date]) }))
} catch (e) {
calendarSelected.value = []
}
}
function onCalendarChange(e) {
const v = e?.fulldate || e?.date || (typeof e === 'string' ? e : '')
if (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}/.test(v)) {
selectedDate.value = v.slice(0, 10)
const month = selectedDate.value.slice(0, 7)
if (month !== calendarMonth) {
loadCalendarCounts(month)
}
loadList()
}
}
function onMonthSwitch(e) {
const year = e?.year
const month = e?.month
if (year == null || month == null) return
const m = `${year}-${`${month}`.padStart(2, '0')}`
loadCalendarCounts(m)
}
function openRecord(row) {
const id = row.planId || row.plan_id
if (!id) {
uni.showToast({ title: '计划无效', icon: 'none' })
return
}
uni.navigateTo({ url: `${PAGE_PATHS.plTransportPlanDetail}?planId=${id}` })
}
function goBack() {
uni.navigateBack({ fail: () => uni.reLaunch({ url: PAGE_PATHS.workbench }) })
}
watch(keyword, () => {
clearTimeout(keywordTimer)
keywordTimer = setTimeout(loadList, 300)
})
onShow(() => {
loadCalendarCounts(calendarMonth || selectedDate.value.slice(0, 7))
loadList()
})
</script>
<!-- 微信端:scss 须在 style 中 @import;script 里 import 只会生成空 js,H5 有样式而小程序无样式 -->
<style lang="scss">
@import '@/styles/bx-theme.scss';
@import '@/styles/pl-site-plan.scss';
</style>
<style lang="scss" scoped>
:deep(.uni-calendar__backtoday) {
display: none;
}
:deep(.uni-calendar),
:deep(.uni-calendar__content),
:deep(.uni-calendar__box) {
box-shadow: none !important;
border: none !important;
background: transparent !important;
}
/* 保险:覆盖 uni-calendar 默认蓝选中态(组件内已改为 #0a9f6d) */
:deep(.uni-calendar-item--checked),
:deep(.uni-calendar-item--isDay),
:deep(.uni-calendar-item--multiple) {
background-color: #0a9f6d !important;
color: #fff !important;
}
:deep(.uni-calendar-item--isDay-text) {
color: #0a9f6d !important;
}
:deep(.uni-calendar-item--checked.uni-calendar-item--isDay-text),
:deep(.uni-calendar-item--isDay.uni-calendar-item--isDay-text) {
color: #fff !important;
}
</style>