Skip to content

Commit

Permalink
确认收货
Browse files Browse the repository at this point in the history
  • Loading branch information
keleSalt committed Oct 16, 2023
1 parent fd7ccde commit 53507d9
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
9 changes: 8 additions & 1 deletion App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
console.log('AppOnError:', err);
});
onShow(() => {
onShow((options) => {
// #ifdef APP-PLUS
// 获取urlSchemes参数
const args = plus.runtime.arguments;
Expand All @@ -26,6 +26,13 @@
success: (res) => { },
});
// #endif
// #ifdef MP-WEIXIN
// 确认收货回调结果
console.log(options,'options');
// #endif
});
</script>

Expand Down
74 changes: 68 additions & 6 deletions pages/order/detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,14 @@
import sheep from '@/sheep';
import { onLoad } from '@dcloudio/uni-app';
import { computed, reactive } from 'vue';
import { isEmpty } from 'lodash';

const statusBarHeight = sheep.$platform.device.statusBarHeight * 2;
const headerBg = sheep.$url.css('/static/img/shop/order/order_bg.png');
const state = reactive({
orderInfo: {},
merchantTradeNo: '', // 商户订单号
comeinType: '', // 进入订单详情的来源类型
});

const addressText = computed(() => {
Expand Down Expand Up @@ -390,14 +393,62 @@
});
}

// 确认收货
async function onConfirm(orderId) {
//确认收货
async function onConfirm(orderId, ignore = false) {
// 需开启确认收货组件
// todo:
// 1.怎么检测是否开启了发货组件功能?如果没有开启的话就不能在这里return出去
// 2.如果开启了走mpConfirm方法,需要在App.vue的show方法中拿到确认收货结果
let isOpenBusinessView = true;
if (
sheep.$platform.name === 'WechatMiniProgram' &&
!isEmpty(state.orderInfo.wechat_extra_data) &&
isOpenBusinessView &&
!ignore
) {
mpConfirm(orderId);
return;
}

// 正常的确认收货流程
const { error, data } = await sheep.$api.order.confirm(orderId);
if (error === 0) {
getOrderDetail(data.order_sn);
}
}

// #ifdef MP-WEIXIN
// 小程序确认收货组件
function mpConfirm(orderId) {
if (!wx.openBusinessView) {
sheep.$helper.toast(`请升级微信版本`);
return;
}
wx.openBusinessView({
businessType: 'weappOrderConfirm',
extraData: {
merchant_id: '1481069012',
merchant_trade_no: state.orderInfo.wechat_extra_data.merchant_trade_no,
transaction_id: state.orderInfo.wechat_extra_data.transaction_id,
},
success(response) {
console.log('success:', response);
if (response.errMsg === 'openBusinessView:ok') {
if (response.extraData.status === 'success') {
onConfirm(orderId, true);
}
}
},
fail(error) {
console.log('error:', error);
},
complete(result) {
console.log('result:', result);
},
});
}
// #endif

// 查看发票
function onOrderInvoice(invoiceId) {
sheep.$router.go('/pages/order/invoice', {
Expand All @@ -423,22 +474,33 @@
});
}
async function getOrderDetail(id) {
const { data, error } = await sheep.$api.order.detail(id);
if (error === 0) {
state.orderInfo = data;
let res = {};
if (state.comeinType === 'wechat') {
res = await sheep.$api.order.detail(id, {
merchant_trade_no: state.merchantTradeNo,
});
} else {
res = await sheep.$api.order.detail(id);
}
if (res.error === 0) {
state.orderInfo = res.data;
} else {
sheep.$router.back();
}
}

onLoad(async (options) => {
let id = '';
let id = 0;
if (options.orderSN) {
id = options.orderSN;
}
if (options.id) {
id = options.id;
}
state.comeinType = options.comein_type;
if (state.comeinType === 'wechat') {
state.merchantTradeNo = options.merchant_trade_no;
}
getOrderDetail(id);
});
</script>
Expand Down
3 changes: 2 additions & 1 deletion sheep/api/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import request from '@/sheep/request';

export default {
// 订单详情
detail: (id) =>
detail: (id,params) =>
request({
url: 'order/order/' + id,
method: 'GET',
params,
}),
// 发票详情
invoice: (id) =>
Expand Down

0 comments on commit 53507d9

Please sign in to comment.