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

View File

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

View File

@ -54,7 +54,7 @@ export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
}
}
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)
console.log(discountAmount);
@ -85,7 +85,7 @@ export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
//返回商品实际支付价格
export function returnProductPayPrice(goods,vipUser){
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
}
//返回商品券抵扣的商品价格