panhui 5 år sedan
förälder
incheckning
4f67c3744b

+ 20 - 0
Utils/OpenTimeUtil.js

@@ -1,3 +1,4 @@
+/* eslint-disable class-methods-use-this */
 /* eslint-disable no-underscore-dangle */
 import moment from "moment";
 
@@ -7,6 +8,12 @@ export default class OpenTimeUtil {
     this.endTime = endTime || "23:00:00";
     this.week = week || "";
     this.weekWords = weekWords || {};
+
+    if (weekWords) {
+      this.valueKey = Object.keys(weekWords);
+    }
+    this.selectStart = this.getTimeSelectValue(this.startTime);
+    this.selectEnd = this.getTimeSelectValue(this.endTime);
   }
 
   getStartTimeStr() {
@@ -48,7 +55,20 @@ export default class OpenTimeUtil {
     this.week = week || [];
   }
 
+  getWeek() {
+    return this.week.split(",").filter(item => {
+      return this.valueKey.includes(item);
+    });
+  }
+
   setWeekWords(weekWords) {
     this.weekWords = weekWords || {};
   }
+
+  getTimeSelectValue(time) {
+    const _time = moment(time, "HH:mm:ss").format("H:m");
+    return _time.split(":").map(item => {
+      return Number(item);
+    });
+  }
 }

+ 107 - 0
components/ClassificationSelect.js

@@ -0,0 +1,107 @@
+import * as React from "react";
+import { View, StyleSheet, TouchableWithoutFeedback } from "react-native";
+import { Cascader, BottomModal } from "beeshell";
+import { useModel } from "flooks";
+
+const styles = StyleSheet.create({
+  inputContainer: {
+    flexDirection: "row",
+    alignItems: "center",
+    paddingVertical: 10,
+    paddingHorizontal: 4,
+  },
+  input: {
+    flex: 1,
+  },
+  label: {
+    width: 80,
+    marginRight: 19,
+    flexShrink: 0,
+  },
+  labelleft: {
+    width: 73,
+    flexShrink: 0,
+  },
+  right: {
+    flexDirection: "row",
+  },
+  code: {
+    paddingHorizontal: 5,
+    marginLeft: 5,
+  },
+  selectContent: {
+    backgroundColor: "#F0F0F0",
+  },
+  titleStyle: {
+    fontSize: 15,
+  },
+  leftLabelTextStyle: {
+    fontSize: 13,
+  },
+  rightLabelTextStyle: {
+    fontSize: 13,
+  },
+  sub: {
+    color: "#787878",
+    position: "absolute",
+    left: 90,
+    zIndex: 2,
+  },
+  upload: {
+    marginTop: 20,
+    width: 67,
+    height: 67,
+  },
+});
+
+export default function OpenTimeCom(props) {
+  const { selectTitle, list, node$, defaultValue, submit } = props;
+  const [Node, setNode] = React.useState();
+  const { cancel, confirm } = useModel("wordsModel");
+  const [selectVal, setSelectVal] = React.useState("");
+  const [selectInfo, setSelectInfo] = React.useState({});
+
+  if (node$) {
+    node$.useSubscription(() => {
+      setSelectVal(defaultValue);
+      Node.open();
+    });
+  }
+  return (
+    <BottomModal
+      ref={c => {
+        setNode(c);
+      }}
+      title={selectTitle}
+      titleStyle={styles.titleStyle}
+      cancelable
+      leftLabelText={cancel}
+      leftLabelTextStyle={styles.leftLabelTextStyle}
+      rightLabelText={confirm}
+      rightLabelTextStyle={styles.rightLabelTextStyle}
+      rightCallback={() => {
+        Node.close();
+        submit(selectInfo);
+      }}
+    >
+      <Cascader
+        style={{
+          width: "100%",
+          height: 200,
+          marginBottom: 50,
+          minHeight: 200,
+        }}
+        data={list}
+        fieldKeys={{
+          labelKey: "name",
+          idKey: "id",
+          activeKey: "choose",
+        }}
+        onChange={(value, info) => {
+          setSelectVal(value[0]);
+          setSelectInfo(info[info.length - 1]);
+        }}
+      />
+    </BottomModal>
+  );
+}

+ 1 - 0
components/Datepicker.js

