|
|
@@ -5,7 +5,8 @@
|
|
|
<view class="search-container">
|
|
|
<view class="search-box">
|
|
|
<image :src="getFileUrl('img/personal/search.png')" mode="widthFix" class="search-icon"></image>
|
|
|
- <input type="text" placeholder="搜索" class="search-input" v-model="searchKeyword" />
|
|
|
+ <input type="text" placeholder="搜索订单编号或菜品名称" class="search-input" v-model="searchKeyword"
|
|
|
+ maxlength="15" @confirm="doSearch" />
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -20,7 +21,7 @@
|
|
|
</view>
|
|
|
|
|
|
<!-- 订单列表 -->
|
|
|
- <scroll-view class="order-list" scroll-y>
|
|
|
+ <scroll-view class="order-list" scroll-y @scrolltolower="handleScrollToLower">
|
|
|
<view v-for="(order, index) in currentOrderList" :key="order.id || index" class="order-card">
|
|
|
<!-- 订单头部 -->
|
|
|
<view class="order-header">
|
|
|
@@ -75,7 +76,7 @@ import { onLoad } from "@dcloudio/uni-app";
|
|
|
import { ref, computed, watch } from "vue";
|
|
|
import { getFileUrl } from "@/utils/file.js";
|
|
|
import { go } from "@/utils/utils.js";
|
|
|
-import { GetMyOrders } from "@/api/dining.js";
|
|
|
+import { GetOrderPage } from "@/api/dining.js";
|
|
|
|
|
|
const activeTab = ref('current');
|
|
|
const searchKeyword = ref('');
|
|
|
@@ -159,18 +160,13 @@ function getStatusClass(status) {
|
|
|
const currentOrders = ref([]);
|
|
|
const historyOrders = ref([]);
|
|
|
|
|
|
-// 当前显示的订单列表(含搜索过滤)
|
|
|
+// 当前显示的订单列表(由接口返回,搜索由接口 keyword 参数完成)
|
|
|
const currentOrderList = computed(() => {
|
|
|
- const orders = activeTab.value === 'current' ? currentOrders.value : historyOrders.value;
|
|
|
- if (!searchKeyword.value) return orders;
|
|
|
- return orders.filter(order =>
|
|
|
- (order.orderNo && order.orderNo.includes(searchKeyword.value)) ||
|
|
|
- (order.storeName && order.storeName.includes(searchKeyword.value))
|
|
|
- );
|
|
|
+ return activeTab.value === 'current' ? currentOrders.value : historyOrders.value;
|
|
|
});
|
|
|
|
|
|
-// type:0 未支付订单,1 历史订单
|
|
|
-const getOrderTypeByTab = (tab) => (tab === 'current' ? 0 : 1);
|
|
|
+// orderStatus:0=进行中(待支付+已支付),3=已完成
|
|
|
+const getOrderStatusByTab = (tab) => (tab === 'current' ? 0 : 3);
|
|
|
|
|
|
async function loadOrderList(tab, append = false) {
|
|
|
const pageKey = tab === 'current' ? 'current' : 'history';
|
|
|
@@ -185,12 +181,18 @@ async function loadOrderList(tab, append = false) {
|
|
|
|
|
|
loading.value = true;
|
|
|
try {
|
|
|
+ const keyword = (searchKeyword.value || '').trim().slice(0, 15);
|
|
|
const params = {
|
|
|
current: page,
|
|
|
size: pageSize,
|
|
|
- type: getOrderTypeByTab(tab)
|
|
|
+ orderStatus: getOrderStatusByTab(tab)
|
|
|
};
|
|
|
- const res = await GetMyOrders(params);
|
|
|
+ if (keyword) params.keyword = keyword;
|
|
|
+ const sid = storeIdRef.value;
|
|
|
+ if (sid != null && sid !== '') params.storeId = Number(sid);
|
|
|
+ const tid = tableIdRef.value;
|
|
|
+ if (tid != null && tid !== '') params.tableId = Number(tid);
|
|
|
+ const res = await GetOrderPage(params);
|
|
|
// /store/order/my-orders:返回 data,可能为 { records, total } 或 { data: { records, total } }
|
|
|
const raw = res && typeof res === 'object' ? res : {};
|
|
|
const list = Array.isArray(raw.records)
|
|
|
@@ -233,6 +235,16 @@ function doLoad() {
|
|
|
loadOrderList(activeTab.value, false);
|
|
|
}
|
|
|
|
|
|
+// 搜索触发(输入框确认时)
|
|
|
+function doSearch() {
|
|
|
+ doLoad();
|
|
|
+}
|
|
|
+
|
|
|
+// 滚动到底部加载更多
|
|
|
+function handleScrollToLower() {
|
|
|
+ loadOrderList(activeTab.value, true);
|
|
|
+}
|
|
|
+
|
|
|
watch(activeTab, (tab) => {
|
|
|
// 每次切换标签都重新拉取该 tab 的数据,保证来回切换时列表会更新
|
|
|
loadOrderList(tab, false);
|