2 changed files with 225 additions and 203 deletions
@ -1,204 +1,224 @@ |
|||||||
import { cancelOrder, takeOrder, delOrder, payOrder } from "@/api/order"; |
import { |
||||||
|
cancelOrder, |
||||||
|
takeOrder, |
||||||
|
delOrder, |
||||||
|
payOrder |
||||||
|
} from "@/api/order"; |
||||||
import dialog from "@/utils/dialog"; |
import dialog from "@/utils/dialog"; |
||||||
import { weappPay } from "@/libs/wechat"; |
import { |
||||||
|
weappPay |
||||||
|
} from "@/libs/wechat"; |
||||||
|
|
||||||
import { _router } from '@/utils' |
import { |
||||||
|
_router |
||||||
|
} from '@/utils' |
||||||
|
|
||||||
export function cancelOrderHandle(orderId) { |
export function cancelOrderHandle(orderId) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
uni.showModal({ |
uni.showModal({ |
||||||
title: '提示', |
title: '提示', |
||||||
content: '确认取消该订单?', |
content: '确认取消该订单?', |
||||||
success(res) { |
success(res) { |
||||||
if (res.confirm) { |
if (res.confirm) { |
||||||
cancelOrder(orderId) |
cancelOrder(orderId) |
||||||
.then(res => { |
.then(res => { |
||||||
uni.showToast({ |
uni.showToast({ |
||||||
title: '取消成功', icon: 'success', duration: 2000 |
title: '取消成功', |
||||||
}); |
icon: 'success', |
||||||
resolve(res); |
duration: 2000 |
||||||
}) |
}); |
||||||
.catch(err => { |
resolve(res); |
||||||
uni.showToast({ |
}) |
||||||
title: '取消失败', icon: 'none', duration: 2000 |
.catch(err => { |
||||||
}); |
uni.showToast({ |
||||||
reject(err); |
title: '取消失败', |
||||||
}); |
icon: 'none', |
||||||
} else if (res.cancel) { |
duration: 2000 |
||||||
} |
}); |
||||||
} |
reject(err); |
||||||
}) |
}); |
||||||
}); |
} else if (res.cancel) {} |
||||||
|
} |
||||||
|
}) |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
export function takeOrderHandle(orderId) { |
export function takeOrderHandle(orderId) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
takeOrder(orderId) |
takeOrder(orderId) |
||||||
.then(res => { |
.then(res => { |
||||||
uni.showToast({ |
uni.showToast({ |
||||||
title: '收货成功', icon: 'success', duration: 2000 |
title: '收货成功', |
||||||
}); |
icon: 'success', |
||||||
resolve(res); |
duration: 2000 |
||||||
}) |
}); |
||||||
.catch(err => { |
resolve(res); |
||||||
uni.showToast({ |
}) |
||||||
title: '收货失败', icon: 'none', duration: 2000 |
.catch(err => { |
||||||
}); |
uni.showToast({ |
||||||
reject(err); |
title: '收货失败', |
||||||
}); |
icon: 'none', |
||||||
}); |
duration: 2000 |
||||||
|
}); |
||||||
|
reject(err); |
||||||
|
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
export function delOrderHandle(orderId) { |
export function delOrderHandle(orderId) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
dialog.confirm({ |
dialog.confirm({ |
||||||
mes: "确认删除该订单?", |
mes: "确认删除该订单?", |
||||||
opts() { |
opts() { |
||||||
delOrder(orderId) |
delOrder(orderId) |
||||||
.then(res => { |
.then(res => { |
||||||
uni.showToast({ |
uni.showToast({ |
||||||
title: '删除成功', icon: 'success', duration: 2000 |
title: '删除成功', |
||||||
}); |
icon: 'success', |
||||||
resolve(res); |
duration: 2000 |
||||||
}) |
}); |
||||||
.catch(err => { |
resolve(res); |
||||||
uni.showToast({ |
}) |
||||||
title: '删除失败', icon: 'none', duration: 2000 |
.catch(err => { |
||||||
}); |
uni.showToast({ |
||||||
reject(err); |
title: '删除失败', |
||||||
}); |
icon: 'none', |
||||||
} |
duration: 2000 |
||||||
}); |
}); |
||||||
}); |
reject(err); |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
// 使用订单号进行支付
|
// 使用订单号进行支付
|
||||||
export async function payOrderHandle(orderId, type, from) { |
export async function payOrderHandle(orderId, type, from) { |
||||||
return new Promise((resolve, reject) => { |
return new Promise((resolve, reject) => { |
||||||
uni.showLoading({ |
uni.showLoading({ |
||||||
title: "支付中", |
title: "支付中", |
||||||
mask: true |
mask: true |
||||||
}); |
}); |
||||||
payOrder(orderId, type, from) |
payOrder(orderId, type, from) |
||||||
.then(async res => { |
.then(async res => { |
||||||
await handleOrderPayResults(res.data, type) |
console.log(res) |
||||||
resolve() |
await handleOrderPayResults(res.data, type) |
||||||
}) |
resolve() |
||||||
.catch(err => { |
}) |
||||||
reject() |
.catch(err => { |
||||||
uni.hideLoading() |
reject() |
||||||
uni.showToast({ |
uni.hideLoading() |
||||||
title: err.msg || err.response.data.msg || err.response.data.message || '订单支付失败', |
uni.showToast({ |
||||||
icon: "none", |
title: err.msg || err.response.data.msg || err.response.data.message || '订单支付失败', |
||||||
duration: 2000, |
icon: "none", |
||||||
}); |
duration: 2000, |
||||||
}); |
}); |
||||||
}); |
}); |
||||||
|
}); |
||||||
} |
} |
||||||
|
|
||||||
// 处理调用支付接口的逻辑
|
// 处理调用支付接口的逻辑
|
||||||
// @type create(创建订单)||pay(支付订单)
|
// @type create(创建订单)||pay(支付订单)
|
||||||
export function handleOrderPayResults(data, type, payType) { |
export function handleOrderPayResults(data, type, payType) { |
||||||
console.log(data, type, payType) |
return new Promise((resolve, reject) => { |
||||||
|
uni.hideLoading() |
||||||
console.log(data, type) |
switch (data.status) { |
||||||
return new Promise((resolve, reject) => { |
// 订单号已存在
|
||||||
uni.hideLoading() |
case "ORDER_EXIST": |
||||||
switch (data.status) { |
resolve() |
||||||
// 订单号已存在
|
break; |
||||||
case "ORDER_EXIST": |
// 取消支付
|
||||||
resolve() |
case "EXTEND_ORDER": |
||||||
break; |
uni.showToast({ |
||||||
// 取消支付
|
title: data.msg, |
||||||
case "EXTEND_ORDER": |
icon: "none", |
||||||
uni.showToast({ |
duration: 2000, |
||||||
title: data.msg, |
}); |
||||||
icon: "none", |
resolve() |
||||||
duration: 2000, |
goOrderDetails(data.result.orderId, type) |
||||||
}); |
break; |
||||||
resolve() |
case "PAY_DEFICIENCY": |
||||||
goOrderDetails(data.result.orderId, type) |
break; |
||||||
break; |
// 支付出错
|
||||||
case "PAY_DEFICIENCY": |
case "PAY_ERROR": |
||||||
break; |
uni.showToast({ |
||||||
// 支付出错
|
title: data.msg, |
||||||
case "PAY_ERROR": |
icon: "none", |
||||||
uni.showToast({ |
duration: 2000, |
||||||
title: data.msg, |
}); |
||||||
icon: "none", |
reject() |
||||||
duration: 2000, |
goOrderDetails(data.result.orderId, type) |
||||||
}); |
break; |
||||||
reject() |
// 未传递支付环境
|
||||||
goOrderDetails(data.result.orderId, type) |
case "SUCCESS": |
||||||
break; |
uni.showToast({ |
||||||
// 未传递支付环境
|
title: data.msg || data.payMsg, |
||||||
case "SUCCESS": |
icon: "none", |
||||||
uni.showToast({ |
duration: 2000, |
||||||
title: data.msg || data.payMsg, |
}); |
||||||
icon: "none", |
resolve() |
||||||
duration: 2000, |
goOrderDetails(data.result.orderId, type) |
||||||
}); |
break; |
||||||
resolve() |
// H5支付
|
||||||
goOrderDetails(data.result.orderId, type) |
case "WECHAT_H5_PAY": |
||||||
break; |
goOrderDetails(data.result.orderId, type) |
||||||
// H5支付
|
console.log(data) |
||||||
case "WECHAT_H5_PAY": |
setTimeout(() => { |
||||||
goOrderDetails(data.result.orderId, type) |
resolve() |
||||||
console.log(data) |
// #ifdef H5
|
||||||
setTimeout(() => { |
// "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx15171343713577e9f3a418b0865ef90000&package=2547890641"
|
||||||
resolve() |
// location.href = data.result.jsConfig.mweb_url;
|
||||||
// #ifdef H5
|
// #endif
|
||||||
// "https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx15171343713577e9f3a418b0865ef90000&package=2547890641"
|
}, 100); |
||||||
// location.href = data.result.jsConfig.mweb_url;
|
break; |
||||||
// #endif
|
// 小程序支付
|
||||||
}, 100); |
case "WECHAT_PAY": |
||||||
break; |
weappPay(data.result.jsConfig).finally(() => { |
||||||
// 小程序支付
|
resolve() |
||||||
case "WECHAT_PAY": |
goOrderDetails(data.result.orderId, type) |
||||||
weappPay(data.result.jsConfig).finally(() => { |
}).then(res => { |
||||||
resolve() |
// #ifdef MP-WEIXIN
|
||||||
goOrderDetails(data.result.orderId, type) |
subscribeMessage() |
||||||
}).then(res => { |
// #endif
|
||||||
// #ifdef MP-WEIXIN
|
}) |
||||||
subscribeMessage() |
break; |
||||||
// #endif
|
// APP支付
|
||||||
}) |
case "WECHAT_APP_PAY": |
||||||
break; |
weappPay(data.result.jsConfig).finally(() => { |
||||||
// APP支付
|
resolve() |
||||||
case "WECHAT_APP_PAY": |
goOrderDetails(data.result.orderId, type) |
||||||
weappPay(data.result.jsConfig).finally(() => { |
}) |
||||||
resolve() |
break; |
||||||
goOrderDetails(data.result.orderId, type) |
} |
||||||
}) |
}) |
||||||
break; |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
} |
||||||
|
|
||||||
export function subscribeMessage() { |
export function subscribeMessage() { |
||||||
// 调用订阅
|
// 调用订阅
|
||||||
console.log('调用订阅') |
console.log('调用订阅') |
||||||
uni.requestSubscribeMessage({ |
uni.requestSubscribeMessage({ |
||||||
tmplIds: ['W5r2c2kzhbq8uxStkPAVx_sk-5aapMFCqe7b7KU5jXI', '2CB_1UyQrbnlyjJa5syraqJ3cfztPPDOAHe3DEXpMjg', 'vuztugw9VbKbKJDAAVePkjqPpT5mdoREpd4Aq7EGPRU'], |
tmplIds: ['W5r2c2kzhbq8uxStkPAVx_sk-5aapMFCqe7b7KU5jXI', '2CB_1UyQrbnlyjJa5syraqJ3cfztPPDOAHe3DEXpMjg', |
||||||
success(res) {
|
'vuztugw9VbKbKJDAAVePkjqPpT5mdoREpd4Aq7EGPRU' |
||||||
console.log(res) |
], |
||||||
}, |
success(res) { |
||||||
fail(error){ |
console.log(res) |
||||||
console.log(error) |
}, |
||||||
} |
fail(error) { |
||||||
}) |
console.log(error) |
||||||
|
} |
||||||
|
}) |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
export function goOrderDetails(id, type) { |
export function goOrderDetails(id, type) { |
||||||
// 创建订单时跳转到详情
|
// 创建订单时跳转到详情
|
||||||
if (type == 'create') { |
if (type == 'create') { |
||||||
console.log(_router) |
console.log(_router) |
||||||
_router.replace({ |
_router.replace({ |
||||||
path: "/pages/order/OrderDetails/index", |
path: "/pages/order/OrderDetails/index", |
||||||
query: { |
query: { |
||||||
id |
id |
||||||
}, |
}, |
||||||
}); |
}); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue