buddhism/components/donate-modal/donate-modal.vue
2025-08-05 15:28:29 +08:00

248 lines
5.0 KiB
Vue

<template>
<view class="donate-modal" v-if="visible" @click="handleClose">
<view class="modal-content" @click.stop>
<!-- 弹窗标题 -->
<view class="modal-header">
<text class="modal-title">{{ title }}</text>
<image class="modal-icon" :src="CommonEnum.LotusMeditation" mode="aspectFit" />
</view>
<!-- 输入区域 -->
<view class="input-section">
<input
class="amount-input"
:placeholder="placeholder"
v-model="localAmount"
type="number"
:disabled="isRandomAmount"
/>
<view class="random-option" @click="toggleRandomAmount">
<view class="radio-button" :class="{ 'checked': isRandomAmount }">
<image v-if="isRandomAmount" class="radio-icon" :src="CommonEnum.Refresh" mode="aspectFit" />
</view>
<text class="option-text">{{ randomText }}</text>
</view>
</view>
<!-- 确认按钮 -->
<view class="confirm-button" @click="handleConfirm">
<text class="button-text">{{ confirmText }}</text>
</view>
</view>
</view>
</template>
<script>
import CommonEnum from "../../enum/common";
export default {
name: 'DonateModal',
props: {
// 是否显示弹窗
visible: {
type: Boolean,
default: false
},
// 弹窗标题
title: {
type: String,
default: '随喜'
},
// 输入框占位符
placeholder: {
type: String,
default: '请输入金额'
},
// 随缘选项文字
randomText: {
type: String,
default: '随缘'
},
// 确认按钮文字
confirmText: {
type: String,
default: '确认行善'
},
// 默认金额
defaultAmount: {
type: String,
default: ''
}
},
data() {
return {
CommonEnum,
localAmount: '',
isRandomAmount: false
}
},
watch: {
visible(newVal) {
if (newVal) {
this.localAmount = this.defaultAmount;
this.isRandomAmount = false;
}
},
defaultAmount(newVal) {
if (this.visible) {
this.localAmount = newVal;
}
}
},
methods: {
// 关闭弹窗
handleClose() {
this.$emit('close');
},
// 切换随机金额选项
toggleRandomAmount() {
this.isRandomAmount = !this.isRandomAmount;
if (this.isRandomAmount) {
this.localAmount = '';
}
},
// 确认操作
handleConfirm() {
if (!this.localAmount && !this.isRandomAmount) {
uni.showToast({
title: '请输入金额或选择随缘',
icon: 'none'
});
return;
}
// 触发确认事件
this.$emit('confirm', {
amount: this.localAmount,
isRandom: this.isRandomAmount
});
}
}
}
</script>
<style lang="scss" scoped>
.donate-modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background-color: #FFFFFF;
border-radius: 20rpx;
padding: 40rpx;
width: 80%;
max-width: 600rpx;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.3);
}
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-bottom: 30rpx;
padding-bottom: 20rpx;
border-bottom: 2rpx solid #F0EBE0;
.modal-title {
font-size: 40rpx;
font-weight: bold;
color: #695347;
}
.modal-icon {
width: 60rpx;
height: 60rpx;
}
}
.input-section {
width: 100%;
margin-bottom: 30rpx;
display: flex;
align-items: center;
gap: 20rpx;
.amount-input {
flex: 1;
height: 100rpx;
background-color: #F5F0E7;
border: 2rpx solid #E0D7C9;
border-radius: 10rpx;
padding: 0 20rpx;
font-size: 36rpx;
color: #695347;
text-align: right;
}
.random-option {
display: flex;
align-items: center;
gap: 10rpx;
cursor: pointer;
.radio-button {
width: 40rpx;
height: 40rpx;
border: 2rpx solid #E0D7C9;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
background-color: #F5F0E7;
&.checked {
border-color: #8B2E2E;
background-color: #8B2E2E;
}
.radio-icon {
width: 24rpx;
height: 24rpx;
}
}
.option-text {
font-size: 32rpx;
color: #695347;
}
}
}
.confirm-button {
width: 100%;
height: 100rpx;
background-color: #8B2E2E;
border-radius: 50rpx;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 8rpx 20rpx rgba(139, 46, 46, 0.3);
transition: all 0.3s ease;
&:active {
background-color: #7A2A2A;
transform: scale(0.98);
}
.button-text {
color: #FFFFFF;
font-size: 36rpx;
font-weight: bold;
}
}
</style>