Files
kangyuan-mobile/components/card_orderBan/card_orderBan.vue
T

309 lines
7.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view
class="flex-center"
:class="{
'ju-flex-end': props.type == 2,
'ju-between': props.type != 2,
}"
>
<view class="more size24" v-if="props.type != 2"></view>
<view class="flex-center ju-flex-end">
<view
v-if="showRemind"
class="btn size28 f500 remind-btn"
@click.stop="btnClick(7)"
>
催一催
</view>
<view v-for="(item, index) in btns" :key="index">
<view
v-if="
item.id !== 3 &&
item.value.split(',').indexOf(String(props?.data?.status)) !== -1 &&
!(item.id === 3 && Number(props?.data?.type) === 5) &&
!(item.id === 3 && props?.data?.payChannelCode === 'cash_payment') &&
!(item.id === 3 && isAllRefunded)
"
class="btn size28 f500"
@click.stop="btnClick(item.id)"
:style="{ color: item.color, background: item.background, border: item.border }"
:class="{ btn1: props.type == 2 }"
>
{{ item.name }}
</view>
</view>
</view>
</view>
</template>
<script setup>
import { computed } from 'vue';
import { ref, getCurrentInstance, defineProps, defineEmits } from 'vue';
import sheep from '@/sheep';
import OrderApi from '@/sheep/api/trade/order';
const { proxy } = getCurrentInstance();
let emit = defineEmits(['downData', 'remind']);
const props = defineProps({
data: {
type: Object,
default() {
return {};
},
},
type: {
type: String,
default: '0', //0列表2订单详情
},
});
// 订单级 refundStatus:0 未退款 / 10 部分退款 / 20 全部退款
// 用户需求:如果是 20(全部退款),就不要展示"申请售后"按钮了。
const refundStatus = computed(() => {
const v = props.data?.refundStatus === undefined ? props.data?.refund_status : props.data?.refundStatus;
return Number(v) || 0;
});
const isAllRefunded = computed(() => refundStatus.value === 20);
const isVerifyCompleted = computed(() => {
const info = props.data || {};
const status = Number(info?.status);
return Boolean(
info?.pickUpVerifyTime ||
info?.verifyTime ||
info?.completedTime ||
status === 30 ||
status === 3,
);
});
const resolveStage = () => {
const data = props.data || {};
const external = Number(data?.preparationStatus);
const rawStatus = Number.isFinite(external) ? external : Number(data?.preparationStatus ?? data?.status ?? 0);
if (isVerifyCompleted.value) return 'done';
if (rawStatus === 1 || rawStatus === 2) return 'wait';
if (
data?.deliveryTime ||
data?.arriveStoreTime ||
data?.deliveredTime ||
rawStatus === 20
) {
return 'delivered';
}
return 'sorting';
};
const isSorting = computed(() => resolveStage() === 'sorting');
const showRemind = computed(() => {
const info = props.data || {};
return (
Number(info?.deliveryType) === 2 &&
Boolean(info?.payStatus) &&
!isVerifyCompleted.value &&
isSorting.value
);
});
let btns = ref([
{
id: 1,
name: '取消订单',
value: '0,70',
},
{
id: 2,
name: '去付款',
value: '0',
color: '#EE0A24',
background: 'rgba(238,10,36,0.2)',
border: 'none',
},
{
//在订单详情退货
id: 3,
name: '申请售后',
value: '10,20',
},
{
id: 4,
name: '确认收货',
value: '20,60',
color: '#EE0A24',
background: 'rgba(238,10,36,0.2)',
border: 'none',
},
{
id: 5,
name: '再次购买',
value: '30,50,40',
color: '#FA9C31',
},
{
id: 6,
name: '取消售后',
value: '60',
},
]);
const btnClick = (index) => {
let timestamp = new Date().getTime();
let payExpireTime = props.data.payExpireTime;
if (timestamp > payExpireTime && props.data.status == 0 && index == 2) {
uni.showToast({
title: '订单已过期',
icon: 'none',
});
return;
}
if (index === 3 && Number(props?.data?.type) === 5) {
return;
}
// 全单已退款(refundStatus===20):保险层面禁止再次发起申请售后
if (index === 3 && isAllRefunded.value) {
uni.showToast({ title: '该订单已全部退款,无需再次申请售后', icon: 'none' });
return;
}
if (index === 3) {
return;
}
let id = props.data?.id;
switch (index) {
case 1:
cancelOrder();
break;
case 2:
payOrder(id);
break;
case 3:
applyAfterSale();
break;
case 4:
confirmReceive();
break;
case 5:
buyAgain();
break;
case 6:
cancelAfterSale();
break;
case 7:
remindStore();
break;
}
};
// 取消订单
const cancelOrder = () => {
let orderId = props.data?.id;
uni.showModal({
title: '提示',
content: '确定要取消订单吗?',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
upData();
const { code } = await OrderApi.cancelOrder(orderId);
if (code === 0) {
uni.showToast({
title: '订单已取消',
icon: 'none',
});
upData();
}
},
});
};
// 去付款
const payOrder = (id) => {
sheep.$router.go('/pages/pay/index', {
id: props.data.payOrderId,
});
};
// 申请售后
const applyAfterSale = () => {
const __src = String(props?.data?.__source || props?.data?.source || '').trim();
const __ty = String(props?.data?.type || '').trim();
// 避免把整个订单对象里的同名字段 type/source/__source 直接展开污染 query(
// 否则普通商城订单也可能因为 data.type=5(或商城订单里的其他数字type)在 apply.vue 里误走 ai 接口)。
sheep.$router.go('/pages/order/aftersale/apply', {
id: props?.data?.id,
orderId: props?.data?.id,
no: props?.data?.no,
...(__src ? { source: __src } : {}),
...(__ty ? { openOrderType: __ty } : {}),
});
};
// 确认收货
const confirmReceive = () => {
let change = false;
if (props.data?.items.length) {
props.data.items.forEach((item) => {
if (item.afterSaleStatus == 10) {
change = true;
return;
}
});
}
if (change) {
uni.showToast({
title: '有售后中的商品,请先处理完售后',
icon: 'none',
});
return;
}
uni.showModal({
title: '提示',
content: '确认收货吗?',
confirmColor: '#FA7E31',
success: async function (res) {
if (!res.confirm) {
return;
}
// 正常的确认收货流程
const { code } = await OrderApi.receiveOrder(props.data?.id);
if (code === 0) {
upData();
}
},
});
};
// 再次购买
const buyAgain = () => {};
// 取消售后
const cancelAfterSale = () => {};
// 催一催
const remindStore = async () => {
emit('remind');
};
const upData = () => {
emit('downData');
};
</script>
<style scoped lang="scss">
.more {
}
.btn {
line-height: 24rpx;
padding: 10rpx 24rpx;
box-sizing: border-box;
border: 2rpx solid #999999;
border-radius: 10rpx;
margin-left: 12rpx;
color: #999999;
}
.btn1 {
// line-height: 74rpx;
// padding: 0 30rpx;
}
.remind-btn {
color: #2556ec;
background: rgba(37, 86, 236, 0.08);
border: 2rpx solid rgba(37, 86, 236, 0.28);
}
</style>