import { View, Text, FlatList, RefreshControl, Modal, TouchableOpacity, Image as NativeImage, } from "react-native"; import { Image } from "expo-image"; import React, { useState, useEffect } from "react"; import { useTailwind } from "tailwind-rn"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import Empty from "../../../components/Empty"; import { ListItem, Button } from "@rneui/themed"; import baseRequest from "../../../utils/baseRequest"; import Toast from "react-native-toast-message"; import * as Clipboard from "expo-clipboard"; import { generateSignature } from "../../../utils/crypto"; //todo:等待接口上线,完善样式,测试 export default function AlreadyAddWechat({}) { const blurhash = "LcKUTa%gOYWBYRt6xuoJo~s8V@fk"; const tailwind = useTailwind(); const insets = useSafeAreaInsets(); //保存获取的订单列表 const [orderList, setOrderList] = useState([]); const [offset, setOffset] = useState(0); const [more, setMore] = useState(1); //获取订单数据 const getOrderList = async (top = false) => { if (!more && top === false) return; const apiUrl = process.env.EXPO_PUBLIC_API_URL; try { const base = await baseRequest(); const signature = await generateSignature({ tab: 2, offset: top ? 0 : offset, limit: 20, ...base, }); const response = await fetch( `${apiUrl}/api/vas/get_add_wechat_list?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ tab: 1, offset: top ? 0 : offset, //如果是下拉刷新则更新最新数据 limit: 20, ...base, }), } ); const data = await response.json(); if (data.ret === -1) { Toast.show({ type: "error", text1: data.msg, topOffset: 60, }); return; } setOffset(data.data.offset); setMore(data.data.more); //如果是下拉刷新则更新最新数据 if (top) { setOrderList(data.data.list); return; } setOrderList([...orderList, ...data.data.list]); } catch (error) { console.error(error); } }; useEffect(() => { getOrderList(); }, []); //下拉刷新 const [refreshing, setRefreshing] = useState(false); const handleRefresh = async () => { setRefreshing(true); await getOrderList(true); setRefreshing(false); }; //二次确认组件 const [isConfirmModalVisible, setIsConfirmModalVisible] = useState(false); const [currentOrder, setCurrentOrder] = useState({}); const ConfirmModal = () => { //保存内容到剪贴板 const copy = async (data) => { await Clipboard.setStringAsync(data); Toast.show({ type: "success", text1: "已复制到剪贴板", topOffset: 60, }); }; return ( setIsConfirmModalVisible(false)} style={{ backgroundColor: "#00000080", ...tailwind("flex-1 justify-center items-center"), }} > {currentOrder.consumer_wechat ? ( {currentOrder?.account?.name} Ta的微信号: {currentOrder?.consumer_wechat} copy(currentOrder?.consumer_wechat)} style={tailwind("flex flex-row")} > 复制 添加时请备注: {currentOrder?.consumer_note} copy(currentOrder?.consumer_note)} style={tailwind("flex flex-row")} > 复制 ) : ( {currentOrder.account?.name} 请确认对方已主动添加您的微信,并您已经通过好友申请。 )} ); }; //订单项组件 const renderItem = ({ item }) => { return ( {item?.account?.name} 请于72小时内添加对方微信 付款时间:{new Date(item?.ct * 1000).toLocaleString()} ); }; return ( handleRefresh()} /> } onEndReached={() => getOrderList()} ListEmptyComponent={} /> ); }