<template>
|
<view class="near-expiry-return-page">
|
<PageHeader title="近效期退货" @back="goBack" />
|
|
<!-- 搜索区域 -->
|
<view class="search-section">
|
<up-search
|
placeholder="产品名称/批次号"
|
v-model="searchForm.keyword"
|
@search="handleQuery"
|
@custom="handleQuery"
|
@clear="handleQuery"
|
:show-action="true"
|
action-text="搜索"
|
:animation="true"
|
></up-search>
|
</view>
|
|
<!-- 列表区域 -->
|
<view class="list-container" v-if="tableData.length > 0">
|
<view v-for="(item, index) in tableData" :key="index" class="list-item">
|
<view class="item-header">
|
<text class="product-name">{{ item.productName }}</text>
|
<up-tag :text="getStatusText(item.status)" :type="getStatusType(item.status)" size="mini"></up-tag>
|
</view>
|
<view class="item-content">
|
<view class="item-row">
|
<text class="item-label">批次号:</text>
|
<text class="item-value">{{ item.batchNumber }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">退回数量:</text>
|
<text class="item-value">{{ item.returnQuantity }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">退回日期:</text>
|
<text class="item-value">{{ item.returnDate }}</text>
|
</view>
|
<view class="item-row">
|
<text class="item-label">到期日期:</text>
|
<text class="item-value">{{ item.expiryDate }}</text>
|
</view>
|
</view>
|
<view class="item-actions">
|
<up-button type="primary" size="mini" @click.stop="openDialog('edit', item)">编辑</up-button>
|
<up-button type="error" size="mini" @click.stop="handleDelete(item)">删除</up-button>
|
</view>
|
</view>
|
<view class="pagination-container">
|
<up-loadmore :status="loadStatus" @loadmore="getList" />
|
</view>
|
</view>
|
|
<view v-else class="no-data">
|
<up-empty mode="data" text="暂无数据"></up-empty>
|
</view>
|
|
<!-- 浮动新增按钮 -->
|
<view class="fab-button" @click="openDialog('add')">
|
<up-icon name="plus" size="24" color="#ffffff"></up-icon>
|
</view>
|
|
<!-- 新增/编辑弹窗 -->
|
<up-popup v-model:show="dialogVisible" mode="center" round closeable @close="closeDialog">
|
<view class="dialog-content">
|
<view class="dialog-header">
|
<text class="dialog-title">{{ operationType === 'add' ? '新增退货台账' : '修改退货台账' }}</text>
|
</view>
|
<up-form :model="form" ref="formRef" label-width="100" label-position="top">
|
<up-form-item label="产品名称" prop="productName" required borderBottom>
|
<up-input v-model="form.productName" placeholder="请输入产品名称" border="surround" />
|
</up-form-item>
|
<up-form-item label="产品规格" prop="productSpec" borderBottom>
|
<up-input v-model="form.productSpec" placeholder="请输入产品规格" border="surround" />
|
</up-form-item>
|
<up-form-item label="批次号" prop="batchNumber" required borderBottom>
|
<up-input v-model="form.batchNumber" placeholder="请输入批次号" border="surround" />
|
</up-form-item>
|
<up-form-item label="退回数量" prop="returnQuantity" required borderBottom>
|
<up-number-box v-model="form.returnQuantity" :min="1" />
|
</up-form-item>
|
<up-form-item label="退回日期" prop="returnDate" required borderBottom>
|
<up-input
|
v-model="form.returnDate"
|
placeholder="请选择退回日期"
|
border="surround"
|
readonly
|
@click="showDatePicker('returnDate')"
|
/>
|
</up-form-item>
|
<up-form-item label="到期日期" prop="expiryDate" borderBottom>
|
<up-input
|
v-model="form.expiryDate"
|
placeholder="请选择到期日期"
|
border="surround"
|
readonly
|
@click="showDatePicker('expiryDate')"
|
/>
|
</up-form-item>
|
<up-form-item label="退回原因" prop="returnReason" borderBottom>
|
<up-textarea v-model="form.returnReason" placeholder="请输入退回原因" count border="surround" />
|
</up-form-item>
|
</up-form>
|
<view class="dialog-footer">
|
<up-button type="primary" text="确认" @click="submitForm" :loading="submitLoading"></up-button>
|
<up-button text="取消" @click="closeDialog" customStyle="margin-top: 20rpx"></up-button>
|
</view>
|
</view>
|
</up-popup>
|
|
<!-- 日期选择器 -->
|
<up-datetime-picker
|
:show="datePickerVisible"
|
v-model="dateValue"
|
mode="date"
|
@confirm="confirmDate"
|
@cancel="datePickerVisible = false"
|
></up-datetime-picker>
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, reactive, onMounted } from 'vue';
|
import {
|
nearExpiryReturnListPage,
|
nearExpiryReturnAdd,
|
nearExpiryReturnUpdate,
|
nearExpiryReturnDel
|
} from '@/api/qualityManagement/nearExpiryReturn.js';
|
import { toast, showConfirm } from '@/utils/common';
|
import dayjs from 'dayjs';
|
|
const searchForm = reactive({
|
keyword: ''
|
});
|
|
const tableData = ref([]);
|
const page = reactive({
|
current: 1,
|
size: 20,
|
total: 0
|
});
|
const loadStatus = ref('loadmore');
|
|
const dialogVisible = ref(false);
|
const operationType = ref('add');
|
const submitLoading = ref(false);
|
const form = reactive({
|
id: null,
|
productName: '',
|
productSpec: '',
|
batchNumber: '',
|
returnQuantity: 1,
|
returnDate: '',
|
expiryDate: '',
|
returnReason: '',
|
status: '0'
|
});
|
|
const datePickerVisible = ref(false);
|
const dateValue = ref(Number(new Date()));
|
const currentDateField = ref('');
|
|
const getStatusText = (status) => {
|
const states = { '0': '待处理', '1': '已处理' };
|
return states[status] || '未知';
|
};
|
|
const getStatusType = (status) => {
|
const types = { '0': 'warning', '1': 'success' };
|
return types[status] || 'info';
|
};
|
|
const getList = () => {
|
if (loadStatus.value === 'loading' || (page.total > 0 && tableData.length >= page.total)) return;
|
|
loadStatus.value = 'loading';
|
const params = {
|
productName: searchForm.keyword || null,
|
current: page.current,
|
size: page.size
|
};
|
|
nearExpiryReturnListPage(params).then(res => {
|
const records = res?.data?.records || [];
|
if (page.current === 1) {
|
tableData.value = records;
|
} else {
|
tableData.value = [...tableData.value, ...records];
|
}
|
page.total = res?.data?.total || 0;
|
|
if (tableData.value.length >= page.total) {
|
loadStatus.value = 'nomore';
|
} else {
|
loadStatus.value = 'loadmore';
|
page.current++;
|
}
|
}).catch(() => {
|
loadStatus.value = 'loadmore';
|
});
|
};
|
|
const handleQuery = () => {
|
page.current = 1;
|
page.total = 0;
|
tableData.value = [];
|
loadStatus.value = 'loadmore';
|
getList();
|
};
|
|
const openDialog = (type, row) => {
|
operationType.value = type;
|
if (type === 'edit' && row) {
|
Object.assign(form, {
|
id: row.id,
|
productName: row.productName,
|
productSpec: row.productSpec,
|
batchNumber: row.batchNumber,
|
returnQuantity: row.returnQuantity,
|
returnDate: row.returnDate,
|
expiryDate: row.expiryDate,
|
returnReason: row.returnReason,
|
status: String(row.status)
|
});
|
} else {
|
Object.assign(form, {
|
id: null,
|
productName: '',
|
productSpec: '',
|
batchNumber: '',
|
returnQuantity: 1,
|
returnDate: dayjs().format('YYYY-MM-DD'),
|
expiryDate: '',
|
returnReason: '',
|
status: '0'
|
});
|
}
|
dialogVisible.value = true;
|
};
|
|
const closeDialog = () => {
|
dialogVisible.value = false;
|
};
|
|
const submitForm = () => {
|
submitLoading.value = true;
|
const api = operationType.value === 'add' ? nearExpiryReturnAdd : nearExpiryReturnUpdate;
|
api(form).then(() => {
|
toast('保存成功');
|
dialogVisible.value = false;
|
handleQuery();
|
}).finally(() => {
|
submitLoading.value = false;
|
});
|
};
|
|
const handleDelete = (row) => {
|
showConfirm('确认删除该退货台账吗?').then(res => {
|
if (res.confirm) {
|
nearExpiryReturnDel([row.id]).then(() => {
|
toast('删除成功');
|
handleQuery();
|
});
|
}
|
});
|
};
|
|
const showDatePicker = (field) => {
|
currentDateField.value = field;
|
dateValue.value = form[field] ? Number(new Date(form[field])) : Number(new Date());
|
datePickerVisible.value = true;
|
};
|
|
const confirmDate = (e) => {
|
form[currentDateField.value] = dayjs(e.value).format('YYYY-MM-DD');
|
datePickerVisible.value = false;
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
onMounted(() => {
|
handleQuery();
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.near-expiry-return-page {
|
padding-bottom: 120rpx;
|
background-color: #f5f7fa;
|
min-height: 100vh;
|
}
|
|
.search-section {
|
padding: 20rpx 30rpx;
|
background-color: #ffffff;
|
position: sticky;
|
top: 0;
|
z-index: 10;
|
}
|
|
.list-container {
|
padding: 20rpx;
|
}
|
|
.list-item {
|
background-color: #ffffff;
|
border-radius: 16rpx;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
|
}
|
|
.item-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 20rpx;
|
}
|
|
.product-name {
|
font-size: 30rpx;
|
font-weight: bold;
|
color: #303133;
|
}
|
|
.item-content {
|
margin-bottom: 20rpx;
|
}
|
|
.item-row {
|
display: flex;
|
margin-bottom: 10rpx;
|
}
|
|
.item-label {
|
color: #909399;
|
width: 160rpx;
|
font-size: 28rpx;
|
}
|
|
.item-value {
|
flex: 1;
|
color: #303133;
|
font-size: 28rpx;
|
}
|
|
.item-actions {
|
display: flex;
|
justify-content: flex-end;
|
gap: 20rpx;
|
border-top: 1rpx solid #ebeef5;
|
padding-top: 20rpx;
|
}
|
|
.pagination-container {
|
padding: 20rpx 0;
|
}
|
|
.no-data {
|
padding-top: 200rpx;
|
}
|
|
.fab-button {
|
position: fixed;
|
right: 40rpx;
|
bottom: 60rpx;
|
width: 100rpx;
|
height: 100rpx;
|
background-color: #3c9cff;
|
border-radius: 50%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
box-shadow: 0 4rpx 16rpx rgba(60, 156, 255, 0.4);
|
z-index: 99;
|
}
|
|
.dialog-content {
|
width: 650rpx;
|
padding: 40rpx;
|
background-color: #ffffff;
|
border-radius: 24rpx;
|
overflow: hidden;
|
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
|
}
|
|
.dialog-header {
|
margin-bottom: 30rpx;
|
text-align: center;
|
}
|
|
.dialog-title {
|
font-size: 32rpx;
|
font-weight: bold;
|
color: #303133;
|
}
|
|
.dialog-footer {
|
margin-top: 40rpx;
|
}
|
</style>
|