BackPasswordScreen.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React, { useState } from "react";
  2. import { Div, Text } from "react-native-magnus";
  3. import { Button } from "@ui-kitten/components";
  4. import { useModel } from "flooks";
  5. import { useCreation, useMount } from "ahooks";
  6. import NavHeaderBar from "../../components/NavHeaderBar";
  7. import SmsInput from "../../components/SmsInput";
  8. import FormInput from "../../components/FormInput";
  9. export default function BackPasswordScreen({ navigation }) {
  10. const { userInfo } = useModel("userModel");
  11. const { login_form_3, login_pla_3, confirm } = useModel("wordsModel");
  12. const { httpPost } = useModel("httpModel");
  13. const { success } = useModel("loadingModel");
  14. const [code, setcode] = useState("");
  15. const [password, setpassword] = useState();
  16. const [password2, setpassword2] = useState();
  17. const { showDialog } = useModel("dialogModel");
  18. const [takePhone, settakePhone] = useState(false);
  19. const { phone } = userInfo;
  20. const showPhone = useCreation(() => {
  21. if (phone) return `${phone.substr(0, 3)} **** ${phone.substr(-4, 4)}`;
  22. return "";
  23. }, [phone]);
  24. function changePassword() {
  25. httpPost(
  26. "/user/changePassword",
  27. {
  28. password,
  29. key: `+86${phone}`,
  30. code,
  31. },
  32. {},
  33. true
  34. ).then(() => {
  35. success("设置成功");
  36. setTimeout(() => {
  37. navigation.goBack();
  38. }, 1500);
  39. });
  40. }
  41. useMount(() => {
  42. if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone)) {
  43. showDialog({
  44. bodyText: "当前客户手机号异常,请联系客服更换密码",
  45. status: "danger",
  46. cancelable: false,
  47. confirmCallback: () => {
  48. navigation.goBack();
  49. },
  50. });
  51. } else {
  52. settakePhone(true);
  53. }
  54. });
  55. const canSubmit = useCreation(() => {
  56. if (phone && code && password && password2 === password) return true;
  57. return false;
  58. }, [phone, password, code, password2]);
  59. return (
  60. <>
  61. <NavHeaderBar title="登录密码设置" />
  62. <Div bg="white" py={15} alignItems="center" mt={10}>
  63. <Text color="black">我们已经向您的手机发送了短信校验码:</Text>
  64. <Text color="black" mt={5}>
  65. {showPhone}
  66. </Text>
  67. </Div>
  68. <Div bg="white" p={20} mt={10}>
  69. {/* 验证码 */}
  70. <SmsInput
  71. label={`${login_form_3}:`}
  72. placeholder={login_pla_3}
  73. labelWidth={50}
  74. phone={phone}
  75. onCodeChange={setcode}
  76. type="login"
  77. takePhone={takePhone}
  78. />
  79. {/* 密码 */}
  80. <FormInput
  81. label="新密码"
  82. value={password}
  83. type="password"
  84. placeholder="输入新密码"
  85. onChange={setpassword}
  86. textAlign="right"
  87. labelStyle={{ width: 50 }}
  88. />
  89. {/* 确认密码 */}
  90. <FormInput
  91. label="确认密码"
  92. value={password2}
  93. type="password"
  94. placeholder="再次输入新密码"
  95. onChange={setpassword2}
  96. textAlign="right"
  97. labelStyle={{ width: 50 }}
  98. />
  99. <Button
  100. disabled={!canSubmit}
  101. onPress={changePassword}
  102. style={{
  103. width: 112,
  104. marginTop: 20,
  105. alignSelf: "center",
  106. }}
  107. >
  108. {confirm}
  109. </Button>
  110. </Div>
  111. </>
  112. );
  113. }