Преглед на файлове

✨ 订单列表:接入 95%

YunaiV преди 1 година
родител
ревизия
163996ca90
променени са 6 файла, в които са добавени 82 реда и са изтрити 82 реда
  1. 4 12
      pages/order/detail.vue
  2. 47 54
      pages/order/list.vue
  3. 1 10
      sheep/api/order.js
  4. 23 1
      sheep/api/trade/order.js
  5. 3 2
      sheep/request/index.js
  6. 4 3
      sheep/request2/index.js

+ 4 - 12
pages/order/detail.vue

@@ -200,7 +200,7 @@
           确认收货
         </button>
 				<button class="ss-reset-button cancel-btn" v-if="state.orderInfo.buttons?.includes('comment')"
-                @tap="onComment(state.orderInfo.id,state.orderInfo)">
+                @tap="onComment(state.orderInfo.id, state.orderInfo)">
           评价
         </button>
 			</view>
@@ -304,12 +304,9 @@
 		}
 
 		// 正常的确认收货流程
-		const {
-			error,
-			data
-		} = await sheep.$api.order.confirm(orderId);
-		if (error === 0) {
-			getOrderDetail(data.order_sn);
+		const { code } = await OrderApi.receiveOrder(orderId);
+		if (code === 0) {
+			await getOrderDetail(orderId);
 		}
 	}
 
@@ -354,11 +351,6 @@
 
 	// 评价
 	function onComment(orderSN, orderId) {
-		console.log(orderId);
-		// return;
-		uni.$once('SELECT_INVOICE', (e) => {
-			state.invoiceInfo = e.invoiceInfo;
-		});
 		sheep.$router.go('/pages/goods/comment/add', {
 			orderSN,
 			orderId

+ 47 - 54
pages/order/list.vue

@@ -6,7 +6,7 @@
 		</su-sticky>
 		<s-empty v-if="state.pagination.total === 0" icon="/static/order-empty.png" text="暂无订单" />
 		<view v-if="state.pagination.total > 0">
-			<view class="bg-white order-list-card-box ss-r-10 ss-m-t-14 ss-m-20" v-for="order in state.pagination.data"
+			<view class="bg-white order-list-card-box ss-r-10 ss-m-t-14 ss-m-20" v-for="order in state.pagination.list"
             :key="order.id" @tap="onOrderDetail(order.id)">
 				<view class="order-card-header ss-flex ss-col-center ss-row-between ss-p-x-20">
 					<view class="order-no">订单号:{{ order.no }}</view>
@@ -75,7 +75,7 @@
 		<!-- 加载更多 -->
 		<uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{
         contentdown: '上拉加载更多',
-      }" @tap="loadmore" />
+      }" @tap="loadMore" />
 	</s-layout>
 </template>
 
@@ -100,23 +100,23 @@
 	} from 'lodash';
   import OrderApi from '@/sheep/api/trade/order';
 
-	const pagination = {
-		data: [],
-		current_page: 1,
-		total: 1
+	const paginationNull = {
+		list: [],
+    total: 0,
+		pageNo: 1,
+    pageSize: 5,
 	};
 
 	// 数据
 	const state = reactive({
 		currentTab: 0, // 选中的 tabMaps 下标
 		pagination: {
-			data: [],
-			current_page: 1,
-			total: 1
+      list: [],
+      total: 0,
+      pageNo: 1,
+      pageSize: 5,
 		},
-		loadStatus: '',
-		deleteOrderId: 0,
-		error: 0,
+		loadStatus: ''
 	});
 
 	const tabMaps = [{
@@ -142,11 +142,12 @@
 
 	// 切换选项卡
 	function onTabsChange(e) {
-		if (state.currentTab === e.index) return;
-
-		state.pagination = pagination;
+		if (state.currentTab === e.index) {
+      return;
+    }
+    // 重头加载代码
+		state.pagination = paginationNull;
 		state.currentTab = e.index;
-
 		getOrderList();
 	}
 
@@ -196,11 +197,9 @@
 		}
 
 		// 正常的确认收货流程
-		const {
-			error
-		} = await sheep.$api.order.confirm(order.id);
-		if (error === 0) {
-			state.pagination = pagination;
+		const { code } = await OrderApi.receiveOrder(order.id);
+		if (code === 0) {
+			state.pagination = paginationNull;
 			await getOrderList();
 		}
 	}
@@ -256,8 +255,8 @@
         const { code } = await OrderApi.cancelOrder(orderId);
         if (code === 0) {
           // 修改数据的状态
-          let index = state.pagination.data.findIndex((order) => order.id === orderId);
-          const orderInfo = state.pagination.data[index];
+          let index = state.pagination.list.findIndex((order) => order.id === orderId);
+          const orderInfo = state.pagination.list[index];
           orderInfo.status = 40;
           handleOrderButtons(orderInfo);
         }
@@ -275,39 +274,31 @@
 					const { code } = await OrderApi.deleteOrder(orderId);
 					if (code === 0) {
             // 删除数据
-						let index = state.pagination.data.findIndex((order) => order.id === orderId);
-						state.pagination.data.splice(index, 1);
+						let index = state.pagination.list.findIndex((order) => order.id === orderId);
+						state.pagination.list.splice(index, 1);
 					}
 				}
 			},
 		});
 	}
 
