buddhism/pages/pray/pray.vue

472 lines
11 KiB
Vue
Raw Normal View History

2025-08-04 17:45:45 +08:00
<template>
<view class="page">
<view class="navbar-container">
<custom-navbar title="在线祈福" />
</view>
<view class="background-container">
<image class="background-image" :src="CommonEnum.BUDDHA_BACKGROUND" mode="aspectFit" />
</view>
<view class="header">
<!-- 香炉图标 -->
<view class="censer-container">
<image class="censer-icon" :src="CommonEnum.CENSER" mode="aspectFit" />
</view>
2025-08-04 17:59:54 +08:00
<!-- 祈福信息表单 -->
2025-08-05 10:43:31 +08:00
<view class="prayer-form-background">
<view class="prayer-form">
<view class="form-title">
<text class="title-text">祈福信息</text>
2025-08-04 17:59:54 +08:00
</view>
2025-08-05 10:43:31 +08:00
<!-- 祈福人姓名 -->
<view class="form-item">
<text class="label">祈福人姓名</text>
<input class="input-field" placeholder="请输入姓名" v-model="formData.name" />
</view>
<!-- 祈福类型 -->
<view class="form-item">
<text class="label">祈福类型</text>
<view class="select-field" @click="showPrayerTypePicker">
<text class="select-text">{{ selectedPrayerType }}</text>
<text class="arrow">></text>
2025-08-04 17:59:54 +08:00
</view>
2025-08-05 10:43:31 +08:00
</view>
<!-- 为他人祈福 -->
<view class="form-item">
<text class="label">为他人祈福</text>
<view class="radio-group">
2025-08-05 14:29:08 +08:00
<view class="radio-item" @click="formData.forOthers = 1">
2025-08-05 10:43:31 +08:00
<text class="radio-text"></text>
2025-08-05 14:29:08 +08:00
<view class="radio-button" :class="{ 'checked': formData.forOthers === 1 }">
<text v-if="formData.forOthers === 1" class="checkmark"></text>
2025-08-05 10:43:31 +08:00
</view>
</view>
2025-08-05 14:29:08 +08:00
<view class="radio-item" @click="formData.forOthers = 2">
2025-08-05 10:43:31 +08:00
<text class="radio-text"></text>
2025-08-05 14:29:08 +08:00
<view class="radio-button" :class="{ 'checked': formData.forOthers === 2 }">
<text v-if="formData.forOthers === 2" class="checkmark"></text>
2025-08-05 10:43:31 +08:00
</view>
2025-08-04 17:59:54 +08:00
</view>
</view>
</view>
2025-08-05 10:43:31 +08:00
<!-- 心愿内容 -->
<view class="form-item">
<text class="label">心愿内容</text>
<view class="textarea-container">
<textarea
class="textarea-field"
placeholder="请填写心愿内容"
v-model="formData.wish"
maxlength="50"
:show-confirm-bar="false"
2025-08-04 17:59:54 +08:00
/>
2025-08-05 10:43:31 +08:00
<text class="char-counter">{{ formData.wish.length }}/50</text>
</view>
2025-08-04 17:59:54 +08:00
</view>
</view>
</view>
<!-- 敬香按钮 -->
2025-08-05 14:41:40 +08:00
<bottom-button
title="敬香"
type="primary"
@click="submitPrayer"
/>
2025-08-04 17:45:45 +08:00
</view>
</view>
</template>
<script>
import CommonEnum from "../../enum/common";
import CustomNavbar from "../../components/custom-navbar/custom-navbar.vue";
2025-08-05 14:41:40 +08:00
import BottomButton from "../../components/bottom-button/bottom-button.vue";
2025-08-05 14:29:08 +08:00
import { submitPrayer } from "@/api/pray/pray";
2025-08-04 17:45:45 +08:00
export default {
components: {
CustomNavbar,
2025-08-05 14:41:40 +08:00
BottomButton,
2025-08-04 17:45:45 +08:00
},
data() {
return {
CommonEnum,
2025-08-04 17:59:54 +08:00
loading: false,
formData: {
name: '',
2025-08-05 14:29:08 +08:00
prayerType: '1', // 默认祈福类型
forOthers: 2, // 默认不为他人祈福
2025-08-04 17:59:54 +08:00
wish: ''
},
2025-08-05 14:29:08 +08:00
prayerTypes: [
{ label: '学业', value: 1 },
{ label: '健康', value: 2 },
{ label: '姻缘', value: 3 },
{ label: '财运', value: 4 },
{ label: '消灾', value: 5 }
],
2025-08-05 11:29:47 +08:00
selectedPrayerType: '学业',
2025-08-05 14:29:08 +08:00
selectedPrayerTypeValue: 1,
2025-08-04 17:59:54 +08:00
showPicker: false
2025-08-04 17:45:45 +08:00
}
},
onLoad() {
// 页面加载时获取数据
this.loadPageData()
},
methods: {
// 加载页面数据
async loadPageData() {
this.loading = true
try {
// TODO: 调用页面数据API
// const response = await getPageData()
// 模拟加载
setTimeout(() => {
this.loading = false
}, 1000)
} catch (error) {
console.error('获取页面数据失败:', error)
this.loading = false
}
2025-08-04 17:59:54 +08:00
},
// 提交祈福
submitPrayer() {
// 表单验证
2025-08-05 14:29:08 +08:00
if (!this.validateForm()) {
return;
2025-08-04 17:59:54 +08:00
}
2025-08-05 14:29:08 +08:00
// 显示确认信息
this.showConfirmation();
},
// 表单验证
validateForm() {
if (!this.formData.name?.trim()) {
uni.showToast({ title: '请输入祈福人姓名', icon: 'none' });
return false;
2025-08-04 17:59:54 +08:00
}
2025-08-05 14:29:08 +08:00
if (!this.selectedPrayerTypeValue) {
uni.showToast({ title: '请选择祈福类型', icon: 'none' });
return false;
}
if (!this.formData.wish?.trim()) {
uni.showToast({ title: '请填写心愿内容', icon: 'none' });
return false;
}
return true;
},
// 显示确认信息
showConfirmation() {
2025-08-04 17:59:54 +08:00
uni.showModal({
title: '确认祈福信息',
2025-08-05 14:29:08 +08:00
content: `祈福人:${this.formData.name}\n祈福类型${this.selectedPrayerType}\n为他人祈福${this.formData.forOthers === 1 ? '是' : '否'}\n心愿内容${this.formData.wish}`,
2025-08-04 17:59:54 +08:00
confirmText: '确认敬香',
cancelText: '修改信息',
success: (res) => {
if (res.confirm) {
2025-08-05 14:29:08 +08:00
this.performPrayer();
2025-08-04 17:59:54 +08:00
}
}
2025-08-05 14:29:08 +08:00
});
2025-08-04 17:59:54 +08:00
},
// 执行祈福
async performPrayer() {
2025-08-05 14:29:08 +08:00
uni.showLoading({ title: '正在敬香...' });
2025-08-04 17:59:54 +08:00
try {
2025-08-05 14:29:08 +08:00
const response = await submitPrayer({
name: this.formData.name.trim(),
type: this.selectedPrayerTypeValue,
isOthers: this.formData.forOthers,
content: this.formData.wish.trim()
});
2025-08-04 17:59:54 +08:00
2025-08-05 14:29:08 +08:00
uni.hideLoading();
2025-08-04 17:59:54 +08:00
2025-08-05 14:29:08 +08:00
if (response.code === 200) {
uni.showToast({ title: '祈福成功!', icon: 'success' });
this.resetForm();
// 跳转到祈福成功页面
setTimeout(() => {
uni.navigateTo({
url: '/pages/pray/praySuccess'
});
}, 1500);
2025-08-05 14:29:08 +08:00
} else {
uni.showToast({ title: response.msg || '祈福失败,请重试', icon: 'none' });
}
2025-08-04 17:59:54 +08:00
} catch (error) {
2025-08-05 14:29:08 +08:00
console.error('祈福请求失败:', error);
uni.hideLoading();
uni.showToast({ title: '网络错误,请重试', icon: 'none' });
2025-08-04 17:59:54 +08:00
}
},
// 重置表单
resetForm() {
this.formData = {
name: '',
2025-08-05 14:29:08 +08:00
prayerType: '1',
forOthers: 2,
2025-08-04 17:59:54 +08:00
wish: ''
}
2025-08-05 11:29:47 +08:00
this.selectedPrayerType = '学业'
2025-08-05 14:29:08 +08:00
this.selectedPrayerTypeValue = 1
2025-08-04 17:59:54 +08:00
},
// 显示祈福类型选择器
showPrayerTypePicker() {
uni.showActionSheet({
2025-08-05 14:29:08 +08:00
itemList: this.prayerTypes.map(item => item.label),
2025-08-04 17:59:54 +08:00
success: (res) => {
2025-08-05 11:29:47 +08:00
if (res.tapIndex !== undefined && res.tapIndex >= 0 && res.tapIndex < this.prayerTypes.length) {
const selectedType = this.prayerTypes[res.tapIndex];
// 更新选中的祈福类型
2025-08-05 14:29:08 +08:00
this.selectedPrayerType = selectedType.label;
this.selectedPrayerTypeValue = selectedType.value;
2025-08-05 11:29:47 +08:00
// 同步更新表单数据
2025-08-05 14:29:08 +08:00
this.formData.prayerType = selectedType.value;
2025-08-05 11:29:47 +08:00
}
2025-08-04 17:59:54 +08:00
},
fail: (res) => {
2025-08-05 11:29:47 +08:00
console.log('用户取消选择或选择失败:', res);
2025-08-04 17:59:54 +08:00
}
});
2025-08-04 17:45:45 +08:00
}
}
}
</script>
<style lang="scss" scoped>
page {
background: #FFFBF5;
}
.page {
position: relative;
width: 100%;
min-height: 100vh;
}
.navbar-container {
background-color: #FAF8F3;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 10;
padding-top: env(safe-area-inset-top);
}
.background-container {
position: fixed;
2025-08-05 10:43:31 +08:00
top: -600rpx;
2025-08-04 17:45:45 +08:00
left: 0;
width: 100%;
2025-08-05 10:43:31 +08:00
height: calc(100vh + 432rpx);
2025-08-04 17:45:45 +08:00
z-index: -1;
overflow: hidden;
2025-08-05 10:43:31 +08:00
.background-image {
width: 100%;
height: 100%;
object-fit: cover;
}
2025-08-04 17:45:45 +08:00
}
.header {
position: relative;
width: 100%;
min-height: 100vh;
display: flex;
align-items: flex-start;
flex-direction: column;
padding: 0 15rpx;
2025-08-05 10:43:31 +08:00
padding-top: 120rpx;
padding-bottom: 160rpx;
2025-08-04 17:45:45 +08:00
z-index: 1;
}
.censer-container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
margin-top: 128rpx;
margin-bottom: 60rpx;
2025-08-05 10:43:31 +08:00
z-index: 3;
.censer-icon {
width: 648rpx;
height: 648rpx;
opacity: 0.8;
}
2025-08-04 17:45:45 +08:00
}
2025-08-05 10:43:31 +08:00
.prayer-form-background {
2025-08-04 18:04:37 +08:00
position: fixed;
left: 50%;
transform: translateX(-50%);
2025-08-05 10:43:31 +08:00
width: 100%;
background-color: #FDFCF5;
display: flex;
2025-08-05 10:54:51 +08:00
padding: 0 50rpx 300rpx 50rpx;
2025-08-05 10:43:31 +08:00
margin-top: 625rpx;
z-index: 2;
.prayer-form {
margin-top: 30rpx;
padding: 30rpx 60rpx 0 60rpx;
width: 650rpx;
display: flex;
flex-direction: column;
justify-content: center;
border: 2rpx solid #c0a4ae;
border-radius: 20rpx;
}
2025-08-04 17:59:54 +08:00
}
.form-title {
display: flex;
align-items: center;
2025-08-05 10:43:31 +08:00
.title-text {
width: 126rpx;
height: 44rpx;
font-weight: 400;
color: #695347;
font-size: 32rpx;
line-height: normal;
}
2025-08-04 17:59:54 +08:00
}
.form-item {
2025-08-05 10:43:31 +08:00
margin: 15rpx 0 15rpx 0 ;
display: flex;
border-bottom: #C7A26D 1px solid;
padding: 25rpx 0 25rpx 0;
2025-08-04 17:59:54 +08:00
2025-08-05 10:43:31 +08:00
.label {
font-size: 28rpx;
color: #666;
font-weight: 500;
white-space: nowrap;
2025-08-04 17:59:54 +08:00
2025-08-05 10:43:31 +08:00
}
2025-08-04 17:59:54 +08:00
2025-08-05 10:43:31 +08:00
.input-field{
2025-08-05 11:29:47 +08:00
padding-left: 40rpx;
2025-08-05 10:43:31 +08:00
}
2025-08-04 17:59:54 +08:00
}
2025-08-05 10:43:31 +08:00
.form-item:last-child {
border-bottom: none;
}
2025-08-04 17:59:54 +08:00
2025-08-05 10:43:31 +08:00
.select-field {
2025-08-04 17:59:54 +08:00
display: flex;
align-items: center;
2025-08-05 10:43:31 +08:00
justify-content: space-between;
2025-08-05 11:29:47 +08:00
padding:0 30rpx 0 66rpx;
2025-08-05 10:43:31 +08:00
width: 100%;
2025-08-04 17:59:54 +08:00
2025-08-05 10:43:31 +08:00
.select-text {
font-size: 28rpx;
color: #333;
}
.arrow {
font-size: 24rpx;
color: #999;
}
2025-08-04 17:59:54 +08:00
}
2025-08-05 10:43:31 +08:00
.radio-group {
2025-08-04 17:59:54 +08:00
display: flex;
align-items: center;
2025-08-05 10:43:31 +08:00
//border: #C7A26D 1px solid;
margin-left: 40rpx;
.radio-item {
display: flex;
align-items: center;
margin-right: 60rpx;
&:last-child {
margin-right: 0;
}
.radio-button {
width: 32rpx;
height: 32rpx;
border: 2rpx solid #DDD;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
margin-right: 12rpx;
box-sizing: border-box;
transition: all 0.3s ease;
&.checked {
border-color: #8B2E2E;
background-color: #8B2E2E;
}
}
.checkmark {
font-size: 20rpx;
color: #FFFFFF;
font-weight: bold;
}
.radio-text {
font-size: 28rpx;
color: #333;
padding-right: 12rpx;
}
}
2025-08-04 17:59:54 +08:00
}
.textarea-container {
position: relative;
2025-08-05 10:43:31 +08:00
.textarea-field {
width: 400rpx;
2025-08-05 10:54:51 +08:00
height: 140rpx;
2025-08-05 10:43:31 +08:00
//border: 1rpx solid #e10c0c;
border-radius: 12rpx;
2025-08-05 11:29:47 +08:00
padding: 0 20rpx 0 66rpx;
2025-08-05 10:43:31 +08:00
font-size: 28rpx;
color: #333;
box-sizing: border-box;
resize: none;
}
.char-counter {
position: absolute;
bottom: 0;
right: 0;
font-size: 22rpx;
color: #999;
}
2025-08-04 17:59:54 +08:00
}
2025-08-04 17:45:45 +08:00
</style>