MerchatApplyScreen.jsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  4. import { ScrollView } from 'react-native-gesture-handler';
  5. import { InputItem } from '@ant-design/react-native';
  6. import { useRequest, useCreation } from '@umijs/hooks';
  7. import { useTranslation } from 'react-i18next';
  8. import useModel from 'flooks';
  9. import User from '../../flooks/User'; // detail模块通用方法
  10. import Toast from '../../flooks/Toast'; // detail模块通用方法
  11. import Header from '../../components/Header';
  12. import request from '../../Utils/RequestUtils';
  13. function saveRequest(data) {
  14. return request.post('/cooperateApply/save', {
  15. data,
  16. });
  17. }
  18. export default function MerchatApplyScreen({ navigation }) {
  19. const { t } = useTranslation();
  20. const { userInfo } = useModel(User, ['id']);
  21. const { warnning, success } = useModel(Toast, []);
  22. const [name, setname] = React.useState('');
  23. const [phone, setphone] = React.useState('');
  24. const [merName, setmerName] = React.useState('');
  25. const [category, setcategory] = React.useState('');
  26. const [address, setaddress] = React.useState('');
  27. const allpyRequest = useRequest((data) => saveRequest(data), {
  28. manual: true,
  29. onError: (e) => {
  30. warnning(e.error);
  31. },
  32. onSuccess: () => {
  33. success(t('shen-qing-ti-jiao-cheng-gong'));
  34. navigation.goBack();
  35. },
  36. });
  37. const canSubmit = useCreation(() => {
  38. if (name && phone && merName && category && address) {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }, [name, phone, merName, category, address]);
  44. return (
  45. <>
  46. <Header title={t('kai-dian-shen-qing')} />
  47. <ScrollView
  48. contentContainerStyle={{
  49. backgroundColor: '#fff',
  50. flexGrow: 1,
  51. }}
  52. >
  53. <Div bg="white">
  54. <InputItem
  55. clear
  56. type="phone"
  57. value={name}
  58. onChange={setname}
  59. placeholder={t('shu-ru-lian-xi-ren')}
  60. style={{ fontSize: 14 }}
  61. >
  62. <Text fontSize="sm">{t('lian-xi-ren')}</Text>
  63. </InputItem>
  64. <InputItem
  65. clear
  66. type="phone"
  67. value={phone}
  68. onChange={setphone}
  69. placeholder={t('shu-ru-lian-xi-dian-hua')}
  70. style={{ fontSize: 14 }}
  71. >
  72. <Text fontSize="sm">{t('lian-xi-dian-hua')}</Text>
  73. </InputItem>
  74. <InputItem
  75. clear
  76. value={merName}
  77. onChange={setmerName}
  78. placeholder={t('shu-ru-dian-pu-ming-cheng')}
  79. style={{ fontSize: 14 }}
  80. >
  81. <Text fontSize="sm">{t('dian-pu-ming-cheng')}</Text>
  82. </InputItem>
  83. <InputItem
  84. clear
  85. value={category}
  86. onChange={setcategory}
  87. placeholder={t('shu-ru-jing-ying-lei-xing')}
  88. style={{ fontSize: 14 }}
  89. >
  90. <Text fontSize="sm">{t('jing-ying-lei-xing')}</Text>
  91. </InputItem>
  92. <InputItem
  93. clear
  94. value={address}
  95. onChange={setaddress}
  96. placeholder={t('qing-shu-ru-dian-pu-di-zhi')}
  97. style={{ fontSize: 14 }}
  98. >
  99. <Text fontSize="sm">{t('dian-pu-di-zhi')}</Text>
  100. </InputItem>
  101. </Div>
  102. <Button
  103. my={30}
  104. mx={130}
  105. fontSize="sm"
  106. block
  107. bg="brand500"
  108. disabled={!canSubmit}
  109. onPress={() => {
  110. allpyRequest.run({
  111. name,
  112. phone,
  113. merName,
  114. category,
  115. address,
  116. userId: userInfo.id,
  117. });
  118. }}
  119. >
  120. {t('ti-jiao')}
  121. </Button>
  122. </ScrollView>
  123. </>
  124. );
  125. }