This commit is contained in:
wuzilong committed 2026-09-17 09:10:10 +08:00
1 parent a0da6427ef
commit 86694f739f
471 files changed
+62075 -44805

No files matched your search

@@ -0,0 +1,243 @@
<template>
<MpBottomSheet v-model="innerVisible" title="从承运商库选择">
<div class="mp-carrier-lib">
<div class="mp-carrier-lib__search">
<input
v-model="keyword"
class="mp-carrier-lib__search-input"
type="search"
placeholder="搜索承运商名称 / 联系人 / 电话"
autocomplete="off"
@keyup.enter="handleSearch"
/>
</div>
<div v-if="loading && !rows.length" class="mp-carrier-lib__empty">加载中…</div>
<div v-else-if="!rows.length" class="mp-carrier-lib__empty">暂无可用承运商</div>
<button
v-for="row in rows"
:key="row.id"
type="button"
class="mp-carrier-lib__row"
@click="handleConfirm(row)"
>
<div class="mp-carrier-lib__row-main">
<div class="mp-carrier-lib__title">{{ row.carrierName || '—' }}</div>
<div class="mp-carrier-lib__desc">{{ rowDesc(row) }}</div>
</div>
<span class="mp-carrier-lib__pick">选用</span>
</button>
<button
v-if="hasMore"
type="button"
class="mp-carrier-lib__more"
:disabled="loading"
@click="loadMore"
>
{{ loading ? '加载中…' : '加载更多' }}
</button>
</div>
</MpBottomSheet>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import MpBottomSheet from '@/components/mp/MpBottomSheet.vue'
import { carrierApi, type Carrier } from '@/api/pl/index'
import { pickBxPageResult } from '@/utils/http/bx'
import { getPlCarrierStatusLabel } from '@/utils/pl-display'
defineOptions({ name: 'MpCarrierLibrarySelectSheet' })
const props = defineProps<{
modelValue: boolean
}>()
const emit = defineEmits<{
'update:modelValue': [value: boolean]
select: [row: Carrier]
}>()
const innerVisible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const loading = ref(false)
const keyword = ref('')
const rows = ref<Carrier[]>([])
const page = ref(1)
const pageSize = 20
const total = ref(0)
let searchTimer: ReturnType<typeof setTimeout> | null = null
const hasMore = computed(() => rows.value.length < total.value)
function rowDesc(row: Carrier) {
const parts: string[] = []
parts.push(getPlCarrierStatusLabel(row.status) || '—')
const name = (row.contactName || '').trim()
const phone = (row.contactPhone || '').trim()
if (name && phone) parts.push(`${name} · ${phone}`)
else if (name || phone) parts.push(name || phone)
return parts.join(' · ')
}
async function fetchList(reset: boolean) {
loading.value = true
try {
if (reset) {
page.value = 1
rows.value = []
}
const res = await carrierApi.list({
q: keyword.value.trim() || undefined,
page: page.value,
pageSize
})
const { list, total: t } = pickBxPageResult<Carrier>(res)
rows.value = reset ? list : [...rows.value, ...list]
total.value = t
} finally {
loading.value = false
}
}
function handleSearch() {
if (searchTimer) {
clearTimeout(searchTimer)
searchTimer = null
}
void fetchList(true)
}
function loadMore() {
if (loading.value || !hasMore.value) return
page.value += 1
void fetchList(false)
}
function handleConfirm(row: Carrier) {
emit('select', row)
innerVisible.value = false
}
function resetAndLoad() {
keyword.value = ''
page.value = 1
total.value = 0
rows.value = []
void fetchList(true)
}
watch(
() => props.modelValue,
(open) => {
if (open) resetAndLoad()
}
)
watch(keyword, () => {
if (!props.modelValue) return
if (searchTimer) clearTimeout(searchTimer)
searchTimer = setTimeout(() => {
void fetchList(true)
}, 320)
})
</script>
<style scoped lang="scss">
.mp-carrier-lib {
padding: 0 8px 8px;
}
.mp-carrier-lib__search {
margin-bottom: 8px;
}
.mp-carrier-lib__search-input {
box-sizing: border-box;
width: 100%;
height: 36px;
padding: 0 12px;
border: 1px solid #dcebe4;
border-radius: 8px;
font-size: 14px;
color: #1f2a26;
background: #fff;
}
.mp-carrier-lib__empty {
padding: 28px 12px;
text-align: center;
color: #6b7b74;
font-size: 13px;
}
.mp-carrier-lib__row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
width: 100%;
padding: 12px 10px;
border: none;
border-bottom: 1px solid #f0f4f2;
background: #fff;
text-align: left;
cursor: pointer;
}
.mp-carrier-lib__row:active {
background: #e9f9f2;
}
.mp-carrier-lib__row-main {
min-width: 0;
flex: 1;
}
.mp-carrier-lib__title {
font-size: 14px;
font-weight: 600;
color: #1f2a26;
}
.mp-carrier-lib__desc {
margin-top: 2px;
font-size: 12px;
color: #6b7b74;
line-height: 1.4;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.mp-carrier-lib__pick {
flex-shrink: 0;
font-size: 12px;
color: #0a9f6d;
font-weight: 600;
}
.mp-carrier-lib__more {
display: block;
width: 100%;
margin-top: 8px;
padding: 12px;
border: none;
border-radius: 8px;
background: #e9f9f2;
color: #087f57;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.mp-carrier-lib__more:disabled {
opacity: 0.6;
cursor: default;
}
</style>
@@ -0,0 +1,340 @@
<template>
<MpBottomSheet v-model="innerVisible" title="选择合同">
<div class="mp-contract-lib">
<p v-if="hintText" class="mp-contract-lib__hint">{{ hintText }}</p>
<div class="mp-contract-lib__search">
<input
v-model="keyword"
class="mp-contract-lib__search-input"
type="search"
placeholder="合同编号 / 产品名称 / 拼音首字母"
autocomplete="off"
@keyup.enter="handleSearch"
/>
</div>
<div v-if="loading && !rows.length" class="mp-contract-lib__empty">加载中…</div>
<div v-else-if="!rows.length" class="mp-contract-lib__empty">暂无可用合同</div>
<button
v-for="row in rows"
:key="row.id"
type="button"
class="mp-contract-lib__row"
:class="{ 'is-disabled': !isSelectable(row), 'is-busy': confirmingId === String(row.id) }"
:disabled="!!confirmingId || !isSelectable(row)"
@click="handlePick(row)"
>
<div class="mp-contract-lib__row-main">
<div class="mp-contract-lib__title">{{ row.contractNo || row.id || '—' }}</div>
<div class="mp-contract-lib__desc">{{ productSummary(row) }}</div>
<div class="mp-contract-lib__meta">
{{ statusLabel(row) }}
<template v-if="row.customerName"> · {{ row.customerName }}</template>
<template v-if="row.signDate"> · {{ row.signDate }}</template>
</div>
</div>
<span class="mp-contract-lib__pick">
{{ confirmingId === String(row.id) ? '…' : isSelectable(row) ? '选用' : '不可选' }}
</span>
</button>
<button
v-if="hasMore"
type="button"
class="mp-contract-lib__more"
:disabled="loading || !!confirmingId"
@click="loadMore"
>
{{ loading ? '加载中…' : '加载更多' }}
</button>
</div>
</MpBottomSheet>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import MpBottomSheet from '@/components/mp/MpBottomSheet.vue'
import { getContract, listContract } from '@/api/crm/contract'
import type { ContractVO } from '@/api/crm/contract/types'
import { useDictStore } from '@/store/modules/dict'
defineOptions({ name: 'MpContractSelectSheet' })
const props = withDefaults(
defineProps<{
modelValue: boolean
customerId?: string
selectableStatuses?: string[]
}>(),
{
customerId: undefined,
selectableStatuses: () => ['approved', 'executing']
}
)
const emit = defineEmits<{
'update:modelValue': [value: boolean]
confirm: [contract: ContractVO]
}>()
const dictStore = useDictStore()
const innerVisible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const loading = ref(false)
const confirmingId = ref('')
const keyword = ref('')
const rows = ref<ContractVO[]>([])
const pageNum = ref(1)
const pageSize = 20
const total = ref(0)
let searchTimer: ReturnType<typeof setTimeout> | null = null
const hasMore = computed(() => rows.value.length < total.value)
const hintText = computed(() => {
const parts: string[] = []
if (props.customerId) parts.push('仅展示当前客户下的合同')
if (props.selectableStatuses?.length) {
const labels = props.selectableStatuses
.map((s) => dictStore.getLabel('crm_contract_status', s))
.filter(Boolean)
if (labels.length) {
parts.push(`仅「${labels.join('」「')}」状态可选`)
}
}
return parts.join(';')
})
function isSelectable(row: ContractVO) {
if (!props.selectableStatuses?.length) return true
return props.selectableStatuses.includes(row.status)
}
function statusLabel(row: ContractVO) {
return dictStore.getLabel('crm_contract_status', row.status) || row.status || '—'
}
function productSummary(row: ContractVO) {
const products = row.products || []
if (!products.length) return '暂无产品明细'
const names = products
.map((p) => String(p.standardProductName || p.productName || '').trim())
.filter(Boolean)
if (!names.length) return `${products.length} 个产品`
const shown = names.slice(0, 3)
const more = names.length > 3 ? '…' : ''
return `${products.length} 个产品:${shown.join('、')}${more}`
}
async function fetchList(reset: boolean) {
loading.value = true
try {
if (reset) {
pageNum.value = 1
rows.value = []
}
const res = await listContract({
pageNum: pageNum.value,
pageSize,
keyword: keyword.value.trim() || undefined,
customerId: props.customerId || undefined,
excludeStatus: 'invalid',
includeProducts: true
})
const list = res.rows || []
rows.value = reset ? list : [...rows.value, ...list]
total.value = res.total || 0
} finally {
loading.value = false
}
}
function handleSearch() {
if (searchTimer) {
clearTimeout(searchTimer)
searchTimer = null
}
void fetchList(true)
}
function loadMore() {
if (loading.value || !hasMore.value) return
pageNum.value += 1
void fetchList(false)
}
async function handlePick(row: ContractVO) {
if (!row?.id || confirmingId.value) return
if (!isSelectable(row)) {
const status = statusLabel(row)
ElMessage.warning(`该合同状态为「${status}」,不可选择`)
return
}
confirmingId.value = String(row.id)
try {
const res = await getContract(row.id)
const detail = ((res as { data?: ContractVO }).data ?? res) as ContractVO
emit('confirm', detail)
innerVisible.value = false
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '加载合同失败')
} finally {
confirmingId.value = ''
}
}
function resetAndLoad() {
keyword.value = ''
pageNum.value = 1
total.value = 0
rows.value = []
confirmingId.value = ''
void fetchList(true)
}
watch(
() => props.modelValue,
(open) => {
if (open) resetAndLoad()
}
)
watch(keyword, () => {
if (!props.modelValue) return
if (searchTimer) clearTimeout(searchTimer)
searchTimer = setTimeout(() => {
void fetchList(true)
}, 320)
})
</script>
<style scoped lang="scss">
.mp-contract-lib {
padding: 0 8px 8px;
}
.mp-contract-lib__hint {
margin: 0 0 8px;
padding: 8px 10px;
font-size: 12px;
line-height: 1.45;
color: #6b7b74;
background: #f7faf8;
border: 1px solid #dcebe4;
border-radius: 8px;
}
.mp-contract-lib__search {
margin-bottom: 8px;
}
.mp-contract-lib__search-input {
box-sizing: border-box;
width: 100%;
height: 36px;
padding: 0 12px;
border: 1px solid #dcebe4;
border-radius: 8px;
font-size: 14px;
color: #1f2a26;
background: #fff;
}
.mp-contract-lib__empty {
padding: 28px 12px;
text-align: center;
color: #6b7b74;
font-size: 13px;
}
.mp-contract-lib__row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
width: 100%;
padding: 12px 10px;
border: none;
border-bottom: 1px solid #f0f4f2;
background: #fff;
text-align: left;
cursor: pointer;
}
.mp-contract-lib__row:active:not(:disabled) {
background: #e9f9f2;
}
.mp-contract-lib__row.is-disabled {
opacity: 0.55;
cursor: not-allowed;
}
.mp-contract-lib__row.is-busy {
opacity: 0.7;
}
.mp-contract-lib__row-main {
min-width: 0;
flex: 1;
}
.mp-contract-lib__title {
font-size: 14px;
font-weight: 600;
color: #1f2a26;
}
.mp-contract-lib__desc {
margin-top: 2px;
font-size: 12px;
color: #6b7b74;
line-height: 1.4;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.mp-contract-lib__meta {
margin-top: 2px;
font-size: 12px;
color: #94a3b8;
}
.mp-contract-lib__pick {
flex-shrink: 0;
font-size: 12px;
color: #0a9f6d;
font-weight: 600;
}
.mp-contract-lib__row.is-disabled .mp-contract-lib__pick {
color: #94a3b8;
}
.mp-contract-lib__more {
display: block;
width: 100%;
margin-top: 8px;
padding: 12px;
border: none;
border-radius: 8px;
background: #e9f9f2;
color: #087f57;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.mp-contract-lib__more:disabled {
opacity: 0.6;
cursor: default;
}
</style>
@@ -0,0 +1,466 @@
<template>
<MpBottomSheet v-model="innerVisible" title="选择产品">
<div class="mp-prod-lib">
<p v-if="hintText" class="mp-prod-lib__hint">{{ hintText }}</p>
<div class="mp-prod-lib__search">
<input
v-model="keyword"
class="mp-prod-lib__search-input"
type="search"
placeholder="产品名称 / 拼音首字母 / 规格型号"
autocomplete="off"
@keyup.enter="handleSearch"
/>
</div>
<div v-if="selectedProducts.length" class="mp-prod-lib__selected">
<span class="mp-prod-lib__selected-label">已选 {{ selectedProducts.length }}</span>
<button
v-for="item in selectedProducts"
:key="String(item.id)"
type="button"
class="mp-prod-lib__chip"
@click="toggleSelect(item)"
>
{{ item.productName || '—' }} ×
</button>
</div>
<div v-if="loading && !rows.length" class="mp-prod-lib__empty">加载中…</div>
<div v-else-if="!rows.length" class="mp-prod-lib__empty">
{{ isRestrictedMode ? '暂无可用产品' : '暂无产品' }}
</div>
<button
v-for="row in rows"
:key="String(row.id)"
type="button"
class="mp-prod-lib__row"
:class="{ 'is-selected': isSelected(row) }"
@click="toggleSelect(row)"
>
<div class="mp-prod-lib__row-main">
<div class="mp-prod-lib__title">
{{ row.productName || '—' }}
<el-tag v-if="Number(row.isToxic) === 1" type="warning" size="small">毒</el-tag>
<el-tag v-if="Number(row.isExplosive) === 1" type="danger" size="small">爆</el-tag>
</div>
<div class="mp-prod-lib__desc">
{{ row.productNo || '—' }}
<template v-if="row.model"> · {{ row.model }}</template>
<template v-if="unitLabel(row)"> · {{ unitLabel(row) }}</template>
</div>
<div v-if="row.categoryName || brandText(row)" class="mp-prod-lib__meta">
<template v-if="row.categoryName">{{ row.categoryName }}</template>
<template v-if="row.categoryName && brandText(row)"> · </template>
<template v-if="brandText(row)">{{ brandText(row) }}</template>
</div>
</div>
<span class="mp-prod-lib__check" aria-hidden="true">{{ isSelected(row) ? '✓' : '' }}</span>
</button>
<button
v-if="hasMore"
type="button"
class="mp-prod-lib__more"
:disabled="loading"
@click="loadMore"
>
{{ loading ? '加载中…' : '加载更多' }}
</button>
</div>
<template #footer>
<div class="mp-prod-lib__foot">
<button type="button" class="mp-prod-lib__btn" @click="innerVisible = false">取消</button>
<button
type="button"
class="mp-prod-lib__btn mp-prod-lib__btn--primary"
:disabled="!selectedProducts.length"
@click="handleConfirm"
>
确定({{ selectedProducts.length }})
</button>
</div>
</template>
</MpBottomSheet>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import MpBottomSheet from '@/components/mp/MpBottomSheet.vue'
import {
fetchProductDetail,
fetchProductList,
type ProductAliasItem,
type ProductBrandItem
} from '@/api/crm/product'
import { useDictStore } from '@/store/modules/dict'
defineOptions({ name: 'MpProductSelectSheet' })
export type MpProductSelectItem = {
id: string | number
productNo?: string
productName?: string
categoryId?: string | number
categoryName?: string
model?: string
unit?: string
taxRate?: number
status?: string
isToxic?: number
isExplosive?: number
brands?: ProductBrandItem[]
aliases?: ProductAliasItem[]
}
const props = defineProps<{
modelValue: boolean
supplierId?: string | number
/**
* 传入数组(含空数组)→ 受限模式:仅按 id 拉详情
* undefined → 完整 CRM 目录
*/
allowedProductIds?: string[]
}>()
const emit = defineEmits<{
'update:modelValue': [value: boolean]
confirm: [products: MpProductSelectItem[]]
}>()
const dictStore = useDictStore()
const innerVisible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const loading = ref(false)
const keyword = ref('')
const rows = ref<MpProductSelectItem[]>([])
const selectedProducts = ref<MpProductSelectItem[]>([])
const pageNum = ref(1)
const pageSize = 20
const total = ref(0)
let searchTimer: ReturnType<typeof setTimeout> | null = null
let emptyAllowedWarnedOnOpen = false
const isRestrictedMode = computed(() => Array.isArray(props.allowedProductIds))
const normalizedAllowedIds = computed(() =>
(isRestrictedMode.value ? props.allowedProductIds || [] : [])
.map((id) => String(id).trim())
.filter(Boolean)
)
const hasMore = computed(
() => !isRestrictedMode.value && rows.value.length < total.value && rows.value.length > 0
)
const hintText = computed(() => {
if (!isRestrictedMode.value) return ''
if (!normalizedAllowedIds.value.length) return '当前合同暂无产品明细,请先完善合同产品'
return '仅展示当前合同关联产品'
})
function unitLabel(row: MpProductSelectItem) {
const raw = String(row.unit || '').trim()
if (!raw) return ''
return dictStore.getLabel('crm_product_unit', raw) || raw
}
function brandText(row: MpProductSelectItem) {
const names = (row.brands || []).map((b) => b.brandName).filter(Boolean)
return names.length ? names.join('、') : ''
}
function isSelected(row: MpProductSelectItem) {
return selectedProducts.value.some((item) => String(item.id) === String(row.id))
}
function toggleSelect(row: MpProductSelectItem) {
const id = String(row.id)
const idx = selectedProducts.value.findIndex((item) => String(item.id) === id)
if (idx >= 0) {
selectedProducts.value.splice(idx, 1)
return
}
selectedProducts.value.push(row)
}
function matchesQuickKeyword(product: MpProductSelectItem, kwRaw: string) {
const kw = kwRaw.toLowerCase()
const name = String(product.productName || '').toLowerCase()
const model = String(product.model || '').toLowerCase()
return name.includes(kw) || model.includes(kw)
}
async function getRestrictedList() {
const ids = normalizedAllowedIds.value
const results = await Promise.all(
ids.map(async (id) => {
try {
const res: any = await fetchProductDetail({ id })
const data = res?.data ?? res
return data?.id != null ? (data as MpProductSelectItem) : null
} catch {
return null
}
})
)
const fetched = results.filter((p): p is MpProductSelectItem => p != null)
if (!fetched.length && !emptyAllowedWarnedOnOpen) {
emptyAllowedWarnedOnOpen = true
ElMessage.warning('所选合同暂无产品明细')
}
const kw = keyword.value.trim()
const list = kw ? fetched.filter((p) => matchesQuickKeyword(p, kw)) : fetched
rows.value = list
total.value = list.length
}
async function fetchList(reset: boolean) {
if (reset) {
pageNum.value = 1
rows.value = []
total.value = 0
}
loading.value = true
try {
if (isRestrictedMode.value) {
await getRestrictedList()
return
}
const res = await fetchProductList({
page: pageNum.value,
pageSize,
keyword: keyword.value.trim() || undefined,
matchProductNo: false,
matchModel: true,
status: 'on',
supplierId:
props.supplierId != null && props.supplierId !== '' ? String(props.supplierId) : undefined
})
const data = (res as any)?.data || res || {}
const list = (data.list || data.rows || []) as MpProductSelectItem[]
total.value = Number(data.total ?? 0)
rows.value = reset ? list : rows.value.concat(list)
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '加载产品失败')
} finally {
loading.value = false
}
}
function handleSearch() {
void fetchList(true)
}
function loadMore() {
if (loading.value || !hasMore.value) return
pageNum.value += 1
void fetchList(false)
}
function handleConfirm() {
if (!selectedProducts.value.length) {
ElMessage.warning('请选择产品')
return
}
emit('confirm', [...selectedProducts.value])
innerVisible.value = false
}
function resetAndLoad() {
keyword.value = ''
selectedProducts.value = []
emptyAllowedWarnedOnOpen = false
void fetchList(true)
}
watch(
() => props.modelValue,
(open) => {
if (open) resetAndLoad()
}
)
watch(keyword, () => {
if (!props.modelValue) return
if (searchTimer) clearTimeout(searchTimer)
searchTimer = setTimeout(() => {
void fetchList(true)
}, 320)
})
</script>
<style scoped lang="scss">
.mp-prod-lib {
padding: 0 8px 8px;
}
.mp-prod-lib__hint {
margin: 0 0 8px;
padding: 8px 10px;
font-size: 12px;
line-height: 1.45;
color: #6b7b74;
background: #f7faf8;
border: 1px solid #dcebe4;
border-radius: 8px;
}
.mp-prod-lib__search {
margin-bottom: 8px;
}
.mp-prod-lib__search-input {
box-sizing: border-box;
width: 100%;
height: 36px;
padding: 0 12px;
border: 1px solid #dcebe4;
border-radius: 8px;
font-size: 14px;
color: #1f2a26;
background: #fff;
}
.mp-prod-lib__selected {
display: flex;
flex-wrap: wrap;
gap: 6px;
align-items: center;
margin-bottom: 8px;
}
.mp-prod-lib__selected-label {
font-size: 12px;
color: #6b7b74;
}
.mp-prod-lib__chip {
max-width: 100%;
padding: 4px 8px;
overflow: hidden;
font-size: 12px;
color: #087f57;
text-overflow: ellipsis;
white-space: nowrap;
background: #e9f9f2;
border: 1px solid #a7f3d0;
border-radius: 999px;
}
.mp-prod-lib__empty {
padding: 28px 12px;
font-size: 13px;
color: #6b7b74;
text-align: center;
}
.mp-prod-lib__row {
display: flex;
gap: 10px;
align-items: center;
width: 100%;
padding: 12px 10px;
text-align: left;
cursor: pointer;
background: #fff;
border: none;
border-bottom: 1px solid #f0f4f2;
}
.mp-prod-lib__row.is-selected {
background: #f3fbf7;
}
.mp-prod-lib__row:active {
background: #e9f9f2;
}
.mp-prod-lib__row-main {
flex: 1;
min-width: 0;
}
.mp-prod-lib__title {
display: flex;
flex-wrap: wrap;
gap: 4px;
align-items: center;
font-size: 14px;
font-weight: 600;
color: #1f2a26;
}
.mp-prod-lib__desc,
.mp-prod-lib__meta {
margin-top: 2px;
font-size: 12px;
line-height: 1.4;
color: #6b7b74;
}
.mp-prod-lib__meta {
color: #94a3b8;
}
.mp-prod-lib__check {
flex-shrink: 0;
width: 22px;
font-size: 16px;
font-weight: 700;
color: #0a9f6d;
text-align: center;
}
.mp-prod-lib__more {
display: block;
width: 100%;
margin-top: 8px;
padding: 12px;
font-size: 13px;
font-weight: 600;
color: #087f57;
background: #e9f9f2;
border: none;
border-radius: 8px;
}
.mp-prod-lib__foot {
display: flex;
flex: 1;
gap: 8px;
align-self: stretch;
box-sizing: border-box;
width: 100%;
min-width: 0;
}
.mp-prod-lib__btn {
flex: 1 1 50%;
width: 0;
min-width: 0;
height: 40px;
font-size: 14px;
font-weight: 600;
color: #1f2a26;
background: #fff;
border: 1px solid #dcebe4;
border-radius: 10px;
}
.mp-prod-lib__btn--primary {
color: #fff;
background: #0a9f6d;
border-color: #0a9f6d;
}
.mp-prod-lib__btn--primary:disabled {
cursor: not-allowed;
opacity: 0.45;
}
</style>
@@ -0,0 +1,251 @@
<template>
<MpBottomSheet v-model="innerVisible" title="从地址库选择">
<div class="mp-addr-lib">
<div class="mp-addr-lib__search">
<input
v-model="keyword"
class="mp-addr-lib__search-input"
type="search"
placeholder="搜索地址名称 / 详细地址 / 联系人"
autocomplete="off"
@keyup.enter="handleSearch"
/>
</div>
<div v-if="loading && !rows.length" class="mp-addr-lib__empty">加载中…</div>
<div v-else-if="!rows.length" class="mp-addr-lib__empty">暂无可用地址</div>
<button
v-for="row in rows"
:key="row.id"
type="button"
class="mp-addr-lib__row"
@click="handleConfirm(row)"
>
<div class="mp-addr-lib__row-main">
<div class="mp-addr-lib__title">{{ row.addressName || '—' }}</div>
<div class="mp-addr-lib__desc">{{ row.fullAddress || '—' }}</div>
<div v-if="contactLine(row)" class="mp-addr-lib__meta">{{ contactLine(row) }}</div>
<div v-if="(row.notes || '').trim()" class="mp-addr-lib__meta">
注意:{{ row.notes }}
</div>
</div>
<span class="mp-addr-lib__pick">选用</span>
</button>
<button
v-if="hasMore"
type="button"
class="mp-addr-lib__more"
:disabled="loading"
@click="loadMore"
>
{{ loading ? '加载中…' : '加载更多' }}
</button>
</div>
</MpBottomSheet>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import MpBottomSheet from '@/components/mp/MpBottomSheet.vue'
import { transportAddressApi, type TransportAddress } from '@/api/pl/index'
import { pickBxPageResult } from '@/utils/http/bx'
const props = defineProps<{
modelValue: boolean
}>()
const emit = defineEmits<{
'update:modelValue': [value: boolean]
select: [row: TransportAddress]
}>()
const innerVisible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const loading = ref(false)
const keyword = ref('')
const rows = ref<TransportAddress[]>([])
const page = ref(1)
const pageSize = 20
const total = ref(0)
let searchTimer: ReturnType<typeof setTimeout> | null = null
const hasMore = computed(() => rows.value.length < total.value)
function contactLine(row: TransportAddress) {
const name = (row.contactName || '').trim()
const phone = (row.contactPhone || '').trim()
if (name && phone) return `${name} · ${phone}`
return name || phone
}
async function fetchList(reset: boolean) {
loading.value = true
try {
if (reset) {
page.value = 1
rows.value = []
}
const res = await transportAddressApi.list({
q: keyword.value.trim() || undefined,
status: '1',
page: page.value,
pageSize
})
const { list, total: t } = pickBxPageResult<TransportAddress>(res)
rows.value = reset ? list : [...rows.value, ...list]
total.value = t
} finally {
loading.value = false
}
}
function handleSearch() {
if (searchTimer) {
clearTimeout(searchTimer)
searchTimer = null
}
void fetchList(true)
}
function loadMore() {
if (loading.value || !hasMore.value) return
page.value += 1
void fetchList(false)
}
function handleConfirm(row: TransportAddress) {
emit('select', row)
innerVisible.value = false
}
function resetAndLoad() {
keyword.value = ''
page.value = 1
total.value = 0
rows.value = []
void fetchList(true)
}
watch(
() => props.modelValue,
(open) => {
if (open) resetAndLoad()
}
)
watch(keyword, () => {
if (!props.modelValue) return
if (searchTimer) clearTimeout(searchTimer)
searchTimer = setTimeout(() => {
void fetchList(true)
}, 320)
})
</script>
<style scoped lang="scss">
.mp-addr-lib {
padding: 0 8px 8px;
}
.mp-addr-lib__search {
margin-bottom: 8px;
}
.mp-addr-lib__search-input {
box-sizing: border-box;
width: 100%;
height: 36px;
padding: 0 12px;
border: 1px solid #dcebe4;
border-radius: 8px;
font-size: 14px;
color: #1f2a26;
background: #fff;
}
.mp-addr-lib__empty {
padding: 28px 12px;
text-align: center;
color: #6b7b74;
font-size: 13px;
}
.mp-addr-lib__row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
width: 100%;
padding: 12px 10px;
border: none;
border-bottom: 1px solid #f0f4f2;
background: #fff;
text-align: left;
cursor: pointer;
}
.mp-addr-lib__row:active {
background: #e9f9f2;
}
.mp-addr-lib__row-main {
min-width: 0;
flex: 1;
}
.mp-addr-lib__title {
font-size: 14px;
font-weight: 600;
color: #1f2a26;
}
.mp-addr-lib__desc {
margin-top: 2px;
font-size: 12px;
color: #6b7b74;
line-height: 1.4;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.mp-addr-lib__meta {
margin-top: 2px;
font-size: 12px;
color: #94a3b8;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.mp-addr-lib__pick {
flex-shrink: 0;
font-size: 12px;
color: #0a9f6d;
font-weight: 600;
}
.mp-addr-lib__more {
display: block;
width: 100%;
margin-top: 8px;
padding: 12px;
border: none;
border-radius: 8px;
background: #e9f9f2;
color: #087f57;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.mp-addr-lib__more:disabled {
opacity: 0.6;
cursor: default;
}
</style>
@@ -0,0 +1,314 @@
<template>
<MpBottomSheet v-model="innerVisible" title="从车辆库选择">
<div class="mp-veh-lib">
<div class="mp-veh-lib__tabs" role="tablist">
<button
type="button"
class="mp-veh-lib__tab"
:class="{ active: activeTab === 'carrier' }"
role="tab"
:aria-selected="activeTab === 'carrier'"
@click="switchTab('carrier')"
>
三方车辆
</button>
<button
type="button"
class="mp-veh-lib__tab"
:class="{ active: activeTab === 'self' }"
role="tab"
:aria-selected="activeTab === 'self'"
@click="switchTab('self')"
>
山峡车辆
</button>
</div>
<div class="mp-veh-lib__search">
<input
v-model="keyword"
class="mp-veh-lib__search-input"
type="search"
placeholder="搜索车牌号"
autocomplete="off"
@keyup.enter="handleSearch"
/>
</div>
<div v-if="loading && !rows.length" class="mp-veh-lib__empty">加载中…</div>
<div v-else-if="!rows.length" class="mp-veh-lib__empty">暂无可用车辆</div>
<button
v-for="row in rows"
:key="row.id"
type="button"
class="mp-veh-lib__row"
@click="handleConfirm(row)"
>
<div class="mp-veh-lib__row-main">
<div class="mp-veh-lib__title">
{{ formatPlVehiclePlateOptionLabel(row.licensePlate, row.trailerNo) }}
</div>
<div class="mp-veh-lib__desc">{{ rowDesc(row) }}</div>
</div>
<span class="mp-veh-lib__pick">选用</span>
</button>
<button
v-if="hasMore"
type="button"
class="mp-veh-lib__more"
:disabled="loading"
@click="loadMore"
>
{{ loading ? '加载中…' : '加载更多' }}
</button>
</div>
</MpBottomSheet>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import MpBottomSheet from '@/components/mp/MpBottomSheet.vue'
import { vehicleApi, type Vehicle } from '@/api/pl/index'
import { pickBxPageResult } from '@/utils/http/bx'
import {
formatPlVehiclePlateOptionLabel,
getPlVehicleStatusLabel,
normalizePlPersonnelSummaryDisplay
} from '@/utils/pl-display'
type VehicleTab = 'carrier' | 'self'
const props = defineProps<{
modelValue: boolean
}>()
const emit = defineEmits<{
'update:modelValue': [value: boolean]
select: [row: Vehicle]
}>()
const innerVisible = computed({
get: () => props.modelValue,
set: (value: boolean) => emit('update:modelValue', value)
})
const loading = ref(false)
const keyword = ref('')
const activeTab = ref<VehicleTab>('carrier')
const rows = ref<Vehicle[]>([])
const page = ref(1)
const pageSize = 20
const total = ref(0)
let searchTimer: ReturnType<typeof setTimeout> | null = null
const hasMore = computed(() => rows.value.length < total.value)
function rowDesc(row: Vehicle) {
const parts: string[] = []
parts.push(getPlVehicleStatusLabel(row.vehicleStatus) || '—')
if (row.loadCapacity != null && String(row.loadCapacity).trim() !== '') {
parts.push(`${row.loadCapacity} 吨`)
}
if (activeTab.value === 'carrier' && row.carrierName) {
parts.push(row.carrierName)
}
const people = normalizePlPersonnelSummaryDisplay(row.personnelSummary)
if (people?.trim()) parts.push(people.trim())
return parts.join(' · ')
}
async function fetchList(reset: boolean) {
loading.value = true
try {
if (reset) {
page.value = 1
rows.value = []
}
const res = await vehicleApi.list({
vehicleType: activeTab.value,
q: keyword.value.trim() || undefined,
page: page.value,
pageSize
})
const { list, total: t } = pickBxPageResult<Vehicle>(res)
rows.value = reset ? list : [...rows.value, ...list]
total.value = t
} finally {
loading.value = false
}
}
function handleSearch() {
if (searchTimer) {
clearTimeout(searchTimer)
searchTimer = null
}
void fetchList(true)
}
function switchTab(tab: VehicleTab) {
if (activeTab.value === tab) return
activeTab.value = tab
keyword.value = ''
void fetchList(true)
}
function loadMore() {
if (loading.value || !hasMore.value) return
page.value += 1
void fetchList(false)
}
function handleConfirm(row: Vehicle) {
emit('select', row)
innerVisible.value = false
}
function resetAndLoad() {
keyword.value = ''
activeTab.value = 'carrier'
page.value = 1
total.value = 0
rows.value = []
void fetchList(true)
}
watch(
() => props.modelValue,
(open) => {
if (open) resetAndLoad()
}
)
watch(keyword, () => {
if (!props.modelValue) return
if (searchTimer) clearTimeout(searchTimer)
searchTimer = setTimeout(() => {
void fetchList(true)
}, 320)
})
</script>
<style scoped lang="scss">
.mp-veh-lib {
padding: 0 8px 8px;
}
.mp-veh-lib__tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0;
margin: 0 0 10px;
padding: 3px;
background: #eef6f2;
border-radius: 10px;
}
.mp-veh-lib__tab {
height: 34px;
border: none;
border-radius: 8px;
background: transparent;
color: #6b7b74;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.mp-veh-lib__tab.active {
background: #fff;
color: #087f57;
font-weight: 700;
box-shadow: 0 1px 3px rgba(15, 30, 24, 0.08);
}
.mp-veh-lib__search {
margin-bottom: 8px;
}
.mp-veh-lib__search-input {
box-sizing: border-box;
width: 100%;
height: 36px;
padding: 0 12px;
border: 1px solid #dcebe4;
border-radius: 8px;
font-size: 14px;
color: #1f2a26;
background: #fff;
}
.mp-veh-lib__empty {
padding: 28px 12px;
text-align: center;
color: #6b7b74;
font-size: 13px;
}
.mp-veh-lib__row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
width: 100%;
padding: 12px 10px;
border: none;
border-bottom: 1px solid #f0f4f2;
background: #fff;
text-align: left;
cursor: pointer;
}
.mp-veh-lib__row:active {
background: #e9f9f2;
}
.mp-veh-lib__row-main {
min-width: 0;
flex: 1;
}
.mp-veh-lib__title {
font-size: 14px;
font-weight: 600;
color: #1f2a26;
}
.mp-veh-lib__desc {
margin-top: 2px;
font-size: 12px;
color: #6b7b74;
line-height: 1.4;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.mp-veh-lib__pick {
flex-shrink: 0;
font-size: 12px;
color: #0a9f6d;
font-weight: 600;
}
.mp-veh-lib__more {
display: block;
width: 100%;
margin-top: 8px;
padding: 12px;
border: none;
border-radius: 8px;
background: #e9f9f2;
color: #087f57;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.mp-veh-lib__more:disabled {
opacity: 0.6;
cursor: default;
}
</style>