2025-09-25 15:18:24 +08:00
|
|
|
|
<script setup>
|
2025-10-14 11:11:48 +08:00
|
|
|
|
import { ref, reactive, watch, onMounted } from "vue";
|
|
|
|
|
|
import { getAppConfig, donateAPI } from "@/apis";
|
2025-09-30 10:53:06 +08:00
|
|
|
|
import useStore from "@/store";
|
|
|
|
|
|
import { storeToRefs } from "pinia";
|
|
|
|
|
|
const store = useStore();
|
|
|
|
|
|
const { config } = storeToRefs(store);
|
2025-10-14 11:11:48 +08:00
|
|
|
|
const { updateConfig } = store;
|
2025-09-25 17:07:37 +08:00
|
|
|
|
|
2025-09-25 15:18:24 +08:00
|
|
|
|
const props = defineProps({
|
2025-09-25 17:07:37 +08:00
|
|
|
|
show: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
onClose: {
|
|
|
|
|
|
type: Function,
|
|
|
|
|
|
default: null,
|
2025-09-25 15:18:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
2025-09-30 10:53:06 +08:00
|
|
|
|
const amounts = ref([]);
|
2025-09-25 15:18:24 +08:00
|
|
|
|
const selected = ref(null);
|
2025-09-27 10:09:02 +08:00
|
|
|
|
const checked = ref(false);
|
2025-09-25 15:18:24 +08:00
|
|
|
|
|
|
|
|
|
|
const formData = reactive({
|
|
|
|
|
|
name: "",
|
|
|
|
|
|
account: "",
|
|
|
|
|
|
organization: "",
|
|
|
|
|
|
suggestion: "",
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-25 17:07:37 +08:00
|
|
|
|
const onPay = async (index) => {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
selected.value = index;
|
2025-09-25 17:07:37 +08:00
|
|
|
|
const result = await donateAPI(
|
2025-09-30 10:53:06 +08:00
|
|
|
|
amounts.value[index],
|
2025-09-25 17:07:37 +08:00
|
|
|
|
formData.name,
|
|
|
|
|
|
formData.account,
|
|
|
|
|
|
formData.organization,
|
|
|
|
|
|
formData.suggestion
|
|
|
|
|
|
);
|
|
|
|
|
|
const params = result.order.jsApi.params;
|
|
|
|
|
|
if (params) {
|
|
|
|
|
|
wx.requestPayment({
|
|
|
|
|
|
timeStamp: params.timeStamp,
|
|
|
|
|
|
nonceStr: params.nonceStr,
|
|
|
|
|
|
package: params.package,
|
|
|
|
|
|
paySign: params.paySign,
|
|
|
|
|
|
signType: "RSA",
|
|
|
|
|
|
async success(res) {
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: "感谢您的支持!",
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
});
|
|
|
|
|
|
props.onClose();
|
|
|
|
|
|
},
|
|
|
|
|
|
fail(res) {
|
|
|
|
|
|
console.log("pay error", res);
|
|
|
|
|
|
uni.showToast({
|
|
|
|
|
|
title: "取消支付",
|
|
|
|
|
|
icon: "none",
|
|
|
|
|
|
});
|
|
|
|
|
|
props.onClose();
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-09-25 15:18:24 +08:00
|
|
|
|
};
|
2025-09-25 17:07:37 +08:00
|
|
|
|
|
2025-09-30 10:53:06 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => config.value.donateAmount,
|
|
|
|
|
|
(value) => {
|
|
|
|
|
|
amounts.value = value || [];
|
|
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-09-25 17:07:37 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.show,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
selected.value = null;
|
2025-09-27 10:09:02 +08:00
|
|
|
|
formData.name = "";
|
|
|
|
|
|
formData.account = "";
|
|
|
|
|
|
formData.organization = "";
|
|
|
|
|
|
formData.suggestion = "";
|
2025-09-25 17:07:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
);
|
2025-10-14 11:11:48 +08:00
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
if (!config.value.donateAmount) {
|
|
|
|
|
|
const config = await getAppConfig();
|
|
|
|
|
|
updateConfig(config);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-09-25 15:18:24 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<view class="container">
|
2025-09-27 16:11:47 +08:00
|
|
|
|
<image src="../static/donate.png" mode="widthFix" />
|
2025-09-25 15:18:24 +08:00
|
|
|
|
<text>感谢您对我们公益项目的支持!</text>
|
|
|
|
|
|
<view class="amounts">
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-for="(item, index) in amounts"
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
hover-class="none"
|
|
|
|
|
|
@click="onPay(index)"
|
|
|
|
|
|
:style="{
|
|
|
|
|
|
background: selected === index ? '#fed848' : 'white',
|
|
|
|
|
|
}"
|
|
|
|
|
|
>
|
|
|
|
|
|
<text>¥</text>
|
|
|
|
|
|
<text>{{ item }}</text>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</view>
|
2025-09-27 10:09:02 +08:00
|
|
|
|
<view
|
|
|
|
|
|
@click="checked = !checked"
|
|
|
|
|
|
:style="{ marginBottom: !checked ? '20rpx' : '0' }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<image v-if="checked" src="../static/checked.png" mode="widthFix" />
|
|
|
|
|
|
<view v-else></view>
|
2025-09-25 15:18:24 +08:00
|
|
|
|
<text>我想给建议(选填)</text>
|
|
|
|
|
|
</view>
|
2025-09-27 10:09:02 +08:00
|
|
|
|
<view v-if="checked">
|
2025-09-25 15:18:24 +08:00
|
|
|
|
<view>
|
|
|
|
|
|
<text>您的姓名</text>
|
|
|
|
|
|
<input v-model="formData.name" />
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<view>
|
|
|
|
|
|
<text>手机/微信号</text>
|
|
|
|
|
|
<input v-model="formData.account" />
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<view>
|
|
|
|
|
|
<text>所在机构</text>
|
|
|
|
|
|
<input v-model="formData.organization" />
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<view>
|
|
|
|
|
|
<text>建议</text>
|
|
|
|
|
|
<textarea v-model="formData.suggestion" />
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.container {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
2025-09-27 10:09:02 +08:00
|
|
|
|
transition: all 0.3s ease-in-out;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > image:first-child {
|
|
|
|
|
|
width: 200rpx;
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: -114rpx;
|
|
|
|
|
|
}
|
|
|
|
|
|
.container > text:nth-child(2) {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
color: #333333;
|
|
|
|
|
|
margin: 40rpx 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
.amounts {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
grid-template-columns: repeat(3, 1fr);
|
|
|
|
|
|
row-gap: 20rpx;
|
2025-09-25 16:13:50 +08:00
|
|
|
|
column-gap: 20rpx;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
.amounts > button {
|
|
|
|
|
|
width: 150rpx;
|
|
|
|
|
|
height: 88rpx;
|
|
|
|
|
|
background-color: #ffffff;
|
|
|
|
|
|
border-radius: 20rpx;
|
|
|
|
|
|
border: 1rpx solid #fed848;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
.amounts > button > text:first-child {
|
|
|
|
|
|
font-size: 20rpx;
|
|
|
|
|
|
margin-right: 3rpx;
|
|
|
|
|
|
}
|
|
|
|
|
|
.amounts > button > text:last-child {
|
|
|
|
|
|
font-size: 34rpx;
|
|
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(4) {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: flex-start;
|
2025-09-25 17:07:37 +08:00
|
|
|
|
margin-top: 20rpx;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(4) > view {
|
2025-09-27 10:09:02 +08:00
|
|
|
|
width: 32rpx;
|
|
|
|
|
|
height: 32rpx;
|
|
|
|
|
|
margin: 0 10rpx;
|
|
|
|
|
|
border: 1rpx solid #e3e3e3;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(4) > image {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
width: 32rpx;
|
|
|
|
|
|
height: 32rpx;
|
2025-09-25 17:07:37 +08:00
|
|
|
|
margin: 0 10rpx;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(4) > text {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
|
color: #333333;
|
|
|
|
|
|
margin: 20rpx 0;
|
|
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(5) {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
margin-bottom: 25rpx;
|
|
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(5) > view {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
margin-bottom: 20rpx;
|
|
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(5) > view > text {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
font-size: 24rpx;
|
|
|
|
|
|
color: #333333;
|
|
|
|
|
|
width: 30%;
|
|
|
|
|
|
text-align: right;
|
|
|
|
|
|
padding-right: 20rpx;
|
|
|
|
|
|
height: 60rpx;
|
|
|
|
|
|
line-height: 60rpx;
|
|
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(5) > view > input {
|
2025-09-25 15:18:24 +08:00
|
|
|
|
border-radius: 12rpx;
|
|
|
|
|
|
border: 1rpx solid #fed848;
|
|
|
|
|
|
height: 40rpx;
|
|
|
|
|
|
line-height: 40rpx;
|
2025-09-25 17:07:37 +08:00
|
|
|
|
padding: 10rpx 20rpx;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
font-size: 30rpx;
|
2025-09-25 16:13:50 +08:00
|
|
|
|
margin-right: 10rpx;
|
2025-09-27 16:11:47 +08:00
|
|
|
|
width: 55%;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
}
|
2025-09-27 16:11:47 +08:00
|
|
|
|
.container > view:nth-child(5) > view > textarea {
|
|
|
|
|
|
width: 55%;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
border-radius: 12rpx;
|
|
|
|
|
|
border: 1rpx solid #fed848;
|
|
|
|
|
|
height: 100rpx;
|
|
|
|
|
|
line-height: 40rpx;
|
2025-09-25 17:07:37 +08:00
|
|
|
|
padding: 10rpx 20rpx;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
font-size: 30rpx;
|
2025-09-25 16:13:50 +08:00
|
|
|
|
margin-right: 10rpx;
|
2025-09-25 15:18:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|