ClassificationEditScreen.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* eslint-disable camelcase */
  2. /* eslint-disable no-unused-vars */
  3. /* eslint-disable no-underscore-dangle */
  4. import * as WebBrowser from "expo-web-browser";
  5. import * as React from "react";
  6. import {
  7. StyleSheet,
  8. } from "react-native";
  9. import { useModel } from "flooks";
  10. import {
  11. Layout,
  12. Button,
  13. Card,
  14. } from "@ui-kitten/components";
  15. import { useRoute } from "@react-navigation/native";
  16. import FormInput from "../../components/FormInput";
  17. import ScrollPage from "../../components/ScrollPage";
  18. const styles = StyleSheet.create({
  19. container: {
  20. flex: 1,
  21. paddingBottom: 33,
  22. },
  23. tabContent: {
  24. backgroundColor: "#fff",
  25. marginTop: 20,
  26. },
  27. img: {
  28. width: 100,
  29. height: 100,
  30. alignSelf: "center",
  31. },
  32. img2: {
  33. width: 97,
  34. height: 21,
  35. alignSelf: "center",
  36. marginTop: 2,
  37. },
  38. text: {
  39. marginTop: 16,
  40. },
  41. layoutLeft: {
  42. flexDirection: "row",
  43. paddingVertical: 10,
  44. justifyContent: "center",
  45. alignItems: "center",
  46. },
  47. form: {
  48. paddingHorizontal: 26,
  49. paddingVertical: 20,
  50. },
  51. textareaContainer: {
  52. backgroundColor: "#F0F0F0",
  53. height: 100,
  54. borderRadius: 4,
  55. },
  56. textarea: {
  57. textAlignVertical: "top", // hack android
  58. fontSize: 13,
  59. color: "#333",
  60. paddingHorizontal: 14,
  61. paddingVertical: 10,
  62. height: 100,
  63. },
  64. });
  65. export default function ClassificationEdit({ navigation }) {
  66. const route = useRoute();
  67. const { httpGet, httpPost } = useModel("httpModel", true);
  68. const { mid } = useModel(
  69. "userModel",
  70. true
  71. );
  72. const { success } = useModel("loadingModel", true);
  73. const {
  74. guide2_title1,
  75. guide2_title2,
  76. guide2_form_1,
  77. guide2_pla_1,
  78. guide2_pla_2,
  79. guide1_pla_2,
  80. guide2_form_2,
  81. guide2_form_3,
  82. guide1_form_4,
  83. guide1_pla_4,
  84. guide1_form_5,
  85. guide1_pla_5,
  86. next,
  87. pass,
  88. passTips,} = useModel("wordsModel");
  89. const { removeCLass } = useModel("goodsModel", true);
  90. const [pageName, changePageName] = React.useState("");
  91. const [id, changeId] = React.useState("");
  92. const [name, changeName] = React.useState("");
  93. const [sort, changeSort] = React.useState("");
  94. const [goodsIds, changeGoodsIds] = React.useState("");
  95. const { selectInfos } = useModel("goodsModel");
  96. React.useEffect(() => {
  97. if (selectInfos.length > 0) {
  98. const _ids = selectInfos.map(item => {
  99. return item.id;
  100. });
  101. changeGoodsIds(_ids.join(","));
  102. }
  103. }, [selectInfos]);
  104. const canNext = React.useMemo(() => {
  105. if (name && sort) {
  106. return true;
  107. }
  108. return false;
  109. }, [name, sort, goodsIds]);
  110. const addClass = () => {
  111. return httpPost(
  112. "/classification/save",
  113. {
  114. id,
  115. name,
  116. sort,
  117. goodsIds,
  118. merchantId: mid,
  119. },
  120. { body: "json" },
  121. true
  122. );
  123. };
  124. const refreshEvent = () => {
  125. const { classifyId, classifyTitle } = route.params || {};
  126. changeId(classifyId || 0);
  127. changePageName(classifyTitle);
  128. return httpGet(`/classification/get/${ classifyId}`, {}, true).then(
  129. res => {
  130. changeName(res.name || "");
  131. changeSort(res.sort || 1);
  132. changeGoodsIds(res.goodsIds || "");
  133. }
  134. );
  135. };
  136. function delEvent() {
  137. removeCLass({ id, goodsIds }, () => {
  138. navigation.goBack();
  139. });
  140. }
  141. return (
  142. <>
  143. <ScrollPage
  144. statusType='primary'
  145. navHeaderBarTitle={pageName}
  146. enabledFresh
  147. refreshEvent={refreshEvent}
  148. >
  149. <Layout style={styles.container}>
  150. <Card appearance='formFilled'>
  151. {/* 类别名称 */}
  152. <FormInput
  153. label={guide2_form_1}
  154. placeholder={guide2_pla_1}
  155. value={name}
  156. onChange={changeName}
  157. style={{ paddingVertical: 3 }}
  158. />
  159. {/* 显示排序 */}
  160. <FormInput
  161. label={guide2_form_2}
  162. value={sort}
  163. type='actionSheet'
  164. list={[1, 2, 3, 4, 5, 6, 7, 8, 9]}
  165. onChange={changeSort}
  166. textAlign='right'
  167. />
  168. {/* 商品 */}
  169. <FormInput
  170. label={guide2_form_3}
  171. value={goodsIds}
  172. type='url'
  173. changePath={() => {
  174. navigation.navigate("AddClassification", {
  175. type: "classification",
  176. classificationId: id,
  177. });
  178. }}
  179. textAlign='right'
  180. />
  181. <Layout style={styles.layoutLeft} level='1'>
  182. <Button
  183. status='primary'
  184. disabled={!canNext}
  185. onPress={() => {
  186. addClass().then(_ => {
  187. success("添加成功");
  188. navigation.goBack();
  189. });
  190. }}
  191. >
  192. 确定
  193. </Button>
  194. <Button
  195. style={{ marginLeft: 20 }}
  196. appearance='outline'
  197. status='info'
  198. onPress={delEvent}
  199. >
  200. 删除
  201. </Button>
  202. </Layout>
  203. </Card>
  204. </Layout>
  205. </ScrollPage>
  206. </>
  207. );
  208. }