import * as WebBrowser from 'expo-web-browser'; import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import { ScrollView } from 'react-native-gesture-handler'; import { Modal, Portal } from 'react-native-paper'; import { Div, Image, Text, Button } from 'react-native-magnus'; import { Flex } from '@ant-design/react-native'; import { useCreation, useMap } from '@umijs/hooks'; import useModel from 'flooks'; import Detail from './model'; import Plus from '../../components/Plus'; export default function SelectSpecification() { const { showSelect, selectInfo, addCart, changeSelect } = useModel(Detail, [ 'showSelect', 'selectInfo', ]); const { id, img, name, discountAmount, amount, specifications, } = selectInfo || { specifications: [] }; // 全部的分类 一级包含二级形式 list const selectspecifications = useCreation(() => { return specifications.filter((item) => { return !item.parent && item.children.length > 0; }); }, [specifications]); // 全部的一级分类的 Map const classify1Map = useCreation(() => { const map = new Map(); selectspecifications.forEach((item) => { map.set(item.id, item); }); return map; }, [selectspecifications]); // 选择模块 const [selectMap, selectMapEvent] = useMap([]); React.useEffect(() => { selectMapEvent.reset(); }, [id]); // 全部选中的二级分类 list const selectClassify2 = useCreation(() => { let list = []; [...selectMap.values()].forEach((item) => { list = list.concat([...item.values()]); }); return list; }, [selectMap]); // 全部选中的二级分类id list const selectClassifyIds = useCreation(() => { return selectClassify2.map((item) => { return item.id; }); }, [selectClassify2]); // 未被选的一级分类 const notSelectClassify1 = useCreation(() => { return [...classify1Map.values()].filter((item) => { return !selectMap.get(item.id) || selectMap.get(item.id).size === 0; }); }, [selectMap, classify1Map]); // 总价 const totalAmount = useCreation(() => { let money = discountAmount || amount; selectClassify2.forEach((item) => { money += item.amount || 0; }); return money; }, [discountAmount, amount, selectClassify2]); return ( changeSelect(false)} contentContainerStyle={styles.contentContainerStyle} > {name} {selectClassify2.length !== 0 && ( 已选择{' '} {selectClassify2 .map((item) => { return item.name; }) .join('/')} )} ¥{totalAmount} {discountAmount !== null && ( ¥{amount} )} {/* { addCart(id); }} /> */} {selectspecifications.map((item) => { return (
{item.name}
{item.children.map((child) => { const choosed = selectClassifyIds.indexOf(child.id) !== -1; return (
); })}
); })}
); } const styles = StyleSheet.create({ contentContainerStyle: { backgroundColor: '#fff', height: '70%', position: 'absolute', bottom: 0, left: 0, right: 0, padding: 20, justifyContent: 'flex-start', zIndex: 3, }, icon: { width: 80, height: 80, borderRadius: 3, }, info: { marginLeft: 8, }, list: { paddingTop: 15, }, });