下单退款相关更新

This commit is contained in:
GaoHao
2025-03-15 18:30:27 +08:00
parent c2135c6119
commit 994cf8bf2b
54 changed files with 682 additions and 2408 deletions

View File

@@ -1,16 +1,23 @@
<template>
<view class="min-page bg-gray u-p-30">
<view class="bg-fff u-p-24 border-r-12 u-flex u-row-between">
<view>全退</view>
<view>
<my-radio v-model="allTui" :disabled="option.productId=='-999'"></my-radio>
<view class="bg-fff u-p-l-30 u-p-r-30 ">
<view class="myTabs u-m-t-20">
<my-tabs :list="pageData.tabsList" :modelValue="pageData.tabsIndex" :textKey="'label'" @change="tabsChange"></my-tabs>
</view>
</view>
<view v-if="pageData.tabsIndex == 2" class="bg-fff u-p-24 border-r-12 u-flex u-row-between" style="margin-top: 30rpx;">
<up-input type="digit" placeholder="请输入退款金额" @change="parseIntNumber($event)" border="surround" v-model="pageData.modify" >
<template #prefix>
<up-text text="¥" margin="0 3px 0 0" type="tips" ></up-text>
</template>
</up-input>
</view>
<view class="u-m-t-24 u-font-24 u-font-24">
<text class="color-red">*</text>
<text>客座费只能全退</text>
</view>
<view class="bg-fff border-r-12 list u-m-t-32">
<view v-if="pageData.tabsIndex != 2" class="bg-fff border-r-12 list u-m-t-32">
<view class="u-flex u-row-between border-top item u-p-t-32 u-p-b-32"
v-for="(item,index) in orderDetail.goodsList" :key="index">
<view>
@@ -43,23 +50,30 @@
<view class="bg-fff u-m-t-32 u-p-24 border-r-12 u-flex u-row-between" >
<view>支付金额</view>
<view>
{{to2(totalPrice)}}
{{to2(orderDetail.info.payAmount)}}
</view>
</view>
<view class="bg-fff u-m-t-32 u-p-24 border-r-12 u-flex u-row-between" >
<view>剩余可退金额</view>
<view class="color-red">
{{to2(orderDetail.info.payAmount - orderDetail.info.refundAmount)}}
</view>
</view>
<view class="bg-fff u-m-t-32 u-p-24 border-r-12 u-flex u-row-between" >
<view>退款金额</view>
<view class="color-red">
{{to2(tuikuanPrice)}}
{{to2(pageData.tabsIndex == 1 ? alltuikuanPrice : (pageData.tabsIndex == 2 ? pageData.modify : tuikuanPrice))}}
</view>
</view>
</template>
<view class="bg-fff u-p-24 border-r-12 u-m-t-32">
<!-- <view class="bg-fff u-p-24 border-r-12 u-m-t-32">
<view>退回优惠券</view>
<view class="u-font-24 color-999 u-m-t-16" v-if="!option.userCouponId">
该订单未使用优惠券
</view>
</view>
</view> -->
<view class="bg-fff u-p-24 border-r-12 u-m-t-32">
<view>
<text class="color-red">*</text>
@@ -92,36 +106,25 @@
import infoBox from '@/commons/utils/infoBox.js';
import {hasPermission} from '@/commons/utils/hasPermission.js'
import { refundOrder } from '@/http/api/order.js'
let allTui = ref(false)
import { mathFloorPrice } from '@/commons/utils/goodsUtil.js'
let note = ref('')
const tuikuan = reactive({
list: ['点错', '数量点错', '客人要求', '协商退费'],
sel: -1
})
const pageData = reactive({
tabsList: [
{label: '部分退款', value: 0},
{label: '全部退款', value: 1},
{label: '自定义退款', value: 2},
],
tabsIndex: 0,
modify: '',
})
const option=reactive({
productId:'-999'
})
onLoad((opt) => {
console.log(JSON.parse(opt.goodsList));
orderDetail.goodsList = JSON.parse(opt.goodsList)
option.productId = orderDetail.goodsList[0].productId
option.orderId = orderDetail.goodsList[0].orderId
if(option.productId=='-999'){
allTui.value=true
}
})
watch(() => allTui.value, (newval) => {
orderDetail.goodsList.map(v => {
v.number = newval ? v.num : 0
})
})
function changeTuiKuanSel(i) {
tuikuan.sel = i
}
const orderDetail = reactive({
goodsList: [],
info: {},
@@ -129,53 +132,120 @@
totalAmount: 0
}
})
onLoad((opt) => {
orderDetail.info = JSON.parse(opt.orderInfo)
orderDetail.goodsList = JSON.parse(opt.goodsList)
console.log(orderDetail)
option.productId = orderDetail.goodsList[0].productId
option.orderId = orderDetail.goodsList[0].orderId
})
/**
* tabs切换
* @param {Object} i
*/
function tabsChange(i) {
pageData.tabsIndex = pageData.tabsList[i].value
if( pageData.tabsIndex == 0){ // 部分退款
orderDetail.goodsList.map(v => {
v.number = '0.00'
})
}
if( pageData.tabsIndex == 1){ // 全部退款
orderDetail.goodsList.map(v => {
v.number = v.num.toFixed(2)
})
}
if( pageData.tabsIndex == 2){ // 自定义退款
orderDetail.goodsList.map(v => {
v.number = '0.00'
})
}
}
function changeTuiKuanSel(i) {
tuikuan.sel = i
}
function parseIntNumber (e) {
if ( e > (orderDetail.info.payAmount - orderDetail.info.refundAmount) ) {
setTimeout(()=>{
pageData.modify = (orderDetail.info.payAmount - orderDetail.info.refundAmount).toFixed(2)
},100)
}
}
/**
* 菜品总数量
*/
const totalNumber = computed(() => {
return orderDetail.goodsList.reduce((prve, cur) => {
return prve + cur.num * 1
}, 0)
})
/**
* 退款菜品总数量
*/
const tuikuanNumber = computed(() => {
return orderDetail.goodsList.reduce((prve, cur) => {
return prve + cur.number * 1
}, 0)
})
const totalPrice = computed(() => {
return orderDetail.goodsList.reduce((prve, cur) => {
return prve + cur.priceAmount * 1
}, 0)
})
/**
* 退款总金额
*/
const tuikuanPrice = computed(() => {
return orderDetail.goodsList.reduce((prve, cur) => {
const n=(cur.number/cur.num*100) * cur.priceAmount
console.log(n)
console.log((n/100).toFixed(2))
console.log(parseFloat(prve) + parseFloat((n/100).toFixed(2)))
return parseFloat(prve) + parseFloat((n/100).toFixed(2))
const n= mathFloorPrice(cur.number * cur.unitPrice,cur)
return (parseFloat(prve) + parseFloat(n)).toFixed(2)
}, 0)
})
/**
* 剩余退款金额
*/
const surplusRefundPrice = computed(() => {
return orderDetail.info.payAmount - orderDetail.goodsList.reduce((prve, cur) => {
const n = parseFloat( mathFloorPrice(cur.refundNum * cur.unitPrice,cur))
return (parseFloat(prve) + parseFloat(n)).toFixed(2)*1
}, 0)
})
/**
* 退款总金额
*/
const alltuikuanPrice = computed(() => {
return orderDetail.info.payAmount - orderDetail.goodsList.reduce((prve, cur) => {
const n = parseFloat( mathFloorPrice(cur.refundNum * cur.unitPrice,cur))
return (parseFloat(prve) + parseFloat(n)).toFixed(2)*1
}, 0)
})
function to2(n) {
return Number(n).toFixed(2);
}
function changeItem(item, step) {
if( item.num <= 0){
return
}
if(item.productId=='-999'){
return
}
console.log(item);
if( pageData.tabsIndex != 0) {
return;
}
let newval = item.number * 1 + step * 1;
if (newval <= 0) {
newval = 0;
}
if (newval >= (item.num-(item.refundNum>0?item.refundNum:0))) {
newval = (item.num-(item.refundNum>0?item.refundNum:0));
if (newval >= (item.num)) {
newval = item.num
}
item.number = newval;
allTui.value = totalNumber.value == tuikuanNumber.value ? true : false;
console.log(totalNumber.value)
console.log(tuikuanNumber.value)
item.number = newval.toFixed(2);
pageData.tabsIndex = totalNumber.value == tuikuanNumber.value ? 1 : 0;
}
/**
@@ -186,20 +256,18 @@
if(!canTuikuan){
return infoBox.showToast('您没有退款权限')
}
if (tuikuanNumber.value <= 0) {
if (pageData.tabsIndex != 2&&tuikuanNumber.value <= 0) {
return infoBox.showToast('退款商品数量不能为0')
}
const selTag=tuikuan.list[tuikuan.sel]
const noteResult=`${selTag?selTag:''}${note.value?(','+note.value):''}`
if (!noteResult) {
return infoBox.showToast('请输入或选择退款原因!')
}
let refundAmount = orderDetail.goodsList.reduce((prve, cur) => {
return prve + (cur.number * 1 * cur.unitPrice)
}, 0)
let params = {
orderId: option.orderId,
refundAmount: refundAmount.toFixed(2),
refundReason: noteResult,
refundDetails: orderDetail.goodsList.filter(v=>v.number*1).map(v=>{
return {
@@ -209,6 +277,16 @@
}
})
}
if( pageData.tabsIndex == 2){
params.modify = true
params.refundAmount = (pageData.modify*1).toFixed(2)
} else {
params.modify = false
params.refundAmount = pageData.tabsIndex == 1 ? alltuikuanPrice.value : tuikuanPrice.value
}
if ( pageData.tabsIndex == 2 && params.refundAmount > orderDetail.info.payAmount){
return infoBox.showToast('退款金额不能大于付款金额!')
}
await refundOrder(params)
infoBox.showToast('退款请求提交成功')
setTimeout(()=>{