SystemClassificationEditScreen.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import ListComponent from "../../components/ListComponent";
  4. import TipNavHeader from "../../components/TipNavHeader";
  5. import { useModel } from "flooks";
  6. import {
  7. Layout,
  8. Input,
  9. Button,
  10. Text,
  11. ListItem,
  12. Icon,
  13. Toggle,
  14. } from "@ui-kitten/components";
  15. import { StyleSheet, View } from "react-native";
  16. import ListUtil from "../../Utils/ListUtil";
  17. import { ClassificationUtil } from "../../Utils/SystemRuleUtil";
  18. import { useRoute } from "@react-navigation/native";
  19. import GoodsCard from "../../components/GoodsCard";
  20. const ForwardIcon = props => (
  21. <Icon
  22. {...props}
  23. name='arrow-ios-forward'
  24. fill='#B4B4B4'
  25. style={{ width: 15, height: 15, fontWeight: 500 }}
  26. />
  27. );
  28. //系统分类编辑
  29. export default function SystemClassificationEditScreen({ navigation }) {
  30. const {
  31. ClassificationManage,
  32. ClassificationManageText6,
  33. getWordsStr,
  34. } = useModel("wordsModel");
  35. const {
  36. getUserInfo,
  37. startingAmount,
  38. preparationTime,
  39. updateMerchant,
  40. } = useModel("userModel");
  41. const route = useRoute();
  42. const { success } = useModel("loadingModel");
  43. const { httpGet } = useModel("httpModel");
  44. const { clossClassTip, saveInfo, removeClassGoods } = useModel(
  45. "goodsModel",
  46. true
  47. );
  48. const [id, setId] = React.useState();
  49. const [title, setTitle] = React.useState();
  50. const [tips, setTipList] = React.useState([]);
  51. const [classifyInfo, setClass] = React.useState(new ClassificationUtil());
  52. const [delId, setDel] = React.useState(0);
  53. const [isOpen, changeIsOpen] = React.useState(false);
  54. const checkEvent = isChecked => {
  55. changeIsOpen(isChecked);
  56. if (!isChecked) {
  57. clossClassTip(() => {
  58. saveInfo({
  59. ...classifyInfo.allInfo,
  60. isOpen: isChecked,
  61. }).then(res => {
  62. getInfo(classifyInfo.id);
  63. });
  64. });
  65. } else {
  66. saveInfo({
  67. ...classifyInfo.allInfo,
  68. isOpen: isChecked,
  69. }).then(res => {
  70. getInfo(classifyInfo.id);
  71. });
  72. }
  73. };
  74. function getList() {
  75. let { classifyId, classifyTitle } = route.params || {};
  76. setId(classifyId || 0);
  77. setDel(0);
  78. return getInfo(classifyId)
  79. .then(_ => {
  80. return httpGet("/classification/allGoods", {
  81. classificationId: classifyId,
  82. });
  83. })
  84. .then(res => {
  85. return Promise.resolve({
  86. content: res || [],
  87. last: true,
  88. });
  89. });
  90. }
  91. function getInfo(classifyId) {
  92. return httpGet("/classification/get/" + classifyId, {}, true).then(
  93. res => {
  94. setTitle(res.name || "");
  95. let classify = new ClassificationUtil(res);
  96. setClass(classify);
  97. setTipList(classify.getMenuTipsList());
  98. changeIsOpen(res.isOpen);
  99. }
  100. );
  101. }
  102. const goodsItem = ({ item, index }) => (
  103. <GoodsCard
  104. appearance='classification'
  105. key={index}
  106. info={item}
  107. removeEvent={() => remove(id, item.id)}
  108. />
  109. );
  110. function remove(classId, goodsId) {
  111. removeClassGoods(classId, goodsId, res => {
  112. setDel(goodsId);
  113. });
  114. }
  115. function TipsTexts() {
  116. let _tips =
  117. [...tips].map((item, index) => {
  118. return <Text key={index}>{getWordsStr(item)}</Text>;
  119. }) || [];
  120. _tips.push(
  121. <Toggle
  122. key='Toggle'
  123. checked={isOpen}
  124. onChange={checkEvent}
  125. style={styles.toggle}
  126. >
  127. {isOpen ? "开启" : "关闭"}
  128. </Toggle>
  129. );
  130. return _tips;
  131. }
  132. return (
  133. <>
  134. <TipNavHeader title={title}>{TipsTexts()}</TipNavHeader>
  135. <Layout style={styles.top}>
  136. <Text category='h6'>{ClassificationManageText6}</Text>
  137. </Layout>
  138. <ListComponent
  139. getInfo={getList}
  140. renderItem={goodsItem}
  141. separatorStyle={styles.separatorStyle}
  142. showEmpty={true}
  143. delId={delId}
  144. style={styles.list}
  145. extraData={{ id: id }}
  146. ListFooterComponent={() => (
  147. <Button
  148. style={styles.addGoods}
  149. appearance='classification'
  150. status='danger'
  151. accessoryLeft={StarIcon}
  152. onPress={() => {
  153. navigation.navigate("AddClassification", {
  154. type: "classification",
  155. classificationId: id,
  156. });
  157. }}
  158. />
  159. )}
  160. />
  161. </>
  162. );
  163. }
  164. const StarIcon = props => <Icon {...props} name='plus' />;
  165. const styles = StyleSheet.create({
  166. text1: {
  167. marginTop: 10,
  168. marginLeft: 57,
  169. maxWidth: 200,
  170. },
  171. list: {
  172. backgroundColor: "#fff",
  173. },
  174. separatorStyle: {
  175. height: 0,
  176. },
  177. right: {
  178. flexDirection: "row",
  179. alignItems: "center",
  180. },
  181. addGoods: {
  182. width: 33,
  183. margin: 15,
  184. },
  185. toggle: {
  186. alignSelf: "flex-start",
  187. marginTop: 10,
  188. },
  189. top: {
  190. backgroundColor: "rgb(238, 238, 238)",
  191. paddingHorizontal: 13,
  192. paddingVertical: 10,
  193. marginTop: 10,
  194. },
  195. });