You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.0 KiB

import { cancelOrder, takeOrder, delOrder, payOrder } from "@/api/order";
import dialog from "@/utils/dialog";
import { weappPay } from "@/libs/wechat";
export function cancelOrderHandle(orderId) {
return new Promise((resolve, reject) => {
5 years ago
uni.showModal({
title: '提示',
content: '确认取消该订单?',
success(res) {
if (res.confirm) {
cancelOrder(orderId)
.then(res => {
5 years ago
uni.showToast({
title: '取消成功', icon: 'success', duration: 2000
});
resolve(res);
})
.catch(err => {
5 years ago
uni.showToast({
title: '取消失败', icon: 'none', duration: 2000
});
reject(err);
});
} else if (res.cancel) {
}
}
})
});
}
export function takeOrderHandle(orderId) {
return new Promise((resolve, reject) => {
takeOrder(orderId)
.then(res => {
5 years ago
uni.showToast({
title: '收货成功', icon: 'success', duration: 2000
});
resolve(res);
})
.catch(err => {
5 years ago
uni.showToast({
title: '收货失败', icon: 'none', duration: 2000
});
reject(err);
});
});
}
export function delOrderHandle(orderId) {
return new Promise((resolve, reject) => {
dialog.confirm({
mes: "确认删除该订单?",
opts() {
delOrder(orderId)
.then(res => {
5 years ago
uni.showToast({
title: '删除成功', icon: 'success', duration: 2000
});
resolve(res);
})
.catch(err => {
5 years ago
uni.showToast({
title: '删除失败', icon: 'none', duration: 2000
});
reject(err);
});
}
});
});
}
export function payOrderHandle(orderId, type, from) {
console.log(orderId, type, from, '支付')
return new Promise((resolve, reject) => {
5 years ago
uni.showLoading({ title: '加载中' })
payOrder(orderId, type, from)
.then(res => {
const data = res.data;
5 years ago
uni.hideLoading()
switch (data.status) {
case "WECHAT_H5_PAY":
location.replace(data.result.jsConfig.mweb_url);
reject(data);
break;
case "ORDER_EXIST":
case "EXTEND_ORDER":
case "PAY_ERROR":
case "PAY_DEFICIENCY":
dialog.toast({ mes: res.msg });
reject(data);
break;
case "SUCCESS":
5 years ago
uni.showToast({ title: res.msg, icon: 'none', duration: 2000 });
resolve(data);
break;
case "WECHAT_PAY":
weappPay(data.result.jsConfig).then(res => {
resolve(data);
});
case "WECHAT_APP_PAY":
weappPay(data.result.jsConfig).then(res => {
resolve(data);
});
}
})
.catch(err => {
5 years ago
uni.hideLoading()
dialog.toast({ mes: "订单支付失败" });
});
});
}