| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- import * as WebBrowser from "expo-web-browser";
- import * as React from "react";
- import ListComponent from "../../components/ListComponent";
- import TipNavHeader from "../../components/TipNavHeader";
- import { useModel } from "flooks";
- import {
- Layout,
- Input,
- Button,
- Text,
- ListItem,
- Icon,
- Toggle,
- } from "@ui-kitten/components";
- import { StyleSheet, View } from "react-native";
- import ListUtil from "../../Utils/ListUtil";
- import {
- ClassificationUtil,
- getClassificationByName,
- } from "../../Utils/SystemRuleUtil";
- import { useRoute } from "@react-navigation/native";
- import GoodsCard from "../../components/GoodsCard";
- const ForwardIcon = props => (
- <Icon
- {...props}
- name='arrow-ios-forward'
- fill='#B4B4B4'
- style={{ width: 15, height: 15, fontWeight: 500 }}
- />
- );
- //系统分类编辑
- export default function SystemClassificationEditScreen({ navigation }) {
- const {
- ClassificationManage,
- ClassificationManageText6,
- getWordsStr,
- } = useModel("wordsModel");
- const {
- getUserInfo,
- startingAmount,
- preparationTime,
- updateMerchant,
- } = useModel("userModel");
- const route = useRoute();
- const { success } = useModel("loadingModel");
- const { httpGet } = useModel("httpModel");
- const { clossClassTip, saveInfo, removeClassGoods } = useModel(
- "goodsModel",
- true
- );
- const [id, setId] = React.useState();
- const [title, setTitle] = React.useState();
- const [tips, setTipList] = React.useState([]);
- const [classifyInfo, setClass] = React.useState(new ClassificationUtil());
- const [delId, setDel] = React.useState(0);
- const [isOpen, changeIsOpen] = React.useState(false);
- const checkEvent = isChecked => {
- changeIsOpen(isChecked);
- if (!isChecked) {
- clossClassTip(() => {
- saveInfo({
- ...classifyInfo.allInfo,
- isOpen: isChecked,
- }).then(res => {
- getInfo(classifyInfo.id);
- });
- });
- } else {
- saveInfo({
- ...classifyInfo.allInfo,
- isOpen: isChecked,
- }).then(res => {
- getInfo(classifyInfo.id);
- });
- }
- };
- function getList() {
- let { classifyId, classifyTitle } = route.params || {};
- setId(classifyId || 0);
- setDel(0);
- return getInfo(classifyId)
- .then(_ => {
- return httpGet("/classification/allGoods", {
- classificationId: classifyId,
- });
- })
- .then(res => {
- let list = res || [];
- list = list.filter(item => {
- return item != null;
- });
- return Promise.resolve({
- content: list,
- last: true,
- });
- });
- }
- function getInfo(classifyId) {
- return httpGet("/classification/get/" + classifyId, {}, true).then(
- res => {
- setTitle(res.name || "");
- let classify = new ClassificationUtil(res);
- setClass(classify);
- setTipList(classify.getMenuTipsList());
- changeIsOpen(res.isOpen);
- }
- );
- }
- const goodsItem = ({ item, index }) => (
- <GoodsCard
- appearance='classification'
- key={index}
- info={item}
- removeEvent={() => remove(id, item.id)}
- />
- );
- function remove(classId, goodsId) {
- removeClassGoods(classId, goodsId, res => {
- setDel(goodsId);
- });
- }
- function TipsTexts() {
- let _tips =
- [...tips].map((item, index) => {
- return <Text key={index}>{getWordsStr(item)}</Text>;
- }) || [];
- _tips.push(
- <Toggle
- key='Toggle'
- checked={isOpen}
- onChange={checkEvent}
- style={styles.toggle}
- >
- {isOpen ? "开启" : "关闭"}
- </Toggle>
- );
- return _tips;
- }
- return (
- <>
- <TipNavHeader title={title}>{TipsTexts()}</TipNavHeader>
- <Layout style={styles.top}>
- <Text category='h6'>{ClassificationManageText6}</Text>
- </Layout>
- <ListComponent
- getInfo={getList}
- renderItem={goodsItem}
- separatorStyle={styles.separatorStyle}
- showEmpty={true}
- delId={delId}
- style={styles.list}
- extraData={{ id: id }}
- ListFooterComponent={() => {
- if (
- classifyInfo.getType() !=
- getClassificationByName("好评") &&
- classifyInfo.getType() !=
- getClassificationByName("折扣")
- ) {
- return (
- <Button
- style={styles.addGoods}
- appearance='classification'
- status='danger'
- accessoryLeft={StarIcon}
- onPress={() => {
- navigation.navigate("AddClassification", {
- type: "classification",
- classificationId: id,
- });
- }}
- />
- );
- } else {
- return <></>;
- }
- }}
- />
- </>
- );
- }
- const StarIcon = props => <Icon {...props} name='plus' />;
- const styles = StyleSheet.create({
- text1: {
- marginTop: 10,
- marginLeft: 57,
- maxWidth: 200,
- },
- list: {
- backgroundColor: "#fff",
- },
- separatorStyle: {
- height: 0,
- },
- right: {
- flexDirection: "row",
- alignItems: "center",
- },
- addGoods: {
- width: 33,
- margin: 15,
- },
- toggle: {
- alignSelf: "flex-start",
- marginTop: 10,
- },
- top: {
- backgroundColor: "rgb(238, 238, 238)",
- paddingHorizontal: 13,
- paddingVertical: 10,
- marginTop: 10,
- },
- });
|