Guide2Screen.js 6.6 KB

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