| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import type { wxpay } from '@/api/globals'
- import router from '@/router'
- export function handleCommonPayMent(orderNumber: string): Promise<wxpay> {
- return new Promise((resolve, reject) => {
- if (!orderNumber) {
- useGlobalToast().show({ msg: '订单号为空!请联系管理员' })
- reject(new Error('订单号为空!请联系管理员'))
- return
- }
- uni.showLoading({ mask: true })
- Apis.common.hybridPayment({ data: { orderNumber } }).then((res) => {
- resolve(res.data)
- }).finally(() => uni.hideLoading()).catch(err => reject(err))
- })
- }
- const { selectedAddress, userInfo } = storeToRefs(useUserStore())
- /**
- *
- * @param businessType
- * @param dvyType 配送类型 1:快递 2:自提 3:及时配送
- * @param remarks
- * @param shopId
- * @param orderItemList
- * @returns 下单获取待支付订单号
- */
- export function getOrderPayMent(businessType: string, dvyType: number, shopId: number, orderItemList: {
- prodCount?: number
- skuId?: number
- }[], remarks?: string): Promise<string> {
- uni.showLoading({ mask: true })
- return new Promise((resolve, reject) => {
- if (!selectedAddress.value) {
- reject(new Error('请选择收货地址'))
- return
- }
- Apis.common.addOrder({
- data: {
- channelId: unref(userInfo).channelId,
- businessType,
- addressId: selectedAddress.value.id,
- dvyType,
- freightAmount: Number(userInfo.value.freightFee),
- shopId,
- orderItemList,
- remarks,
- },
- }).then(res => resolve(res.data)).catch(err => reject(err)).finally(() => uni.hideLoading())
- })
- }
- /**
- *
- * @param orderInfo
- * @returns 统一拉起微信支付
- */
- export function getWxCommonPayment(orderPay: wxpay) {
- console.log(orderPay, 'orderInfo')
- uni.showLoading({ mask: true })
- return new Promise((resolve, reject) => {
- const orderInfo = {
- appid: orderPay.appId,
- timeStamp: orderPay.timeStamp,
- nonceStr: orderPay.nonceStr,
- package: orderPay.package,
- signType: orderPay.signType,
- paySign: orderPay.paySign,
- }
- uni.requestPayment({
- provider: 'wxpay',
- orderInfo,
- ...orderInfo,
- success(res) {
- paySuccess()
- resolve(res)
- },
- fail(e) {
- console.log(e, '失败')
- reject(e)
- },
- complete() {
- uni.hideLoading()
- },
- })
- })
- }
- /**
- * 星闪豹
- * 支付成功统一跳转
- */
- export function paySuccess() {
- const { paySuccessPath, payBackIndexPath } = storeToRefs(useSysStore())
- paySuccessPath.value = 'xsb-order'
- payBackIndexPath.value = 'subPack-xsb/commonTab/index'
- router.replace({ name: 'common-paySuccess' })
- }
|