|
@@ -1,17 +1,16 @@
|
|
|
import * as WebBrowser from 'expo-web-browser';
|
|
import * as WebBrowser from 'expo-web-browser';
|
|
|
import * as React from 'react';
|
|
import * as React from 'react';
|
|
|
-import { StyleSheet, View, Image } from 'react-native';
|
|
|
|
|
|
|
+import { StyleSheet, View } from 'react-native';
|
|
|
import { ScrollView } from 'react-native-gesture-handler';
|
|
import { ScrollView } from 'react-native-gesture-handler';
|
|
|
import { Modal, Portal } from 'react-native-paper';
|
|
import { Modal, Portal } from 'react-native-paper';
|
|
|
|
|
+import { Div, Image, Text, Button } from 'react-native-magnus';
|
|
|
import { Flex } from '@ant-design/react-native';
|
|
import { Flex } from '@ant-design/react-native';
|
|
|
import { useCreation, useMap } from '@umijs/hooks';
|
|
import { useCreation, useMap } from '@umijs/hooks';
|
|
|
|
|
|
|
|
import useModel from 'flooks';
|
|
import useModel from 'flooks';
|
|
|
import Detail from './model';
|
|
import Detail from './model';
|
|
|
|
|
|
|
|
-import Text from '../../components/Text';
|
|
|
|
|
import Plus from '../../components/Plus';
|
|
import Plus from '../../components/Plus';
|
|
|
-import Button from '../../components/Button';
|
|
|
|
|
|
|
|
|
|
export default function SelectSpecification() {
|
|
export default function SelectSpecification() {
|
|
|
const { showSelect, selectInfo, addCart, changeSelect } = useModel(Detail, [
|
|
const { showSelect, selectInfo, addCart, changeSelect } = useModel(Detail, [
|
|
@@ -52,10 +51,12 @@ export default function SelectSpecification() {
|
|
|
|
|
|
|
|
// 全部选中的二级分类 list
|
|
// 全部选中的二级分类 list
|
|
|
const selectClassify2 = useCreation(() => {
|
|
const selectClassify2 = useCreation(() => {
|
|
|
- const list = [...selectMap.values()].map((item) => {
|
|
|
|
|
- return [...item.values()];
|
|
|
|
|
|
|
+ let list = [];
|
|
|
|
|
+ [...selectMap.values()].forEach((item) => {
|
|
|
|
|
+ list = list.concat([...item.values()]);
|
|
|
});
|
|
});
|
|
|
- return [...selectMap.values()].length > 0 ? list.flat() : [];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
}, [selectMap]);
|
|
}, [selectMap]);
|
|
|
|
|
|
|
|
// 全部选中的二级分类id list
|
|
// 全部选中的二级分类id list
|
|
@@ -81,56 +82,6 @@ export default function SelectSpecification() {
|
|
|
return money;
|
|
return money;
|
|
|
}, [discountAmount, amount, selectClassify2]);
|
|
}, [discountAmount, amount, selectClassify2]);
|
|
|
|
|
|
|
|
- const classify2 = (list) => {
|
|
|
|
|
- return list.map((item, index) => {
|
|
|
|
|
- const choosed = selectClassifyIds.indexOf(item.id) !== -1;
|
|
|
|
|
- return (
|
|
|
|
|
- <Button
|
|
|
|
|
- key={item.id}
|
|
|
|
|
- width="100%"
|
|
|
|
|
- height={23}
|
|
|
|
|
- color={choosed ? '#FFF5D8' : '#EEEEEE'}
|
|
|
|
|
- fontColor={choosed ? '#FFC21C' : '#000000'}
|
|
|
|
|
- size="mini"
|
|
|
|
|
- style={{
|
|
|
|
|
- width: '30%',
|
|
|
|
|
- marginTop: 5,
|
|
|
|
|
- marginRight: (index + 1) % 3 ? '5%' : 0,
|
|
|
|
|
- }}
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- if (choosed) {
|
|
|
|
|
- const selects = selectMapEvent.get(item.parent);
|
|
|
|
|
- selects.delete(item.id);
|
|
|
|
|
- selectMapEvent.set(item.parent, selects);
|
|
|
|
|
- } else if (
|
|
|
|
|
- classify1Map.get(item.parent).multiple &&
|
|
|
|
|
- selectMapEvent.get(item.parent)
|
|
|
|
|
- ) {
|
|
|
|
|
- const selects = selectMapEvent.get(item.parent);
|
|
|
|
|
- selects.set(item.id, item);
|
|
|
|
|
- selectMapEvent.set(item.parent, selects);
|
|
|
|
|
- } else {
|
|
|
|
|
- selectMapEvent.set(item.parent, new Map([[item.id, item]]));
|
|
|
|
|
- }
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
- {item.name}
|
|
|
|
|
- </Button>
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const classify1 = (list) => {
|
|
|
|
|
- return list.map((item) => {
|
|
|
|
|
- return (
|
|
|
|
|
- <View key={item.id} style={styles.list}>
|
|
|
|
|
- <Text>{item.name}</Text>
|
|
|
|
|
- <Flex wrap="wrap">{classify2(item.children)}</Flex>
|
|
|
|
|
- </View>
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<Portal>
|
|
<Portal>
|
|
|
<Modal
|
|
<Modal
|
|
@@ -140,13 +91,19 @@ export default function SelectSpecification() {
|
|
|
contentContainerStyle={styles.contentContainerStyle}
|
|
contentContainerStyle={styles.contentContainerStyle}
|
|
|
>
|
|
>
|
|
|
<Flex align="stretch">
|
|
<Flex align="stretch">
|
|
|
- <Image style={styles.icon} resizeMode="cover" source={{ uri: img }} />
|
|
|
|
|
|
|
+ <Image
|
|
|
|
|
+ w={80}
|
|
|
|
|
+ h={80}
|
|
|
|
|
+ style={styles.icon}
|
|
|
|
|
+ resizeMode="cover"
|
|
|
|
|
+ source={{ uri: img }}
|
|
|
|
|
+ />
|
|
|
<Flex.Item style={styles.info}>
|
|
<Flex.Item style={styles.info}>
|
|
|
<Text size="s1" bold>
|
|
<Text size="s1" bold>
|
|
|
{name}
|
|
{name}
|
|
|
</Text>
|
|
</Text>
|
|
|
{selectClassify2.length !== 0 && (
|
|
{selectClassify2.length !== 0 && (
|
|
|
- <Text size="c1" type="info">
|
|
|
|
|
|
|
+ <Text fontSize="sm" color="gray300">
|
|
|
已选择{' '}
|
|
已选择{' '}
|
|
|
{selectClassify2
|
|
{selectClassify2
|
|
|
.map((item) => {
|
|
.map((item) => {
|
|
@@ -157,16 +114,14 @@ export default function SelectSpecification() {
|
|
|
)}
|
|
)}
|
|
|
|
|
|
|
|
<Flex.Item />
|
|
<Flex.Item />
|
|
|
- <Text size="s1" type="error">
|
|
|
|
|
|
|
+ <Text fontSize="sm" color="red500">
|
|
|
¥{totalAmount}
|
|
¥{totalAmount}
|
|
|
{discountAmount !== null && (
|
|
{discountAmount !== null && (
|
|
|
<Text
|
|
<Text
|
|
|
- size="c1"
|
|
|
|
|
- type="info"
|
|
|
|
|
- style={{
|
|
|
|
|
- textDecorationLine: 'line-through',
|
|
|
|
|
- marginLeft: 10,
|
|
|
|
|
- }}
|
|
|
|
|
|
|
+ textdecorationline="line-through"
|
|
|
|
|
+ fontSize="sm"
|
|
|
|
|
+ color="gray300"
|
|
|
|
|
+ ml={10}
|
|
|
>
|
|
>
|
|
|
¥{amount}
|
|
¥{amount}
|
|
|
</Text>
|
|
</Text>
|
|
@@ -181,14 +136,58 @@ export default function SelectSpecification() {
|
|
|
</Flex>
|
|
</Flex>
|
|
|
|
|
|
|
|
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
|
<ScrollView contentContainerStyle={{ flexGrow: 1 }}>
|
|
|
- {classify1(selectspecifications)}
|
|
|
|
|
|
|
+ {selectspecifications.map((item) => {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Div key={item.id} py={20}>
|
|
|
|
|
+ <Text>{item.name}</Text>
|
|
|
|
|
+ <Div row flexWrap="wrap" justifyContent="space-between">
|
|
|
|
|
+ {item.children.map((child) => {
|
|
|
|
|
+ const choosed = selectClassifyIds.indexOf(child.id) !== -1;
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Div key={child.id} w="32%" mt={5}>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ rounded="xs"
|
|
|
|
|
+ bg={choosed ? 'brand200' : 'gray200'}
|
|
|
|
|
+ color={choosed ? 'brand500' : 'gray600'}
|
|
|
|
|
+ fontSize="xs"
|
|
|
|
|
+ block
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ if (choosed) {
|
|
|
|
|
+ const selects = selectMapEvent.get(child.parent);
|
|
|
|
|
+ selects.delete(child.id);
|
|
|
|
|
+ selectMapEvent.set(child.parent, selects);
|
|
|
|
|
+ } else if (
|
|
|
|
|
+ classify1Map.get(child.parent).multiple &&
|
|
|
|
|
+ selectMapEvent.get(child.parent)
|
|
|
|
|
+ ) {
|
|
|
|
|
+ const selects = selectMapEvent.get(child.parent);
|
|
|
|
|
+ selects.set(child.id, child);
|
|
|
|
|
+ selectMapEvent.set(child.parent, selects);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ selectMapEvent.set(
|
|
|
|
|
+ child.parent,
|
|
|
|
|
+ new Map([[child.id, child]])
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ {child.name}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Div>
|
|
|
|
|
+ );
|
|
|
|
|
+ })}
|
|
|
|
|
+ </Div>
|
|
|
|
|
+ </Div>
|
|
|
|
|
+ );
|
|
|
|
|
+ })}
|
|
|
</ScrollView>
|
|
</ScrollView>
|
|
|
|
|
|
|
|
<Button
|
|
<Button
|
|
|
disabled={notSelectClassify1.length}
|
|
disabled={notSelectClassify1.length}
|
|
|
block
|
|
block
|
|
|
- size="large"
|
|
|
|
|
- type="primary"
|
|
|
|
|
|
|
+ bg="brand500"
|
|
|
|
|
+ fontSize="xl"
|
|
|
onPress={() => addCart(id, selectClassifyIds.join(','), 1)}
|
|
onPress={() => addCart(id, selectClassifyIds.join(','), 1)}
|
|
|
>
|
|
>
|
|
|
选好了
|
|
选好了
|