From 163996ca9059e8fe82b8c76f820ecab23dd668c7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 13 Dec 2023 20:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E8=AE=A2=E5=8D=95=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=9A=E6=8E=A5=E5=85=A5=2095%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/order/detail.vue | 16 ++----- pages/order/list.vue | 101 ++++++++++++++++++--------------------- sheep/api/order.js | 11 +---- sheep/api/trade/order.js | 24 +++++++++- sheep/request/index.js | 5 +- sheep/request2/index.js | 7 +-- 6 files changed, 82 insertions(+), 82 deletions(-) diff --git a/pages/order/detail.vue b/pages/order/detail.vue index a2123835..ae792a34 100644 --- a/pages/order/detail.vue +++ b/pages/order/detail.vue @@ -200,7 +200,7 @@ 确认收货 @@ -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 diff --git a/pages/order/list.vue b/pages/order/list.vue index 59558805..d1f9bb7c 100644 --- a/pages/order/list.vue +++ b/pages/order/list.vue @@ -6,7 +6,7 @@ - 订单号:{{ order.no }} @@ -75,7 +75,7 @@ + }" @tap="loadMore" /> @@ -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(); diff --git a/sheep/api/order.js b/sheep/api/order.js index 02441b4e..1bcf9817 100644 --- a/sheep/api/order.js +++ b/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', diff --git a/sheep/api/trade/order.js b/sheep/api/trade/order.js index b6b6e749..1211a5c7 100644 --- a/sheep/api/trade/order.js +++ b/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; diff --git a/sheep/request/index.js b/sheep/request/index.js index 94d5bc08..e9b16c09 100644 --- a/sheep/request/index.js +++ b/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); }; diff --git a/sheep/request2/index.js b/sheep/request2/index.js index d7d27b7b..a525e9a9 100644 --- a/sheep/request2/index.js +++ b/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); };