| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- import * as WebBrowser from "expo-web-browser";
- import * as React from "react";
- import {
- Image,
- Platform,
- StyleSheet,
- TouchableOpacity,
- View,
- ImageBackground,
- } from "react-native";
- import scrollPage from "../decorator/scrollPage";
- import { useModel } from "flooks";
- import {
- Layout,
- Tab,
- TabView,
- Text,
- useTheme,
- Button,
- Card,
- List,
- } from "@ui-kitten/components";
- import FormInput from "../components/FormInput";
- import { useFocusEffect } from "@react-navigation/native";
- import ScrollPage from "../components/ScrollPage";
- import NavHeaderBar from "../components/NavHeaderBar";
- 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) => (
- <Text {...props} category='s1'>
- {title}
- </Text>
- );
- export default function AddGoodsClassification({ navigation, route }) {
- const theme = useTheme();
- const { changeBackground } = useModel("barModel");
- const { httpGet, httpPost } = useModel("httpModel", true);
- const { registerSecend, guideStep } = useModel("userModel", true);
- const { success } = useModel("loadingModel", true);
- const {
- goodsClassificationTitle1,
- goodsClassificationTitle2,
- goodsClassificationTitle3,
- add,
- remove,
- successText,
- removeTips,
- addClassTips,
- } = useModel("wordsModel");
- const { showDialog } = useModel("dialogModel", true);
- const [categoryList, changeCategoryList] = 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(
- React.useCallback(() => {
- 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 [sort, changeSort] = React.useState("");
- const [goodsIds, changeGoodsIds] = React.useState("");
- const canNext = React.useMemo(() => {
- return true;
- }, [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 (
- <>
- <NavHeaderBar title={goodsClassificationTitle1} />
- <ScrollPage>
- <Layout style={styles.container}>
- <Card
- appearance='headerList'
- header={(props) => {
- return Header(props, goodsClassificationTitle2);
- }}
- disabled={true}
- >
- <List
- data={topGoods}
- style={styles.list}
- renderItem={chooseGoodsItem}
- ListEmptyComponent={EmptyComponent}
- />
- </Card>
- <Card
- appearance='headerList'
- header={(props) => {
- return Header(props, goodsClassificationTitle3);
- }}
- disabled={true}
- >
- <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>
- </>
- );
- }
- 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,
- },
- });
|