Files

290 lines
7.1 KiB
Vue
Raw Permalink Normal View History

2023-10-11 11:27:47 +08:00
<template>
<view class="order-info-container">
<Header
system-bar-area-bg="#fff"
header-area-bg="#fff"
:scroll-top="scrollTop">
订单详情
</Header>
<image
:src="orderDetailsBg"
class="bg-image"
mode="widthFix"
2023-10-11 11:27:47 +08:00
/>
<view
class="main-inner"
v-if="orderInfoData">
<!-- 订单状态信息 -->
<OrderState
:order-info-data="orderInfoData"
:remain-time-str="remainTimeStr" />
<!-- 地址 -->
<OrderAddress :order-info-data="orderInfoData" />
<!-- group info 是拼团且已支付 -->
<OrderGroupInfo
v-if="orderInfoData.campaignType && orderInfoData.campaignType===1 && orderInfoData._status._type!=='0' && orderInfoData.teamworkId"
:order-info-data="orderInfoData" />
<!-- goods list -->
<OrderGoodsInfo :order-info-data="orderInfoData" />
<!-- order info -->
<OrderOrderInfo :order-info-data="orderInfoData" />
<!-- logistics info -->
<OrderLogisticsInfo
v-if="expressData"
:order-info-data="orderInfoData"
:express-data="expressData" />
2023-10-11 11:27:47 +08:00
<view class="bottom-bar-bg"></view>
<!-- options -->
<view class="order-actions bottom-bar">
<OrderOptions
style="width: 100%"
:status="orderInfoData._status._type"
:shop-type="orderInfoData.shippingType"
@cancel="showModal(MODAL_TYPE.CANCEL)"
@confirm="showModal(MODAL_TYPE.CONFIRM)"
@delete="showModal(MODAL_TYPE.DELETE)"
@pay="handlePay"
@refund="toSelectRefundGood(orderInfoData.id)"
@check-off-code="checkOffCode(orderInfoData.writeOffCode)"
@invite="goGroupByDetail({teamworkId:orderInfoData.teamworkId})"
@cancel-refund="showModal(MODAL_TYPE.CANCEL_CHECK)"
/>
2023-10-11 11:27:47 +08:00
</view>
</view>
</view>
2023-11-14 17:21:03 +08:00
<!-- 支付弹窗 -->
<PayPopup
ref="payPopupRef"
2023-11-17 20:55:32 +08:00
@confrim="paySuccess"
2023-11-14 17:21:03 +08:00
/>
2023-11-17 20:55:32 +08:00
<Modal
ref="modalRef"
:content="modalTitle"
@confirm="confirmModal" />
2023-11-17 20:55:32 +08:00
<!-- 核销 -->
<CheckOffCode ref="checkOffCodeRef" />
2023-11-17 20:55:32 +08:00
2023-10-11 11:27:47 +08:00
</template>
<script setup>
import Header from "@/components/Header/index.vue"
import { orderDetailsBg } from "@/utils/images";
import { ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { cancelAfterVerification, orderExpress, orderInfo, orderTake } from '@/api/order'
2023-10-11 11:27:47 +08:00
import { orderReStatus } from '@/config'
2023-11-14 17:21:03 +08:00
import { useRouter } from "@/hooks/useRouter";
import PayPopup from "@/components/PayPopup/index.vue";
2023-11-17 20:55:32 +08:00
import Modal from "@/components/Modal/index.vue";
import { useInterface } from "@/hooks/useInterface";
import { formatRemainTime } from "@/utils/utils";
import { useOrder } from "@/hooks/useOrder";
import { usePay } from "@/hooks/usePay";
import OrderOptions from "@/pages/orderInfo/component/OrderOptions.vue";
import CheckOffCode from "@/components/order/CheckOffCode.vue";
import OrderState from "@/pages/orderInfo/component/OrderState.vue";
import OrderAddress from "@/pages/orderInfo/component/OrderAddress.vue";
import { useScroll } from "@/hooks/useScroll";
import OrderGroupInfo from "@/pages/orderInfo/component/OrderGroupInfo.vue";
import OrderGoodsInfo from "@/pages/orderInfo/component/OrderGoodsInfo.vue";
import OrderOrderInfo from "@/pages/orderInfo/component/OrderOrderInfo.vue";
import OrderLogisticsInfo from "@/pages/orderInfo/component/OrderLogisticsInfo.vue";
import { useJump } from "@/hooks/useJump";
const {goGroupByDetail} = useJump()
2023-11-17 20:55:32 +08:00
2023-10-11 11:27:47 +08:00
const {scrollTop} = useScroll();
2023-10-11 11:27:47 +08:00
const {payPopupRef, openPay, paySuccess} = usePay()
const {getParams, getUrlParams, push, goBack} = useRouter()
2023-11-17 20:55:32 +08:00
const {toast} = useInterface();
2023-10-11 11:27:47 +08:00
const orderInfoData = ref(null)
const orderInfoStatusMsg = ref('')
const expressData = ref(null)
2023-11-17 20:55:32 +08:00
const remainTimeStr = ref('')
2023-10-11 11:27:47 +08:00
const handleOrderInfo = async (option) => {
const res = await orderInfo(option)
orderInfoData.value = res
2023-11-14 17:21:03 +08:00
res.status = res.paid === 1 && res.status === 0 ? 99 : res.status
2023-10-11 11:27:47 +08:00
handleMsg(res.status)
2023-11-17 20:55:32 +08:00
if (parseInt(res._status._type) > 1) {
if (parseInt(res._status._type) === 2) {
2023-11-17 20:55:32 +08:00
remainTimeStr.value = formatRemainTime(res._status._payRemainTime)
}
// _type: 2待收货 3已收货 4已完成 8代发货 6待成团 7已成团
if ([2, 3, 4].includes(parseInt(res._status._type))) {
if (res.shippingType === 2) return // 核销订单不需要物流
await orderExpress({
orderCode: orderInfoData.value.orderId,
shipperCode: orderInfoData.value.deliverySn,
logisticCode: orderInfoData.value.deliveryId,
}).then(res => {
expressData.value = res.traces.reverse()
}).catch(err => {
console.log(err, 'err')
})
}
2023-10-11 11:27:47 +08:00
}
}
const {
MODAL_TYPE,
modalRef,
checkOffCodeRef,
modalType,
modalTitle,
showModal,
cancelOrder,
deleteOrder,
toEvaluate,
toSelectRefundGood,
showWsReceipt,
checkOffCode,
} = useOrder(handleOrderInfo)
2023-10-11 11:27:47 +08:00
const handlePay = () => {
2023-11-14 17:21:03 +08:00
openPay(orderInfoData.value.orderId)
}
2023-10-11 11:27:47 +08:00
2023-11-14 17:21:03 +08:00
// 返回列表
const goList = () => {
2023-11-15 19:59:37 +08:00
let status = 0
switch (orderInfoData.value.status) {
2023-11-15 19:59:37 +08:00
case -1:
status = -1
break
case 0:
status = 0
break
2023-11-22 18:55:55 +08:00
case 4:
status = -1
break
2023-11-15 19:59:37 +08:00
case 99:
status = 1
break
default:
status = orderInfoData.value.status + 1
2023-11-15 19:59:37 +08:00
}
2023-11-14 17:21:03 +08:00
push({url: '/pages/orderList/orderList'}, {
data: {
2023-11-15 19:59:37 +08:00
type: status
2023-11-22 18:55:55 +08:00
}
2023-10-11 11:27:47 +08:00
})
}
2023-11-17 20:55:32 +08:00
/**
* 确认弹窗
*/
function confirmModal() {
const funcArr = [doDeleteOrder, doCancelOrder, doTakeGoods, doCancelAnOrder]
2023-11-17 20:55:32 +08:00
funcArr[modalType.value]()
}
const handleMsg = (status) => {
orderInfoStatusMsg.value = orderReStatus[status]
}
async function doDeleteOrder() {
deleteOrder(orderInfoData.value).then(() => {
setTimeout(() => {
goList()
}, 2000)
2023-11-17 20:55:32 +08:00
})
}
async function doCancelOrder() {
cancelOrder(orderInfoData.value).then(() => {
setTimeout(() => {
goList()
}, 2000)
2023-11-17 20:55:32 +08:00
})
2023-10-11 11:27:47 +08:00
}
async function doTakeGoods() {
2023-11-17 20:55:32 +08:00
let option = {
uni: orderInfoData.value.orderId,
}
let payInfo = JSON.parse(orderInfoData.value.payInfo)
showWsReceipt(payInfo.transaction_id).then(async (res) => {
if (res === 'success') {
await orderTake(option)
toast({title: '收货成功'});
await handleOrderInfo({
key: option.uni
})
}
2023-11-17 20:55:32 +08:00
})
}
const doCancelAnOrder = async () => {
await cancelAfterVerification({id: orderInfoData.value.orderId})
toast({title: '取消成功'})
goBack()
2023-11-14 17:21:03 +08:00
}
onShow(() => {
const params = getUrlParams()
2023-10-11 11:27:47 +08:00
handleOrderInfo({
2023-11-14 17:21:03 +08:00
key: params.orderId
2023-10-11 11:27:47 +08:00
})
})
</script>
2023-11-14 17:21:03 +08:00
<style lang="scss">
2023-11-22 18:55:55 +08:00
@import "../../style/images";
2023-11-14 17:21:03 +08:00
.order-info-container {
width: 100%;
position: relative;
2023-11-14 17:21:03 +08:00
.bg-image {
position: absolute;
left: 0;
width: 100%;
height: 300rpx;
z-index: 0;
2023-10-11 11:27:47 +08:00
}
.main-inner {
position: relative;
z-index: 1;
@include usePadding(30, 30);
2023-10-11 11:27:47 +08:00
}
}
2023-10-11 11:27:47 +08:00
.orderList {
padding: 20rpx 0;
2023-10-11 11:27:47 +08:00
}
2023-10-11 11:27:47 +08:00
.order-infos {
margin: 0 40rpx;
padding: 40rpx 0 20rpx;
&:after {
content: '';
}
}
2023-11-14 17:21:03 +08:00
.no-express {
2023-11-14 17:21:03 +08:00
font-size: 26rpx;
padding: 20rpx 14rpx 30rpx;
}
.order-actions{
bottom: env(safe-area-inset-bottom);
}
2023-10-11 11:27:47 +08:00
</style>