879 lines
20 KiB
Vue

<template>
<view class="receiving-list">
<view class="normar_container">
<page-nav :title="title"></page-nav>
<!-- 搜索和筛选区域 -->
<view class="search-filter">
<!-- 搜索框 -->
<view class="search-box">
<view class="search-box-inner">
<u-search v-model="searchKeyword" placeholder="搜索运单号、货主、商品条码、车牌" bg-color="#f5f5f5" shape="round"
:show-action="false" @search="handleSearch" @clear="handleSearch"></u-search>
<view class="scan-camera-btn" @click="handleManualScan">
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
</view>
</view>
</view>
<!-- 筛选按钮 -->
<view class="filter-actions">
<view class="filter-buttons">
<u-button size="mini" type="primary" plain @click="showFilterPopup">
筛选
</u-button>
<u-button size="mini" type="success" @click="createReceiving">
<u-icon name="plus" size="16"></u-icon>
新建收货
</u-button>
</view>
</view>
<!-- 状态标签 -->
<scroll-view class="status-tags" scroll-x :show-scrollbar="false">
<view class="status-tag" v-for="status in statusList" :key="status.value"
:class="{ active: activeStatus === status.value }" @click="changeStatus(status.value)">
<text class="tag-name">{{ status.label }}</text>
<u-badge :value="status.count" size="mini"></u-badge>
</view>
</scroll-view>
</view>
<!-- 收货列表 -->
<scroll-view class="receiving-list-content" scroll-y>
<!-- 列表为空提示 -->
<view class="empty-state" v-if="!loading && receivingList.length === 0">
<u-icon name="list-dot" size="100" color="#ccc"></u-icon>
<text class="empty-text">暂无收货任务</text>
<text class="empty-hint">点击"新建收货"开始创建收货单</text>
</view>
<!-- 收货单列表 -->
<view class="receiving-items">
<view class="receiving-item" v-for="item in receivingList" :key="item.id"
@click="viewReceivingDetail(item)">
<!-- 单号区域 -->
<view class="item-header">
<text class="order-no">{{ item.receiving_number }}</text>
<u-tag :text="getStatusText(item.status)" :type="getStatusType(item.status)"
size="mini"></u-tag>
</view>
<!-- 基本信息 -->
<view class="item-info">
<view class="info-row">
<u-icon name="home" size="16" color="#999"></u-icon>
<text class="info-label">货主:</text>
<text class="info-value">{{ item['store.store_remask'] || '--' }}</text>
</view>
<view class="info-row">
<u-icon name="car" size="16" color="#999"></u-icon>
<text class="info-label">车牌/运单:</text>
<text class="info-value">{{ item.license_plate || item.tracking_number || '--' }}</text>
</view>
<view class="info-row">
<u-icon name="account" size="16" color="#999"></u-icon>
<text class="info-label">创建人:</text>
<text class="info-value">{{ item['creator.real_name'] || '--' }}</text>
</view>
<view class="info-row" v-if="item.images && item.images.length>0">
<u-icon name="photo" size="16" color="#999"></u-icon>
<text class="info-label">照片:</text>
<span class="info-value" @click.stop="showImgs(item.images)">
<image class="miniImg" v-for="(url, index) in item.images" :key="index" :src="url"></image>
</span>
</view>
</view>
<!-- 操作按钮 -->
<view class="item-actions">
<view class="action-left">
<text class="create-time">创建:{{ formatRelativeTime(item.created_at) }}</text>
</view>
</view>
</view>
</view>
<!-- 底部安全区域 -->
<view class="safe-area-bottom"></view>
</scroll-view>
<pagination :pageNum.sync="currentPage" :pageSize="pageSize" :total="totalItems" :showTotal="true"
:prevText="'上一页'" :nextText="'下一页'" :showFirstLast="true" :firstText="'首页'" :lastText="'末页'"
@change="handlePageChange" />
</view>
<!-- 筛选弹出层 -->
<u-popup :show="filterVisible" mode="bottom" :closeable="true" border-radius="20" @close="filterVisible = false">
<view class="filter-popup">
<view class="popup-header">
<text class="popup-title">筛选条件</text>
</view>
<u--form class="filter-content" labelWidth="auto" labelPosition="left" :model="where" ref="uForm">
<u-form-item label="货主" prop="store" borderBottom @click="handleShowStore">
<view>{{storeName}}</view>
</u-form-item>
<u-form-item label="创建时间" borderBottom>
<view class="date-range" @click="showSelectDate = true">
<text>{{where.startDate}} - {{where.endDate}}</text>
</view>
</u-form-item>
<u-form-item label="" borderBottom>
<view class="quick-date-buttons">
<u-button size="small" :type="dateModel === 'today' ? 'primary' : 'default'" @click="setDateRange('today')">今日</u-button>
<u-button size="small" :type="dateModel === 'week' ? 'primary' : 'default'" @click="setDateRange('week')">本周</u-button>
<u-button size="small" :type="dateModel === 'month' ? 'primary' : 'default'" @click="setDateRange('month')">本月</u-button>
</view>
</u-form-item>
</u--form>
<view class="popup-actions">
<u-button type="default" shape="circle" @click="resetFilter">
重置
</u-button>
<u-button type="primary" shape="circle" @click="applyFilter">
确定
</u-button>
</view>
</view>
</u-popup>
<!-- 货主选择组件 -->
<inputAndSelect title="选择货主" :list="stores" :show="showStore" :value="storeId"
@change="handleStoreChange" @close="showStore=false"></inputAndSelect>
<!-- 时间选择器 -->
<u-calendar :show="showSelectDate" mode="range" @confirm="handleDateConfirm" @close="showSelectDate=false" :minDate="minDate" :maxDate="maxDate"></u-calendar>
<!-- 加载遮罩 -->
<u-loading-page :loading="loading" bg-color="rgba(255,255,255,0.9)"></u-loading-page>
</view>
</template>
<script>
export default {
data() {
return {
title: "收货列表",
// 搜索和筛选
searchKeyword: '',
activeStatus: 'all',
filterVisible: false,
storeName: "全部",
// 日期模式
dateModel: 'today',
minDate:(() => {
const now = new Date();
const sixMonthsAgo = new Date(now);
sixMonthsAgo.setMonth(now.getMonth() - 3);
return this.formatDate(sixMonthsAgo);
})(),
maxDate:this.formatDate(new Date()),
// 筛选条件
showSelectDate: false,
showStore: false,
// 列表数据
receivingList: [],
loading: false,
storeId:null,
refreshing: false,
pageSize: 20,
currentPage: 1,
totalItems: 0,
// 筛选条件
where: {
startDate: this.formatDate(new Date()),
endDate: this.formatDate(new Date()),
},
// 状态列表
statusList: [
{
label: '全部',
value: 'all',
count: 0
},
{
label: '收货中',
value: 'receiving',
count: 0
},
{
label: '已完成',
value: 'completed',
count: 0
},
{
label: '已取消',
value: 'cancelled',
count: 0
}
],
// 货主列表
stores: [],
}
},
onLoad() {
this.$store.dispatch('broadcast/setCallbacks', {
onResult: this.scan
});
this.$store.dispatch('broadcast/start');
},
onShow() {
this.$store.dispatch('broadcast/resume');
this.loadReceivingList();
},
onHide() {
this.$store.dispatch('broadcast/stop');
},
onUnload() {
this.$store.dispatch('broadcast/stop');
},
onPullDownRefresh() {
this.onRefresh();
},
watch: {
currentPage(newval) {
console.log('页码变化:', newval);
this.loadReceivingList();
}
},
methods: {
// 日期格式化函数
formatDate(date) {
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
},
// 获取日期范围
getDateRange(type) {
const now = new Date();
let startDate, endDate;
switch(type) {
case 'today':
startDate = endDate = now;
break;
case 'week':
// 本周一
const monday = new Date(now);
monday.setDate(now.getDate() - now.getDay() + 1);
startDate = monday;
endDate = now;
break;
case 'month':
// 本月第一天
const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
startDate = firstDay;
endDate = now;
break;
default:
startDate = endDate = now;
}
return {
startDate: this.formatDate(startDate),
endDate: this.formatDate(endDate)
};
},
// 设置日期范围
setDateRange(type) {
this.dateModel = type;
const dateRange = this.getDateRange(type);
this.where.startDate = dateRange.startDate;
this.where.endDate = dateRange.endDate;
},
// 时间选择确认
handleDateConfirm(data) {
console.log('选择的时间范围:', data);
this.where.startDate = data[0];
this.where.endDate = data[1];
this.dateModel = 'custom';
this.showSelectDate = false;
},
// 货主选择
handleStoreChange(option) {
if(!option){
this.storeName = "全部";
this.storeId = null;
}else{
this.storeName = option.label;
this.storeId = option.value;
}
this.showStore = false;
},
async scan(data) {
console.log("扫描数据:", data.data);
this.searchKeyword = data.data;
this.handleSearch();
},
normalizeUniScanResult(scanResult) {
if (!scanResult) {
return '';
}
if (typeof scanResult === 'string') {
return scanResult.trim();
}
if (typeof scanResult.result === 'string') {
return scanResult.result.trim();
}
if (Array.isArray(scanResult.result)) {
const firstResult = scanResult.result.find(item => item);
if (typeof firstResult === 'string') {
return firstResult.trim();
}
if (firstResult && typeof firstResult.data === 'string') {
return firstResult.data.trim();
}
}
if (typeof scanResult.data === 'string') {
return scanResult.data.trim();
}
return '';
},
handleManualScan() {
uni.scanCode({
onlyFromCamera: false,
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
success: (res) => {
const rawCode = this.normalizeUniScanResult(res);
if (!rawCode) {
uni.showToast({
title: '未识别到有效内容',
icon: 'none'
});
return;
}
this.scan({
data: rawCode,
source: 'uni.scanCode'
});
},
fail: (error) => {
const errMsg = String(error?.errMsg || '').toLowerCase();
if (errMsg.includes('cancel')) {
return;
}
uni.showToast({
title: '扫码失败,请重试',
icon: 'none'
});
}
});
},
async loadStore() {
try {
const res = await this.$http("common.store", {});
console.log("货主数据:", res);
if (res.stores) {
// 添加全部选项
this.stores = res.stores;
}
} catch (error) {
console.error('加载货主失败:', error);
}
},
// 加载收货列表
async loadReceivingList() {
if (this.loading) return;
this.loading = true;
try {
// 构建查询条件
const queryWhere = {};
this.loadStore();
// 添加基础筛选条件
if (this.storeId) {
queryWhere.store_id = {field:'store_id',operator:'eq',type:'number',value:this.storeId};
}
// 添加日期范围条件
if (this.where.startDate && this.where.endDate) {
queryWhere.created_at = {
field: "created_at",
type: "daterange",
operator: "between",
value: [this.where.startDate, this.where.endDate]
};
}
// 添加状态筛选
if (this.activeStatus !== 'all') {
queryWhere.status = {field:'status',operator:'eq',type:'string',value:this.activeStatus};
}
// 添加搜索条件
if (this.searchKeyword) {
queryWhere.quickWhere = {
value: this.searchKeyword
};
delete queryWhere.created_at;
delete queryWhere.store_id;
}
console.log('查询条件:', queryWhere);
const res = await this.$http("storage.receiving.getReceivingList", {
pagination: {
page: this.currentPage,
pageSize: this.pageSize,
},
where: queryWhere
});
if (res.code == "200") {
const {
list,
pagination,
summary
} = res.data;
const {
total,
page
} = pagination;
this.totalItems = total;
this.currentPage = page;
this.receivingList = list || [];
// 更新状态统计
if (summary) {
this.updateStatusCount(summary);
}
}
} catch (error) {
console.error('加载收货列表失败:', error);
uni.showToast({
title: '加载失败',
icon: 'error'
});
} finally {
this.loading = false;
this.refreshing = false;
uni.stopPullDownRefresh();
}
},
// 更新状态统计
updateStatusCount(summary) {
this.statusList = this.statusList.map(status => {
const count = summary[status.value] || 0;
return { ...status, count };
});
},
// 获取状态文本
getStatusText(status) {
const statusMap = {
'receiving': '收货中',
'completed': '已完成',
'cancelled': '已取消'
};
return statusMap[status] || '未知状态';
},
// 获取状态类型
getStatusType(status) {
const typeMap = {
'cancelled': 'warning',
'receiving': 'primary',
'completed': 'success',
};
return typeMap[status] || 'info';
},
handleShowStore(){
this.showStore = true;
console.log("显示选择货主")
},
// 搜索处理
handleSearch() {
this.currentPage = 1;
this.loadReceivingList();
},
// 状态切换
changeStatus(status) {
this.activeStatus = status;
this.currentPage = 1;
this.loadReceivingList();
},
// 下拉刷新
onRefresh() {
this.refreshing = true;
this.currentPage = 1;
this.loadReceivingList();
},
// 显示筛选弹窗
showFilterPopup() {
this.filterVisible = true;
},
// 重置筛选
resetFilter() {
this.where = {
store: 0,
startDate: this.formatDate(new Date()),
endDate: this.formatDate(new Date()),
};
this.storeName = "全部";
this.dateModel = 'today';
this.activeStatus = 'all';
this.searchKeyword = '';
},
// 应用筛选
applyFilter() {
this.filterVisible = false;
this.currentPage = 1;
this.loadReceivingList();
},
// 新建收货
createReceiving() {
this.$store.dispatch('broadcast/stop');
uni.navigateTo({
url: './receivingCreate',
animationType: 'slide-in-right'
});
},
// 查看收货详情
viewReceivingDetail(item) {
this.$store.dispatch('broadcast/stop');
uni.navigateTo({
url: `./receivingDetail?id=${item.id}`,
animationType: 'slide-in-right'
});
},
// 格式化相对时间
formatRelativeTime(timestamp) {
if (!timestamp) return '--';
const date = new Date(timestamp);
const now = new Date();
const diff = now - date;
if (diff < 60 * 1000) {
return '刚刚';
} else if (diff < 60 * 60 * 1000) {
const minutes = Math.floor(diff / (60 * 1000));
return `${minutes}分钟前`;
} else if (diff < 24 * 60 * 60 * 1000) {
const hours = Math.floor(diff / (60 * 60 * 1000));
return `${hours}小时前`;
} else if (diff < 30 * 24 * 60 * 60 * 1000) {
const days = Math.floor(diff / (24 * 60 * 60 * 1000));
return `${days}天前`;
} else {
return this.formatDate(date);
}
},
// 显示图片预览
showImgs(urls) {
if (!urls || urls.length === 0) return;
uni.previewImage({
urls: urls
});
},
handlePageChange(page) {
this.currentPage = page;
}
}
}
</script>
<style lang="scss" scoped>
.receiving-list {
min-height: 100vh;
background-color: #f8f8f8;
// 搜索和筛选区域
.search-filter {
background: white;
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #f0f0f0;
.search-box {
margin-bottom: 20rpx;
.search-box-inner {
display: flex;
align-items: center;
gap: 16rpx;
::v-deep .u-search {
flex: 1;
}
.scan-camera-btn {
width: 76rpx;
height: 76rpx;
border-radius: 38rpx;
background: #eef4ff;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
&:active {
opacity: 0.85;
}
}
}
}
.filter-actions {
margin-bottom: 20rpx;
.filter-buttons {
display: flex;
gap: 20rpx;
::v-deep .u-btn {
flex: 1;
}
}
}
.status-tags {
white-space: nowrap;
height: 70rpx;
.status-tag {
display: inline-flex;
align-items: center;
padding: 10rpx 30rpx;
margin-right: 20rpx;
background: #f5f5f5;
border-radius: 30rpx;
position: relative;
&.active {
background: #007aff;
.tag-name {
color: white;
}
}
.tag-name {
font-size: 30rpx;
color: #666;
}
}
}
}
// 收货列表内容
.receiving-list-content {
height: 100rpx;
flex: 1;
.empty-state {
padding: 100rpx 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.empty-text {
display: block;
font-size: 40rpx;
color: #999;
margin-top: 30rpx;
margin-bottom: 15rpx;
}
.empty-hint {
display: block;
font-size: 30rpx;
color: #ccc;
}
}
.receiving-items {
padding: 20rpx;
.receiving-item {
background: white;
border-radius: 16rpx;
padding: 30rpx;
margin-bottom: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
.item-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25rpx;
padding-bottom: 15rpx;
border-bottom: 1rpx solid #f0f0f0;
.order-no {
font-size: 42rpx;
font-weight: 600;
color: #333;
}
}
.item-info {
margin-bottom: 25rpx;
.info-row {
display: flex;
align-items: center;
margin-bottom: 15rpx;
&:last-child {
margin-bottom: 0;
}
.info-label {
font-size: 32rpx;
color: #666;
margin-left: 10rpx;
margin-right: 15rpx;
min-width: 180rpx;
}
.info-value {
font-size: 30rpx;
color: #333;
flex: 1;
display: flex;
align-items: center;
flex-wrap: wrap;
.miniImg {
width: 60rpx;
height: 60rpx;
border-radius: 8rpx;
margin-right: 10rpx;
border: 1rpx solid #eee;
}
}
}
}
.item-actions {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 20rpx;
border-top: 1rpx solid #f0f0f0;
.create-time {
font-size: 32rpx;
color: #999;
}
.action-right {
display: flex;
gap: 15rpx;
::v-deep .u-btn {
height: 60rpx;
font-size: 30rpx;
}
}
}
}
}
.safe-area-bottom {
height: env(safe-area-inset-bottom);
}
}
// 筛选弹窗
.filter-popup {
padding-bottom: env(safe-area-inset-bottom);
.popup-header {
padding: 40rpx 30rpx 20rpx;
border-bottom: 1rpx solid #f0f0f0;
.popup-title {
font-size: 36rpx;
font-weight: 600;
color: #333;
}
}
.filter-content {
max-height: 800rpx;
padding: 30rpx;
.date-range {
font-size: 28rpx;
color: #333;
padding: 10rpx 0;
}
.quick-date-buttons {
display: flex;
gap: 20rpx;
::v-deep .u-btn {
flex: 1;
}
}
}
.popup-actions {
padding: 30rpx;
border-top: 1rpx solid #f0f0f0;
display: flex;
gap: 20rpx;
::v-deep .u-btn {
flex: 1;
height: 90rpx;
font-size: 32rpx;
}
}
}
}
.u-form-item__body__left {
width: 30%;
}
</style>