@@ -46,6 +46,7 @@ export default function MyDatepicker(props) {
             numberOfYears={10}
             date={dateValue}
             onChange={date => {
+              console.log(date);
               chooseValue(date);
             }}
           />

+ 124 - 0
components/ListComponentParent.js

@@ -0,0 +1,124 @@
+/* eslint-disable no-console */
+/* eslint-disable react/jsx-props-no-spreading */
+/* eslint-disable no-underscore-dangle */
+import * as React from "react";
+import { Divider, List, Layout } from "@ui-kitten/components";
+import { useFocusEffect } from "@react-navigation/native";
+import { useModel } from "flooks";
+import { useBoolean } from "@umijs/hooks";
+import EmptyComponent from "./EmptyComponent";
+
+export default function ListComponent(props) {
+  const { clearLoading } = useModel("loadingModel");
+  const loading = useBoolean();
+  const refreshing = useBoolean();
+
+  const {
+    dataList,
+    getInfo,
+    renderItem,
+    ListHeaderComponent,
+    style,
+    separatorStyle,
+    ListFooterComponent,
+    showEmpty,
+    emptyEvent,
+    showList,
+    extraData,
+    delId,
+    startState, // 父级调刷新
+    initialNumToRender,
+    saveList, // 保持状态
+    list$,
+  } = props;
+
+  function setList(newList) {
+    dispatch({
+      type: "setInfo",
+      payload: { list: newList, finish: true },
+    });
+  }
+
+  function getList() {
+    if (getInfo != null) {
+      return getInfo(page, size).then(res => {
+        if (emptyEvent) {
+          if (res.numberOfElements === 0) {
+            emptyEvent(true);
+          } else {
+            emptyEvent(false);
+          }
+        }
+
+        dispatch({
+          type: "setInfo",
+          payload: { list: res.content, finish: res.last },
+        });
+      });
+    }
+    return Promise.reject();
+  }
+
+  // 刷新接口
+  function onRefresh() {
+    refreshing.setTrue();
+
+    getList().finally(() => {
+      refreshing.setFalse();
+    });
+  }
+
+  // 到页面底部加载更多
+  function gotEnd() {
+    loading.setTrue();
+    getList().finally(() => {
+      loading.setFalse();
+    });
+  }
+
+  useFocusEffect(
+    React.useCallback(() => {
+      // onRefresh();
+    }, [])
+  );
+
+  const changePorps = React.useMemo(() => {
+    let _props = { renderItem: () => <Layout /> };
+    if (showList !== false) {
+      _props = { renderItem };
+
+      if (extraData) {
+        _props = {
+          ..._props,
+          extraData,
+        };
+      }
+    }
+    return _props;
+  }, [showList, extraData]);
+
+  const ListEmptyComponent = React.useMemo(() => {
+    if (showEmpty && !refreshing && !loading) {
+      return EmptyComponent;
+    }
+    return <></>;
+  }, [showEmpty, refreshing, loading.state]);
+
+  return (
+    <List
+      refreshing={refreshing.state}
+      style={[style]}
+      data={dataList}
+      removeClippedSubviews
+      initialNumToRender={initialNumToRender || 10}
+      ListHeaderComponent={ListHeaderComponent}
+      ListEmptyComponent={ListEmptyComponent}
+      onRefresh={onRefresh}
+      onEndReached={0.2}
+      ItemSeparatorComponent={() => <Divider style={[separatorStyle]} />}
+      onEndReachedThreshold={gotEnd}
+      ListFooterComponent={ListFooterComponent}
+      {...changePorps}
+    />
+  );
+}

+ 343 - 0
components/OpenTimeCom.js

@@ -0,0 +1,343 @@
+/* eslint-disable prefer-const */
+/* eslint-disable no-underscore-dangle */
+import React from "react";
+import { StyleSheet, LayoutAnimation, Platform, UIManager } from "react-native";
+import { range, convert2Digit } from "beeshell/dist/common/utils";
+import {
+  CheckBox,
+  Layout,
+  Modal,
+  Button,
+  Card,
+  Text,
+  MenuItem,
+  Icon,
+} from "@ui-kitten/components";
+import { Scrollpicker } from "beeshell";
+import { useModel } from "flooks";
+import { useBoolean } from "@umijs/hooks";
+import moment from "moment";
+import OpenTimeUtil from "../Utils/OpenTimeUtil";
+
+if (Platform.OS === "android") {
+  if (UIManager.setLayoutAnimationEnabledExperimental) {
+    UIManager.setLayoutAnimationEnabledExperimental(true);
+  }
+}
+
+const styles = StyleSheet.create({
+  checkBoxAll: {
+    paddingVertical: 10,
+  },
+  checkBoxItem: {
+    paddingVertical: 2,
+    paddingHorizontal: 10,
+  },
+  time: {
+    // width: 100,
+    // height: 300,
+  },
+  backdrop: {
+    backgroundColor: "rgba(0, 0, 0, 0.5)",
+  },
+  btnList: {
+    flexDirection: "row",
+    justifyContent: "space-between",
+    paddingTop: 15,
+  },
+  hideHeight: {
+    height: 0,
+    borderWidth: 0,
+  },
+  btn: {
+    flex: 1,
+    minWidth: 50,
+  },
+});
+
+const ForwardIcon = props => <Icon {...props} name="arrow-ios-forward" />;
+
+const titleText = (props, title, value) => (
+  <Text {...props} category="s1" numberOfLines={1} ellipsizeMode="tail">
+    {title}
+    <Text category="c1" style={{ paddingLeft: 10 }}>
+      {value}
+    </Text>
+  </Text>
+);
+
+export default function OpenTimeCom({ submit, openTime, node$ }) {
+  const {
+    MONDAY,
+    TUESDAY,
+    WEDNESDAY,
+    THURSDAY,
+    FRIDAY,
+    SATURDAY,
+    SUNDAY,
+    every,
+    confirm,
+    cancel,
+    start,
+    end,
+    hour,
+    min,
+    weekName,
+    weekWords,
+  } = useModel("wordsModel");
+  const open = useBoolean();
+  const weeks = [
+    {
+      key: "MONDAY",
+      label: MONDAY,
+    },
+    {
+      key: "TUESDAY",
+      label: TUESDAY,
+    },
+    {
+      key: "WEDNESDAY",
+      label: WEDNESDAY,
+    },
+    {
+      key: "THURSDAY",
+      label: THURSDAY,
+    },
+    {
+      key: "FRIDAY",
+      label: FRIDAY,
+    },
+    {
+      key: "SATURDAY",
+      label: SATURDAY,
+    },
+    {
+      key: "SUNDAY",
+      label: SUNDAY,
+    },
+  ];
+  const [checkList, changeChecked] = React.useState([]);
+  const listItems = weeks.map((item, index) => (
+    <CheckBox
+      style={styles.checkBoxItem}
+      key={index}
+      checked={checkList.includes(item.key)}
+      onChange={checked => {
+        const _checkList = [...checkList];
+        if (checked) {
+          _checkList.push(item.key);
+        } else {
+          _checkList.splice(_checkList.indexOf(item.key), 1);
+        }
+        changeChecked(_checkList);
+      }}
+    >
+      {item.label}
+    </CheckBox>
+  ));
+  const list = React.useMemo(() => {
+    const hourSum = 24;
+    const minuteSum = 60;
+    const hours = range(hourSum / 1).map(item => {
+      item = convert2Digit(item * 1);
+      return {
+        label: `${item} ${hour}`,
+        value: item,
+      };
+    });
+    const minutes = range(minuteSum / 10).map(item => {
+      item = convert2Digit(item * 10);
+      return {
+        label: `${item} ${min}`,
+        value: item,
+      };
+    });
+    return [hours, minutes];
+  }, [open.state]);
+
+  const [time1, setTime1] = React.useState([8, 0]);
+  const [time2, setTime2] = React.useState([20, 0]);
+
+  const [showTime1, changeShowTime1] = React.useState(true);
+  const [showTime2, changeShowTime2] = React.useState(false);
+  const [showWeek, changeShowWeek] = React.useState(false);
+
+  const backOpenTime = React.useMemo(() => {
+    return new OpenTimeUtil(
+      moment(`${time1[0]}:${time1[1] * 10}`, "H:m").format("HH:mm:ss"),
+      moment(`${time2[0]}:${time2[1] * 10}`, "H:m").format("HH:mm:ss"),
+      checkList.toString(),
+      weekWords()
+    );
+  }, [openTime, checkList, time1, time2]);
+
+  const allChecked = React.useMemo(() => {
+    if (weeks.length === checkList.length) {
+      return true;
+    }
+    return false;
+  }, [weeks, checkList]);
+
+  const indeterminate = React.useMemo(() => {
+    if (!allChecked && checkList.length > 0) {
+      return true;
+    }
+    return false;
+  }, [allChecked, checkList]);
+
+  const canSubmit = React.useMemo(() => {
+    if (time1.length === 2 && time2.length === 2 && checkList.length > 0) {
+      return true;
+    }
+    return false;
+  }, [time1, time2, checkList]);
+
+  if (node$) {
+    node$.useSubscription(() => {
+      setTime1(openTime.selectStart);
+      setTime2(openTime.selectEnd);
+      changeChecked(openTime.getWeek());
+      open.setTrue();
+    });
+  }
+
+  function hideElseShow(key) {
+    changeShowTime1(key === 1);
+    changeShowTime2(key === 2);
+    changeShowWeek(key === 3);
+
+    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
+  }
+
+  return (
+    <>
+      <Modal
+        visible={open.state && list.length > 0}
+        backdropStyle={styles.backdrop}
+        onBackdropPress={() => {
+          open.setFalse();
+        }}
+      >
+        <Card disabled appearance="modalCrad" style={{ width: 242 }}>
+          <Layout>
+            <MenuItem
+              appearance="cardContent"
+              title={props =>
+                titleText(props, start, backOpenTime.getStartTimeStr())
+              }
+              accessoryRight={ForwardIcon}
+              onPress={() => {
+                hideElseShow(1);
+              }}
+            />
+          </Layout>
+          <Card
+            disabled
+            appearance="modalCrad"
+            style={[{ width: 222 }, showTime1 ? {} : styles.hideHeight]}
+          >
+            <Scrollpicker
+              key="time1"
+              list={list}
+              proportion={[1, 1]}
+              offsetCount={1}
+              value={time1}
+              onChange={(index, value) => {
+                const _time1 = [...time1];
+                _time1[index] = value;
+                setTime1(_time1);
+              }}
+            />
+          </Card>
+          <Layout>
+            <MenuItem
+              appearance="cardContent"
+              title={props =>
+                titleText(props, end, backOpenTime.getEndTimeStr())
+              }
+              accessoryRight={ForwardIcon}
+              onPress={() => {
+                hideElseShow(2);
+              }}
+            />
+          </Layout>
+          <Card
+            disabled
+            appearance="modalCrad"
+            style={[{ width: 222 }, showTime2 ? {} : styles.hideHeight]}
+          >
+            <Scrollpicker
+              key="time2"
+              list={list}
+              proportion={[1, 1]}
+              offsetCount={1}
+              value={time2}
+              onChange={(index, value) => {
+                const _time2 = [...time2];
+                _time2[index] = value;
+                setTime2(_time2);
+              }}
+            />
+          </Card>
+          <Layout>
+            <MenuItem
+              appearance="cardContent"
+              title={props =>
+                titleText(props, weekName, backOpenTime.getWeekStr())
+              }
+              accessoryRight={ForwardIcon}
+              onPress={() => {
+                hideElseShow(3);
+              }}
+            />
+          </Layout>
+          <Card
+            appearance="modalCrad"
+            style={[showWeek ? {} : styles.hideHeight]}
+          >
+            <CheckBox
+              style={styles.checkBoxAll}
+              checked={allChecked}
+              indeterminate={indeterminate}
+              onChange={checked => {
+                changeChecked(
+                  checked
+                    ? weeks.map(item => {
+                        return item.key;
+                      })
+                    : []
+                );
+              }}
+            >
+              {every}
+            </CheckBox>
+
+            {listItems}
+          </Card>
+          <Layout style={styles.btnList}>
+            <Button
+              style={styles.btn}
+              appearance="outline"
+              status="info"
+              onPress={() => {
+                open.setFalse();
+              }}
+            >
+              {cancel}
+            </Button>
+            <Button
+              style={[styles.btn, { marginLeft: 10 }]}
+              disabled={!canSubmit}
+              onPress={() => {
+                submit(backOpenTime);
+                open.setFalse();
+              }}
+            >
+              {confirm}
+            </Button>
+          </Layout>
+        </Card>
+      </Modal>
+    </>
+  );
+}

+ 9 - 1
screens/Coupon/AddScreen.js

@@ -3,6 +3,7 @@
 import * as WebBrowser from "expo-web-browser";
 import * as React from "react";
 import { StyleSheet } from "react-native";
+import moment from "moment";
 import { useModel } from "flooks";
 import { useFocusEffect } from "@react-navigation/native";
 import { Layout, Button, useTheme, Divider } from "@ui-kitten/components";
@@ -76,7 +77,14 @@ export default function CouponAddScreen({ navigation, route }) {
   }, [id]);
 
   const canNext = React.useMemo(() => {
-    if (name && amount && startDate && endDate) {
+    if (
+      name &&
+      amount &&
+      startDate &&
+      endDate &&
+      moment(startDate, "YYYY-MM-DD").format("X") <
+        moment(endDate, "YYYY-MM-DD").format("X")
+    ) {
       return true;
     }
     return false;

+ 497 - 0
screens/Goods/GoodsSpecificationScreenNew.js

@@ -0,0 +1,497 @@
+/* eslint-disable no-else-return */
+/* eslint-disable prefer-const */
+/* eslint-disable react/jsx-one-expression-per-line */
+/* eslint-disable no-underscore-dangle */
+/* eslint-disable no-shadow */
+import * as WebBrowser from "expo-web-browser";
+import * as React from "react";
+import { StyleSheet, View } from "react-native";
+import { useModel } from "flooks";
+import {
+  Layout,
+  Text,
+  useTheme,
+  Button,
+  Input,
+  Toggle,
+} from "@ui-kitten/components";
+import { useFocusEffect, useRoute } from "@react-navigation/native";
+import { useEventEmitter } from "@umijs/hooks";
+import ActionButton from "react-native-action-button";
+import ListComponent from "../../components/ListComponentParent";
+import NavHeaderBar from "../../components/NavHeaderBar";
+
+const styles = StyleSheet.create({
+  lay: {
+    backgroundColor: "#fff",
+    flex: 1,
+  },
+  padBot: {
+    paddingBottom: 100,
+  },
+  list: {
+    paddingVertical: 10,
+    paddingHorizontal: 15,
+    backgroundColor: "transparent",
+    flex: 0,
+  },
+  item: {
+    flexDirection: "row",
+    alignItems: "center",
+    paddingVertical: 10,
+  },
+  input: {
+    marginHorizontal: 5,
+    minWidth: 49,
+    // width: 49,
+  },
+  text: {
+    flex: 1,
+  },
+  flexRow: {
+    flexDirection: "row",
+    alignItems: "center",
+  },
+  buttonlast: {
+    marginLeft: 10,
+  },
+  button: {
+    alignSelf: "flex-start",
+  },
+  money: {
+    marginLeft: 10,
+  },
+  addNew2: {
+    width: 80,
+    alignSelf: "center",
+  },
+  separatorStyle: {
+    height: 0,
+  },
+});
+
+export default function GoodsSpecificationScreen() {
+  const theme = useTheme();
+  const { changeBackground } = useModel("barModel", true);
+  // const { mid } = useModel("userModel");
+  const { httpGet, httpPost } = useModel("httpModel", true);
+  const { success, warnning } = useModel("loadingModel", true);
+  const { showDialog } = useModel("dialogModel");
+  const [allEditInfo, setEdit] = React.useState([]);
+  const [goodsId, setGoodsId] = React.useState(0);
+  const [startState, changeState] = React.useState(true);
+  const [editList, setEditList] = React.useState([]);
+  const [addNew, changeNew] = React.useState([]);
+  const [dataList, setDataList] = React.useState([]);
+  const list$ = useEventEmitter();
+
+  const {
+    delText,
+    editText,
+    confirm,
+    cancel,
+    successText,
+    removeTips,
+  } = useModel("wordsModel");
+  const { addClassGoods } = useModel("goodsModel");
+  useFocusEffect(
+    React.useCallback(() => {
+      changeBackground(theme["color-primary-500"]);
+    }, [])
+  );
+
+  const route = useRoute();
+
+  function getList() {
+    const { params } = route;
+    const { goodsId } = params || {};
+    setGoodsId(goodsId);
+    return httpGet(
+      "/goodsSpecification/parent",
+      {
+        goodsId: goodsId || 0,
+      },
+      true
+    ).then(res => {
+      setDataList(res);
+      return Promise.resolve({
+        content: res,
+        last: true,
+      });
+    });
+  }
+
+  const listByOrder = (list1, list2, type, extra) => {
+    let list = [...list1];
+    if (type === "add") {
+      list2.forEach((item, index) => {
+        if (item.addType === "1") {
+          list.push({ name: "", multiple: false, addIndex: index });
+        } else {
+          let _index = list.findIndex(_i => {
+            return _i.id === item.parent;
+          });
+          list.splice(_index + 1, 0, {
+            name: "",
+            amount: "",
+            parent: item.parent,
+            addIndex: index,
+          });
+        }
+      });
+    } else if (type === "save") {
+      list = list.map(item => {
+        if (
+          (item.addIndex === extra && extra != null) ||
+          item.id === list2[0].id
+        ) {
+          item = { ...list2[0] };
+        }
+        return item;
+      });
+    } else if (type === "edit") {
+      list = list.map(item => {
+        if (item.id === extra) {
+          item = {
+            ...item,
+            edit: true,
+          };
+        }
+        return item;
+      });
+    } else if (type === "cancel" && extra.id) {
+      list = list.map(item => {
+        if (item.id === extra.id) {
+          item.edit = false;
+        }
+        return item;
+      });
+    } else if (type === "del" || (!extra.id && type === "cancel")) {
+      list = list.filter(item => {
+        return (
+          (extra.id && item.id !== extra.id) ||
+          (!extra.id && item.addIndex !== extra.addIndex)
+        );
+      });
+    }
+    setEdit(list);
+    return list;
+  };
+
+  const editInfo = id => {
+    const _editList = [...editList];
+    _editList.push(id);
+    setEditList(_editList);
+    list$.emit({
+      type: "edit",
+      list: [],
+      changeEvent: listByOrder,
+      extra: id,
+    });
+  };
+  const delInfo = info => {
+    showDialog({
+      bodyText: removeTips,
+      status: "danger",
+      cancelable: true,
+      confirmCallback: () => {
+        if (!info.parent) {
+          let _allEditInfo = [...allEditInfo];
+          let _children = _allEditInfo.filter(item => {
+            return item.parent === info.id;
+          });
+          if (_children.length > 0) {
+            showDialog({
+              bodyText: "当前分类存在规格,请删除规格后再删除",
+              status: "danger",
+            });
+            return;
+          }
+        }
+        httpPost(`/goodsSpecification/del/${info.id}`)
+          .then(() => {
+            success(successText);
+            // changeState(true);
+            list$.emit({
+              type: "del",
+              list: [],
+              changeEvent: listByOrder,
+              extra: info,
+            });
+          })
+          .catch(e => {
+            warnning(e.error);
+          });
+      },
+    });
+  };
+  // 取消
+  const cancelInfo = info => {
+    if (info.id) {
+      let _editList = [...editList];
+      _editList = _editList.filter(item => {
+        return item !== info.id;
+      });
+      setEditList(_editList);
+      list$.emit({
+        type: "cancel",
+        list: [],
+        changeEvent: listByOrder,
+        extra: info,
+      });
+    } else {
+      let _addNew = [...addNew];
+      _addNew.splice(info.addIndex, 1);
+      changeNew(_addNew);
+
+      list$.emit({
+        type: "cancel",
+        list: [],
+        changeEvent: listByOrder,
+        extra: info,
+      });
+    }
+    // changeState(true);
+  };
+
+  // 保存
+  const saveInfo = info => {
+    // const _editInfo = { ...allEditInfo };
+    // let name = "";
+    // let amount = "";
+    // if (_editInfo[info.id || "new"]) {
+    //   name = _editInfo[info.id || "new"].name;
+    //   amount = _editInfo[info.id || "new"].amount;
+    // }
+    const data = {
+      ...info,
+      goodsId,
+    };
+    delete data.addIndex;
+    addClassGoods(data).then(res => {
+      if (info.id) {
+        let _editList = [...editList];
+        _editList = _editList.filter(item => {
+          return item !== info.id;
+        });
+        setEditList(_editList);
+        list$.emit({
+          type: "save",
+          list: [res],
+          changeEvent: listByOrder,
+        });
+      } else {
+        let _addNew = [...addNew];
+        _addNew.splice(info.addIndex, 1);
+        changeNew(_addNew);
+        list$.emit({
+          type: "save",
+          list: [res],
+          extra: info.addIndex,
+          changeEvent: listByOrder,
+        });
+      }
+    });
+  };
+
+  //
+  const addFullReduction = info => {
+    let list = [...addNew];
+    let hasType1 = list.find(item => {
+      return item.addType === "1";
+    });
+
+    if (info && info.parent) {
+      let hasParent = list.find(item => {
+        return item.parent === info.parent;
+      });
+      if (!hasParent) {
+        list.push(info);
+        changeNew(list);
+        list$.emit({
+          type: "add",
+          list: [
+            {
+              ...info,
+            },
+          ],
+          changeEvent: listByOrder,
+        });
+      }
+    } else if (!info && !hasType1) {
+      list.push({
+        addType: "1",
+      });
+      changeNew(list);
+      list$.emit({
+        type: "add",
+        list: [
+          {
+            addType: "1",
+          },
+        ],
+        changeEvent: listByOrder,
+      });
+    }
+  };
+
+  const saveItem = (info, index) => {
+    let editNowInfo = { ...info };
+    return (
+      <View Key={index}>
+        <Layout style={styles.item}>
+          <Layout style={[styles.text, styles.flexRow]}>
+            {editNowInfo.parent ? (
+              <Text category="c1">添加{editNowInfo.name}</Text>
+            ) : (
+              <Text category="s1">分类名:{editNowInfo.name}</Text>
+            )}
+            {!!editNowInfo.parent && (
+              <Layout style={styles.money}>
+                <Text category="c1">¥{editNowInfo.amount}</Text>
+              </Layout>
+            )}
+            {!editNowInfo.parent && (
+              <Layout style={styles.money}>
+                <Text category="s1">
+                  {editNowInfo.multiple ? "多选" : "单选"}
+                </Text>
+              </Layout>
+            )}
+          </Layout>
+
+          <Button
+            size="small"
+            appearance="outline"
+            onPress={() => editInfo(editNowInfo.id)}
+          >
+            {editText}
+          </Button>
+          <Button
+            size="small"
+            status="danger"
+            style={styles.buttonlast}
+            onPress={() => delInfo(editNowInfo, index)}
+          >
+            {delText}
+          </Button>
+        </Layout>
+        {!editNowInfo.parent && (
+          <Button
+            style={styles.addNew2}
+            onPress={() =>
+              addFullReduction({ addType: "2", parent: editNowInfo.id })
+            }
+          >
+            添加规格
+          </Button>
+        )}
+      </View>
+    );
+  };
+
+  const editItem = (info, index) => {
+    let _allEditInfo = [...allEditInfo];
+    let editNowInfo = { ..._allEditInfo[index] };
+    return (
+      <Layout style={styles.item}>
+        <Layout style={[styles.text, styles.flexRow]}>
+          <Text>{editNowInfo.parent ? "规格" : "类名"}</Text>
+          <Input
+            size="small"
+            defaultValue={editNowInfo.name}
+            style={styles.input}
+            key={`${index}_0`}
+            onChangeText={text => {
+              editNowInfo.name = text;
+              _allEditInfo.splice(index, 1, editNowInfo);
+              setEdit(_allEditInfo);
+            }}
+          />
+          {!!editNowInfo.parent && (
+            <>
+              <Text>价钱</Text>
+              <Input
+                size="small"
+                defaultValue={info.amount}
+                style={styles.input}
+                key={`${index}_2`}
+                keyboardType="numeric"
+                onChangeText={text => {
+                  editNowInfo.amount = text;
+                  _allEditInfo.splice(index, 1, editNowInfo);
+                  setEdit(_allEditInfo);
+                }}
+              />
+            </>
+          )}
+          {!editNowInfo.parent && (
+            <>
+              <Text>是否多选</Text>
+              <Toggle
+                key="Toggle"
+                checked={editNowInfo.multiple}
+                onChange={checked => {
+                  editNowInfo.multiple = checked;
+                  _allEditInfo.splice(index, 1, editNowInfo);
+                  setEdit(_allEditInfo);
+                }}
+              />
+            </>
+          )}
+        </Layout>
+
+        <Button
+          disabled={
+            !editNowInfo.name ||
+            (!!editNowInfo.parent && editNowInfo.amount === "")
+          }
+          size="small"
+          onPress={() => saveInfo(editNowInfo)}
+        >
+          {confirm}
+        </Button>
+        <Button
+          size="small"
+          appearance="outline"
+          style={styles.buttonlast}
+          onPress={() => cancelInfo(editNowInfo)}
+        >
+          {cancel}
+        </Button>
+      </Layout>
+    );
+  };
+
+  const renderItem = ({ item, index }) => {
+    if (!item.id || item.edit) {
+      return editItem(item, index);
+    }
+    return saveItem(item);
+  };
+
+  return (
+    <>
+      <NavHeaderBar title="商品规格编辑" />
+
+      <Layout style={[styles.lay]}>
+        <ListComponent
+          getInfo={getList}
+          dataList={dataList}
+          renderItem={renderItem}
+          style={styles.list}
+          separatorStyle={styles.separatorStyle}
+          showEmpty
+          extraData={{ allEditInfo }}
+          startState={startState}
+          list$={list$}
+        />
+        <ActionButton
+          buttonColor={theme["color-primary-500"]}
+          onPress={addFullReduction}
+          position="left"
+        />
+      </Layout>
+    </>
+  );
+}

+ 66 - 8
screens/HomeScreenPage3.js

@@ -10,11 +10,14 @@ import {
 } from "@ui-kitten/components";
 import { StyleSheet } from "react-native";
 import { useModel } from "flooks";
+import { useEventEmitter, useMount } from "@umijs/hooks";
 import Textarea from "react-native-textarea";
 import OpenTimeUtil from "../Utils/OpenTimeUtil";
 import ListUtil from "../Utils/ListUtil";
 import UpLoadImage from "../components/UpLoadImage";
 import * as RootNavigation from "../navigation/RootNavigation";
+import OpenTimeCom from "../components/OpenTimeCom";
+import ClassificationSelect from "../components/ClassificationSelect";
 
 const ForwardIcon = props => (
   <Icon
@@ -117,7 +120,15 @@ export default function HomePage3() {
     startTime,
   } = useModel("userModel");
   const categoryList = new ListUtil(category);
-  const { success } = useModel("loadingModel");
+  const { loading, success } = useModel("loadingModel");
+  const { httpGet } = useModel("httpModel", true);
+  const [allCategoryList, setallCategoryList] = React.useState([]);
+
+  useMount(() => {
+    httpGet("/category/tree", { id: 1 }).then(res => {
+      setallCategoryList(res);
+    });
+  });
 
   const {
     home3Title1,
@@ -127,6 +138,9 @@ export default function HomePage3() {
     weekWords,
   } = useModel("wordsModel");
 
+  const node$ = useEventEmitter();
+  const SelectNode$ = useEventEmitter();
+
   const imgList = React.useMemo(() => {
     const list = img ? img.split(",") : [];
     list.push("");
@@ -134,12 +148,11 @@ export default function HomePage3() {
   }, [img]);
 
   const openTime = React.useMemo(() => {
-    if (startTime && endTime && week && weekWords) {
+    if (startTime && endTime && week) {
       // eslint-disable-next-line no-underscore-dangle
-      const _o = new OpenTimeUtil(startTime, endTime, week, weekWords());
-      return _o.getShowStr();
+      return new OpenTimeUtil(startTime, endTime, week, weekWords());
     }
-    return "";
+    return new OpenTimeUtil();
   }, [startTime, endTime, week, weekWords]);
 
   // eslint-disable-next-line no-shadow
@@ -216,6 +229,7 @@ export default function HomePage3() {
             size="small"
             style={styles.button}
             onPress={() => {
+              loading();
               updateMerchant({
                 introduction: text,
               }).then(() => {
@@ -246,7 +260,9 @@ export default function HomePage3() {
           }
           accessoryRight={ForwardIcon}
           style={styles.menuItem}
-          onPress={() => {}}
+          onPress={() => {
+            SelectNode$.emit();
+          }}
         />
         <MenuItem
           title={props =>
@@ -274,11 +290,13 @@ export default function HomePage3() {
         />
         <MenuItem
           title={props =>
-            Label(props, getWordsStr("guideHome_form_4"), openTime)
+            Label(props, getWordsStr("guideHome_form_4"), openTime.getShowStr())
           }
           accessoryRight={ForwardIcon}
           style={styles.menuItem}
-          onPress={() => {}}
+          onPress={() => {
+            node$.emit();
+          }}
         />
         <MenuItem
           title={getWordsStr("guideHome_form_5")}
@@ -289,6 +307,46 @@ export default function HomePage3() {
           }}
         />
       </Menu>
+
+      <OpenTimeCom
+        submit={_openTimeUtil => {
+          loading();
+          updateMerchant({
+            startTime: _openTimeUtil.startTime,
+            endTime: _openTimeUtil.endTime,
+            week: _openTimeUtil.week,
+          }).then(() => {
+            success("成功");
+          });
+        }}
+        openTime={openTime}
+        node$={node$}
+      />
+      <ClassificationSelect
+        selectTitle={getWordsStr("guideHome_form_1")}
+        list={allCategoryList}
+        node$={SelectNode$}
+        defaultValue={categoryList}
+        submit={selectVal => {
+          const info = { ...selectVal[selectVal.length - 1] };
+          delete info.pId;
+          delete info.choose;
+          delete info.active;
+          console.log(info);
+          loading();
+          updateMerchant({
+            category: {
+              active: true,
+              children: [],
+              id: 139,
+              name: "水果生榨",
+              parent: 23,
+            },
+          }).then(() => {
+            success("成功");
+          });
+        }}
+      />
     </Layout>
   );
 }

+ 3 - 9
screens/Set/ClassificationManageScreen.js

@@ -34,13 +34,6 @@ export default function ClassificationManageScreen({ navigation, route }) {
     ClassificationManageText5,
   } = useModel("wordsModel");
 
-  const {
-    getUserInfo,
-    startingAmount,
-    preparationTime,
-    updateMerchant,
-  } = useModel("userModel");
-  const { success } = useModel("loadingModel");
 
   const { httpGet } = useModel("httpModel");
 
@@ -78,7 +71,8 @@ export default function ClassificationManageScreen({ navigation, route }) {
             </Text>
           ) : (
             <Text category="c1" status="info">
-              {new ListUtil(item.goodsIds).getLength()}件商品
+              {new ListUtil(item.goodsIds).getLength()}
+              件商品
             </Text>
           )}
           <ForwardIcon {...props} />
@@ -102,7 +96,7 @@ export default function ClassificationManageScreen({ navigation, route }) {
         getInfo={getList}
         renderItem={renderItem}
         separatorStyle={styles.separatorStyle}
-        showEmpty={true}
+        showEmpty
         style={styles.list}
         ListFooterComponent={() => (
           <Button