purchase-let/pagesOrder/detail/detail.vue

547 lines
15 KiB
Vue
Raw Normal View History

2024-04-26 18:04:56 +08:00
<template>
<view class="">
2024-05-06 17:58:41 +08:00
<view class="count_down" v-if="datas.paid==0&&countDown">
还剩<text>{{countDown}}</text>订单自动取消
</view>
2024-05-08 14:50:27 +08:00
<view class="m-card m-address" style="margin-top: 20rpx;">
2024-05-11 16:45:33 +08:00
<view class="address-info" @click="callPhone(shopInfo.service_phone)">
2024-05-08 14:50:27 +08:00
<view class="top" style="align-items: flex-start;">
<view style="color: #333;display: flex;align-items: center;">
<up-icon name="map"></up-icon>
<text style="margin: 0 10rpx;">自提点</text>
</view>
<view v-if="shopInfo.mer_id">
<view>{{shopInfo.mer_name}}</view>
<view>
<text>{{shopInfo.service_phone}}</text>
<text
style="color: #20b128;margin-left: 10rpx;font-size: 22rpx;">{{shopInfo.distance}}</text>
</view>
</view>
</view>
</view>
2024-05-11 16:45:33 +08:00
<view class="address-btn" v-if="shopInfo.paid==0">
<view style="width: 80px;"><up-button @click.stop="shopListShow=true" size="small" shape="circle"
2024-05-08 14:50:27 +08:00
color="#f6f6f6" :customStyle="{color:'#666666'}">修改</up-button></view>
</view>
</view>
2024-05-13 11:06:09 +08:00
<view class="m-card m-address" style="margin-top: 20rpx;" v-if="addressInfo && addressInfo.address_id">
2024-04-26 18:04:56 +08:00
<view class="address-info">
<view class="top">
2024-05-06 17:58:41 +08:00
<up-icon name="account"></up-icon>
<view class="t-name">{{addressInfo.real_name}}</view>
<view>{{addressInfo.phone}}</view>
2024-04-26 18:04:56 +08:00
</view>
<view class="bottom u-line-2">
2024-05-06 17:58:41 +08:00
{{addressInfo.detail}}
2024-04-26 18:04:56 +08:00
</view>
</view>
2024-05-06 14:26:18 +08:00
<view class="address-btn" v-if="datas.paid==0">
2024-04-27 18:02:43 +08:00
<view style="width: 80px;"><up-button @click="showAddress = true" size="small" shape="circle" color="#f6f6f6"
:customStyle="{color:'#666666'}">修改</up-button></view>
2024-04-26 18:04:56 +08:00
</view>
</view>
2024-05-13 11:06:09 +08:00
<view class="m-card m-address" style="margin-top: 20rpx;" v-else>
<view class="address-info">
<view class="top">
<up-icon name="account"></up-icon>
<view class="t-name">未填写收货人信息</view>
</view>
</view>
<view class="address-btn" v-if="datas.paid==0">
<view style="width: 80px;"><up-button @click="showAddress = true" size="small" shape="circle" color="#f6f6f6"
:customStyle="{color:'#666666'}">修改</up-button></view>
</view>
</view>
2024-05-06 17:58:41 +08:00
<view class="m-card m-good" v-for="(item,index) in datas.goods_list" :key="index">
2024-05-06 10:11:25 +08:00
<view class="image">
<up-image :src="item.imgs" width="160rpx" height="160rpx"></up-image>
</view>
2024-04-26 18:04:56 +08:00
<view class="body-content">
<view>
<view class="title">
2024-05-06 10:11:25 +08:00
<view>{{item.class_name}}</view>
<view>¥{{item.sell}}</view>
2024-04-26 18:04:56 +08:00
</view>
<view class="tips">
2024-05-06 14:54:47 +08:00
<view>{{item.goods_unit}}</view>
2024-05-06 10:11:25 +08:00
<view>x{{item.nums}}</view>
2024-04-26 18:04:56 +08:00
</view>
</view>
<view class="time">
2024-05-06 14:54:47 +08:00
{{item.msg}}
2024-04-26 18:04:56 +08:00
</view>
</view>
</view>
2024-05-06 14:26:18 +08:00
<view class="m-card good-info" v-if="datas.paid==0">
2024-05-06 10:11:25 +08:00
<view v-if="datas.goods_list" class="row">
<view>商品总价 <text>共计{{datas.goods_list.length}}款商品</text></view>
<view><text>¥</text>{{c_price(datas.total, 0)}}<text>.{{c_price(datas.total, 1)}}</text></view>
2024-04-26 18:04:56 +08:00
</view>
<view class="row">
<view>运费</view>
<view><text>¥</text>0<text>.00</text></view>
</view>
<view class="row-need">
<view style="margin-right: 10rpx;">需付款</view>
2024-05-06 17:58:41 +08:00
<view v-if="datas.total"><text>¥</text>{{c_price(datas.total, 0)}}<text>.{{c_price(datas.total, 1)}}</text></view>
2024-04-26 18:04:56 +08:00
</view>
</view>
<view class="m-card good-info">
<view class="head-title">订单信息</view>
2024-05-06 14:26:18 +08:00
<block v-if="datas.paid==0">
<view class="row">
<view>订单编号</view>
<up-copy :content="datas.number">
<text>{{datas.number}} | 复制</text>
</up-copy>
</view>
<view class="row">
<view>下单时间</view>
<view>{{datas.create_time}}</view>
</view>
<view class="row" style="margin-bottom: 0;">
<view>支付状态</view>
<view v-if="datas.paid">已支付</view>
<view v-else class="red">待支付</view>
</view>
</block>
<block v-else>
<view v-if="datas.goods_list" class="row">
<view>实付款</view>
<view><text>¥</text>{{c_price(datas.total, 0)}}<text>.{{c_price(datas.total, 1)}}</text></view>
</view>
<view class="row">
<view>订单编号</view>
<up-copy :content="datas.number">
<text>{{datas.number}} | 复制</text>
</up-copy>
</view>
<view class="row">
<view>支付方式</view>
<view>{{datas.pay_type==3?'余额支付':'微信支付'}}</view>
</view>
<view class="row">
<view>下单时间</view>
<view>{{datas.create_time}}</view>
</view>
<view class="row" style="margin-bottom: 0;">
<view>支付状态</view>
<view v-if="datas.paid">已支付</view>
<view v-else class="red">待支付</view>
</view>
</block>
2024-04-26 18:04:56 +08:00
</view>
<view style="width: 100%;height: 200rpx;"></view>
2024-04-27 18:02:43 +08:00
2024-05-06 14:54:47 +08:00
<view class="fiexd-btn-box" v-if="datas.number">
<block v-if="!datas.paid">
<view style="color: #777777;" @click="showCancel=true">取消订单</view>
<view style="width: 450rpx;">
2024-05-07 13:39:08 +08:00
<up-button color="#20B128" shape="circle" @click="rePay" :throttleTime="1000">立即支付 ¥{{datas.total}}</up-button>
2024-05-06 14:54:47 +08:00
</view>
</block>
<block v-else>
<view></view>
<view style="width: 450rpx;">
2024-05-08 14:50:27 +08:00
<up-button v-if="datas.status==0||datas.status==1" color="#20B128" shape="circle" @click="showTake=true">确认收货</up-button>
2024-05-08 15:25:03 +08:00
<up-button v-else color="#20B128" plain shape="circle" @click="purchaseAgain">再次购买</up-button>
2024-05-06 14:54:47 +08:00
</view>
</block>
2024-04-26 18:04:56 +08:00
</view>
2024-04-27 18:02:43 +08:00
2024-05-06 17:58:41 +08:00
<orderCanclePopup :show="showCancel" @close="showCancel=false" @change="submitCancel" />
2024-05-08 14:50:27 +08:00
<addressPopup ref="addressRef" :show="showAddress" :list="addressList" @close="showAddress=false" @change="changeAddress" />
<shopListPopupVue ref="shopRef" :show="shopListShow" :list="merchantList"
@close="shopListShow=false" @change="changeShop" @search="searchShop" />
<modal :show="showTake" title="确认收货" content="请确认您已收到货" @close="showTake=false" @change="confirmReceipt"></modal>
2024-04-26 18:04:56 +08:00
</view>
</template>
<script setup>
2024-05-06 14:26:18 +08:00
import { onLoad, onBackPress } from "@dcloudio/uni-app";
2024-05-08 14:50:27 +08:00
import { nextTick, ref } from "vue";
2024-04-27 18:02:43 +08:00
import addressPopup from "@/components/addressPopup.vue";
2024-05-06 17:58:41 +08:00
import orderCanclePopup from "@/components/orderCanclePopup.vue";
2024-05-08 14:50:27 +08:00
import shopListPopupVue from "@/components/shopListPopup.vue";
2024-04-27 18:02:43 +08:00
import modal from "@/components/modal.vue";
2024-05-08 15:25:03 +08:00
import { orderDetailApi, cancelOrderApi, rePaymentApi, confirmReceiptApi, purchaseAgainApi } from "@/api/order.js"
2024-05-06 17:58:41 +08:00
import { addressListsApi, merchantListApi } from "@/api/user.js";
2024-04-26 18:04:56 +08:00
2024-04-27 18:02:43 +08:00
const showCancel = ref(false);
2024-05-08 14:50:27 +08:00
const showTake = ref(false);
2024-04-26 18:04:56 +08:00
2024-05-06 17:58:41 +08:00
const submitCancel = (e) => {
2024-04-27 18:02:43 +08:00
showCancel.value = false;
2024-05-07 13:39:08 +08:00
cancelOrderApi({
order_id: datas.value.id,
value: e.value
}).then(res=>{
uni.showToast({
title: '取消成功',
icon: 'none'
})
uni.navigateBack({
success: () => {
uni.$emit('reLoadOrderList')
}
});
2024-04-27 18:02:43 +08:00
})
}
2024-04-30 16:24:55 +08:00
const datas = ref({})
const getDetails = ()=>{
2024-05-06 10:11:25 +08:00
orderDetailApi({
order_id: datas.value.id
}).then(res=>{
datas.value = res.data;
2024-05-08 14:50:27 +08:00
shopInfo.value = res.data.merchant_info;
if(addressList.value.length>0 && res.data.paid){
addressInfo.value = addressList.value.find(item=>item.address_id == res.data.address_id);
}else {
addressInfo.value = {
address_id: res.data.address_id,
real_name: res.data.real_name,
phone: res.data.user_phone,
detail: res.data.user_address
}
}
nextTick(()=>{
shopRef.value.setCheck(shopInfo.value.mer_id);
addressRef.value.setCheck(addressInfo.value.address_id);
})
2024-05-06 17:58:41 +08:00
if(!res.data.paid){
targetDate = new Date(res.data.create_time).getTime() + 30*60*1000;
// 每秒更新一次倒计时
timer = setInterval(updateCountdown, 1000);
updateCountdown();
}
2024-05-07 13:39:08 +08:00
}).catch(err=>{
uni.navigateBack();
2024-04-30 16:24:55 +08:00
})
}
2024-05-06 10:11:25 +08:00
const c_price = (price, index=0)=>{
price = price + '';
return price.split('.')[index] || (index ? '00' : '0');
}
2024-05-06 14:26:18 +08:00
2024-05-08 14:50:27 +08:00
// 选择地址
const addressRef = ref(null);
const showAddress = ref(false);
2024-05-13 11:06:09 +08:00
const addressInfo = ref({
address_id:''
});
2024-05-08 14:50:27 +08:00
const changeAddress = (e) => {
addressInfo.value = e;
showAddress.value = false;
}
const openAddress = ()=>{
if(addressList.length>0) showAddress.value=true;
else uni.navigateTo({
url: '/pagesOrder/addressEdit/addressEdit'
})
}
2024-05-06 17:58:41 +08:00
// 地址相关
const addressList = ref([]);
const getAddressList = ()=>{
addressListsApi().then(res=>{
addressList.value = res.data.lists;
addressList.value.forEach(item=>{
if(item.is_default) {
addressInfo.value = item;
}
})
if(addressList.value.length>0){
addressInfo.value = addressList.value[0];
}
2024-05-08 14:50:27 +08:00
if(addressInfo.value.address_id) nextTick(()=>{
addressRef.value.setCheck(addressInfo.value.address_id);
})
2024-05-06 17:58:41 +08:00
})
}
getAddressList();
2024-05-08 14:50:27 +08:00
const shopRef = ref(false);
const shopListShow = ref(false);
const merchantList = ref([]);
const myAddressInfo = ref({
long: "",
lat: ""
})
const shopInfo = ref({
mer_id: ''
});
const getMerchantList = (mer_name = null) => {
merchantListApi({
...myAddressInfo.value,
mer_name: mer_name ? mer_name : ''
}).then(res => {
merchantList.value = res.data.lists;
if (mer_name === null && myAddressInfo.value.long && merchantList.value.length > 0 && !shopInfo
.value.mer_id) {
shopInfo.value = merchantList.value[0];
nextTick(()=>{
shopRef.value.setCheck(shopInfo.value.mer_id);
})
}
})
2024-05-06 17:58:41 +08:00
}
2024-05-08 14:50:27 +08:00
getMerchantList();
// 定位
const LoadAddress = () => {
uni.getLocation({
success: (res) => {},
fail: (err) => {
uni.$u.toast('定位失败, 请手动选择提货点!')
},
complete: (res) => {
myAddressInfo.value.long = res.longitude || "";
myAddressInfo.value.lat = res.latitude || "";
getMerchantList();
}
})
}
const changeShop = (e) => {
LoadAddress();
shopInfo.value = e;
shopListShow.value = false;
}
const searchShop = (e) => {
getMerchantList(e)
2024-05-06 17:58:41 +08:00
}
2024-05-06 14:54:47 +08:00
const rePay = ()=>{
rePaymentApi({
order_id: datas.value.id,
2024-05-08 14:50:27 +08:00
mer_id: shopInfo.value.mer_id,
address_id: addressInfo.value.address_id,
2024-05-06 14:54:47 +08:00
pay_type: 1
}).then(res=>{
2024-05-07 13:39:08 +08:00
if(!res.data?.nonceStr) return uni.$u.toast('支付失败!');
uni.requestPayment({
provider: 'wxpay',
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: (e) => {
if(e.errMsg == 'requestPayment:ok'){
uni.showModal({
title: '订单支付成功',
confirmText: '确认',
success: (e) => {
uni.navigateBack({
success: () => {
uni.$emit('reLoadOrderList')
}
});
}
})
}else uni.$u.toast('支付失败')
},
fail: (e) => {
uni.$u.toast('用户取消支付')
}
})
}).catch(err=>{
uni.$u.toast('网络错误')
2024-05-06 14:54:47 +08:00
})
}
2024-05-08 15:25:03 +08:00
// 再次购买
const purchaseAgain = ()=>{
purchaseAgainApi({
order_id: datas.value.id
}).then(res=>{
uni.$u.toast('已加入购物车');
})
}
2024-05-06 14:26:18 +08:00
// 设置目标日期
let targetDate = "";
2024-05-06 17:58:41 +08:00
let countDown = ref("");
2024-05-06 14:26:18 +08:00
let timer = null;
// 更新倒计时函数
function updateCountdown() {
const now = new Date().getTime();
const distance = targetDate - now;
2024-05-06 17:58:41 +08:00
if(distance<0) return clearInterval(timer);
2024-05-06 14:26:18 +08:00
// 计算剩余时间
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
2024-05-06 17:58:41 +08:00
countDown.value = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
2024-05-06 14:26:18 +08:00
// 如果目标日期已过,显示提示信息
if (distance < 0) {
console.log('倒计时结束');
2024-05-06 17:58:41 +08:00
countDown.value = ""
2024-05-06 14:26:18 +08:00
}
}
2024-05-08 14:50:27 +08:00
// 确认收货
const confirmReceipt = ()=>{
confirmReceiptApi({
order_id: datas.value.id
}).then(res=>{
showTake.value = false;
uni.$u.toast('确认收货成功');
uni.navigateBack({
success: () => {
uni.$emit('reLoadOrderList');
}
})
})
}
2024-05-11 16:45:33 +08:00
// 拨打电话
const callPhone = (phone)=>{
uni.makePhoneCall({
phoneNumber: phone
})
}
2024-04-27 18:02:43 +08:00
onLoad((option) => {
uni.setNavigationBarTitle({
2024-05-06 17:58:41 +08:00
title: option.type == 0 ? '等待付款' : '订单详情'
2024-04-27 18:02:43 +08:00
})
2024-05-06 10:11:25 +08:00
if(option.id) {
datas.value.id = option.id;
getDetails()
}
2024-04-26 18:04:56 +08:00
})
2024-05-06 14:26:18 +08:00
onBackPress(()=>{
clearInterval(timer);
console.log("清除");
})
2024-04-26 18:04:56 +08:00
</script>
<style lang="scss">
2024-04-27 18:02:43 +08:00
.count_down {
2024-05-06 14:26:18 +08:00
padding-top: 20rpx;
2024-04-27 18:02:43 +08:00
text-align: center;
color: #444444;
text {
color: #F55726;
padding: 0 10rpx;
}
2024-04-26 18:04:56 +08:00
}
2024-04-27 18:02:43 +08:00
.m-card {
width: 710rpx;
margin: 0 auto;
background-color: #fff;
border-radius: 14rpx;
box-sizing: border-box;
padding: 20rpx;
color: #333333;
}
.m-address {
margin-bottom: 20rpx;
display: flex;
justify-content: space-between;
color: #999999;
.address-info {
width: 510rpx;
.top {
display: flex;
font-size: 28rpx;
.t-name {
color: #444;
margin: 0 10rpx;
}
}
.bottom {
font-size: 24rpx;
2024-04-26 18:04:56 +08:00
}
}
}
2024-04-27 18:02:43 +08:00
.m-good {
2024-04-26 18:04:56 +08:00
display: flex;
justify-content: space-between;
2024-04-27 18:02:43 +08:00
margin-bottom: 20rpx;
.image {
width: 160rpx;
height: 160rpx;
margin-right: 20rpx;
2024-05-06 10:11:25 +08:00
border-radius: 14rpx;
overflow: hidden;
2024-04-27 18:02:43 +08:00
}
.body-content {
width: 490rpx;
2024-04-26 18:04:56 +08:00
display: flex;
2024-04-27 18:02:43 +08:00
flex-direction: column;
2024-04-26 18:04:56 +08:00
justify-content: space-between;
2024-04-27 18:02:43 +08:00
color: #989898;
.title {
display: flex;
justify-content: space-between;
font-size: 28rpx;
color: #444;
}
.tips {
display: flex;
justify-content: space-between;
font-size: 24rpx;
margin-top: 10rpx;
}
.time {
background-color: #F6F6F6;
padding: 5rpx 10rpx;
font-size: 26rpx;
color: #444;
border-radius: 10rpx;
}
2024-04-26 18:04:56 +08:00
}
2024-04-27 18:02:43 +08:00
}
.good-info {
margin-bottom: 20rpx;
.head-title {
margin-bottom: 18rpx;
color: #000;
font-weight: bold;
}
.row {
2024-04-26 18:04:56 +08:00
display: flex;
justify-content: space-between;
2024-04-27 18:02:43 +08:00
margin-bottom: 18rpx;
.red {
color: #F55726;
}
2024-04-26 18:04:56 +08:00
}
2024-04-27 18:02:43 +08:00
.row-need {
display: flex;
justify-content: flex-end;
2024-04-26 18:04:56 +08:00
color: #F55726;
}
2024-04-27 18:02:43 +08:00
text {
font-size: 22rpx;
}
2024-04-26 18:04:56 +08:00
}
2024-04-27 18:02:43 +08:00
2024-05-06 17:58:41 +08:00
2024-04-27 18:02:43 +08:00
</style>