SystemClassificationEditScreen.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 checkEvent = isChecked => {
  54. if (!isChecked) {
  55. clossClassTip(() => {
  56. saveInfo({
  57. ...classifyInfo.allInfo,
  58. isOpen: isChecked,
  59. }).then(res => {
  60. getInfo();
  61. });
  62. });
  63. } else {
  64. saveInfo({
  65. ...classifyInfo.allInfo,
  66. isOpen: isChecked,
  67. }).then(res => {
  68. getInfo();
  69. });
  70. }
  71. };
  72. function getList() {
  73. let { classifyId, classifyTitle } = route.params || {};
  74. setId(classifyId || 0);
  75. setDel(0);
  76. return getInfo(classifyId)
  77. .then(_ => {
  78. return httpGet("/classification/allGoods", {
  79. classificationId: classifyId,
  80. });
  81. })
  82. .then(res => {
  83. return Promise.resolve({
  84. content: res || [],
  85. last: true,
  86. });
  87. });
  88. }
  89. function getInfo(classifyId) {
  90. return httpGet("/classification/get/" + classifyId, {}, true).then(
  91. res => {
  92. setTitle(res.name || "");
  93. let classify = new ClassificationUtil(res);
  94. setClass(classify);
  95. setTipList(classify.getMenuTipsList());
  96. }
  97. );
  98. }
  99. const goodsItem = ({ item, index }) => (
  100. <GoodsCard
  101. appearance='classification'
  102. key={index}
  103. info={item}
  104. removeEvent={() => remove(id, item.id)}
  105. />
  106. );
  107. function remove(classId, goodsId) {
  108. removeClassGoods(classId, goodsId, res => {
  109. setDel(goodsId);
  110. });
  111. }
  112. function TipsTexts() {
  113. let _tips =
  114. [...tips].map((item, index) => {
  115. return <Text key={index}>{getWordsStr(item)}</Text>;
  116. }) || [];
  117. _tips.push(
  118. <Toggle
  119. key='Toggle'
  120. checked={classifyInfo.isOpen}
  121. onChange={checkEvent}
  122. style={styles.toggle}
  123. >
  124. {classifyInfo.isOpen ? "开启" : "关闭"}
  125. </Toggle>
  126. );
  127. return _tips;
  128. }
  129. return (
  130. <>
  131. <TipNavHeader title={title}>{TipsTexts()}</TipNavHeader>
  132. <Layout style={styles.top}>
  133. <Text category='h6'>{ClassificationManageText6}</Text>
  134. </Layout>
  135. <ListComponent
  136. getInfo={getList}
  137. renderItem={goodsItem}
  138. separatorStyle={styles.separatorStyle}
  139. showEmpty={true}
  140. delId={delId}
  141. style={styles.list}
  142. extraData={{ id: id }}
  143. ListFooterComponent={() => (
  144. <Button
  145. style={styles.addGoods}
  146. appearance='classification'
  147. status='danger'
  148. accessoryLeft={StarIcon}
  149. onPress={() => {
  150. navigation.navigate("AddClassification", {
  151. type: "classification",
  152. classificationId: id,
  153. });
  154. }}
  155. />
  156. )}
  157. />
  158. </>
  159. );
  160. }
  161. const StarIcon = props => <Icon {...props} name='plus' />;
  162. const styles = StyleSheet.create({
  163. text1: {
  164. marginTop: 10,
  165. marginLeft: 57,
  166. maxWidth: 200,
  167. },
  168. list: {
  169. backgroundColor: "#fff",
  170. },
  171. separatorStyle: {
  172. height: 0,
  173. },
  174. right: {
  175. flexDirection: "row",
  176. alignItems: "center",
  177. },
  178. addGoods: {
  179. width: 33,
  180. margin: 15,
  181. },
  182. toggle: {
  183. alignSelf: "flex-start",
  184. marginTop: 10,
  185. },
  186. top: {
  187. backgroundColor: "rgb(238, 238, 238)",
  188. paddingHorizontal: 13,
  189. paddingVertical: 10,
  190. marginTop: 10,
  191. },
  192. });