fill data API NetDetail

This commit is contained in:
2025-11-06 23:38:53 +07:00
parent 04ca091f49
commit b97e4e1097
6 changed files with 66 additions and 273 deletions

View File

@@ -1,191 +1,18 @@
import { IconSymbol } from "@/components/ui/icon-symbol"; import { IconSymbol } from "@/components/ui/icon-symbol";
import { useTrip } from "@/state/use-trip";
import React, { useRef, useState } from "react"; import React, { useRef, useState } from "react";
import { Animated, Text, TouchableOpacity, View } from "react-native"; import { Animated, Text, TouchableOpacity, View } from "react-native";
import NetDetailModal from "./modal/NetDetailModal/NetDetailModal"; import NetDetailModal from "./modal/NetDetailModal/NetDetailModal";
import styles from "./style/NetListTable.styles"; import styles from "./style/NetListTable.styles";
// ---------------------------
// 🧩 Interface
// ---------------------------
interface FishCatch {
fish_species_id: number;
fish_name: string;
catch_number: number;
catch_unit: string;
fish_size: number;
fish_rarity: number;
fish_condition: string;
gear_usage: string;
}
interface NetItem {
id: string;
stt: string;
trangThai: string;
thoiGianBatDau?: string;
thoiGianKetThuc?: string;
viTriHaThu?: string;
viTriThuLuoi?: string;
doSauHaThu?: string;
doSauThuLuoi?: string;
catchList?: FishCatch[];
ghiChu?: string;
}
// ---------------------------
// 🧵 Dữ liệu mẫu
// ---------------------------
const data: NetItem[] = [
{
id: "1",
stt: "Mẻ 3",
trangThai: "Đã hoàn thành",
thoiGianBatDau: "08:00 - 01/11/2025",
thoiGianKetThuc: "12:30 - 01/11/2025",
viTriHaThu: "16°12'34\"N 107°56'12\"E",
viTriThuLuoi: "16°13'45\"N 107°57'23\"E",
doSauHaThu: "45m",
doSauThuLuoi: "48m",
catchList: [
{
fish_species_id: 3,
fish_name: "Cá chim trắng",
catch_number: 978,
catch_unit: "kg",
fish_size: 111,
fish_rarity: 2,
fish_condition: "Chết",
gear_usage: "",
},
{
fish_species_id: 13,
fish_name: "Cá song đỏ",
catch_number: 1061,
catch_unit: "kg",
fish_size: 154,
fish_rarity: 2,
fish_condition: "Còn sống",
gear_usage: "",
},
{
fish_species_id: 15,
fish_name: "Cá hồng",
catch_number: 613,
catch_unit: "kg",
fish_size: 199,
fish_rarity: 2,
fish_condition: "Còn sống",
gear_usage: "",
},
],
ghiChu: "Thời tiết tốt, sản lượng cao",
},
{
id: "2",
stt: "Mẻ 2",
trangThai: "Đã hoàn thành",
thoiGianBatDau: "14:00 - 31/10/2025",
thoiGianKetThuc: "18:45 - 31/10/2025",
viTriHaThu: "16°10'20\"N 107°54'30\"E",
viTriThuLuoi: "16°11'30\"N 107°55'40\"E",
doSauHaThu: "40m",
doSauThuLuoi: "42m",
catchList: [
{
fish_species_id: 2,
fish_name: "Cá nục",
catch_number: 1102,
catch_unit: "kg",
fish_size: 12,
fish_rarity: 1,
fish_condition: "Bị thương",
gear_usage: "",
},
{
fish_species_id: 11,
fish_name: "Cá ngừ đại dương",
catch_number: 828,
catch_unit: "kg",
fish_size: 120,
fish_rarity: 1,
fish_condition: "Chết",
gear_usage: "",
},
],
ghiChu: "Biển động nhẹ",
},
{
id: "3",
stt: "Mẻ 1",
trangThai: "Đã hoàn thành",
thoiGianBatDau: "06:30 - 31/10/2025",
thoiGianKetThuc: "11:00 - 31/10/2025",
viTriHaThu: "16°08'15\"N 107°52'45\"E",
viTriThuLuoi: "16°09'25\"N 107°53'55\"E",
doSauHaThu: "35m",
doSauThuLuoi: "38m",
catchList: [
{
fish_species_id: 6,
fish_name: "Cá mú trắng",
catch_number: 1620,
catch_unit: "kg",
fish_size: 75,
fish_rarity: 2,
fish_condition: "Chết",
gear_usage: "",
},
{
fish_species_id: 8,
fish_name: "Cá hồng phớn",
catch_number: 648,
catch_unit: "kg",
fish_size: 25,
fish_rarity: 3,
fish_condition: "Còn sống",
gear_usage: "Lưới rê",
},
{
fish_species_id: 9,
fish_name: "Cá hổ Napoleon",
catch_number: 1111,
catch_unit: "kg",
fish_size: 86,
fish_rarity: 4,
fish_condition: "Bị thương",
gear_usage: "Lưới rê",
},
{
fish_species_id: 17,
fish_name: "Cá nược",
catch_number: 1081,
catch_unit: "kg",
fish_size: 195,
fish_rarity: 1,
fish_condition: "Chết",
gear_usage: "",
},
{
fish_species_id: 18,
fish_name: "Cá đuối quạt",
catch_number: 1198,
catch_unit: "kg",
fish_size: 21,
fish_rarity: 4,
fish_condition: "Chết",
gear_usage: "Câu tay",
},
],
ghiChu: "Mẻ lưới đầu tiên, sản lượng tốt",
},
];
const NetListTable: React.FC = () => { const NetListTable: React.FC = () => {
const [collapsed, setCollapsed] = useState(true); const [collapsed, setCollapsed] = useState(true);
const [contentHeight, setContentHeight] = useState<number>(0); const [contentHeight, setContentHeight] = useState<number>(0);
const animatedHeight = useRef(new Animated.Value(0)).current; const animatedHeight = useRef(new Animated.Value(0)).current;
const [modalVisible, setModalVisible] = useState(false); const [modalVisible, setModalVisible] = useState(false);
const [selectedNet, setSelectedNet] = useState<NetItem | null>(null); const [selectedNet, setSelectedNet] = useState<Model.FishingLog | null>(null);
const { trip } = useTrip();
const data: Model.FishingLog[] = trip?.fishing_logs ?? [];
const tongSoMe = data.length; const tongSoMe = data.length;
const handleToggle = () => { const handleToggle = () => {
@@ -199,7 +26,7 @@ const NetListTable: React.FC = () => {
}; };
const handleStatusPress = (id: string) => { const handleStatusPress = (id: string) => {
const net = data.find((item) => item.id === id); const net = data.find((item) => item.fishing_log_id === id);
if (net) { if (net) {
setSelectedNet(net); setSelectedNet(net);
setModalVisible(true); setModalVisible(true);
@@ -240,16 +67,20 @@ const NetListTable: React.FC = () => {
</View> </View>
{/* Body */} {/* Body */}
{data.map((item) => ( {data.map((item, index) => (
<View key={item.id} style={styles.row}> <View key={item.fishing_log_id} style={styles.row}>
{/* Cột STT */} {/* Cột STT */}
<Text style={styles.sttCell}>{item.stt}</Text> <Text style={styles.sttCell}>Mẻ {index + 1}</Text>
{/* Cột Trạng thái */} {/* Cột Trạng thái */}
<View style={[styles.cell, styles.statusContainer]}> <View style={[styles.cell, styles.statusContainer]}>
<View style={styles.statusDot} /> <View style={styles.statusDot} />
<TouchableOpacity onPress={() => handleStatusPress(item.id)}> <TouchableOpacity
<Text style={styles.statusText}>{item.trangThai}</Text> onPress={() => handleStatusPress(item.fishing_log_id)}
>
<Text style={styles.statusText}>
{item.status ? "Đã hoàn thành" : "Chưa hoàn thành"}
</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
@@ -265,16 +96,20 @@ const NetListTable: React.FC = () => {
</View> </View>
{/* Body */} {/* Body */}
{data.map((item) => ( {data.map((item, index) => (
<View key={item.id} style={styles.row}> <View key={item.fishing_log_id} style={styles.row}>
{/* Cột STT */} {/* Cột STT */}
<Text style={styles.sttCell}>{item.stt}</Text> <Text style={styles.sttCell}>Mẻ {index + 1}</Text>
{/* Cột Trạng thái */} {/* Cột Trạng thái */}
<View style={[styles.cell, styles.statusContainer]}> <View style={[styles.cell, styles.statusContainer]}>
<View style={styles.statusDot} /> <View style={styles.statusDot} />
<TouchableOpacity onPress={() => handleStatusPress(item.id)}> <TouchableOpacity
<Text style={styles.statusText}>{item.trangThai}</Text> onPress={() => handleStatusPress(item.fishing_log_id)}
>
<Text style={styles.statusText}>
{item.status ? "Đã hoàn thành" : "Chưa hoàn thành"}
</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
</View> </View>
@@ -289,6 +124,13 @@ const NetListTable: React.FC = () => {
setModalVisible(false); setModalVisible(false);
}} }}
netData={selectedNet} netData={selectedNet}
stt={
selectedNet
? data.findIndex(
(item) => item.fishing_log_id === selectedNet.fishing_log_id
) + 1
: undefined
}
/> />
</View> </View>
); );

View File

@@ -14,38 +14,11 @@ import { FishCardList } from "./components/FishCardList";
import { InfoSection } from "./components/InfoSection"; import { InfoSection } from "./components/InfoSection";
import { NotesSection } from "./components/NotesSection"; import { NotesSection } from "./components/NotesSection";
// ---------------------------
// 🧩 Interface
// ---------------------------
interface FishCatch {
fish_species_id: number;
fish_name: string;
catch_number: number;
catch_unit: string;
fish_size: number;
fish_rarity: number;
fish_condition: string;
gear_usage: string;
}
interface NetDetail {
id: string;
stt: string;
trangThai: string;
thoiGianBatDau?: string;
thoiGianKetThuc?: string;
viTriHaThu?: string;
viTriThuLuoi?: string;
doSauHaThu?: string;
doSauThuLuoi?: string;
catchList?: FishCatch[];
ghiChu?: string;
}
interface NetDetailModalProps { interface NetDetailModalProps {
visible: boolean; visible: boolean;
onClose: () => void; onClose: () => void;
netData: NetDetail | null; netData: Model.FishingLog | null;
stt?: number;
} }
// --------------------------- // ---------------------------
@@ -55,9 +28,12 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
visible, visible,
onClose, onClose,
netData, netData,
stt,
}) => { }) => {
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const [editableCatchList, setEditableCatchList] = useState<FishCatch[]>([]); const [editableCatchList, setEditableCatchList] = useState<
Model.FishingLogInfo[]
>([]);
const [selectedFishIndex, setSelectedFishIndex] = useState<number | null>( const [selectedFishIndex, setSelectedFishIndex] = useState<number | null>(
null null
); );
@@ -74,8 +50,8 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
// Khởi tạo dữ liệu khi netData thay đổi // Khởi tạo dữ liệu khi netData thay đổi
React.useEffect(() => { React.useEffect(() => {
if (netData?.catchList) { if (netData?.info) {
setEditableCatchList(netData.catchList); setEditableCatchList(netData.info);
} }
}, [netData]); }, [netData]);
@@ -93,7 +69,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
// if (!netData) return null; // if (!netData) return null;
const isCompleted = netData?.trangThai === "Đã hoàn thành"; const isCompleted = netData?.status === 2; // ví dụ: status=2 là hoàn thành
// Danh sách tên cá có sẵn // Danh sách tên cá có sẵn
const fishNameOptions = [ const fishNameOptions = [
@@ -210,7 +186,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
const handleCancel = () => { const handleCancel = () => {
setIsEditing(false); setIsEditing(false);
setEditableCatchList(netData?.catchList || []); setEditableCatchList(netData?.info || []);
}; };
const handleToggleExpanded = (index: number) => { const handleToggleExpanded = (index: number) => {
@@ -221,7 +197,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
const updateCatchItem = ( const updateCatchItem = (
index: number, index: number,
field: keyof FishCatch, field: keyof Model.FishingLogInfo,
value: string | number value: string | number
) => { ) => {
setEditableCatchList((prev) => setEditableCatchList((prev) =>
@@ -245,7 +221,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
}; };
const handleAddNewFish = () => { const handleAddNewFish = () => {
const newFish: FishCatch = { const newFish: Model.FishingLogInfo = {
fish_species_id: 0, fish_species_id: 0,
fish_name: "", fish_name: "",
catch_number: 0, catch_number: 0,
@@ -289,7 +265,8 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
// Chỉ tính tổng số lượng cá có đơn vị là 'kg' // Chỉ tính tổng số lượng cá có đơn vị là 'kg'
const totalCatch = editableCatchList.reduce( const totalCatch = editableCatchList.reduce(
(sum, item) => (item.catch_unit === "kg" ? sum + item.catch_number : sum), (sum, item) =>
item.catch_unit === "kg" ? sum + (item.catch_number ?? 0) : sum,
0 0
); );
@@ -346,6 +323,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
<InfoSection <InfoSection
netData={netData ?? undefined} netData={netData ?? undefined}
isCompleted={isCompleted} isCompleted={isCompleted}
stt={stt}
/> />
{/* Danh sách cá bắt được */} {/* Danh sách cá bắt được */}
@@ -375,7 +353,7 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
/> />
{/* Ghi chú */} {/* Ghi chú */}
<NotesSection ghiChu={netData?.ghiChu} /> <NotesSection ghiChu={netData?.weather_description} />
</ScrollView> </ScrollView>
</View> </View>
</Modal> </Modal>

View File

@@ -3,19 +3,8 @@ import { Text, TextInput, View } from "react-native";
import styles from "../../style/NetDetailModal.styles"; import styles from "../../style/NetDetailModal.styles";
import { FishSelectDropdown } from "./FishSelectDropdown"; import { FishSelectDropdown } from "./FishSelectDropdown";
interface FishCatch {
fish_species_id: number;
fish_name: string;
catch_number: number;
catch_unit: string;
fish_size: number;
fish_rarity: number;
fish_condition: string;
gear_usage: string;
}
interface FishCardFormProps { interface FishCardFormProps {
fish: FishCatch; fish: Model.FishingLogInfo;
index: number; index: number;
isEditing: boolean; isEditing: boolean;
fishNameOptions: string[]; fishNameOptions: string[];
@@ -32,7 +21,7 @@ interface FishCardFormProps {
// setSelectedGearIndex: (index: number | null) => void; // setSelectedGearIndex: (index: number | null) => void;
onUpdateCatchItem: ( onUpdateCatchItem: (
index: number, index: number,
field: keyof FishCatch, field: keyof Model.FishingLogInfo,
value: string | number value: string | number
) => void; ) => void;
} }
@@ -65,7 +54,7 @@ export const FishCardForm: React.FC<FishCardFormProps> = ({
{isEditing ? ( {isEditing ? (
<FishSelectDropdown <FishSelectDropdown
options={fishNameOptions} options={fishNameOptions}
selectedValue={fish.fish_name} selectedValue={fish.fish_name ?? ""}
isOpen={selectedFishIndex === index} isOpen={selectedFishIndex === index}
onToggle={() => onToggle={() =>
setSelectedFishIndex(selectedFishIndex === index ? null : index) setSelectedFishIndex(selectedFishIndex === index ? null : index)
@@ -110,7 +99,7 @@ export const FishCardForm: React.FC<FishCardFormProps> = ({
{isEditing ? ( {isEditing ? (
<FishSelectDropdown <FishSelectDropdown
options={unitOptions} options={unitOptions}
selectedValue={fish.catch_unit} selectedValue={fish.catch_unit ?? ""}
isOpen={selectedUnitIndex === index} isOpen={selectedUnitIndex === index}
onToggle={() => onToggle={() =>
setSelectedUnitIndex(selectedUnitIndex === index ? null : index) setSelectedUnitIndex(selectedUnitIndex === index ? null : index)

View File

@@ -2,19 +2,8 @@ import React from "react";
import { Text, View } from "react-native"; import { Text, View } from "react-native";
import styles from "../../style/NetDetailModal.styles"; import styles from "../../style/NetDetailModal.styles";
interface FishCatch {
fish_species_id: number;
fish_name: string;
catch_number: number;
catch_unit: string;
fish_size: number;
fish_rarity: number;
fish_condition: string;
gear_usage: string;
}
interface FishCardHeaderProps { interface FishCardHeaderProps {
fish: FishCatch; fish: Model.FishingLogInfo;
} }
export const FishCardHeader: React.FC<FishCardHeaderProps> = ({ fish }) => { export const FishCardHeader: React.FC<FishCardHeaderProps> = ({ fish }) => {

View File

@@ -5,19 +5,8 @@ import styles from "../../style/NetDetailModal.styles";
import { FishCardForm } from "./FishCardForm"; import { FishCardForm } from "./FishCardForm";
import { FishCardHeader } from "./FishCardHeader"; import { FishCardHeader } from "./FishCardHeader";
interface FishCatch {
fish_species_id: number;
fish_name: string;
catch_number: number;
catch_unit: string;
fish_size: number;
fish_rarity: number;
fish_condition: string;
gear_usage: string;
}
interface FishCardListProps { interface FishCardListProps {
catchList: FishCatch[]; catchList: Model.FishingLogInfo[];
isEditing: boolean; isEditing: boolean;
expandedFishIndex: number[]; expandedFishIndex: number[];
selectedFishIndex: number | null; selectedFishIndex: number | null;
@@ -31,7 +20,7 @@ interface FishCardListProps {
onToggleExpanded: (index: number) => void; onToggleExpanded: (index: number) => void;
onUpdateCatchItem: ( onUpdateCatchItem: (
index: number, index: number,
field: keyof FishCatch, field: keyof Model.FishingLogInfo,
value: string | number value: string | number
) => void; ) => void;
setSelectedFishIndex: (index: number | null) => void; setSelectedFishIndex: (index: number | null) => void;

View File

@@ -17,31 +17,37 @@ interface NetDetail {
} }
interface InfoSectionProps { interface InfoSectionProps {
netData?: NetDetail; netData?: Model.FishingLog;
isCompleted: boolean; isCompleted: boolean;
stt?: number;
} }
export const InfoSection: React.FC<InfoSectionProps> = ({ export const InfoSection: React.FC<InfoSectionProps> = ({
netData, netData,
isCompleted, isCompleted,
stt,
}) => { }) => {
if (!netData) { if (!netData) {
return null; return null;
} }
const infoItems = [ const infoItems = [
{ label: "Số thứ tự", value: netData.stt }, { label: "Số thứ tự", value: `Mẻ ${stt}` },
{ {
label: "Trạng thái", label: "Trạng thái",
value: netData.trangThai, value: netData.status === 1 ? "Đã hoàn thành" : "Chưa hoàn thành",
isStatus: true, isStatus: true,
}, },
{ {
label: "Thời gian bắt đầu", label: "Thời gian bắt đầu",
value: netData.thoiGianBatDau || "Chưa cập nhật", value: netData.start_at
? new Date(netData.start_at).toLocaleString()
: "Chưa cập nhật",
}, },
{ {
label: "Thời gian kết thúc", label: "Thời gian kết thúc",
value: netData.thoiGianKetThuc || "Chưa cập nhật", value: netData.start_at
? new Date(netData.end_at).toLocaleString()
: "Chưa cập nhật",
}, },
{ {
label: "Vị trí hạ thu", label: "Vị trí hạ thu",
@@ -70,7 +76,7 @@ export const InfoSection: React.FC<InfoSectionProps> = ({
<View <View
style={[ style={[
styles.statusBadge, styles.statusBadge,
isCompleted item.value === "Đã hoàn thành"
? styles.statusBadgeCompleted ? styles.statusBadgeCompleted
: styles.statusBadgeInProgress, : styles.statusBadgeInProgress,
]} ]}
@@ -78,7 +84,7 @@ export const InfoSection: React.FC<InfoSectionProps> = ({
<Text <Text
style={[ style={[
styles.statusBadgeText, styles.statusBadgeText,
isCompleted item.value === "Đã hoàn thành"
? styles.statusBadgeTextCompleted ? styles.statusBadgeTextCompleted
: styles.statusBadgeTextInProgress, : styles.statusBadgeTextInProgress,
]} ]}