import { View, Text, ScrollView, ActivityIndicator, TextInput, KeyboardAvoidingView, Platform, } from "react-native"; import React, { useState } from "react"; import { useTailwind } from "tailwind-rn"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import Toast from "react-native-toast-message"; import baseRequest from "../../utils/baseRequest"; import { generateSignature } from "../../utils/crypto"; import { Button, Divider, CheckBox, Switch } from "@rneui/themed"; export default function CreateSpace({ navigation, route }) { const tailwind = useTailwind(); const insets = useSafeAreaInsets(); const [isSubmitting, setIsSubmitting] = useState(false); //空间介绍 const [spaceIntro, setSpaceIntro] = useState(); //解锁空间价格 const [spacePrice, setSpacePrice] = useState(); //铁粉价格 const [ironFanPrice, setIronFanPrice] = useState(); //启用超粉功能 const [isSuperFanOn, setIsSuperFanOn] = useState(true); //超粉价格 const [superFanPrice, setSuperFanPrice] = useState(); //超粉单次开通有效期 const [superFanExpiration, setSuperFanExpiration] = useState(0); //是否开通超粉送微信 const [unlockWechat, setUnlockWechat] = useState(false); const handleSubmit = async () => { if (!spaceIntro || !spacePrice || !ironFanPrice) { Toast.show({ type: "error", text1: "请完善内容后提交", topOffset: 60, }); return; } if (isSuperFanOn && !superFanPrice) { Toast.show({ type: "error", text1: "请填写超粉价格", topOffset: 60, }); return; } const _spacePrice = parseInt(spacePrice * 100, 10); if (isNaN(_spacePrice) || _spacePrice < 0) { Toast.show({ type: "error", text1: "请输入有效的解锁空间价格", topOffset: 60, }); return; } const _ironFanPrice = parseInt(ironFanPrice * 100, 10); if (isNaN(_ironFanPrice) || _ironFanPrice < 100 || _ironFanPrice > 388800) { Toast.show({ type: "error", text1: "请输入有效的铁粉价格", topOffset: 60, }); return; } const _superFanPrice = parseInt(superFanPrice * 100, 10); if ( isSuperFanOn && (isNaN(_superFanPrice) || _superFanPrice < 100 || _superFanPrice > 388800) ) { Toast.show({ type: "error", text1: "请输入有效的超粉价格", topOffset: 60, }); return; } if (isSuperFanOn && _superFanPrice <= _ironFanPrice) { Toast.show({ type: "error", text1: "请输入大于铁粉价格的超粉价格", topOffset: 60, }); return; } if (isSubmitting) return; setIsSubmitting(true); const apiUrl = process.env.EXPO_PUBLIC_API_URL; try { const base = await baseRequest(); const body = { profile: spaceIntro, admission_price: parseInt(spacePrice * 100, 10), ironfanship_price: parseInt(ironFanPrice * 100, 10), is_superfanship_enabled: isSuperFanOn ? 1 : 0, superfanship_price: parseInt(superFanPrice * 100, 10), superfanship_valid_period: superFanExpiration, is_superfanship_give_wechat: unlockWechat ? 1 : 0, ...base, }; const signature = await generateSignature(body); const _response = await fetch( `${apiUrl}/api/zone/create?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), } ); const _data = await _response.json(); if (_data.ret === -1) { Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } navigation.goBack(); } catch (error) { console.error(error); } finally { setIsSubmitting(false); } }; return ( *空间介绍 setSpaceIntro(value)} placeholder="介绍下你的空间吧~" placeholderTextColor="#FFFFFF80" underlineColorAndroid="transparent" multiline textAlignVertical="top" style={tailwind( "h-32 bg-[#FFFFFF1A] text-white rounded-2xl mt-2 p-2" )} /> *解锁空间价格 ¥0~3888,仅支持整数 setSpacePrice(value)} keyboardType="numeric" placeholder="解锁后可查看空间内免费动态" placeholderTextColor="#FFFFFF80" style={tailwind("text-white")} underlineColorAndroid="transparent" textAlign="top" /> *铁粉价格 ¥1~3888,仅支持整数 setIronFanPrice(value)} keyboardType="numeric" placeholder="解锁后可查看空间内铁粉专享动态" placeholderTextColor="#FFFFFF80" style={tailwind("text-white")} underlineColorAndroid="transparent" textAlign="top" /> *启用超粉功能 setIsSuperFanOn(value)} thumbColor="#ffffff" trackColor={{ true: "#FF669E", false: "#FFFFFF1A" }} style={tailwind("mx-1")} /> {isSuperFanOn && ( 超粉价格 ¥1~3888,仅支持整数 setSuperFanPrice(value)} keyboardType="numeric" placeholder="最高身份,可查看空间所有动态" placeholderTextColor="#FFFFFF80" style={tailwind("text-white")} underlineColorAndroid="transparent" textAlign="top" /> 超粉单次开通有效期 setSuperFanExpiration(0)} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> setSuperFanExpiration(0)} style={tailwind("text-base font-medium text-white")} > 永久 setSuperFanExpiration(4)} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> setSuperFanExpiration(4)} style={tailwind("text-base font-medium text-white")} > 年度 setSuperFanExpiration(3)} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> setSuperFanExpiration(3)} style={tailwind("text-base font-medium text-white")} > 半年 setSuperFanExpiration(2)} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> setSuperFanExpiration(2)} style={tailwind("text-base font-medium text-white")} > 季度 setSuperFanExpiration(1)} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> setSuperFanExpiration(1)} style={tailwind("text-base font-medium text-white")} > 月度 开通超粉赠送微信 setUnlockWechat(value)} thumbColor="#ffffff" trackColor={{ true: "#FF669E", false: "#FFFFFF1A" }} style={tailwind("mx-1")} /> )} ); }