SystemClassificationEditScreen.js 5.1 KB

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