Guide2Screen.js 8.4 KB

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