513 lines
16 KiB
Vue
513 lines
16 KiB
Vue
<!-- 售后申请 -->
|
||
<template>
|
||
<s-pages title="申请售后" :pink_bg="true">
|
||
<!-- 售后商品 -->
|
||
<view class="goods-box">
|
||
<template v-if="state.itemId > 0 && state.item?.id">
|
||
<s-goods-item
|
||
:img="state.item.picUrl"
|
||
:title="state.item.spuName"
|
||
:skuText="state.item.properties?.map((property) => property.valueName).join(' ')"
|
||
:price="state.item.price"
|
||
:num="state.item.count"
|
||
/>
|
||
</template>
|
||
<template v-else-if="state.orderItems?.length">
|
||
<s-goods-item
|
||
v-for="(item, index) in state.orderItems"
|
||
:key="item?.id || index"
|
||
:img="item.picUrl"
|
||
:title="item.spuName"
|
||
:skuText="item.properties?.map((property) => property.valueName).join(' ')"
|
||
:price="item.price"
|
||
:num="item.count"
|
||
:style="index < state.orderItems.length - 1 ? { marginBottom: '16rpx' } : {}"
|
||
/>
|
||
</template>
|
||
</view>
|
||
|
||
<uni-forms ref="form" v-model="formData" :rules="rules" label-position="top">
|
||
<!-- 售后类型 -->
|
||
<view class="card">
|
||
<view class="refund-item m-b-32">
|
||
<view class="item-title ss-m-b-20">售后类型</view>
|
||
<view class="ss-flex-col">
|
||
<radio-group @change="onRefundChange">
|
||
<label
|
||
class="ss-flex ss-col-center ss-p-y-10"
|
||
v-for="(item, index) in state.wayList"
|
||
:key="index"
|
||
>
|
||
<radio
|
||
:checked="formData.type === item.value"
|
||
color="var(--color32)"
|
||
style="transform: scale(0.8)"
|
||
:value="item.value"
|
||
/>
|
||
<view class="item-value ss-m-l-8">{{ item.text }}</view>
|
||
</label>
|
||
</radio-group>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<!-- 退款金额 -->
|
||
<view class="card">
|
||
<view
|
||
class="refund-item ss-flex ss-col-center ss-row-between"
|
||
@tap="state.showModal = true"
|
||
>
|
||
<text class="item-title">退款金额</text>
|
||
<view class="ss-flex ss-col-center">
|
||
<text class="ss-m-r-20">¥{{ fen2yuan(state.payPrice) }}</text>
|
||
</view>
|
||
</view>
|
||
<!-- 申请原因 -->
|
||
|
||
<view class="refund-item ss-flex ss-col-center ss-row-between" @tap="toReason()">
|
||
<text class="item-title">申请原因</text>
|
||
<view class="ss-flex refund-cause ss-col-center" style="color: #999">
|
||
<text class="ss-m-r-20" v-if="formData.applyReason">{{ formData.applyReason }}</text>
|
||
<text class="ss-m-r-20" v-else>请选择申请原因~</text>
|
||
<text class="cicon-forward" style="height: 28rpx"></text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 留言 -->
|
||
<view class="refund-item">
|
||
<view class="item-title ss-m-b-20">相关描述</view>
|
||
<view class="describe-box">
|
||
<uni-easyinput
|
||
:inputBorder="false"
|
||
class="describe-content p-x-26 p-y-26 m-b-32"
|
||
type="textarea"
|
||
maxlength="120"
|
||
autoHeight
|
||
v-model="formData.applyDescription"
|
||
placeholder="客官~请描述您遇到的问题,建议上传照片"
|
||
/>
|
||
<view class="upload-img">
|
||
<s-uploader
|
||
v-model:url="formData.applyPicUrls"
|
||
fileMediatype="image"
|
||
limit="9"
|
||
mode="grid"
|
||
:imageStyles="{ width: '168rpx', height: '168rpx' }"
|
||
/>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</uni-forms>
|
||
|
||
<!-- 底部按钮 -->
|
||
<su-fixed bottom placeholder>
|
||
<view class="foot-wrap bg24">
|
||
<view class="ai-button" @tap="submit">提交</view>
|
||
</view>
|
||
</su-fixed>
|
||
|
||
<!-- 申请原因弹窗 -->
|
||
<su-popup :show="state.showModal" round="10" :showClose="true" @close="state.showModal = false">
|
||
<view class="modal-box page_box bg24">
|
||
<view class="modal-head item-title head_box ss-flex ss-row-center ss-col-center">
|
||
申请原因
|
||
</view>
|
||
<view class="modal-content content_box">
|
||
<radio-group @change="onChange">
|
||
<label class="radio ss-flex ss-col-center" v-for="item in state.reasonList" :key="item">
|
||
<view class="ss-flex-1 ss-p-20">{{ item }}</view>
|
||
<radio :value="item" color="var(--color32)" :checked="item === state.currentValue" />
|
||
</label>
|
||
</radio-group>
|
||
</view>
|
||
<view class="modal-foot foot_box ss-flex ss-row-center ss-col-center p-x-24 p-y-20">
|
||
<view class="ai-button" @tap="onReason">确认</view>
|
||
</view>
|
||
</view>
|
||
</su-popup>
|
||
</s-pages>
|
||
</template>
|
||
|
||
<script setup>
|
||
import sheep from '@/sheep';
|
||
import { onLoad } from '@dcloudio/uni-app';
|
||
import { computed, reactive, ref } from 'vue';
|
||
import OrderApi from '@/sheep/api/trade/order';
|
||
import TradeConfigApi from '@/sheep/api/trade/config';
|
||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||
import AfterSaleApi from '@/sheep/api/trade/afterSale';
|
||
import {
|
||
getOrderDetail as getAiOrderDetail,
|
||
getOpenOrderDetail,
|
||
} from '@/sheep/api/ai';
|
||
|
||
const form = ref(null);
|
||
const state = reactive({
|
||
orderId: 0, // 订单编号
|
||
itemId: 0, // 订单项编号
|
||
source: '', // 订单来源:空=普通商城订单 | aishop=店铺订单
|
||
order: {}, // 订单
|
||
item: {}, // 订单项
|
||
orderItems: [], // 用于展示的订单项列表(整单售后时展示全部,单品售后时展示单个)
|
||
config: {}, // 交易配置
|
||
payPrice: 0, // 退款金额:单品取item.payPrice,整单取外层order.payPrice
|
||
|
||
// 售后类型
|
||
wayList: [
|
||
{
|
||
text: '仅退款',
|
||
value: '10',
|
||
},
|
||
{
|
||
text: '退款退货',
|
||
value: '20',
|
||
},
|
||
],
|
||
reasonList: [], // 可选的申请原因数组
|
||
showModal: false, // 是否显示申请原因弹窗
|
||
currentValue: '', // 当前选择的售后原因
|
||
});
|
||
let formData = reactive({
|
||
way: '',
|
||
applyReason: '',
|
||
applyDescription: '',
|
||
applyPicUrls: [],
|
||
});
|
||
const rules = reactive({});
|
||
|
||
// 提交表单:接口 POST /trade/after-sale/create
|
||
// Body 直接就是数组:AppAfterSaleCreateReqVO[]
|
||
// - 单品售后(state.itemId > 0):数组只含 1 项,orderItemId = 当前商品项 id
|
||
// - 整单售后(state.itemId = 0):数组包含订单全部商品,每一项 orderItemId = 对应商品项 id,refundPrice = 该商品项自己的 payPrice
|
||
// 每个 VO 字段:orderItemId(必填)、way(1仅退款/2退货退款 必填)、refundPrice(单位分 必填)
|
||
// applyReason(必填 string)、applyDescription(选填)、applyPicUrls(选填 逗号拼接字符串)
|
||
async function submit() {
|
||
if (!formData.way) {
|
||
uni.showToast({ title: '请选择售后类型', icon: 'none' });
|
||
return;
|
||
}
|
||
if (!formData.applyReason) {
|
||
uni.showToast({ title: '请选择申请原因', icon: 'none' });
|
||
return;
|
||
}
|
||
// 通用字段(整单/单品都一样)
|
||
// way:不再做前端值到后端值的映射,配置的是多少就传多少(wayList.value = '10' 仅退款 / '20' 退货退款,直接转整数传)
|
||
const way = parseInt(formData.way, 10);
|
||
const applyReason = String(formData.applyReason);
|
||
const applyDescription = String(formData.applyDescription || '');
|
||
// applyPicUrls:类型应该是数组或 null(用户最新要求);有值传数组,没值传 null(不传空字符串)
|
||
let applyPicUrls = null;
|
||
if (Array.isArray(formData.applyPicUrls)) {
|
||
const list = formData.applyPicUrls.filter(Boolean);
|
||
applyPicUrls = list.length ? list : null;
|
||
} else if (formData.applyPicUrls) {
|
||
applyPicUrls = [String(formData.applyPicUrls)];
|
||
} else {
|
||
applyPicUrls = null;
|
||
}
|
||
|
||
// 选择要提交的订单项列表
|
||
let targetItems = [];
|
||
if (state.itemId > 0 && state.item?.id) {
|
||
// 单品售后:只传当前选择的这一个订单项
|
||
targetItems = [state.item];
|
||
} else {
|
||
// 整单售后:传所有商品项(orderItems 就是整个订单的 items 列表)
|
||
targetItems = Array.isArray(state.orderItems) ? state.orderItems.slice() : [];
|
||
}
|
||
if (!targetItems.length) {
|
||
uni.showToast({ title: '缺少可申请售后的商品', icon: 'none' });
|
||
return;
|
||
}
|
||
|
||
// 组装数组 AppAfterSaleCreateReqVO[](直接就是数组,不要外层对象包裹)
|
||
const body = targetItems
|
||
.filter((it) => it && it.id)
|
||
.map((it) => ({
|
||
orderItemId: it.id,
|
||
way,
|
||
// 退款金额:按订单项自己的 payPrice(单品=选中项payPrice,整单每项=对应项payPrice),安全兜底转 Number
|
||
refundPrice: Number(it.payPrice ?? 0) || 0,
|
||
applyReason,
|
||
applyDescription,
|
||
applyPicUrls,
|
||
}));
|
||
|
||
if (!body.length) {
|
||
uni.showToast({ title: '缺少订单项信息', icon: 'none' });
|
||
return;
|
||
}
|
||
|
||
const { code } = await AfterSaleApi.createAfterSale(body);
|
||
if (code === 0) {
|
||
uni.showToast({ title: '申请成功' });
|
||
uni.navigateBack({ delta: 1 });
|
||
} else {
|
||
uni.navigateBack({ delta: 1 });
|
||
}
|
||
}
|
||
//申请原因
|
||
function toReason() {
|
||
if (!formData.way) {
|
||
uni.showToast({
|
||
title: '请选择售后类型',
|
||
icon: 'none',
|
||
});
|
||
} else {
|
||
state.showModal = true;
|
||
}
|
||
}
|
||
// 选择售后类型
|
||
function onRefundChange(e) {
|
||
formData.way = e.detail.value;
|
||
// 清理理由
|
||
state.reasonList =
|
||
formData.way === '10'
|
||
? state.config.afterSaleRefundReasons || []
|
||
: state.config.afterSaleReturnReasons || [];
|
||
formData.applyReason = '';
|
||
state.currentValue = '';
|
||
}
|
||
|
||
// 选择申请原因
|
||
function onChange(e) {
|
||
state.currentValue = e.detail.value;
|
||
}
|
||
|
||
// 确定
|
||
function onReason() {
|
||
formData.applyReason = state.currentValue;
|
||
state.showModal = false;
|
||
}
|
||
|
||
onLoad(async (options) => {
|
||
// 解析参数:兼容单品入口(传orderId+itemId)和整单入口(传订单对象即props.data.id)
|
||
const orderId = parseInt(options.orderId || options.id);
|
||
const itemId = options.itemId ? parseInt(options.itemId) : 0;
|
||
// 订单来源:'aishop' = 普通店铺订单;空=普通商城订单。
|
||
// 注:用 source/__source/orderSource 三个命名从 options 里读,但 NEVER 从整个订单对象里读"同名字段 type"来判断是否开通店铺订单。
|
||
const source = String(options.source || options.orderSource || options.__source || '').trim();
|
||
// 开通店铺订单标记:只从 openOrderType / openOrder 里读(而不是订单对象里通用的 type 字段,避免普通商城订单的 type=0~4 被误命中)。
|
||
const openOrderType = String(options.openOrderType || options.openOrder || '').trim();
|
||
if (!orderId) {
|
||
sheep.$helper.toast(`缺少订单信息,请检查`);
|
||
return;
|
||
}
|
||
state.orderId = orderId;
|
||
state.itemId = itemId;
|
||
state.source = source;
|
||
|
||
// 读取订单详情:严格按入口参数分流,禁止普通商城订单 / 普通店铺订单误调开通店铺接口 /aishop/order/get-detail-open
|
||
//
|
||
// 开通店铺订单(ONLY:openOrderType === '5')
|
||
// → /aishop/order/get-detail-open
|
||
// 普通店铺订单(source === 'aishop' && 不是开通店铺)
|
||
// → /aishop/order/get-detail
|
||
// 普通商城订单(其他任何情况,包括没传 source/type 都算普通商城兜底)
|
||
// → /trade/order/get-detail ONLY
|
||
//
|
||
// 最后一道保险:如果我们选择了 getOpenOrderDetail,但返回的数据类型不是 5,说明命中错误 → 自动回退到对应接口。
|
||
let detailResult = null;
|
||
const isOpenOrder = openOrderType === '5';
|
||
const isAiStoreOrder = source === 'aishop';
|
||
|
||
async function loadMallOrder() {
|
||
return OrderApi.getOrderDetail(state.orderId);
|
||
}
|
||
async function loadAiOrder() {
|
||
return getAiOrderDetail({ id: state.orderId });
|
||
}
|
||
async function loadOpenOrder() {
|
||
const res = await getOpenOrderDetail({ id: state.orderId });
|
||
if (res?.code === 0 && res?.data && Number(res.data?.type) === 5) return res;
|
||
// 开了 openOrderType=5 但接口返回并不是 type=5 → 回退:按是否 aishop 来源决定
|
||
return isAiStoreOrder ? loadAiOrder() : loadMallOrder();
|
||
}
|
||
|
||
if (isOpenOrder) {
|
||
// 只有入口明确传 openOrderType=5 才调用开通店铺接口;返回不满足 type===5 时内部自动回退
|
||
detailResult = await loadOpenOrder();
|
||
} else if (isAiStoreOrder) {
|
||
// 普通店铺订单:只调店铺详情接口 /aishop/order/get-detail;绝对不碰 /get-detail-open
|
||
detailResult = await loadAiOrder();
|
||
} else {
|
||
// ★ 普通商城订单:只调 /trade/order/get-detail;永远不请求任何 aishop 前缀的接口
|
||
detailResult = await loadMallOrder();
|
||
}
|
||
if (!detailResult) {
|
||
return;
|
||
}
|
||
const { code, data } = detailResult;
|
||
if (code !== 0) {
|
||
return;
|
||
}
|
||
state.order = data;
|
||
|
||
// 按itemId精确查找订单项(单品入口),否则默认取第1项(整单入口仅用于商品卡片展示)
|
||
if (state.itemId > 0) {
|
||
state.item = data.items.find((item) => item.id === state.itemId) || {};
|
||
state.orderItems = state.item?.id ? [state.item] : [];
|
||
} else {
|
||
state.item = data.items?.[0] || {};
|
||
state.orderItems = Array.isArray(data.items) ? data.items : [];
|
||
}
|
||
|
||
// 退款金额:单品用订单项的payPrice,整单使用订单外层的payPrice(含randomDiscountPrice等优惠抵扣后的值)
|
||
if (state.itemId > 0 && state.item?.id) {
|
||
state.payPrice = state.item.payPrice;
|
||
} else {
|
||
state.payPrice = state.order.payPrice;
|
||
}
|
||
|
||
// 设置选项
|
||
if (state.order.status === 10) {
|
||
state.wayList.splice(1, 1);
|
||
}
|
||
|
||
// 读取配置
|
||
state.config = (await TradeConfigApi.getTradeConfig()).data;
|
||
});
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.card {
|
||
background: #fff;
|
||
}
|
||
|
||
.item-title {
|
||
font-size: 30rpx;
|
||
font-weight: bold;
|
||
// color: #ffffff;
|
||
// margin-bottom: 20rpx;
|
||
}
|
||
|
||
// 售后项目
|
||
.refund-item {
|
||
background: #fff;
|
||
border-bottom: 2rpx solid #f1f1f1; //var(--color24)
|
||
padding: 30rpx;
|
||
margin: 0 22rpx;
|
||
|
||
&:last-child {
|
||
border: none;
|
||
}
|
||
|
||
// 留言
|
||
.describe-box {
|
||
// width: 690rpx;
|
||
//background: var(--color24);
|
||
// padding: 30rpx;
|
||
box-sizing: border-box;
|
||
border-radius: 20rpx;
|
||
|
||
.describe-content {
|
||
min-height: 200rpx;
|
||
font-size: 24rpx;
|
||
font-weight: 400;
|
||
color: #333;
|
||
background: #f9fafc;
|
||
border-radius: 24rpx;
|
||
// padding: 26rpx;
|
||
}
|
||
}
|
||
|
||
// 联系方式
|
||
.input-box {
|
||
height: 84rpx;
|
||
background: rgba(249, 250, 251, 1);
|
||
border-radius: 20rpx;
|
||
}
|
||
}
|
||
|
||
.goods-box {
|
||
padding: 20rpx;
|
||
margin: 32rpx 0;
|
||
background: #fff;
|
||
}
|
||
|
||
.ai-button {
|
||
border-radius: 12rpx;
|
||
color: #fff;
|
||
}
|
||
|
||
.foot-wrap {
|
||
height: 120rpx;
|
||
width: 100%;
|
||
padding: 10rpx 40rpx;
|
||
box-sizing: border-box;
|
||
|
||
.submit-btn {
|
||
height: 100%;
|
||
}
|
||
}
|
||
|
||
.foot_box {
|
||
height: 100rpx;
|
||
|
||
.sub-btn {
|
||
width: 336rpx;
|
||
line-height: 74rpx;
|
||
border-radius: 38rpx;
|
||
color: rgba(#fff, 0.9);
|
||
font-size: 28rpx;
|
||
}
|
||
|
||
.contcat-btn {
|
||
width: 336rpx;
|
||
line-height: 74rpx;
|
||
background: rgba(238, 238, 238, 1);
|
||
border-radius: 38rpx;
|
||
font-size: 28rpx;
|
||
font-weight: 400;
|
||
color: rgba(51, 51, 51, 1);
|
||
}
|
||
}
|
||
|
||
.modal-box {
|
||
width: 750rpx;
|
||
// height: 680rpx;
|
||
border-radius: 30rpx 30rpx 0 0;
|
||
|
||
.modal-head {
|
||
height: 100rpx;
|
||
font-size: 30rpx;
|
||
}
|
||
|
||
.modal-content {
|
||
font-size: 28rpx;
|
||
}
|
||
|
||
.modal-foot {
|
||
.close-btn {
|
||
width: 710rpx;
|
||
line-height: 80rpx;
|
||
border-radius: 40rpx;
|
||
color: rgba(#fff, 0.9);
|
||
}
|
||
}
|
||
}
|
||
|
||
.success-box {
|
||
width: 600rpx;
|
||
padding: 90rpx 0 64rpx 0;
|
||
|
||
.cicon-check-round {
|
||
font-size: 96rpx;
|
||
color: #04b750;
|
||
}
|
||
|
||
.success-title {
|
||
font-weight: 500;
|
||
color: #333333;
|
||
font-size: 32rpx;
|
||
}
|
||
|
||
.success-btn {
|
||
width: 492rpx;
|
||
height: 70rpx;
|
||
background: linear-gradient(90deg, var(--ui-BG-Main-gradient), var(--ui-BG-Main));
|
||
border-radius: 35rpx;
|
||
}
|
||
}
|
||
</style>
|