SystemClassificationEditScreen.js 6.1 KB

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