| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- /* eslint-disable no-underscore-dangle */
- import * as WebBrowser from "expo-web-browser";
- import * as React from "react";
- import { StyleSheet } from "react-native";
- import { Layout, Text, useTheme, Card, List } from "@ui-kitten/components";
- import { useFocusEffect, useRoute } from "@react-navigation/native";
- // import ActionButton from "react-native-action-button";
- import { useModel } from "flooks";
- import ScrollPage from "../components/ScrollPage";
- import NavHeaderBar from "../components/NavHeaderBar";
- import GoodsCard from "../components/GoodsCard";
- import EmptyComponent from "../components/EmptyComponent";
- const Header = (props, title) => (
- <Text {...props} category="s1">
- {title}
- </Text>
- );
- const styles = StyleSheet.create({
- flex1: {
- backgroundColor: "rgba(0,0,0,0)",
- paddingHorizontal: 15,
- paddingBottom: 20,
- },
- list: {
- backgroundColor: "rgba(0,0,0,0)",
- },
- container: {
- backgroundColor: "#EEEEEE",
- paddingTop: 20,
- },
- tabContent: {
- backgroundColor: "#fff",
- marginTop: 20,
- },
- img: {
- width: 100,
- height: 100,
- alignSelf: "center",
- },
- img2: {
- width: 97,
- height: 21,
- alignSelf: "center",
- marginTop: 2,
- },
- text: {
- marginTop: 16,
- },
- layoutLeft: {
- // flexDirection: "row",
- paddingVertical: 10,
- justifyContent: "center",
- alignItems: "center",
- },
- form: {
- paddingHorizontal: 26,
- paddingVertical: 20,
- },
- textareaContainer: {
- backgroundColor: "#F0F0F0",
- height: 100,
- borderRadius: 4,
- },
- textarea: {
- textAlignVertical: "top", // hack android
- fontSize: 13,
- color: "#333",
- paddingHorizontal: 14,
- paddingVertical: 10,
- height: 100,
- },
- });
- export default function AddGoodsClassification({}) {
- const theme = useTheme();
- const { changeBackground } = useModel("barModel");
- const { httpGet, httpPost } = useModel("httpModel", true);
- const { success } = useModel("loadingModel", true);
- const {
- goodsClassificationTitle1,
- goodsClassificationTitle2,
- goodsClassificationTitle3,
- add,
- remove,
- successText,
- removeTips,
- addClassTips,
- } = useModel("wordsModel");
- const { showDialog } = useModel("dialogModel", true);
- const { selectInfos, changeSelect } = useModel("goodsModel");
- const [goods, changeGoods] = React.useState([]);
- const [selectId, changeSelectId] = React.useState(0);
- const [goodsClass, setGoodsClass] = React.useState([]);
- const [pageType, changeType] = React.useState();
- const topGoods = React.useMemo(() => {
- if (pageType === "signboard") {
- return goods.filter(item => {
- return item.signboard;
- });
- }
- if (pageType === "recommend") {
- return goods.filter(item => {
- return item.recommend;
- });
- }
- return [...goodsClass];
- }, [goods, goodsClass]);
- const elseGoods = React.useMemo(() => {
- if (pageType === "signboard") {
- return goods.filter(item => {
- return !item.signboard;
- });
- }
- if (pageType === "recommend") {
- return goods.filter(item => {
- return !item.recommend;
- });
- }
- const _topIds = topGoods.map(item => {
- return item.id;
- });
- return goods.filter(item => {
- return _topIds.indexOf(item.id) === -1;
- });
- }, [goods, goodsClass]);
- function getSelectGoods() {
- httpGet("/classification/allGoods", {
- classificationId: selectId,
- }).then(res => {
- let list = res || [];
- list = list.filter(item => {
- return item != null;
- });
- setGoodsClass(list);
- });
- }
- function getAllGoods() {
- httpGet("/goods/my").then(res => {
- changeGoods(res);
- });
- }
- function changeSignboard(id, signboard, tips, info) {
- if (pageType === "signboard" || pageType === "recommend") {
- httpPost(
- "/goods/save",
- {
- id,
- [pageType]: signboard,
- },
- { body: "json" }
- ).then(res => {
- success(tips + successText);
- const _goods = goods.map(item => {
- if (item.id !== id) {
- return item;
- }
- return res;
- });
- changeGoods(_goods);
- });
- } else if (pageType === "classification" && selectId === "new") {
- const _goodsClass = [...goodsClass];
- if (signboard) {
- _goodsClass.push(info);
- } else {
- _goodsClass.splice(
- _goodsClass.findIndex(item => {
- return item.id === id;
- }),
- 1
- );
- }
- success(tips + successText);
- setGoodsClass(_goodsClass);
- changeSelect(_goodsClass);
- } else if (signboard) {
- const ids = topGoods.map(item => {
- return item.id;
- });
- ids.push(id);
- httpGet(
- "/classification/saveGoods",
- {
- classificationId: selectId,
- string: ids.join(","),
- },
- { body: "json" }
- ).then(() => {
- success(tips + successText);
- getSelectGoods();
- });
- } else {
- httpGet(
- "/classification/delGoods",
- {
- classificationId: selectId,
- goodId: id,
- },
- { body: "json" }
- ).then(() => {
- success(tips + successText);
- getSelectGoods();
- });
- }
- }
- const route = useRoute();
- useFocusEffect(
- React.useCallback(() => {
- changeBackground(theme["color-primary-500"]);
- const { params } = route;
- const { type, classificationId } = params;
- if (type === "classification") {
- changeSelectId(classificationId);
- }
- if (type) {
- changeType(type);
- } else {
- changeType("signboard");
- }
- getAllGoods();
- }, [])
- );
- React.useEffect(() => {
- if (selectId && selectId !== "new") {
- getSelectGoods();
- } else if (selectId === "new") {
- setGoodsClass(selectInfos);
- }
- }, [selectId]);
- const chooseGoodsItem = ({ item }) => (
- <GoodsCard
- info={item}
- key={item.id}
- isAdd
- removeEvent={() => {
- showDialog({
- bodyText: removeTips,
- status: "danger",
- cancelable: true,
- confirmCallback: () => {
- changeSignboard(item.id, false, remove, item);
- },
- });
- }}
- />
- );
- const goodsItem = ({ item }) => (
- <GoodsCard
- info={item}
- key={item.id}
- isAdd={false}
- addEvent={() => {
- if (topGoods.length < 2 || pageType !== "recommend") {
- changeSignboard(item.id, true, add, item);
- } else {
- showDialog({
- bodyText: addClassTips,
- });
- }
- }}
- />
- );
- return (
- <>
- <NavHeaderBar title={goodsClassificationTitle1} />
- <ScrollPage>
- <Layout style={styles.container}>
- <Card
- appearance="headerList"
- header={props => {
- return Header(props, goodsClassificationTitle2);
- }}
- disabled
- >
- <List
- data={topGoods}
- style={styles.list}
- renderItem={chooseGoodsItem}
- ListEmptyComponent={EmptyComponent}
- />
- </Card>
- <Card
- appearance="headerList"
- header={props => {
- return Header(props, goodsClassificationTitle3);
- }}
- disabled
- >
- <List
- data={elseGoods}
- style={styles.list}
- renderItem={goodsItem}
- ListEmptyComponent={EmptyComponent}
- />
- </Card>
- </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>
- </>
- );
- }
|