import { View, Text, ScrollView, TouchableOpacity, TextInput, KeyboardAvoidingView, Platform, ActivityIndicator, } from "react-native"; import React, { useState, useMemo, useCallback, useEffect } from "react"; import { useTailwind } from "tailwind-rn"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Divider, Icon, Button, CheckBox } from "@rneui/themed"; import { Image } from "expo-image"; import { Formik } from "formik"; import Picker from "../../../components/Picker"; import MediaPicker from "../../../components/MediaPicker"; import Toast from "react-native-toast-message"; import { get } from "../../../utils/storeInfo"; import { multiUpload } from "../../../utils/upload"; import baseRequest from "../../../utils/baseRequest"; import { generateSignature } from "../../../utils/crypto"; import MediaGrid from "../../../components/MediaGrid"; import * as ImagePicker from "expo-image-picker"; import * as VideoThumbnails from "expo-video-thumbnails"; const blurhash = "LcKUTa%gOYWBYRt6xuoJo~s8V@fk"; export default function CompleteStreamerInformation({ navigation, route }) { const tailwind = useTailwind(); const insets = useSafeAreaInsets(); //保存封面图以及控制上传封面图Modal出现 const [displayImage, setDisplayImage] = useState([]); //选择封面图 const pickDisPlayImage = async () => { let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, quality: 1, }); if (!result.canceled) { setDisplayImage(result.assets); } }; //保存展示视频 const [displayVideo, setDisplayVideo] = useState([]); //为视频生成封面 const generateThumbnail = useCallback(async (uri) => { try { const videoCover = await VideoThumbnails.getThumbnailAsync(uri); return videoCover; } catch (e) { console.warn(e); } }, []); //选择视频 const pickDisPlayVideo = async () => { let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Videos, quality: 1, }); if (!result.canceled) { for (let i = 0; i < result.assets.length; i++) { if (result.assets[i].duration > 0) { const videoCover = await generateThumbnail(result.assets[i].uri); result.assets[i].cover = videoCover.uri; } } setDisplayVideo(result.assets); } }; const [wechatInputShow, setWechatInputShow] = useState(1); //保存新添加的相册图片 const [photos, setPhotos] = useState([]); //展示旧相册图片组件 const [oldPhotos, setOldPhotos] = useState([]); //保存主播标签 const [tags, setTags] = useState([]); //点击标签 const handlePressTag = (tag, isChecked) => { if (isChecked) { setTags(tags.filter((item) => item !== tag)); } else { if (tags.length >= 3) { Toast.show({ type: "error", text1: "最多只能选择3个标签", topOffset: 60, }); return; } setTags([...tags, tag]); } }; //标签组件 const TagItem = ({ tag, label }) => { const isChecked = tags.includes(tag); return ( handlePressTag(tag, isChecked)} style={ isChecked ? tailwind("border border-[#FF669E] rounded-full px-2 py-1 m-1") : tailwind("border border-gray-400 rounded-full px-2 py-1 m-1") } > {label} ); }; //生成年龄、身高、体重、胸围、腰围、臀围、星座、省份数组 const generateItems = useCallback((min, max) => { const items = []; for (let i = min; i <= max; i++) { items.push({ label: i.toString(), value: i.toString() }); } return items; }, []); const ages = useMemo(() => generateItems(18, 60), []); const heights = useMemo(() => generateItems(140, 200), []); const weights = useMemo(() => generateItems(35, 100), []); const constellations = [ { label: "白羊座", value: "白羊座" }, { label: "金牛座", value: "金牛座" }, { label: "双子座", value: "双子座" }, { label: "巨蟹座", value: "巨蟹座" }, { label: "狮子座", value: "狮子座" }, { label: "处女座", value: "处女座" }, { label: "天秤座", value: "天秤座" }, { label: "天蝎座", value: "天蝎座" }, { label: "射手座", value: "射手座" }, { label: "摩羯座", value: "摩羯座" }, { label: "水瓶座", value: "水瓶座" }, { label: "双鱼座", value: "双鱼座" }, ]; const provinces = [ { label: "北京市", value: "北京市" }, { label: "天津市", value: "天津市" }, { label: "河北省", value: "河北省" }, { label: "山西省", value: "山西省" }, { label: "内蒙古自治区", value: "内蒙古自治区" }, { label: "辽宁省", value: "辽宁省" }, { label: "吉林省", value: "吉林省" }, { label: "黑龙江省", value: "黑龙江省" }, { label: "上海市", value: "上海市" }, { label: "江苏省", value: "江苏省" }, { label: "浙江省", value: "浙江省" }, { label: "安徽省", value: "安徽省" }, { label: "福建省", value: "福建省" }, { label: "江西省", value: "江西省" }, { label: "山东省", value: "山东省" }, { label: "河南省", value: "河南省" }, { label: "湖北省", value: "湖北省" }, { label: "湖南省", value: "湖南省" }, { label: "广东省", value: "广东省" }, { label: "广西壮族自治区", value: "广西壮族自治区" }, { label: "海南省", value: "海南省" }, { label: "重庆市", value: "重庆市" }, { label: "四川省", value: "四川省" }, { label: "贵州省", value: "贵州省" }, { label: "云南省", value: "云南省" }, { label: "西藏自治区", value: "西藏自治区" }, { label: "陕西省", value: "陕西省" }, { label: "甘肃省", value: "甘肃省" }, { label: "青海省", value: "青海省" }, { label: "宁夏回族自治区", value: "宁夏回族自治区" }, { label: "新疆维吾尔自治区", value: "新疆维吾尔自治区" }, { label: "台湾省", value: "台湾省" }, { label: "香港特别行政区", value: "香港特别行政区" }, { label: "澳门特别行政区", value: "澳门特别行政区" }, ]; //基本资料 const [data, setData] = useState(); const [allTag, setAllTag] = useState({}); //正在加载数据 const [isLoading, setIsloading] = useState(true); const [isWaitingReview, setIsWaitingReview] = useState(false); useEffect(() => { const getData = async () => { const account = await get("account"); const apiUrl = process.env.EXPO_PUBLIC_API_URL; const base = await baseRequest(); try { //获取当前审批状态 const body = { ...base, }; const signature = await generateSignature(body); const statusResponse = await fetch( `${apiUrl}/api/streamer_auth_approval/get_statuses?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), } ); const statusData = await statusResponse.json(); if (statusData.ret === -1) { Toast.show({ type: "error", text1: statusData.msg, topOffset: 60, }); return; } if (statusData?.data?.details_status === 0) setIsWaitingReview(true); if (statusData?.data?.details_status !== 2) { setData({ ...account, streamer: {} }); return; } //获取已填信息 const body2 = { approve_status: 2, ...base, }; const signature2 = await generateSignature(body2); const _response = await fetch( `${apiUrl}/api/streamer_auth_approval_his/list_details?signature=${signature2}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body2), } ); const _data = await _response.json(); if (_data.ret === -1) { Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } setData({ ...account, streamer: _data.data.list[0] }); setWechatInputShow(_data.data.list[0].wechat_lock_type); setTags(_data.data.list[0].tag); if (_data.data.list[0]) setDisplayImage([ { notChanged: true, id: { image_ids: _data.data.list[0].cover.image_ids }, uri: _data.data.list[0].cover.images[0].urls[0], }, ]); setDisplayVideo([ { notChanged: true, id: { video_ids: _data.data.list[0].shorts?.video_ids }, cover: _data.data.list[0].shorts?.videos[0]?.cover_urls[0], }, ]); setOldPhotos(_data.data.list[0].album.images); } catch (error) { console.error(error); } finally { setIsloading(false); } }; const getAllTag = async () => { const apiUrl = process.env.EXPO_PUBLIC_API_URL; const base = await baseRequest(); try { //获取所有的标签 const signature = await generateSignature({ ...base, }); const _response = await fetch( `${apiUrl}/api/streamer_tag/list?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, }), } ); const tagData = await _response.json(); if (tagData.ret === -1) { Toast.show({ type: "error", text1: tagData.msg, topOffset: 60, }); return; } setAllTag(tagData.data); } catch (error) { console.error(error); } }; getData(); getAllTag(); }, []); //正在提交状态 const [isSubmitting, setIsSubmitting] = useState(false); //是否正在拖动图片,用于禁用ScrollView的滚动 const [dragging, setDragging] = useState(false); //loading时展示加载中 if (isLoading) { return ( ); } //审核中的情况 if (isWaitingReview) { return ( 正在审核中,请耐心等待 ); } return ( {data.streamer?.remarks && ( 驳回原因: {data.streamer?.remarks} )} { if ( !values.fans || !values.gender || !values.wechat_add_way || !values.price || !values.info || displayImage.length === 0 || displayVideo.length === 0 || !values.age || !values.height || !values.weight || !values.constellation || !values.location || !values.auto_response_message || tags.length === 0 ) { Toast.show({ type: "error", text1: "请完善信息后提交", topOffset: 60, }); return; } const fans = parseInt(values.fans, 10); if (isNaN(fans) || fans < 1) { Toast.show({ type: "error", text1: "请输入有效的全网粉丝量(大于等于1的整数)", topOffset: 60, }); return; } const price = parseInt(values.price, 10); if (isNaN(price) || price < 1) { Toast.show({ type: "error", text1: "请输入有效的微信价格(大于等于1的整数)", topOffset: 60, }); return; } if (values.wechat_add_way === "0" && !values.wechat) { Toast.show({ type: "error", text1: "请填写微信号", topOffset: 60, }); return; } //相册不得低于2张 if (oldPhotos.length + photos.length < 2) { Toast.show({ type: "error", text1: "相册至少需要上传2张照片哦!", topOffset: 60, }); return; } //相册不得超过9张 if (oldPhotos.length + photos.length > 9) { Toast.show({ type: "error", text1: "相册最多只能上传9张照片哦!", topOffset: 60, }); return; } setIsSubmitting(true); const cover = displayImage[0].notChanged ? displayImage[0].id : await multiUpload(displayImage); const shorts = displayVideo[0].notChanged ? displayVideo[0].id : await multiUpload(displayVideo); const newPhotosIds = await multiUpload(photos); const oldPhotosIds = oldPhotos.map((item) => item.id); const album = { image_ids: [...oldPhotosIds, ...newPhotosIds?.image_ids], }; if ( !cover.image_ids.length || !shorts.video_ids.length || !album.image_ids.length ) { Toast.show({ type: "error", text1: "上传失败,请联系客服进行上传", topOffset: 60, }); setIsSubmitting(false); return; } //获取环境变量 const apiUrl = process.env.EXPO_PUBLIC_API_URL; //上传表单 const base = await baseRequest(); const body = { gender: parseInt(values.gender, 10), wechat_contact: values.wechat, bio: values.info, cover: cover, shorts: shorts, album: album, age: parseInt(values.age, 10), height: parseInt(values.height, 10), weight: parseInt(values.weight, 10), constellation: values.constellation, city: values.location, tag: tags, wechat_lock_type: parseInt(values.wechat_add_way, 10), fans: parseInt(values.fans, 10), wechat_coin_price: parseInt(values.price, 10) * 10, auto_response_message: values.auto_response_message, ...base, }; const signature = await generateSignature(body); try { const response = await fetch( `${apiUrl}/api/streamer_auth_approval/create_details?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), } ); const streamerData = await response.json(); if (streamerData.ret === -1) { Toast.show({ type: "error", text1: streamerData.msg, topOffset: 60, }); return; } //提交成功后toast提示并返回“我的”页面 Toast.show({ type: "success", text1: "提交成功", topOffset: 60, }); navigation.goBack(); } catch (error) { console.error(error); } finally { setIsSubmitting(false); } }} > {({ handleChange, handleSubmit, values, setFieldValue }) => ( <> * 头像(需在“我的”修改) * 昵称(需在“我的”修改) {data?.name} * 全网粉丝量(万) * 性别 * 添加标签 {Object.entries(allTag).map(([tag, label]) => { return ; })} * 添加微信方式 { setWechatInputShow(1); setFieldValue("wechat_add_way", "1"); }} style={tailwind("flex-row items-center")} > { setWechatInputShow(1); setFieldValue("wechat_add_way", "1"); }} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> 主动添加对方 { setWechatInputShow(0); setFieldValue("wechat_add_way", "0"); }} style={tailwind("flex-row items-center")} > { setWechatInputShow(0); setFieldValue("wechat_add_way", "0"); }} iconType="material-community" checkedIcon="checkbox-marked" uncheckedIcon="checkbox-blank-outline" checkedColor="#FF669E" containerStyle={tailwind("p-0 m-0 bg-transparent")} size={18} /> 向对方展示微信 {wechatInputShow === 0 && ( <> * 微信号 )} * 加微信价格(元) * 个性签名 * 封面图 pickDisPlayImage()} style={tailwind("flex-row items-center")} > {displayImage.length !== 0 ? ( ) : ( 将在“发现”和“主页”展示 )} * 展示视频 pickDisPlayVideo()} style={tailwind("flex-row items-center")} > {displayVideo.length !== 0 ? ( ) : ( 将在“发现”和“主页”展示 )} * 相册 将在“主页”展示(2~9张) * 年龄(岁) * 身高(cm) * 体重(kg) *星座 *所在地 * 私信自动回复 )} ); }