|
|
@@ -7,7 +7,7 @@ import { StyleSheet } from "react-native";
|
|
|
import { Layout, Text, useTheme, Button, Card } from "@ui-kitten/components";
|
|
|
import { useModel } from "flooks";
|
|
|
import { useFocusEffect, useRoute } from "@react-navigation/native";
|
|
|
-import { useCreation, useUnmount } from "@umijs/hooks";
|
|
|
+import { useCreation, useUnmount, useMount } from "@umijs/hooks";
|
|
|
import moment from "moment";
|
|
|
import Textarea from "react-native-textarea";
|
|
|
import ScrollPage from "../components/ScrollPage";
|
|
|
@@ -76,13 +76,14 @@ export default function Guide1Screen({ navigation }) {
|
|
|
const theme = useTheme();
|
|
|
const { changeBackground } = useModel("barModel");
|
|
|
const { httpGet, httpPost } = useModel("httpModel", true);
|
|
|
- const { success, loading } = useModel("loadingModel", true);
|
|
|
+ const { success, loading, clearLoading } = useModel("loadingModel", true);
|
|
|
const { mid, changeGuideStep } = useModel("userModel", true);
|
|
|
const {
|
|
|
addClassification,
|
|
|
editGoodsMap,
|
|
|
saveClassByList,
|
|
|
removeGoodsClassMap,
|
|
|
+ sortClassification,
|
|
|
} = useModel("goodsModel");
|
|
|
|
|
|
const {
|
|
|
@@ -110,7 +111,7 @@ export default function Guide1Screen({ navigation }) {
|
|
|
const route = useRoute();
|
|
|
const [routeName, setRouteName] = React.useState("");
|
|
|
|
|
|
- const [id, changeId] = React.useState("");
|
|
|
+ const [id, changeId] = React.useState("NEW");
|
|
|
|
|
|
const [name, changeName] = React.useState("");
|
|
|
const [amount, changeAmount] = React.useState("");
|
|
|
@@ -132,11 +133,6 @@ export default function Guide1Screen({ navigation }) {
|
|
|
});
|
|
|
}, [goodsSpecification]);
|
|
|
|
|
|
- useUnmount(() => {
|
|
|
- removeGoodsClassMap();
|
|
|
- console.log('离开')
|
|
|
- });
|
|
|
-
|
|
|
function getInfo(res) {
|
|
|
changeName(res.name || "");
|
|
|
if (res.discountAmount) {
|
|
|
@@ -166,31 +162,37 @@ export default function Guide1Screen({ navigation }) {
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
- useFocusEffect(
|
|
|
- React.useCallback(() => {
|
|
|
- changeBackground(theme["color-primary-500"]);
|
|
|
- const { params, name } = route;
|
|
|
- setRouteName(name);
|
|
|
- if (params) {
|
|
|
- if (params.id) {
|
|
|
- changeId(params.id);
|
|
|
- loading();
|
|
|
- httpGet(`/goods/get/${params.id}`).then(res => {
|
|
|
- getInfo(res);
|
|
|
|
|
|
- if (editGoodsMap.has(params.id)) {
|
|
|
- changeGoodsSpecification(editGoodsMap.get(params.id));
|
|
|
- } else {
|
|
|
- changeGoodsSpecification(res.specifications);
|
|
|
- }
|
|
|
+ useMount(() => {
|
|
|
+ const { params, name } = route;
|
|
|
+ setRouteName(name);
|
|
|
+ if (params) {
|
|
|
+ if (params.id) {
|
|
|
+ changeId(params.id);
|
|
|
+ loading();
|
|
|
+ httpGet(`/goods/get/${params.id}`, {}, true)
|
|
|
+ .then(res => {
|
|
|
+ getInfo(res);
|
|
|
+ changeGoodsSpecification(sortClassification(res.specifications));
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ clearLoading();
|
|
|
});
|
|
|
- }
|
|
|
- } else {
|
|
|
- getInfo({});
|
|
|
- if (editGoodsMap.has("NEW")) {
|
|
|
- changeGoodsSpecification(editGoodsMap.get("NEW"));
|
|
|
- }
|
|
|
}
|
|
|
+ }
|
|
|
+ });
|
|
|
+ useUnmount(() => {
|
|
|
+ removeGoodsClassMap();
|
|
|
+ });
|
|
|
+
|
|
|
+ React.useEffect(() => {
|
|
|
+ if (editGoodsMap.has(id)) {
|
|
|
+ changeGoodsSpecification(editGoodsMap.get(id));
|
|
|
+ }
|
|
|
+ }, [editGoodsMap.get(id)]);
|
|
|
+ useFocusEffect(
|
|
|
+ React.useCallback(() => {
|
|
|
+ changeBackground(theme["color-primary-500"]);
|
|
|
}, [])
|
|
|
);
|
|
|
|
|
|
@@ -362,7 +364,7 @@ export default function Guide1Screen({ navigation }) {
|
|
|
true
|
|
|
)
|
|
|
.then(res => {
|
|
|
- if (!id) {
|
|
|
+ if (id === "NEW") {
|
|
|
const { params } = route;
|
|
|
const { classifyId } = params || {};
|
|
|
if (classifyId) {
|
|
|
@@ -373,7 +375,7 @@ export default function Guide1Screen({ navigation }) {
|
|
|
return saveClassByList(postByList, res.id);
|
|
|
})
|
|
|
.then(() => {
|
|
|
- success(`${id ? "修改" : "添加"}成功`);
|
|
|
+ success(`${id !== "NEW" ? "修改" : "添加"}成功`);
|
|
|
if (routeName !== "AddGoods") {
|
|
|
changeGuideStep("2");
|
|
|
} else {
|
|
|
@@ -384,7 +386,7 @@ export default function Guide1Screen({ navigation }) {
|
|
|
>
|
|
|
{routeName !== "AddGoods" ? next : confirm}
|
|
|
</Button>
|
|
|
- {routeName === "AddGoods" && !!id && (
|
|
|
+ {routeName === "AddGoods" && id !== "NEW" && (
|
|
|
<Button
|
|
|
appearance="ghost"
|
|
|
status="info"
|