OMS_H5/src/views/List/index.vue

311 lines
6.9 KiB
Vue
Raw Normal View History

<template>
<div class="order-list-page">
<!-- 搜索栏 -->
<div class="search-container">
<van-search
v-model="searchKeyword"
placeholder="搜索订单编号、客户名称"
@search="handleSearch"
@clear="handleClear"
class="custom-search"
>
<template #left-icon>
<svg class="search-icon" viewBox="0 0 24 24" fill="none">
<circle cx="11" cy="11" r="8" stroke="currentColor" stroke-width="2"/>
<path d="M21 21L16.65 16.65" stroke="currentColor" stroke-width="2"/>
</svg>
</template>
</van-search>
</div>
<!-- 下拉刷新 -->
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
<!-- 订单列表 -->
<van-list
v-model:loading="loading"
:finished="finished"
finished-text="没有更多了"
@load="onLoad"
>
<div v-for="order in orderList" :key="order.id" class="order-item" @click="goToDetail(order.id)">
<div class="order-header">
<div class="order-code">{{ order.orderCode }}</div>
<div class="status-tag pending">
待审批
</div>
</div>
<div class="order-info">
<div class="info-row">
<span class="label">项目名称</span>
<span class="value">{{ order.projectName }}</span>
</div>
<div class="info-row">
<span class="label">客户名称</span>
<span class="value">{{ order.customerName }}</span>
</div>
<div class="info-row">
<span class="label">订单金额</span>
<span class="value amount">{{ formatAmount(order.shipmentAmount) }}</span>
</div>
<div class="info-row">
<span class="label">创建时间</span>
<span class="value">{{ formatDate(order.createTime, 'YYYY-MM-DD HH:mm') }}</span>
</div>
</div>
</div>
<!-- 空状态 -->
<div v-if="!loading && orderList.length === 0" class="empty-state">
<van-empty description="暂无订单数据" />
</div>
</van-list>
</van-pull-refresh>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { storeToRefs } from 'pinia'
import { useOrderStore } from '@/store/order'
import { formatOrderStatus, formatAmount, formatDate } from '@/utils'
import type { OrderStatus } from '@/types'
const router = useRouter()
const orderStore = useOrderStore()
const { orderList, loading, finished } = storeToRefs(orderStore)
// 搜索相关
const searchKeyword = ref('')
const refreshing = ref(false)
// 获取状态样式类
const getStatusClass = (status: OrderStatus) => {
const classMap = {
'0': 'pending',
'1': 'approved',
'2': 'rejected'
}
return classMap[status] || 'pending'
}
// 加载数据
const onLoad = async () => {
try {
await orderStore.loadOrderList()
} catch (error) {
console.error('加载订单列表失败:', error)
}
}
// 下拉刷新
const onRefresh = async () => {
try {
await orderStore.loadOrderList(true)
refreshing.value = false
} catch (error) {
refreshing.value = false
console.error('刷新失败:', error)
}
}
// 搜索处理
const handleSearch = async () => {
try {
await orderStore.searchOrders(searchKeyword.value.trim())
} catch (error) {
console.error('搜索失败:', error)
}
}
// 清空搜索
const handleClear = async () => {
searchKeyword.value = ''
try {
await orderStore.searchOrders('')
} catch (error) {
console.error('清空搜索失败:', error)
}
}
// 跳转到详情页
const goToDetail = (id: number) => {
router.push(`/detail/${id}`)
}
onMounted(() => {
// 重置状态并加载数据
orderStore.resetListState()
onLoad()
})
</script>
<style lang="scss" scoped>
.order-list-page {
min-height: 100vh;
background: #ffffff;
padding: 16px;
box-sizing: border-box;
position: relative;
}
.order-item {
background: #ffffff;
margin-bottom: 16px;
padding: 16px;
cursor: pointer;
transition: all 0.2s ease;
border-radius: 8px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
border: 1px solid #f0f0f0;
&:active {
transform: translateY(1px);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
}
.order-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
padding-bottom: 12px;
border-bottom: 1px solid #f0f0f0;
}
.order-code {
font-size: 16px;
font-weight: 600;
color: #333333;
}
.status-tag {
font-size: 12px;
padding: 4px 12px;
border-radius: 12px;
font-weight: 500;
&.pending {
background: #FFF3E0;
color: #FF9800;
border: 1px solid #FFE0B2;
}
&.approved {
background: #E8F5E8;
color: #4CAF50;
border: 1px solid #C8E6C9;
}
&.rejected {
background: #FFEBEE;
color: #F44336;
border: 1px solid #FFCDD2;
}
}
.order-info {
.info-row {
display: flex;
margin-bottom: 8px;
align-items: center;
&:last-child {
margin-bottom: 0;
}
.label {
width: 80px;
color: #666666;
font-size: 14px;
font-weight: 400;
flex-shrink: 0;
}
.value {
flex: 1;
color: #333333;
font-size: 14px;
font-weight: 400;
word-break: break-all;
line-height: 1.4;
&.amount {
color: #1976D2;
font-weight: 600;
}
}
}
}
.empty-state {
padding: 80px 20px;
text-align: center;
position: relative;
:deep(.van-empty) {
.van-empty__image {
width: 160px;
height: 160px;
filter: drop-shadow(0 8px 32px rgba(102, 126, 234, 0.2));
animation: float 3s ease-in-out infinite;
}
.van-empty__description {
font-size: 18px;
color: rgba(255, 255, 255, 0.9);
font-weight: 500;
margin-top: 24px;
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
}
}
// 搜索栏容器
.search-container {
position: relative;
z-index: 10;
margin-bottom: 20px;
}
// 搜索栏样式优化
:deep(.custom-search) {
border-radius: 16px;
overflow: hidden;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
backdrop-filter: blur(20px);
background: rgba(255, 255, 255, 0.95);
border: 1px solid rgba(255, 255, 255, 0.2);
transition: all 0.3s ease;
&:focus-within {
transform: translateY(-2px);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
}
.van-search__content {
background: transparent;
padding: 12px 16px;
.van-field__control {
font-size: 15px;
font-weight: 500;
color: #333;
&::placeholder {
color: #999;
font-weight: normal;
}
}
}
}
.search-icon {
width: 20px;
height: 20px;
color: #666;
margin-right: 8px;
}
</style>