xc-app/pages/mine/orderStatusDetail.vue

895 lines
23 KiB
Vue

<!-- 订单状态详情 -->
<template>
<view class="order-detail-page">
<!-- @click="goBack" type="click" -->
<HeaderCom></HeaderCom>
<scroll-view scroll-y="true" class="scroll-view">
<view class="main">
<view class="shop">
<view class="contain">
<image v-if="detailData.productCoverResource" :src="detailData.productCoverResource.url" mode="aspectFit" class="shop-icon"></image>
</view>
<view class="detail">
<view class="name">{{detailData.productName}}</view>
<!-- <view class="remark"></view> -->
<view class="price">
<!-- <view class="value">¥{{detailData.amount}}</view> -->
<view class="value">
<template v-if="detailData.type === 'MALL'">
{{detailData.points}}积分
</template>
</view>
<view class="num">x{{detailData.quantity}}</view>
</view>
</view>
</view>
<view class="item">
<view class="label">运费</view>
<view class="value">¥ {{detailData.deliveryFee || 0}}</view>
</view>
<view class="item">
<view class="label">实付积分</view>
<view class="value" v-if="detailData.type === 'BOX_DELIVERY'">0</view>
<view class="value" v-else>{{detailData.points}}积分</view>
</view>
<view class="item-big">
<view class="label">实际支付</view>
<view class="value" v-if="detailData.type === 'BOX_DELIVERY'">¥ {{detailData.deliveryFee || 0}}</view>
<view class="value" v-else-if="detailData.type === 'MALL'">
<text>{{detailData.totalPoints}}积分</text>
<text style="margin-left: 10px;">¥ {{detailData.deliveryFee}}</text>
</view>
<view class="value" v-else>¥ {{detailData.points}}</view>
<!-- <view class="value">{{detailData.points}}积分</view> -->
</view>
</view>
<view class="main">
<view class="item">
<view class="label">订单编号</view>
<view class="value" @click="copy(detailData.no)">{{detailData.no}}</view>
</view>
<view class="item">
<view class="label">下单时间</view>
<view class="value">{{detailData.paidAt ? formatDateTime(detailData.paidAt) : '-'}}</view>
</view>
<view class="item">
<view class="label">订单状态</view>
<view class="value">{{statusObj[detailData.status]}}</view>
</view>
<view class="item">
<view class="label">支付方式</view>
<view class="value">{{detailData.method ? paidWith[detailData.method] : '-'}}</view>
</view>
<!-- <view class="item">
<view class="label">配送服务</view>
<view class="value">¥ {{detailData.deliveryFee || 0}}</view>
</view> -->
</view>
</scroll-view>
<view class="footer" v-if="detailData.status === 'WAITING_FOR_RECEIPT' || detailData.status === 'SHIPPED' || detailData.status === 'RECEIVED' || detailData.status === 'COMPLETED' || detailData.status === 'WAITING_FOR_SHIPMENT'">
<view class="btn" @click="handleCustomer">联系客服</view>
<view class="btn" @click="logistics"
v-if="detailData.status === 'WAITING_FOR_RECEIPT' || detailData.status === 'SHIPPED' || detailData.status === 'RECEIVED'">
物流信息</view>
<view class="btn " v-if="detailData.status === 'WAITING_FOR_SHIPMENT' && expireTime > new Date().getTime()"
@click.stop="orderRefund">取消订单</view>
<view class="btn " v-if="detailData.status === 'COMPLETED'" @click.stop="againProduct">再次购买</view>
<view class="btn btn-active" @click="orderReceipt"
v-if="detailData.status === 'WAITING_FOR_RECEIPT' || detailData.status === 'RECEIVED'">
确认收货</view>
</view>
<popup-view v-model="openShow" mode="bottom" border-radius="15" zIndex="1">
<view class="dlg-main" @click.stop="">
<view class="header">
<view class="title">物流明细</view>
<image src="" mode="" class="close" @click="openShow = false"></image>
</view>
<view class="popup-scroll">
<logistics :wlInfo="detailData.logistics" :img="detailData.productCoverResource.url"
:name="detailData.productName" :address="address" :logisticsStatus="detailData.logisticsStatus">
</logistics>
</view>
<!-- <image src="@/static/order/close.png" mode="" class="popup-close" @click.stop="close"></image> -->
</view>
</popup-view>
<popup-view v-model="logOutvisible" mode="center" border-radius="15" zIndex="1">
<view class="log-out">
<view class="log-title">温馨提示</view>
<view class="log-sub">以下物品已超过发货时间,取消后将自动兑换为积分</view>
<scroll-view scroll-y="true" class="log-out-tip">
<!-- 该物品已超过发货时间,取消后将自动兑换为{{recoveryPoint}}分 -->
<view class="re-list" v-for="(item,index) in reList" :key="index">
<image v-if="item.productCoverResource" :src="item.productCoverResource.url" mode="" class="re-img"></image>
<view class="re-info">
<view class="re-name">{{item.productAbbreviation}}</view>
<view class="re-point">回收积分:{{item.recoveryPoint}}</view>
</view>
</view>
</scroll-view>
<view class="log-out-footer">
<view class="cancel" @click="closeBoxRefund">取消</view>
<view class="shu"></view>
<view class="log-out-submit" @click="submitBoxRefund">确定</view>
</view>
</view>
</popup-view>
<!-- 所有页面的弹框 -->
<page-popup page="/pages/mine/orderStatusDetail"></page-popup>
</view>
</template>
<script>
import { myMixins } from "@/mixins/mixins.js";
import {
orderDetail,
delOrder,
orderReceive,
orderCancel,
orderReceiptApi,
orderDetailId,
orderRefundApi,
refundTimeApi,
boxRefundTimeApi,
boxRefundTimeExpiredApi
} from '@/API/order.js'
import {
customerApi
} from '@/API/user.js'
import {
mathAdd
} from '@/utils/mathUtils.js'
import {
uniCopy
} from '@/utils/uniCopyUtils.js'
import logistics from '@/components/xinyu-logistics/xinyu-logistics.vue'
import HeaderCom from '@/pages/components/header.vue'
export default {
mixins: [myMixins],
data() {
return {
no: '',
id:'',
detailData: {
logistics: {},
productCoverResource:{}
},
totalPrice: "",
statusList: [{
label: "待付款",
value: 'WAITING_FOR_PAYMENT'
},
{
label: "待发货",
value: 'WAITING_FOR_SHIPMENT'
},
{
label: "已发货",
value: 'SHIPPED'
},
{
label: "待收货",
value: 'WAITING_FOR_RECEIPT'
},
{
label: "已收货",
value: 'RECEIVED'
},
{
label: "已完成",
value: 'COMPLETED'
},
{
label: "已取消",
value: 'CANCELED'
},
{
label: "已退款",
value: 'REFUNDED'
},
{
label: "已回收",
value: 'RECOVERED'
},
],
statusObj: {
"WAITING_FOR_PAYMENT": "待付款",
"WAITING_FOR_SHIPMENT": "待发货",
"SHIPPED": "已发货",
"WAITING_FOR_RECEIPT": "待收货",
"RECEIVED": "已收货",
"COMPLETED": "已完成",
"CANCELED": "已取消",
"REFUNDED": "已退款",
"RECOVERED": "已回收"
},
paidWith: {
'POINTS': '积分支付',
'ALIPAY': '支付宝支付',
'WECHAT': '微信支付',
'COIN': '代币',
'NONE': "无需支付"
},
openShow: false,
address: '',
customer:'',
typeObj:{
MALL:"商城购买", BOX:"盲盒购买", BOX_DELIVERY:"盲盒提取", COIN_RECHARGE:"代币充值", OTHER:"其他"
},
expireTime:'',//过期时间
logOutvisible:false,
shipExpiredTime:'',
timer:null,
recoveryPoint:0,
reList:[]
}
},
components: {
logistics,HeaderCom
},
onLoad(opation) {
if(opation.id){
this.id = opation.id
}
this.no = opation.no
if(this.id){
this.getIdDetail()
}else{
this.getDetail()
}
this.getCustomer()
},
methods: {
closeBoxRefund(){
clearInterval(this.timer)
this.timer = null
this.logOutvisible = false
},
submitBoxRefund(){
uni.showLoading()
orderRefundApi({id:this.detailData.id}).then(res => {
this.$api.msg(res.message)
if(res.code === 200){
clearInterval(this.timer)
this.timer = null
this.logOutvisible = false
setTimeout(() => {
if(this.id){
this.getIdDetail()
}else{
this.getDetail()
}
},500)
}
}).catch(err => {
uni.hideLoading()
})
},
getRefundTime(){
refundTimeApi().then(res => {
console.log(res)
if(res.code === 200){
// this.expireTime = res.data
// 初始时间
const initialDate = new Date(this.detailData.paidAt);
// 增加的秒数
const secondsToAdd = res.data;
const millisecondsToAdd = secondsToAdd * 1000;
// 计算新的时间
const newDate = new Date(initialDate.getTime() + millisecondsToAdd);
// 格式化输出新的时间
const year = newDate.getFullYear();
const month = String(newDate.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,所以要加 1
const day = String(newDate.getDate()).padStart(2, '0');
const hours = String(newDate.getHours()).padStart(2, '0');
const minutes = String(newDate.getMinutes()).padStart(2, '0');
const seconds = String(newDate.getSeconds()).padStart(2, '0');
const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
this.expireTime = new Date(formattedTime).getTime()
console.log("formattedTime:",formattedTime);
console.log("formattedTime:",new Date(formattedTime).getTime()); // 输出结果
console.log("formattedTime:",new Date().getTime());
}else{
this.$api.msg(res.message)
}
})
},
orderRefund(){
if(this.expireTime < new Date().getTime()){
this.$api.msg('超过取消时长,无法取消')
setTimeout(() => {
if(this.id){
this.getIdDetail()
}else{
this.getDetail()
}
},500)
return
}
if (this.detailData.type === 'BOX_DELIVERY') {
uni.showLoading()
boxRefundTimeExpiredApi({
id: this.id
}).then(res => {
uni.hideLoading()
if (res.code === 200) {
if(res.data.length === 0){
uni.showLoading()
orderRefundApi({
id: item.id
}).then(result => {
uni.hideLoading()
this.$api.msg(result.message)
if (result.code === 200) {
setTimeout(() => {
if(this.id){
this.getIdDetail()
}else{
this.getDetail()
}
},500)
}
}).catch(err => {
uni.hideLoading()
})
}else{
this.reList = res.data
this.logOutvisible = true
}
// this.recoveryPoint = res.data.recoveryPoint
// let shipExpiredTime = res.data.shipExpiredTime ? res.data.shipExpiredTime : ''
// if(shipExpiredTime){
// const secondsPerDay = 86400; // 1天有86400秒
// // 将时间戳除以每天的秒数
// const currentTime = Math.floor(Date.now() / 1000);
// const targetTime = Math.floor(new Date(shipExpiredTime).getTime() / 1000);
// const countdown = targetTime - currentTime;
// if (countdown <= 0) {
// this.logOutvisible = true
// }else{
// uni.showLoading()
// orderRefundApi({id:this.detailData.id}).then(result => {
// this.$api.msg(result.message)
// if(result.code === 200){
// setTimeout(() => {
// if(this.id){
// this.getIdDetail()
// }else{
// this.getDetail()
// }
// },500)
// }
// }).catch(err => {
// uni.hideLoading()
// })
// }
// // this.timeFn(shipExpiredTime)
// // this.timer = setInterval(() => {
// // this.timeFn(shipExpiredTime)
// // // const secondsPerDay = 86400; // 1天有86400秒
// // // // 将时间戳除以每天的秒数
// // // const currentTime = Math.floor(Date.now() / 1000);
// // // const targetTime = Math.floor(new Date(shipExpiredTime).getTime() / 1000);
// // // if (isNaN(targetTime)) {
// // // this.shipExpiredTime = '';
// // // }else{
// // // const countdown = targetTime - currentTime;
// // // if (countdown <= 0) {
// // // this.shipExpiredTime = '已过期'
// // // }else if(countdown > secondsPerDay){
// // // const days = parseInt(countdown / secondsPerDay);
// // // this.shipExpiredTime = `${days}天`
// // // this.isShow = true
// // // }else {
// // // const hours = Math.floor(countdown / 3600);
// // // const minutes = Math.floor((countdown % 3600) / 60);
// // // const seconds = countdown % 60;
// // // this.shipExpiredTime = `${this.padZero(hours)}:${this.padZero(minutes)}:${this.padZero(seconds)}`
// // // }
// // // }
// // },1000)
// }
} else {
this.$api.msg(res.message)
}
}).catch(err => {
uni.hideLoading()
})
} else {
uni.showLoading()
orderRefundApi({id:this.detailData.id}).then(res => {
this.$api.msg(res.message)
if(res.code === 200){
setTimeout(() => {
if(this.id){
this.getIdDetail()
}else{
this.getDetail()
}
},500)
}
}).catch(err => {
uni.hideLoading()
})
}
},
timeFn(shipExpiredTime){
if(shipExpiredTime){
const secondsPerDay = 86400; // 1天有86400秒
// 将时间戳除以每天的秒数
const currentTime = Math.floor(Date.now() / 1000);
const targetTime = Math.floor(new Date(shipExpiredTime).getTime() / 1000);
if (isNaN(targetTime)) {
this.shipExpiredTime = '';
}else{
const countdown = targetTime - currentTime;
if (countdown <= 0) {
this.shipExpiredTime = '已过期'
}else if(countdown > secondsPerDay){
const days = parseInt(countdown / secondsPerDay);
this.shipExpiredTime = `${days}天`
this.isShow = true
}else {
const hours = Math.floor(countdown / 3600);
const minutes = Math.floor((countdown % 3600) / 60);
const seconds = countdown % 60;
this.shipExpiredTime = `${this.padZero(hours)}:${this.padZero(minutes)}:${this.padZero(seconds)}`
}
}
}
},
padZero(num) {
return num.toString().padStart(2, '0');
},
getIdDetail(){
orderDetailId(this.id).then(res => {
uni.hideLoading()
if (res.code === 200) {
this.detailData = res.data
this.address = this.detailData.receiver.address
this.getRefundTime()
} else {
this.$api.msg(res.message)
}
}).catch(err => {
uni.hideLoading()
})
},
getCustomer() {
customerApi().then(res => {
if (res.code === 200) {
this.customer = res.data
} else {
this.$api.msg(res.message)
}
})
},
handleCustomer() {
// window.open(this.customer)
window.location.href = this.customer
},
orderReceipt() {
uni.showLoading()
orderReceiptApi({
id: this.detailData.id
}).then(res => {
uni.hideLoading(),
this.$api.msg(res.message)
if (res.code === 200) {
// this.getDetail()
if(this.id){
this.getIdDetail()
}else{
this.getDetail()
}
}
})
},
formatDateTime(value) {
if (!value) return '';
const date = new Date(value);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
},
goBack() {
uni.switchTab({
url:`/pages/mine/mine`
})
},
againProduct() {
uni.navigateTo({
url: `/pages/shop/detail?id=${this.detailData.productId}`
})
},
makePhoneCall() {
uni.makePhoneCall({
phoneNumber: '18620545056'
});
},
copy(no) {
uni.setClipboardData({
data: no,
})
},
// 获取详情
getDetail() {
uni.showLoading()
orderDetail(this.no, {
no: this.no
}).then(res => {
uni.hideLoading()
if (res.code === 200) {
this.detailData = res.data[0]
this.address = this.detailData.receiver.address
this.getRefundTime()
} else {
this.$api.msg(res.message)
}
}).catch(err => {
uni.hideLoading()
})
},
// 删除订单
del() {
uni.showLoading()
orderCancel({
no: this.detailData.no
}).then(res => {
uni.hideLoading()
this.$api.msg(res.message)
if (res.code === 200) {
this.getDetail()
}
}).catch(err => {
uni.hideLoading()
})
},
// 确认收货
receive() {
uni.showLoading()
orderReceive({
no: this.detailData.no
}).then(res => {
uni.hideLoading()
this.$api.msg(res.message)
if (res.code === 200) {
this.getDetail()
}
}).catch(err => {
uni.hideLoading()
})
},
buy() {
uni.navigateTo({
url: `/pages/order/confirm?id=${this.detailData.productId}&orderId=${this.detailData.id}&quantity=${this.detailData.quantity}&skuId=${this.detailData.skuId}&no=${this.detailData.no}&paidWith=${this.detailData.paidWith}`
})
},
logistics() {
this.detailData.logistics['logisticsStatus'] = this.detailData.logisticsStatus
this.openShow = true
},
close() {
this.openShow = false
},
}
}
</script>
<style lang="scss">
page {
background-color: #f5f5f5;
}
.order-detail-page {
padding: 112rpx 32rpx 32rpx 32rpx;
.scroll-view{
height: calc(100vh - 320rpx);
.main{
width: 686rpx;
background: #FFFFFF;
border-radius: 24rpx;
margin-bottom: 24rpx;
padding: 0 24rpx;
.shop{
width: 100%;
display: flex;
align-items: center;
padding: 24rpx 0;
border-bottom: 1px solid #F2F2F2;
.contain{
width: 160rpx;
height: 160rpx;
border-radius: 0 24rpx 24rpx 0;
background-image: url('@/static/new/shop-bg.png');
background-size: contain;
display: flex;
align-items: center;
justify-content: center;
.shop-icon{
width: 142rpx;
height: 132rpx;
}
}
.detail{
margin-left: 24rpx;
height: 160rpx;
.name{
width: 444rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-weight: 500;
font-size: 28rpx;
color: #000000;
}
.remark{
width: 444rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-weight: 500;
font-size: 24rpx;
color: #999999;
margin-top: 8rpx;
}
.price{
// margin-top: 34rpx;
margin-top: 76rpx;
display: flex;
align-items: center;
justify-content: space-between;
width: 444rpx;
.value{
font-weight: bold;
font-size: 32rpx;
color: #000000;
}
.num{
font-weight: 500;
font-size: 28rpx;
color: #999999;
}
}
}
}
.item{
// width: 686rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24rpx;
.label{
font-weight: 500;
font-size: 28rpx;
color: #666666;
}
.value{
font-weight: 500;
font-size: 28rpx;
color: #000000;
}
}
.item-big{
// width: 686rpx;
height: 96rpx;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 24rpx;
border-top: 1px solid #F2F2F2;
.label{
font-weight: 500;
font-size: 28rpx;
color: #666666;
}
.value{
font-weight: 800;
font-size: 36rpx;
color: #000000;
}
}
}
}
.footer{
display: flex;
align-items: center;
justify-content: end;
width: 100%;
height: 144rpx;
background-color: #fff;
position: fixed;
bottom: 0;
left: 0;
padding: 0 32rpx;
.btn{
width: 212rpx;
height: 96rpx;
background: #FFFFFF;
border-radius: 16rpx;
border: 2px solid #EBEBEB;
display: flex;
align-items: center;
justify-content: center;
font-weight: 500;
font-size: 32rpx;
color: #666666;
margin-left: 24rpx;
}
.active-btn{
background: linear-gradient( 90deg, #39B2FF 0%, #3354FF 100%), #D9D9D9;
border: none;
color: #FFFFFF;
}
}
.dlg-main {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
.header{
display: flex;
align-items: center;
justify-content: space-between;
width: 750rpx;
height: 96rpx;
padding: 0 32rpx;
.title{
font-weight: bold;
font-size: 32rpx;
color: #000000;
}
.close{
width: 48rpx;
height: 48rpx;
}
}
.popup-scroll {
width: 706rpx;
height: 900rpx;
background-color: #fff;
border-radius: 20rpx;
overflow-y: scroll;
}
.popup-close {
margin-top: 36rpx;
width: 54rpx;
height: 54rpx;
}
}
.log-out{
width: 630rpx;
// height: 300rpx;
background: #FFFFFF;
border-radius: 16rpx;
.log-title{
text-align: center;
font-size: 40rpx;
color: #000;
font-weight: bold;
padding-top: 20rpx;
}
.log-sub{
text-align: center;
font-size: 24rpx;
color: #999;
}
.log-out-tip{
padding: 40rpx 20rpx;
height: 400rpx;
overflow-y: auto;
// height: 200rpx;
font-weight: 500;
font-size: 32rpx;
color: rgba(0,0,0,0.85);
text-align: center;
.re-list{
display: flex;
align-items: center;
margin-bottom: 10rpx;
padding-bottom: 10rpx;
border-bottom: 1px solid rgba(0,0,0,0.06);
.re-img{
width: 100rpx;
height: 100rpx;
border-radius: 10rpx;
border: 1px solid red;
}
.re-info{
margin-left: 10rpx;
width: 400rpx;
height: 100rpx;
display: flex;
// align-items: center;
justify-content: space-between;
flex-direction: column;
.re-name{
width: 400rpx;
text-align: left;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-weight: 500;
font-size: 28rpx;
color: #000000;
}
.re-point{
width: 400rpx;
text-align: left;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-weight: 500;
font-size: 28rpx;
color: #999999;
}
}
}
}
.log-out-footer{
display: flex;
align-items: center;
justify-content: space-between;
border-top: 2rpx solid rgba(0,0,0,0.06);
height: 100rpx;
.cancel{
width: 294rpx;
height: 100rpx;
line-height: 100rpx;
font-weight: 500;
font-size: 32rpx;
color: #000000;
text-align: center;
border-right: 1px solid rgba(0,0,0,0.06);
}
.log-out-submit{
width: 294rpx;
height: 100rpx;
line-height: 100rpx;
font-weight: 500;
font-size: 32rpx;
color: #E55353;
text-align: center;
}
}
}
}
</style>