Parcourir la source

商品规格保存

panhui il y a 5 ans
Parent
commit
1046610cc8
3 fichiers modifiés avec 110 ajouts et 109 suppressions
  1. 30 3
      models/goodsModel.js
  2. 77 91
      screens/EditGoods.js
  3. 3 15
      screens/Guide1Screen.js

+ 30 - 3
models/goodsModel.js

@@ -275,12 +275,39 @@ export default {
     // 批量保存规格
     // 批量保存规格
     saveClassByList(list, goodsId) {
     saveClassByList(list, goodsId) {
       const { httpPost } = model("httpModel");
       const { httpPost } = model("httpModel");
-      if (list.length > 0) {
+      const saveList = [];
+      list.forEach(item => {
+        const saveItem = { ...item };
+        if (saveItem.children) {
+          saveItem.children = saveItem.children.map(child => {
+            return {
+              name: child.name,
+              amount: child.amount,
+              goodsId,
+            };
+          });
+          delete saveItem.edit;
+          delete saveItem.childIndex;
+          if (saveItem.id < 0) {
+            delete saveItem.id;
+          }
+          saveList.push(saveItem);
+        } else if (saveItem.id || saveItem.parent > 0) {
+          delete saveItem.edit;
+          delete saveItem.childIndex;
+          if (saveItem.id < 0) {
+            delete saveItem.id;
+          }
+          saveList.push(saveItem);
+        }
+      });
+      console.log(saveList);
+      if (saveList.length > 0) {
         return httpPost(
         return httpPost(
-          "/goodsSpecification/saveAll",
+          "/goodsSpecification/saveSpecs",
           {
           {
             spec: JSON.stringify(
             spec: JSON.stringify(
-              list.map(item => {
+              saveList.map(item => {
                 return { ...item, goodsId };
                 return { ...item, goodsId };
               })
               })
             ),
             ),

+ 77 - 91
screens/EditGoods.js

@@ -1,109 +1,95 @@
 /* eslint-disable no-underscore-dangle */
 /* eslint-disable no-underscore-dangle */
 import * as WebBrowser from "expo-web-browser";
 import * as WebBrowser from "expo-web-browser";
 import * as React from "react";
 import * as React from "react";
-import {
-    StyleSheet,
-} from "react-native";
-import {
-    Layout,
-    useTheme,
-    Button,
-    List,
-} from "@ui-kitten/components";
+import { StyleSheet } from "react-native";
+import { Layout, useTheme, Button, List } from "@ui-kitten/components";
 import { useModel } from "flooks";
 import { useModel } from "flooks";
 import { useFocusEffect } from "@react-navigation/native";
 import { useFocusEffect } from "@react-navigation/native";
 import NavHeaderBar from "../components/NavHeaderBar";
 import NavHeaderBar from "../components/NavHeaderBar";
 import GoodsCardLarge from "../components/GoodsCard";
 import GoodsCardLarge from "../components/GoodsCard";
 import EmptyComponent from "../components/EmptyComponent";
 import EmptyComponent from "../components/EmptyComponent";
 
 
-
 const styles = StyleSheet.create({
 const styles = StyleSheet.create({
-    container: {
-        flex: 1,
-    },
-    bntLay: {
-        paddingVertical: 5,
-        flexDirection: "row",
-        alignItems: "center",
-        justifyContent: "center",
-        backgroundColor: "#EEEEEE",
-        flexShrink: 0,
-    },
-    list: {
-        flex: 1,
-        backgroundColor: "#EEEEEE",
-        paddingTop: 10,
-        paddingHorizontal: 15,
-    },
+  container: {
+    flex: 1,
+  },
+  bntLay: {
+    paddingVertical: 5,
+    flexDirection: "row",
+    alignItems: "center",
+    justifyContent: "center",
+    backgroundColor: "#EEEEEE",
+    flexShrink: 0,
+  },
+  list: {
+    flex: 1,
+    backgroundColor: "#EEEEEE",
+    paddingTop: 10,
+    paddingHorizontal: 15,
+  },
 });
 });
 
 
-
 export default function EditGoods({ navigation }) {
 export default function EditGoods({ navigation }) {
-    const theme = useTheme();
-    const { changeBackground } = useModel("barModel");
-    // const {  } = useModel("userModel");
-    const { httpGet } = useModel("httpModel");
-    const [goods, changeGoods] = React.useState("");
-    const {
-        userTitle3,
-        addGoods2,
-	} = useModel("wordsModel");
-	
-	function getAllGoods() {
-        httpGet("/goods/my").then(res => {
-            changeGoods(res);
-        });
-    }
-    useFocusEffect(
-        React.useCallback(() => {
-            changeBackground(theme["color-primary-500"]);
-            getAllGoods();
-        }, [])
-    );
+  const theme = useTheme();
+  const { changeBackground } = useModel("barModel");
+  // const {  } = useModel("userModel");
+  const { httpGet } = useModel("httpModel");
+  const [goods, changeGoods] = React.useState("");
+  const { userTitle3, addGoods2 } = useModel("wordsModel");
 
 
-   
+  function getAllGoods() {
+    httpGet("/goods/my").then(res => {
+      changeGoods(res);
+    });
+  }
+  useFocusEffect(
+    React.useCallback(() => {
+      changeBackground(theme["color-primary-500"]);
+      getAllGoods();
+    }, [])
+  );
 
 
-    const goodsItem = ({ item, index }) => (
-      <GoodsCardLarge
-        appearance='classification'
-        type='goodsList'
-        key={item.id}
-        info={item}
-        canEdit
-        style={{ marginBottom: 7 }}
-        onPress={() => {
-                navigation.navigate("AddGoods", {
-                    id: item.id,
-                });
-            }}
-        changeInfo={info => {
-                const _goods = [...goods];
-                _goods.splice(index, 1, info);
-                changeGoods(_goods);
-            }}
-      />
-    );
+  const goodsItem = ({ item, index }) => (
+    <GoodsCardLarge
+      appearance="classification"
+      type="goodsList"
+      key={item.id}
+      info={item}
+      canEdit
+      style={{ marginBottom: 7 }}
+      onPress={() => {
+        navigation.navigate("AddGoods", {
+          id: item.id,
+        });
+      }}
+      changeInfo={info => {
+        const _goods = [...goods];
+        _goods.splice(index, 1, info);
+        changeGoods(_goods);
+      }}
+    />
+  );
 
 
-    return (
-      <>
-        <NavHeaderBar title={userTitle3} />
-        <Layout style={styles.container}>
-          <Layout style={styles.bntLay}>
-            <Button
-              onPress={() => {
-                            navigation.navigate("AddGoods");
-                        }}
-            >
-              {addGoods2}
-            </Button>
-          </Layout>
-          <List
-            style={styles.list}
-            data={goods}
-            renderItem={goodsItem}
-            ListEmptyComponent={EmptyComponent}
-          />
+  return (
+    <>
+      <NavHeaderBar title={userTitle3} />
+      <Layout style={styles.container}>
+        <Layout style={styles.bntLay}>
+          <Button
+            onPress={() => {
+              navigation.navigate("AddGoods");
+            }}
+          >
+            {addGoods2}
+          </Button>
         </Layout>
         </Layout>
-      </>
-    );
+        <List
+          style={styles.list}
+          data={goods}
+          renderItem={goodsItem}
+          ListEmptyComponent={EmptyComponent}
+        />
+      </Layout>
+    </>
+  );
 }
 }

+ 3 - 15
screens/Guide1Screen.js

@@ -8,7 +8,6 @@ import { Layout, Text, useTheme, Button, Card } from "@ui-kitten/components";
 import { useModel } from "flooks";
 import { useModel } from "flooks";
 import { useFocusEffect, useRoute } from "@react-navigation/native";
 import { useFocusEffect, useRoute } from "@react-navigation/native";
 import { useCreation, useUnmount, useMount } from "@umijs/hooks";
 import { useCreation, useUnmount, useMount } from "@umijs/hooks";
-import moment from "moment";
 import Textarea from "react-native-textarea";
 import Textarea from "react-native-textarea";
 import ScrollPage from "../components/ScrollPage";
 import ScrollPage from "../components/ScrollPage";
 import FormInput from "../components/FormInput";
 import FormInput from "../components/FormInput";
@@ -118,10 +117,9 @@ export default function Guide1Screen({ navigation }) {
   const [discountAmount, changeDiscountAmount] = React.useState("");
   const [discountAmount, changeDiscountAmount] = React.useState("");
   const [inventory, changeInventory] = React.useState(0);
   const [inventory, changeInventory] = React.useState(0);
   const [week, changeWeek] = React.useState("");
   const [week, changeWeek] = React.useState("");
-  const [startTime, changeStartTime] = React.useState("08:00");
-  const [endTime, changeEndTime] = React.useState("22:00");
+  const [startTime, changeStartTime] = React.useState("08:00:00");
+  const [endTime, changeEndTime] = React.useState("18:00:00");
   const [introduction, changeIntroduction] = React.useState();
   const [introduction, changeIntroduction] = React.useState();
-  const [defaultValue, ChangeDefaultValue] = React.useState("");
   const [goodsSpecification, changeGoodsSpecification] = React.useState([]);
   const [goodsSpecification, changeGoodsSpecification] = React.useState([]);
 
 
   const [img, changeImg] = React.useState();
   const [img, changeImg] = React.useState();
@@ -150,17 +148,7 @@ export default function Guide1Screen({ navigation }) {
     changeIntroduction(res.introduction || "");
     changeIntroduction(res.introduction || "");
     // if (res.img && res.img.length) {
     // if (res.img && res.img.length) {
     changeImg(res.img);
     changeImg(res.img);
-    // }
-
-    if (res.week) {
-      ChangeDefaultValue([
-        `${moment(res.startTime, "HH:mm:ss").format("HH:mm")}~${moment(
-          res.endTime,
-          "HH:mm:ss"
-        ).format("HH:mm")}`,
-        res.week,
-      ]);
-    }
+    // 
   }
   }
 
 
   useMount(() => {
   useMount(() => {