-	// 获取订单列表 TODO 芋艿:待测试
-	async function getOrderList(page = 1, list_rows = 5) {
+	// 获取订单列表
+	async function getOrderList() {
 		state.loadStatus = 'loading';
-		let res = await sheep.$api.order.list({
-			status: tabMaps[state.currentTab].value,
-			pageSize: list_rows,
-			pageNo: page,
-			commentStatus: tabMaps[state.currentTab].value == 30 ? false : null
+		let { code, data } = await OrderApi.getOrderPage({
+      pageNo: state.pagination.pageNo,
+      pageSize: state.pagination.pageSize,
+      status: tabMaps[state.currentTab].value,
+			commentStatus: tabMaps[state.currentTab].value === 30 ? false : null
 		});
-		state.error = res.code;
-		if (res.code === 0) {
-      res.data.list.forEach(order => handleOrderButtons(order));
-			let orderList = _.concat(state.pagination.data, res.data.list);
-			state.pagination = {
-				...res.data,
-				data: orderList,
-			};
-			console.log(state.pagination)
-			if (state.pagination.data.length < state.pagination.total) {
-				state.loadStatus = 'more';
-			} else {
-				state.loadStatus = 'noMore';
-			}
-		}
-	}
+    if (code !== 0) {
+      return;
+    }
+    data.list.forEach(order => handleOrderButtons(order));
+    state.pagination.list = _.concat(state.pagination.list, data.list)
+    state.pagination.total = data.total;
+    state.loadStatus = state.pagination.list.length < state.pagination.total ? 'more' : 'noMore';
+  }
 
 	onLoad(async (options) => {
 		if (options.type) {
@@ -317,20 +308,22 @@
 	});
 
 	// 加载更多
-	function loadmore() {
-		if (state.loadStatus !== 'noMore') {
-			getOrderList(parseInt((state.pagination.data.length / 5) + 1));
+	function loadMore() {
+		if (state.loadStatus === 'noMore') {
+      return
 		}
-	}
+    state.pagination.pageNo++;
+    getOrderList();
+  }
 
 	// 上拉加载更多
 	onReachBottom(() => {
-		loadmore();
+		loadMore();
 	});
 
 	// 下拉刷新
 	onPullDownRefresh(() => {
-		state.pagination = pagination;
+		state.pagination = paginationNull;
 		getOrderList();
 		setTimeout(function() {
 			uni.stopPullDownRefresh();

+ 1 - 10
sheep/api/order.js

@@ -37,16 +37,7 @@ export default {
 				showLoading: false,
 			},
 		}),
-	// 订单列表
-	list: (params) =>
-		request({
-			url: '/app-api/trade/order/page',
-			method: 'GET',
-			params,
-			custom: {
-				showLoading: false,
-			},
-		}),
+
 	// list: (params) =>
 	//   request({
 	//     url: 'order/order',

+ 23 - 1
sheep/api/trade/order.js

@@ -1,4 +1,5 @@
 import request2 from '@/sheep/request2';
+import request from '@/sheep/request';
 
 const OrderApi = {
   // 计算订单信息
@@ -48,6 +49,27 @@ const OrderApi = {
       },
     });
   },
+  // 订单列表
+  getOrderPage: (params) => {
+    return request({
+      url: '/app-api/trade/order/page',
+      method: 'GET',
+      params,
+      custom: {
+        showLoading: false,
+      },
+    });
+  },
+  // 确认收货
+  receiveOrder: (id) => {
+    return request2({
+      url: `/app-api/trade/order/receive`,
+      method: 'PUT',
+      params: {
+        id,
+      },
+    });
+  },
   // 取消订单
   cancelOrder: (id) => {
     return request2({
@@ -67,7 +89,7 @@ const OrderApi = {
         id,
       },
     });
-  }
+  },
 };
 
 export default OrderApi;

+ 3 - 2
sheep/request/index.js

@@ -94,6 +94,7 @@ http.interceptors.request.use(
 		if (config.url.indexOf('/app-api/') !== -1) {
 			config.header['Accept'] = '*/*'
 			config.header['tenant-id'] = '1';
+      config.header['terminal'] = '20';
 			config.header['Authorization'] = 'Bearer test247';
 		}
 		return config;
@@ -212,8 +213,8 @@ const request = (config) => {
 	}
 	// TODO 芋艿:额外拼接
 	if (config.url.indexOf('/app-api/') >= 0) {
-		config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
-		// config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
+		// config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
+		config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
 	}
 	return http.middleware(config);
 };

+ 4 - 3
sheep/request2/index.js

@@ -96,7 +96,8 @@ http.interceptors.request.use(
 		if (config.url.indexOf('/app-api/') !== -1) {
 			config.header['Accept'] = '*/*'
 			config.header['tenant-id'] = '1';
-			config.header['Authorization'] = 'Bearer test247';
+      config.header['terminal'] = '20';
+      config.header['Authorization'] = 'Bearer test247';
 		}
 		// console.log(config, '看参数')
 		return config;
@@ -216,9 +217,9 @@ const request = (config) => {
 	// TODO 芋艿:额外拼接
 	if (config.url.indexOf('/app-api/') >= 0) {
 		// 设置接口地址
-		config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
+		// config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
 		// config.url = 'https://app.test.huizhizao.vip/prod-api' + config.url; // 调用【云端】
-		// config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
+		config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
 	}
 	return http.middleware(config);
 };