|
@@ -18,12 +18,16 @@ import {
|
|
|
useTheme,
|
|
useTheme,
|
|
|
Button,
|
|
Button,
|
|
|
Card,
|
|
Card,
|
|
|
|
|
+ List,
|
|
|
} from "@ui-kitten/components";
|
|
} from "@ui-kitten/components";
|
|
|
import FormInput from "../components/FormInput";
|
|
import FormInput from "../components/FormInput";
|
|
|
import { useFocusEffect } from "@react-navigation/native";
|
|
import { useFocusEffect } from "@react-navigation/native";
|
|
|
import ScrollPage from "../components/ScrollPage";
|
|
import ScrollPage from "../components/ScrollPage";
|
|
|
import NavHeaderBar from "../components/NavHeaderBar";
|
|
import NavHeaderBar from "../components/NavHeaderBar";
|
|
|
import GoodsCard from "../components/GoodsCard";
|
|
import GoodsCard from "../components/GoodsCard";
|
|
|
|
|
+import EmptyComponent from "../components/EmptyComponent";
|
|
|
|
|
+import ActionButton from "react-native-action-button";
|
|
|
|
|
+import TabBarIcon from "../components/TabBarIcon";
|
|
|
|
|
|
|
|
const Header = (props, title) => (
|
|
const Header = (props, title) => (
|
|
|
<Text {...props} category='s1'>
|
|
<Text {...props} category='s1'>
|
|
@@ -34,23 +38,87 @@ const Header = (props, title) => (
|
|
|
export default function AddGoodsClassification({ navigation, route }) {
|
|
export default function AddGoodsClassification({ navigation, route }) {
|
|
|
const theme = useTheme();
|
|
const theme = useTheme();
|
|
|
const { changeBackground } = useModel("barModel");
|
|
const { changeBackground } = useModel("barModel");
|
|
|
- const { httpGet } = useModel("httpModel", true);
|
|
|
|
|
|
|
+ const { httpGet, httpPost } = useModel("httpModel", true);
|
|
|
const { registerSecend, guideStep } = useModel("userModel", true);
|
|
const { registerSecend, guideStep } = useModel("userModel", true);
|
|
|
|
|
+ const { success } = useModel("loadingModel", true);
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
goodsClassificationTitle1,
|
|
goodsClassificationTitle1,
|
|
|
goodsClassificationTitle2,
|
|
goodsClassificationTitle2,
|
|
|
goodsClassificationTitle3,
|
|
goodsClassificationTitle3,
|
|
|
|
|
+ add,
|
|
|
|
|
+ remove,
|
|
|
|
|
+ successText,
|
|
|
|
|
+ removeTips,
|
|
|
|
|
+ addClassTips,
|
|
|
} = useModel("wordsModel");
|
|
} = useModel("wordsModel");
|
|
|
- const { showDialog } = useModel("dialogModel");
|
|
|
|
|
|
|
+ const { showDialog } = useModel("dialogModel", true);
|
|
|
const [categoryList, changeCategoryList] = React.useState([]);
|
|
const [categoryList, changeCategoryList] = React.useState([]);
|
|
|
const [merchantNatureList, changeMerchantNatureList] = React.useState([]);
|
|
const [merchantNatureList, changeMerchantNatureList] = React.useState([]);
|
|
|
|
|
+ const [goods, changeGoods] = React.useState([]);
|
|
|
|
|
+ const [selectId, changeSelectId] = React.useState(0);
|
|
|
|
|
+ const [goodsClass, setGoodsClass] = React.useState([]);
|
|
|
|
|
+ const [pageType, changeType] = React.useState("signboard");
|
|
|
useFocusEffect(
|
|
useFocusEffect(
|
|
|
React.useCallback(() => {
|
|
React.useCallback(() => {
|
|
|
changeBackground(theme["color-primary-500"]);
|
|
changeBackground(theme["color-primary-500"]);
|
|
|
|
|
+ console.log(route);
|
|
|
|
|
+ if (route.params.type == "classification") {
|
|
|
|
|
+ changeSelectId(route.params.classificationId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (route.params.type) {
|
|
|
|
|
+ changeType(route.params.type);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ changeType("signboard");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getAllGoods();
|
|
|
}, [])
|
|
}, [])
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ React.useEffect(() => {
|
|
|
|
|
+ if (selectId && selectId != "new") {
|
|
|
|
|
+ getSelectGoods();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [selectId]);
|
|
|
|
|
+ function getSelectGoods() {
|
|
|
|
|
+ httpGet("/classification/allGoods", {
|
|
|
|
|
+ classificationId: selectId,
|
|
|
|
|
+ }).then((res) => {
|
|
|
|
|
+ setGoodsClass(res);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ function getAllGoods() {
|
|
|
|
|
+ httpGet("/goods/my").then((res) => {
|
|
|
|
|
+ changeGoods(res);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const topGoods = React.useMemo(() => {
|
|
|
|
|
+ if (pageType == "signboard") {
|
|
|
|
|
+ return goods.filter((item) => {
|
|
|
|
|
+ return item.signboard;
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return [...goodsClass];
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [goods, goodsClass]);
|
|
|
|
|
+
|
|
|
|
|
+ const elseGoods = React.useMemo(() => {
|
|
|
|
|
+ if (pageType === "signboard") {
|
|
|
|
|
+ return goods.filter((item) => {
|
|
|
|
|
+ return !item.signboard;
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let _topIds = topGoods.map((item) => {
|
|
|
|
|
+ return item.id;
|
|
|
|
|
+ });
|
|
|
|
|
+ return goods.filter((item) => {
|
|
|
|
|
+ return _topIds.indexOf(item.id) === -1;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [goods, goodsClass]);
|
|
|
|
|
+
|
|
|
const [name, changeName] = React.useState("");
|
|
const [name, changeName] = React.useState("");
|
|
|
const [sort, changeSort] = React.useState("");
|
|
const [sort, changeSort] = React.useState("");
|
|
|
const [goodsIds, changeGoodsIds] = React.useState("");
|
|
const [goodsIds, changeGoodsIds] = React.useState("");
|
|
@@ -59,6 +127,107 @@ export default function AddGoodsClassification({ navigation, route }) {
|
|
|
return true;
|
|
return true;
|
|
|
}, [name]);
|
|
}, [name]);
|
|
|
|
|
|
|
|
|
|
+ const chooseGoodsItem = ({ item, index }) => (
|
|
|
|
|
+ <GoodsCard
|
|
|
|
|
+ info={item}
|
|
|
|
|
+ key={item.id}
|
|
|
|
|
+ isAdd={true}
|
|
|
|
|
+ removeEvent={() => {
|
|
|
|
|
+ showDialog({
|
|
|
|
|
+ bodyText: removeTips,
|
|
|
|
|
+ status: "danger",
|
|
|
|
|
+ cancelable: true,
|
|
|
|
|
+ confirmCallback: () => {
|
|
|
|
|
+ changeSignboard(item.id, false, remove, item);
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
+ const goodsItem = ({ item, index }) => (
|
|
|
|
|
+ <GoodsCard
|
|
|
|
|
+ info={item}
|
|
|
|
|
+ key={item.id}
|
|
|
|
|
+ isAdd={false}
|
|
|
|
|
+ addEvent={() => {
|
|
|
|
|
+ if (topGoods.length < 2 || pageType != "signboard") {
|
|
|
|
|
+ changeSignboard(item.id, true, add, item);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ showDialog({
|
|
|
|
|
+ bodyText: addClassTips,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ function changeSignboard(id, signboard, tips, info) {
|
|
|
|
|
+ if (pageType == "signboard") {
|
|
|
|
|
+ httpPost(
|
|
|
|
|
+ "/goods/save",
|
|
|
|
|
+ {
|
|
|
|
|
+ id,
|
|
|
|
|
+ signboard,
|
|
|
|
|
+ },
|
|
|
|
|
+ { body: "json" }
|
|
|
|
|
+ ).then((res) => {
|
|
|
|
|
+ success(tips + successText);
|
|
|
|
|
+ let _goods = goods.map((item) => {
|
|
|
|
|
+ if (item.id != id) {
|
|
|
|
|
+ return item;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ changeGoods(_goods);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (pageType == "classification" && selectId == "new") {
|
|
|
|
|
+ let _goodsClass = [...goodsClass];
|
|
|
|
|
+ if (signboard) {
|
|
|
|
|
+ _goodsClass.push(info);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ _goodsClass.splice(
|
|
|
|
|
+ _goodsClass.findIndex((item) => {
|
|
|
|
|
+ return item.id == id;
|
|
|
|
|
+ }),
|
|
|
|
|
+ 1
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ success(tips + successText);
|
|
|
|
|
+ setGoodsClass(_goodsClass);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (signboard) {
|
|
|
|
|
+ let ids = topGoods.map((item) => {
|
|
|
|
|
+ return item.id;
|
|
|
|
|
+ });
|
|
|
|
|
+ ids.push(id);
|
|
|
|
|
+ httpGet(
|
|
|
|
|
+ "/classification/saveGoods",
|
|
|
|
|
+ {
|
|
|
|
|
+ classificationId: selectId,
|
|
|
|
|
+ string: ids.join(","),
|
|
|
|
|
+ },
|
|
|
|
|
+ { body: "json" }
|
|
|
|
|
+ ).then((res) => {
|
|
|
|
|
+ success(tips + successText);
|
|
|
|
|
+ getSelectGoods();
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ httpGet(
|
|
|
|
|
+ "/classification/delGoods",
|
|
|
|
|
+ {
|
|
|
|
|
+ classificationId: selectId,
|
|
|
|
|
+ goodId: id,
|
|
|
|
|
+ },
|
|
|
|
|
+ { body: "json" }
|
|
|
|
|
+ ).then((res) => {
|
|
|
|
|
+ success(tips + successText);
|
|
|
|
|
+ getSelectGoods();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
|
<NavHeaderBar title={goodsClassificationTitle1} />
|
|
<NavHeaderBar title={goodsClassificationTitle1} />
|
|
@@ -69,9 +238,14 @@ export default function AddGoodsClassification({ navigation, route }) {
|
|
|
header={(props) => {
|
|
header={(props) => {
|
|
|
return Header(props, goodsClassificationTitle2);
|
|
return Header(props, goodsClassificationTitle2);
|
|
|
}}
|
|
}}
|
|
|
|
|
+ disabled={true}
|
|
|
>
|
|
>
|
|
|
- <GoodsCard />
|
|
|
|
|
- <GoodsCard />
|
|
|
|
|
|
|
+ <List
|
|
|
|
|
+ data={topGoods}
|
|
|
|
|
+ style={styles.list}
|
|
|
|
|
+ renderItem={chooseGoodsItem}
|
|
|
|
|
+ ListEmptyComponent={EmptyComponent}
|
|
|
|
|
+ />
|
|
|
</Card>
|
|
</Card>
|
|
|
|
|
|
|
|
<Card
|
|
<Card
|
|
@@ -79,22 +253,48 @@ export default function AddGoodsClassification({ navigation, route }) {
|
|
|
header={(props) => {
|
|
header={(props) => {
|
|
|
return Header(props, goodsClassificationTitle3);
|
|
return Header(props, goodsClassificationTitle3);
|
|
|
}}
|
|
}}
|
|
|
|
|
+ disabled={true}
|
|
|
>
|
|
>
|
|
|
- <GoodsCard />
|
|
|
|
|
- <GoodsCard />
|
|
|
|
|
|
|
+ <List
|
|
|
|
|
+ data={elseGoods}
|
|
|
|
|
+ style={styles.list}
|
|
|
|
|
+ renderItem={goodsItem}
|
|
|
|
|
+ ListEmptyComponent={EmptyComponent}
|
|
|
|
|
+ />
|
|
|
</Card>
|
|
</Card>
|
|
|
</Layout>
|
|
</Layout>
|
|
|
|
|
+ <ActionButton
|
|
|
|
|
+ style={{ zIndex: 2 }}
|
|
|
|
|
+ buttonColor={theme["color-primary-500"]}
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ let ids = topGoods.map((item) => {
|
|
|
|
|
+ return item.id;
|
|
|
|
|
+ });
|
|
|
|
|
+ ids = ids.join(",");
|
|
|
|
|
+ console.log(ids);
|
|
|
|
|
+ navigation.navigate(route.params.preKey, {
|
|
|
|
|
+ choosIds: ids,
|
|
|
|
|
+ });
|
|
|
|
|
+ }}
|
|
|
|
|
+ position='center'
|
|
|
|
|
+ />
|
|
|
</ScrollPage>
|
|
</ScrollPage>
|
|
|
</>
|
|
</>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
const styles = StyleSheet.create({
|
|
|
|
|
+ flex1: {
|
|
|
|
|
+ backgroundColor: "rgba(0,0,0,0)",
|
|
|
|
|
+ paddingHorizontal: 15,
|
|
|
|
|
+ paddingBottom: 20,
|
|
|
|
|
+ },
|
|
|
|
|
+ list: {
|
|
|
|
|
+ backgroundColor: "rgba(0,0,0,0)",
|
|
|
|
|
+ },
|
|
|
container: {
|
|
container: {
|
|
|
- flex: 1,
|
|
|
|
|
- paddingBottom: 33,
|
|
|
|
|
backgroundColor: "#EEEEEE",
|
|
backgroundColor: "#EEEEEE",
|
|
|
- paddingVertical: 20,
|
|
|
|
|
|
|
+ paddingTop: 20,
|
|
|
},
|
|
},
|
|
|
tabContent: {
|
|
tabContent: {
|
|
|
backgroundColor: "#fff",
|
|
backgroundColor: "#fff",
|