Classification.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StyleSheet, FlatList } from 'react-native';
  4. import { Div, Text } from 'react-native-magnus';
  5. import { TouchableRipple } from 'react-native-paper';
  6. import { useRequest } from '@umijs/hooks';
  7. import useModel from 'flooks';
  8. import Detail from './model';
  9. function Item({ name, isChoose, select }) {
  10. return (
  11. <TouchableRipple onPress={select}>
  12. <Div py={10} px={20} bg={isChoose ? 'white' : ''}>
  13. <Text color={isChoose ? 'brand500' : ''} textAlign="left">
  14. {name}
  15. </Text>
  16. </Div>
  17. </TouchableRipple>
  18. );
  19. }
  20. export default function Classification({ height }) {
  21. const { id, selectClass, changeSelectClass } = useModel(Detail, [
  22. 'id',
  23. 'selectClass',
  24. ]);
  25. const [classifications, setclassifications] = React.useState([]);
  26. useRequest(
  27. () => {
  28. const params = {
  29. query: {
  30. merchantId: id,
  31. isOpen: true,
  32. },
  33. page: 0,
  34. size: 100,
  35. };
  36. const urls = Object.keys(params).map((item) => {
  37. return `${item}=${encodeURI(JSON.stringify(params[item]))}`;
  38. });
  39. return `/classification/all?${urls.join('&')}`;
  40. },
  41. {
  42. refreshDeps: [id],
  43. onSuccess: (result) => {
  44. setclassifications(result.content);
  45. if (!result.empty) {
  46. changeSelectClass(result.content[0].id);
  47. }
  48. },
  49. }
  50. );
  51. // classification;
  52. return (
  53. <Div maxW={95} w={95} pb={100}>
  54. {classifications.map((item) => {
  55. return (
  56. <Item
  57. key={item.id}
  58. name={item.name}
  59. isChoose={selectClass === item.id}
  60. select={() => {
  61. changeSelectClass(item.id);
  62. }}
  63. />
  64. );
  65. })}
  66. </Div>
  67. );
  68. }
  69. const styles = StyleSheet.create({
  70. left: {
  71. width: 95,
  72. maxWidth: 95,
  73. paddingBottom: 100,
  74. },
  75. item: {
  76. paddingHorizontal: 15,
  77. paddingVertical: 10,
  78. },
  79. });