This commit is contained in:
YeMingfei666 2024-11-18 16:23:05 +08:00
commit 8e201b7554
3 changed files with 68 additions and 65 deletions

View File

@ -3,16 +3,23 @@
<template #desc> <template #desc>
<view class="u-text-left u-p-30 color-666"> <view class="u-text-left u-p-30 color-666">
<view class="u-m-t-32 u-flex "> <view class="u-m-t-32 u-flex ">
<view class="color-red">*</view> <view class="u-m-l-32" v-if="accountPoints.calcRes.usable">
<view class="u-m-l-32"> <text class="color-red">*</text>
<text class=""
v-if="accountPoints.calcRes.equivalentPoints">100积分等于{{to2(accountPoints.calcRes.equivalentPoints*100)}},</text>
<text>
最大抵扣积分{{accountPoints.calcRes.maxUsablePoints}}
</text>
<text>,
最小抵扣积分0
</text>
</view> </view>
</view> </view>
<view class="u-m-t-40 u-flex "> <view class="u-m-t-40 u-flex ">
<view>积分</view> <view>积分</view>
<view class="u-m-l-32 border u-p-l-10 u-p-r-10 u-flex-1"> <view class="u-m-l-32 border u-p-l-10 u-p-r-10 u-flex-1">
<uni-easyinput type="number" @input="currentPriceInput" @change="currentPriceChange" paddingNone :inputBorder="false" <uni-easyinput type="number" @input="pointsInput" @change="pointsChange" paddingNone
v-model="form.currentPrice" :inputBorder="false" v-model="form.points" placeholder="输入积分抵扣数量"></uni-easyinput>
placeholder="输入实际金额"></uni-easyinput>
</view> </view>
</view> </view>
</view> </view>
@ -34,7 +41,8 @@
import { import {
reactive, reactive,
nextTick, nextTick,
ref,watch ref,
watch
} from 'vue'; } from 'vue';
import myModel from '@/components/my-components/my-model.vue' import myModel from '@/components/my-components/my-model.vue'
import myButton from '@/components/my-components/my-button.vue' import myButton from '@/components/my-components/my-button.vue'
@ -45,76 +53,68 @@
type: String, type: String,
default: '积分抵扣' default: '积分抵扣'
}, },
data: { accountPoints:{
type: Array, type:Object,
default: [] default:()=>{
}, return {
discount:{ calcRes:{
type: [Number,String], usable: false,
default:100 unusableReason: '',
minDeductionPoints: 0,
maxUsablePoints: 0
}
}
}
}, },
price: { price: {
type: [Number, String], type: [Number, String],
default: 0 default: 0
} }
}) })
function currentPriceInput(newval){
form.discount=(newval*100/form.price).toFixed() function to2(n) {
if (!n) {
return ''
} }
function discountInput(newval){ return n.toFixed(2)
form.currentPrice=(form.price*newval/100).toFixed(2)
} }
function currentPriceChange(newval){
function pointsInput(e){
setTimeout(()=>{
form.points=Math.floor(e)
},100)
}
function pointsChange(newval) {
form.points=Math.floor(newval)
if (newval < 0) { if (newval < 0) {
form.currentPrice=0 form.points = 0
form.discount=100 return infoBox.showToast('积分抵扣不能小于0')
return infoBox.showToast('实收金额不能小于0')
} }
if(newval>props.price){ if (newval > props.accountPoints.calcRes.maxUsablePoints) {
form.currentPrice=props.price form.points = props.price
form.discount=0 return infoBox.showToast('积分抵扣不能大于'+props.accountPoints.calcRes.maxUsablePoints)
return infoBox.showToast('实收金额不能大于应付金额')
}
}
function discountChange(newval){
if(newval<0){
form.currentPrice=props.price
form.discount=0
return infoBox.showToast('优惠折扣不能小于0')
}
if(newval>100){
form.discount=100
form.currentPrice=0
return infoBox.showToast('优惠折扣不能大于100')
} }
} }
const $form = {
price:props.price,
currentPrice: props.price,
discount: 100
}
const form = reactive({ const form = reactive({
...$form points: props.price,
}) })
watch(() => props.price, (newval) => { watch(() => props.price, (newval) => {
console.log(newval); form.points = newval
form.price=newval
form.currentPrice=newval
}) })
function resetForm() { function resetForm() {
Object.assign(form, { form.points=0
...$form
})
} }
const model = ref(null) const model = ref(null)
function open() { function open() {
model.value.open() model.value.open()
form.price=props.price form.points = props.price
form.currentPrice=props.price
form.discount=props.discount
} }
function close() { function close() {
@ -123,8 +123,7 @@
const emits = defineEmits(['confirm']) const emits = defineEmits(['confirm'])
function confirm() { function confirm() {
console.log(form); emits('confirm',Math.floor(form.points) )
emits('confirm',{...form,currentPrice:Number(form.currentPrice).toFixed(2)})
close() close()
} }
defineExpose({ defineExpose({
@ -139,6 +138,7 @@
overflow: hidden; overflow: hidden;
border-color: #999; border-color: #999;
} }
.lh34 { .lh34 {
line-height: 34rpx; line-height: 34rpx;
} }

View File

@ -196,7 +196,7 @@
<edit-discount @confirm="editDiscountConfirm" title="优惠金额" :ref="setModel" name="editMoney" <edit-discount @confirm="editDiscountConfirm" title="优惠金额" :ref="setModel" name="editMoney"
:price="order.amount"></edit-discount> :price="order.amount"></edit-discount>
<edit-accountPoints ref="refPoints"></edit-accountPoints> <edit-accountPoints @confirm="pointsConfirm" :price="accountPoints.num" :accountPoints="accountPoints" ref="refPoints"></edit-accountPoints>
</view> </view>
</template> </template>
@ -251,6 +251,9 @@
}, },
price: 0 price: 0
}) })
function pointsConfirm(e){
accountPoints.num=e
}
async function calcUsablePoints() { async function calcUsablePoints() {
if (!order.memberId) { if (!order.memberId) {
return return

View File

@ -54,7 +54,7 @@ export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
} }
} }
const memberPrice = item.memberPrice ? item.memberPrice : item.price; const memberPrice = item.memberPrice ? item.memberPrice : item.price;
const price = item ? (vipUser(vipUser,item) ? memberPrice : item.price) : 0; const price = item ? (isUseVipPrice(vipUser,item) ? memberPrice : item.price) : 0;
const discountAmount = (price * coup.num).toFixed(2) const discountAmount = (price * coup.num).toFixed(2)
console.log(discountAmount); console.log(discountAmount);
@ -85,7 +85,7 @@ export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
//返回商品实际支付价格 //返回商品实际支付价格
export function returnProductPayPrice(goods,vipUser){ export function returnProductPayPrice(goods,vipUser){
const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price; const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price;
const price = (vipUser,item) ? memberPrice : item.price; const price = isUseVipPrice(vipUser,goods) ? memberPrice : goods.price;
return price return price
} }
//返回商品券抵扣的商品价格 //返回商品券抵扣的商品价格