订单支付增加编辑积分

This commit is contained in:
2024-11-18 16:22:21 +08:00
parent 66e415051b
commit 86e920017b
2 changed files with 66 additions and 63 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>
@@ -20,9 +27,9 @@
<template #btn> <template #btn>
<view class="u-p-30"> <view class="u-p-30">
<view class="u-m-t-10"> <view class="u-m-t-10">
<my-button @tap="confirm" shape="circle" fontWeight="700" >修改</my-button> <my-button @tap="confirm" shape="circle" fontWeight="700">修改</my-button>
<view class=""> <view class="">
<my-button @tap="close" type="cancel" bgColor="#fff" >取消</my-button> <my-button @tap="close" type="cancel" bgColor="#fff">取消</my-button>
</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) {
function discountInput(newval){ return ''
form.currentPrice=(form.price*newval/100).toFixed(2)
}
function currentPriceChange(newval){
if(newval<0){
form.currentPrice=0
form.discount=100
return infoBox.showToast('实收金额不能小于0')
}
if(newval>props.price){
form.currentPrice=props.price
form.discount=0
return infoBox.showToast('实收金额不能大于应付金额')
} }
return n.toFixed(2)
} }
function discountChange(newval){
if(newval<0){ function pointsInput(e){
form.currentPrice=props.price setTimeout(()=>{
form.discount=0 form.points=Math.floor(e)
return infoBox.showToast('优惠折扣不能小于0') },100)
}
function pointsChange(newval) {
form.points=Math.floor(newval)
if (newval < 0) {
form.points = 0
return infoBox.showToast('积分抵扣不能小于0')
} }
if(newval>100){ if (newval > props.accountPoints.calcRes.maxUsablePoints) {
form.discount=100 form.points = props.price
form.currentPrice=0 return infoBox.showToast('积分抵扣不能大于'+props.accountPoints.calcRes.maxUsablePoints)
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({
@@ -134,11 +133,12 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.border{ .border {
border-radius: 8rpx; border-radius: 8rpx;
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