AddScreen.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* eslint-disable camelcase */
  2. /* eslint-disable no-undef */
  3. /* eslint-disable no-shadow */
  4. import * as WebBrowser from "expo-web-browser";
  5. import * as React from "react";
  6. import { StyleSheet } from "react-native";
  7. import { useModel } from "flooks";
  8. import { useFocusEffect } from "@react-navigation/native";
  9. import {
  10. Layout,
  11. Button,
  12. useTheme,
  13. Radio,
  14. } from "@ui-kitten/components";
  15. import FormInput from "../../components/FormInput";
  16. import NavHeaderBar from "../../components/NavHeaderBar";
  17. const styles = StyleSheet.create({
  18. form: {
  19. paddingHorizontal: 10,
  20. },
  21. radio: {
  22. paddingVertical: 15,
  23. paddingHorizontal: 15,
  24. },
  25. btn: {
  26. marginHorizontal: 15,
  27. marginVertical: 10,
  28. },
  29. });
  30. export default function BankScreen({ navigation, route }) {
  31. const theme = useTheme();
  32. const { changeBackground } = useModel("barModel");
  33. const {
  34. bindBankText1,
  35. bankTitle1,
  36. bankTitle2,
  37. bankTitle3,
  38. bankTitle4,
  39. register_form_4,
  40. bankPla1,
  41. bankPla2,
  42. bankPla3,
  43. bankPla4,
  44. register_pla_4,
  45. login_form_3,
  46. login_pla_3,
  47. bankTitle5,
  48. next,
  49. successText,
  50. add,
  51. confirm,
  52. delText,
  53. } = useModel("wordsModel");
  54. const { httpPost, httpGet } = useModel("httpModel", true);
  55. const { userId } = useModel("userModel");
  56. const { success } = useModel("loadingModel");
  57. const { removeEvent } = useModel("dialogModel", true);
  58. const [id, setId] = React.useState(0);
  59. const [prePage, setPrePage] = React.useState("Bank");
  60. useFocusEffect(
  61. React.useCallback(() => {
  62. changeBackground(theme["color-primary-500"]);
  63. const { params } = route;
  64. const { id, pageName } = params || {};
  65. if (id) {
  66. setId(id);
  67. }
  68. if (pageName) {
  69. setPrePage(pageName);
  70. }
  71. }, [])
  72. );
  73. const [bankName, changeBankName] = React.useState("");
  74. const [cardNo, changeCardId] = React.useState("");
  75. const [realName, changeRealName] = React.useState("");
  76. const [idNo, changeIdNo] = React.useState("");
  77. const [phone, changePhone] = React.useState("");
  78. const [code, changeCode] = React.useState("");
  79. const [checked, setChecked] = React.useState(true);
  80. React.useEffect(() => {
  81. if (id) {
  82. httpGet(`/bankCard/get/${id}`, {}, true).then(res => {
  83. function getVal(value) {
  84. return value || "";
  85. }
  86. changeBankName(getVal(res.bankName));
  87. changeCardId(getVal(res.cardNo));
  88. changeRealName(getVal(res.realName));
  89. changeIdNo(getVal(res.idNo));
  90. changePhone(getVal(res.phone));
  91. // changeCode(getVal(res.code));
  92. });
  93. }
  94. }, [id]);
  95. const canNext = React.useMemo(() => {
  96. if (
  97. bankName &&
  98. cardNo &&
  99. realName &&
  100. idNo &&
  101. phone &&
  102. (code || id) &&
  103. checked
  104. ) {
  105. return true;
  106. }
  107. return false;
  108. }, [bankName, cardNo, realName, idNo, phone, code, checked, id]);
  109. const submit = () => {
  110. httpPost(
  111. "/bankCard/save",
  112. {
  113. id: id || "",
  114. bankName,
  115. cardNo,
  116. realName,
  117. idNo,
  118. phone,
  119. code,
  120. userId,
  121. },
  122. {
  123. body: "json",
  124. },
  125. true
  126. ).then(res => {
  127. success(add + successText);
  128. const query = {};
  129. if (prePage === "reCharge") {
  130. query.selectId = res.id;
  131. }
  132. navigation.navigate(prePage, query);
  133. });
  134. };
  135. const remove = () => {
  136. removeEvent(() => {
  137. httpPost(`/bankCard/del/${ id}`, {}, true).then(() => {
  138. success(delText + successText);
  139. navigation.navigate(prePage);
  140. });
  141. });
  142. };
  143. return (
  144. <>
  145. <NavHeaderBar title={bindBankText1} />
  146. <Layout style={styles.form}>
  147. {/* 银行 */}
  148. <FormInput
  149. appearance='inner'
  150. label={bankTitle1}
  151. placeholder={bankPla1}
  152. value={bankName}
  153. onChange={changeBankName}
  154. />
  155. {/* 银行卡 */}
  156. <FormInput
  157. appearance='inner'
  158. label={bankTitle2}
  159. placeholder={bankPla2}
  160. value={cardNo}
  161. onChange={changeCardId}
  162. />
  163. {/* 姓名 */}
  164. <FormInput
  165. appearance='inner'
  166. label={bankTitle3}
  167. placeholder={bankPla3}
  168. value={realName}
  169. onChange={changeRealName}
  170. />
  171. {/* 身份证号 */}
  172. <FormInput
  173. appearance='inner'
  174. label={bankTitle4}
  175. placeholder={bankPla4}
  176. value={idNo}
  177. onChange={changeIdNo}
  178. />
  179. {/* 手机号 */}
  180. <FormInput
  181. appearance='inner'
  182. type='phone'
  183. label={register_form_4}
  184. placeholder={register_pla_4}
  185. value={phone}
  186. onChange={changePhone}
  187. />
  188. {/* 验证码 */}
  189. {id === 0 && (
  190. <FormInput
  191. appearance='inner'
  192. type='code'
  193. label={login_form_3}
  194. placeholder={login_pla_3}
  195. value={code}
  196. onChange={changeCode}
  197. btnText='发送验证码'
  198. />
  199. )}
  200. </Layout>
  201. {id === 0 && (
  202. <Radio
  203. style={styles.radio}
  204. checked={checked}
  205. onChange={nextChecked => setChecked(nextChecked)}
  206. >
  207. {bankTitle5}
  208. </Radio>
  209. )}
  210. <Button style={styles.btn} disabled={!canNext} onPress={submit}>
  211. {prePage === "reCharge" ? next : confirm}
  212. </Button>
  213. {id !== 0 && (
  214. <Button appearance='ghost' status='info' onPress={remove}>
  215. {delText}
  216. </Button>
  217. )}
  218. </>
  219. );
  220. }