SystemClassificationEditScreen.js 6.6 KB

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