309 行
6.5 KiB
Vue
309 行
6.5 KiB
Vue
<template>
|
||
<view class="drawer-mask" v-if="visible" @tap="close">
|
||
<view class="drawer-sheet" @tap.stop>
|
||
<!-- 顶部橙色导航头(对标图五「选择物流公司」) -->
|
||
<view class="drawer-head">
|
||
<view class="dh-back clickable-hover" @tap="close">
|
||
<image class="dh-back-img" src="/static/icons/back-white.svg" mode="aspectFit" />
|
||
</view>
|
||
<text class="dh-title">选择物流公司</text>
|
||
<view class="dh-right-placeholder"></view>
|
||
</view>
|
||
|
||
<!-- 搜索栏 -->
|
||
<view class="search-wrap">
|
||
<view class="search-box">
|
||
<image class="search-ico" src="/static/icons/search-gray.svg" mode="aspectFit" />
|
||
<input
|
||
class="search-input"
|
||
v-model="keyword"
|
||
placeholder="搜索"
|
||
placeholder-style="color: #999999;"
|
||
/>
|
||
<view class="clear-btn" v-if="keyword" @tap="keyword = ''">
|
||
<image class="clear-ico" src="/static/icons/close.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 按首字母分组列表 -->
|
||
<scroll-view class="drawer-body" scroll-y="true">
|
||
<view class="empty-box" v-if="loading">
|
||
<text class="empty-txt">正在加载物流公司...</text>
|
||
</view>
|
||
<view class="empty-box" v-else-if="loadError">
|
||
<text class="empty-txt">{{ loadError }}</text>
|
||
<view class="retry-btn clickable-hover" @tap="loadCompanies(true)">
|
||
<text class="retry-txt">重新加载</text>
|
||
</view>
|
||
</view>
|
||
<template v-else-if="filteredGroups.length">
|
||
<view class="letter-group" v-for="grp in filteredGroups" :key="grp.letter">
|
||
<view class="letter-bar">
|
||
<text class="letter-txt">{{ grp.letter }}</text>
|
||
</view>
|
||
<view
|
||
class="company-row clickable-hover"
|
||
v-for="name in grp.items"
|
||
:key="name"
|
||
:class="{ active: currentName === name }"
|
||
@tap="selectCompany(name)"
|
||
>
|
||
<text class="cr-name">{{ name }}</text>
|
||
<image v-if="currentName === name" class="cr-check" src="/static/icons/check-orange.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
</template>
|
||
<view class="empty-box" v-else>
|
||
<text class="empty-txt">未找到匹配的物流公司</text>
|
||
</view>
|
||
</scroll-view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, computed, watch } from 'vue';
|
||
import api from '@/utils/api.js';
|
||
|
||
const props = defineProps({
|
||
visible: { type: Boolean, default: false },
|
||
currentName: { type: String, default: '' }
|
||
});
|
||
|
||
const emit = defineEmits(['update:visible', 'select']);
|
||
const keyword = ref('');
|
||
|
||
let cachedGroups = null;
|
||
const rawGroups = ref(cachedGroups ? cachedGroups : []);
|
||
const loading = ref(false);
|
||
const loadError = ref('');
|
||
|
||
async function loadCompanies(force = false) {
|
||
if (!force && cachedGroups && cachedGroups.length > 0) {
|
||
rawGroups.value = cachedGroups;
|
||
loadError.value = '';
|
||
return;
|
||
}
|
||
if (loading.value) return;
|
||
loading.value = true;
|
||
loadError.value = '';
|
||
try {
|
||
const res = await api.expressCompanies();
|
||
const groups = Array.isArray(res && res.groups) ? res.groups : [];
|
||
if (groups.length === 0) {
|
||
rawGroups.value = [];
|
||
loadError.value = '暂无可用物流公司配置,请稍后重试';
|
||
return;
|
||
}
|
||
cachedGroups = groups;
|
||
rawGroups.value = groups;
|
||
} catch (e) {
|
||
rawGroups.value = [];
|
||
loadError.value = (e && (e.message || e.msg)) || '物流公司列表加载失败,请重试';
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
watch(
|
||
() => props.visible,
|
||
(val) => {
|
||
if (val && rawGroups.value.length === 0) {
|
||
loadCompanies(false);
|
||
}
|
||
},
|
||
{ immediate: true }
|
||
);
|
||
|
||
const filteredGroups = computed(() => {
|
||
const kw = keyword.value.trim().toLowerCase();
|
||
if (!kw) return rawGroups.value;
|
||
const res = [];
|
||
for (const g of rawGroups.value) {
|
||
const hits = (g.items || []).filter(name => name.toLowerCase().includes(kw) || String(g.letter || '').toLowerCase() === kw);
|
||
if (hits.length) {
|
||
res.push({ letter: g.letter, items: hits });
|
||
}
|
||
}
|
||
return res;
|
||
});
|
||
|
||
function selectCompany(name) {
|
||
emit('select', name);
|
||
close();
|
||
}
|
||
|
||
function close() {
|
||
emit('update:visible', false);
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.drawer-mask {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.55);
|
||
z-index: 999;
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.drawer-sheet {
|
||
background: #F5F6F8;
|
||
height: 92vh;
|
||
border-top-left-radius: 24rpx;
|
||
border-top-right-radius: 24rpx;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.drawer-head {
|
||
height: 96rpx;
|
||
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 0 24rpx;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.dh-back {
|
||
width: 64rpx;
|
||
height: 64rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.dh-back-img {
|
||
width: 36rpx;
|
||
height: 36rpx;
|
||
}
|
||
|
||
.dh-title {
|
||
font-size: 32rpx;
|
||
font-weight: 600;
|
||
color: #FFFFFF;
|
||
}
|
||
|
||
.dh-right-placeholder {
|
||
width: 64rpx;
|
||
}
|
||
|
||
.search-wrap {
|
||
padding: 18rpx 24rpx;
|
||
background: #F5F6F8;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.search-box {
|
||
height: 72rpx;
|
||
background: #FFFFFF;
|
||
border-radius: 12rpx;
|
||
padding: 0 24rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.search-ico {
|
||
width: 30rpx;
|
||
height: 30rpx;
|
||
margin-right: 14rpx;
|
||
opacity: 0.6;
|
||
}
|
||
|
||
.search-input {
|
||
flex: 1;
|
||
height: 72rpx;
|
||
font-size: 28rpx;
|
||
color: #1F1F1F;
|
||
}
|
||
|
||
.clear-btn {
|
||
padding: 10rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.clear-ico {
|
||
width: 26rpx;
|
||
height: 26rpx;
|
||
opacity: 0.5;
|
||
}
|
||
|
||
.drawer-body {
|
||
flex: 1;
|
||
min-height: 0;
|
||
background: #FFFFFF;
|
||
}
|
||
|
||
.letter-bar {
|
||
height: 56rpx;
|
||
padding: 0 28rpx;
|
||
background: #D9D9D9;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.letter-txt {
|
||
font-size: 28rpx;
|
||
font-weight: 700;
|
||
color: #333333;
|
||
}
|
||
|
||
.company-row {
|
||
min-height: 96rpx;
|
||
padding: 0 28rpx;
|
||
background: #FFFFFF;
|
||
border-bottom: 1rpx solid #F0F0F2;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.cr-name {
|
||
font-size: 28rpx;
|
||
color: #333333;
|
||
}
|
||
|
||
.company-row.active .cr-name {
|
||
color: #F0710D;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.cr-check {
|
||
width: 32rpx;
|
||
height: 32rpx;
|
||
}
|
||
|
||
.empty-box {
|
||
padding: 80rpx 32rpx;
|
||
text-align: center;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 24rpx;
|
||
}
|
||
|
||
.empty-txt {
|
||
font-size: 26rpx;
|
||
color: #888888;
|
||
}
|
||
|
||
.retry-btn {
|
||
padding: 14rpx 36rpx;
|
||
border-radius: 32rpx;
|
||
border: 1rpx solid #F0710D;
|
||
background: #FFF7F0;
|
||
}
|
||
|
||
.retry-txt {
|
||
font-size: 26rpx;
|
||
color: #F0710D;
|
||
font-weight: 500;
|
||
}
|
||
</style>
|