|
|
@@ -78,14 +78,14 @@
|
|
|
</el-table>
|
|
|
|
|
|
<!-- 分页 -->
|
|
|
- <el-pagination
|
|
|
- v-model:current-page="queryParams.pageNum"
|
|
|
- v-model:page-size="queryParams.pageSize"
|
|
|
- :page-sizes="[10, 20, 30, 50]"
|
|
|
+ <pagination
|
|
|
+ v-model:page="queryParams.pageNum"
|
|
|
+ v-model:limit="queryParams.pageSize"
|
|
|
+ v-model:way="queryParams.way"
|
|
|
+ :cursor-mode="true"
|
|
|
+ :has-more="hasMore"
|
|
|
:total="total"
|
|
|
- layout="prev, next"
|
|
|
- @current-change="handleCurrentChange"
|
|
|
- class="mt-4"
|
|
|
+ @pagination="getList"
|
|
|
/>
|
|
|
</el-dialog>
|
|
|
</template>
|
|
|
@@ -115,15 +115,34 @@ const brandOptions = ref<BrandVO[]>([]);
|
|
|
const categoryList = ref<categoryTreeVO[]>([]);
|
|
|
const total = ref(0);
|
|
|
|
|
|
-const queryParams = ref<BaseQuery>({
|
|
|
+const queryParams = ref<any>({
|
|
|
pageNum: 1,
|
|
|
pageSize: 10,
|
|
|
productNo: undefined,
|
|
|
itemName: undefined,
|
|
|
+ brandName: undefined,
|
|
|
brandId: undefined,
|
|
|
- topCategoryId: undefined
|
|
|
+ productTag: undefined,
|
|
|
+ purchaseNature: undefined,
|
|
|
+ supplierType: undefined,
|
|
|
+ supplierNature: undefined,
|
|
|
+ projectOrg: undefined,
|
|
|
+ topCategoryId: undefined,
|
|
|
+ mediumCategoryId: undefined,
|
|
|
+ bottomCategoryId: undefined,
|
|
|
+ isSelf: undefined,
|
|
|
+ productReviewStatus: undefined,
|
|
|
+ productStatus: undefined,
|
|
|
+ lastSeenId: undefined,
|
|
|
+ firstSeenId: undefined,
|
|
|
+ way: undefined,
|
|
|
+ params: {}
|
|
|
});
|
|
|
|
|
|
+const hasMore = ref(true); // 是否还有更多数据
|
|
|
+// 页面历史记录,存储每页的第一个id和最后一个id,用于支持双向翻页
|
|
|
+const pageHistory = ref([]);
|
|
|
+
|
|
|
// 对话框状态变化
|
|
|
const handleDialogChange = (val: boolean) => {
|
|
|
emit('update:modelValue', val);
|
|
|
@@ -139,27 +158,99 @@ const formatTaxRate = (taxRate: number | string | undefined): string => {
|
|
|
|
|
|
// 对话框打开时触发
|
|
|
const handleOpen = () => {
|
|
|
+ // 重置查询参数到第一页
|
|
|
+ queryParams.value.pageNum = 1;
|
|
|
+ queryParams.value.lastSeenId = undefined;
|
|
|
+ queryParams.value.firstSeenId = undefined;
|
|
|
+ queryParams.value.way = undefined;
|
|
|
+ pageHistory.value = [];
|
|
|
loadProductList();
|
|
|
};
|
|
|
|
|
|
// 对话框关闭时触发
|
|
|
const handleClose = () => {
|
|
|
- // 可以在这里重置数据
|
|
|
+ // 重置查询参数
|
|
|
+ queryParams.value.pageNum = 1;
|
|
|
+ queryParams.value.productNo = undefined;
|
|
|
+ queryParams.value.itemName = undefined;
|
|
|
+ queryParams.value.brandId = undefined;
|
|
|
+ queryParams.value.bottomCategoryId = undefined;
|
|
|
+ queryParams.value.productStatus = undefined;
|
|
|
+ productList.value = [];
|
|
|
+ pageHistory.value = [];
|
|
|
};
|
|
|
|
|
|
-// 加载商品列表
|
|
|
-const loadProductList = async () => {
|
|
|
- if (loading.value) return;
|
|
|
+// // 加载商品列表
|
|
|
+// const loadProductList = async () => {
|
|
|
+// if (loading.value) return;
|
|
|
|
|
|
+// loading.value = true;
|
|
|
+// try {
|
|
|
+// const res = await listBase(queryParams.value);
|
|
|
+// productList.value = res.rows || [];
|
|
|
+// total.value = res.total || 0;
|
|
|
+// } catch (error) {
|
|
|
+// console.error('加载商品列表失败:', error);
|
|
|
+// productList.value = [];
|
|
|
+// total.value = 0;
|
|
|
+// } finally {
|
|
|
+// loading.value = false;
|
|
|
+// }
|
|
|
+// };
|
|
|
+
|
|
|
+/** 查询产品基础信息列表 */
|
|
|
+const loadProductList = async () => {
|
|
|
loading.value = true;
|
|
|
try {
|
|
|
- const res = await listBase(queryParams.value);
|
|
|
+ const params = { ...queryParams.value };
|
|
|
+ const currentPageNum = queryParams.value.pageNum;
|
|
|
+
|
|
|
+ // 第一页不需要游标参数
|
|
|
+ if (currentPageNum === 1) {
|
|
|
+ delete params.lastSeenId;
|
|
|
+ delete params.way;
|
|
|
+ } else {
|
|
|
+ // way参数:0=上一页,1=下一页
|
|
|
+ if (queryParams.value.way === 0) {
|
|
|
+ // 上一页:使用目标页(即当前显示页)的firstId
|
|
|
+ const nextPageHistory = pageHistory.value[currentPageNum];
|
|
|
+ if (nextPageHistory) {
|
|
|
+ params.firstSeenId = nextPageHistory.firstId;
|
|
|
+ params.way = 0;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 下一页:使用前一页的lastId作为lastSeenId
|
|
|
+ const prevPageHistory = pageHistory.value[currentPageNum - 1];
|
|
|
+ if (prevPageHistory) {
|
|
|
+ params.lastSeenId = prevPageHistory.lastId;
|
|
|
+ params.way = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const res = await listBase(params);
|
|
|
productList.value = res.rows || [];
|
|
|
+
|
|
|
+ // 判断是否还有更多数据
|
|
|
+ hasMore.value = productList.value.length === queryParams.value.pageSize;
|
|
|
+
|
|
|
+ // 记录当前页的第一个id和最后一个id
|
|
|
+ if (productList.value.length > 0) {
|
|
|
+ const firstItem = productList.value[0];
|
|
|
+ const lastItem = productList.value[productList.value.length - 1];
|
|
|
+ //如果长度小于currentPageNum则创建
|
|
|
+
|
|
|
+ if (pageHistory.value.length <= currentPageNum) {
|
|
|
+ pageHistory.value[currentPageNum] = {
|
|
|
+ firstId: firstItem.id,
|
|
|
+ lastId: lastItem.id
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
total.value = res.total || 0;
|
|
|
} catch (error) {
|
|
|
- console.error('加载商品列表失败:', error);
|
|
|
- productList.value = [];
|
|
|
- total.value = 0;
|
|
|
+ console.error('获取列表失败:', error);
|
|
|
} finally {
|
|
|
loading.value = false;
|
|
|
}
|
|
|
@@ -211,9 +302,14 @@ const handleAddProduct = (product: BaseVO) => {
|
|
|
emit('update:modelValue', false);
|
|
|
};
|
|
|
|
|
|
+// 分页查询
|
|
|
+const getList = () => {
|
|
|
+ loadProductList();
|
|
|
+};
|
|
|
+
|
|
|
// 初始化
|
|
|
onMounted(() => {
|
|
|
- // loadBrandList(); // 暂时注释掉
|
|
|
+ // loadBrandList();
|
|
|
loadCategoryTree();
|
|
|
});
|
|
|
</script>
|