Guide2Screen.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. const { selectInfos, changeSelect } = useModel("goodsModel");
  63. useFocusEffect(
  64. React.useCallback(() => {
  65. changeBackground(theme["color-primary-500"]);
  66. if (route.name) {
  67. changePageName(route.name);
  68. }
  69. }, [])
  70. );
  71. React.useEffect(() => {
  72. if (selectInfos.length > 0) {
  73. let _ids = selectInfos.map(item => {
  74. return item.id;
  75. });
  76. changeGoodsIds(_ids.join(","));
  77. }
  78. }, [selectInfos]);
  79. const canNext = React.useMemo(() => {
  80. if (name && sort) {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. }, [name, sort, goodsIds]);
  86. const addClass = () => {
  87. return httpPost(
  88. "/classification/save",
  89. {
  90. name,
  91. sort,
  92. goodsIds,
  93. merchantId: mid,
  94. },
  95. { body: "json" }
  96. ).then(res => {});
  97. };
  98. return (
  99. <>
  100. {pageName != "AddNewClass" && <GuideHeaderBar />}
  101. {pageName === "AddNewClass" && <NavHeaderBar title='添加分类' />}
  102. <ScrollPage>
  103. <Layout style={styles.container}>
  104. {pageName != "AddNewClass" && (
  105. <Card appearance='headFilled'>
  106. <Text category='s1'>{guide2_title1}</Text>
  107. <Text category='s1'>{guide2_title2}</Text>
  108. </Card>
  109. )}
  110. <Card appearance='formFilled'>
  111. {/* 类别名称 */}
  112. <FormInput
  113. label={guide2_form_1}
  114. placeholder={guide2_pla_1}
  115. value={name}
  116. onChange={changeName}
  117. style={{ paddingVertical: 3 }}
  118. />
  119. {/* 显示排序 */}
  120. <FormInput
  121. label={guide2_form_2}
  122. value={sort}
  123. type='actionSheet'
  124. list={[1, 2, 3, 4, 5, 6, 7, 8, 9]}
  125. onChange={changeSort}
  126. textAlign='right'
  127. />
  128. {/* 商品 */}
  129. <FormInput
  130. label={guide2_form_3}
  131. value={goodsIds}
  132. type='url'
  133. changePath={() => {
  134. RootNavigation.navigate("AddClassification", {
  135. type: "classification",
  136. classificationId: "new",
  137. preKey: route.name,
  138. });
  139. }}
  140. textAlign='right'
  141. />
  142. {pageName === "AddNewClass" && (
  143. <Layout style={styles.layoutLeft} level='1'>
  144. <Button
  145. status='primary'
  146. disabled={!canNext}
  147. onPress={() => {
  148. addClass().then(_ => {
  149. success("添加成功");
  150. RootNavigation.goBack();
  151. changeSelect([]);
  152. });
  153. }}
  154. >
  155. 确定
  156. </Button>
  157. </Layout>
  158. )}
  159. </Card>
  160. {pageName !== "AddNewClass" && (
  161. <ConnectButton>
  162. <Layout style={styles.layoutLeft} level='1'>
  163. <Button
  164. status='primary'
  165. disabled={!canNext}
  166. onPress={() => {
  167. addClass()
  168. .then(_ => {
  169. success("添加成功");
  170. changeGuideStep(3);
  171. })
  172. .then(e => {});
  173. }}
  174. >
  175. {next}
  176. </Button>
  177. <Button
  178. style={{ marginTop: 10 }}
  179. appearance='ghost'
  180. status='primary'
  181. onPress={() => {
  182. showDialog({
  183. bodyText: passTips,
  184. cancelable: true,
  185. confirmCallback: () => {
  186. changeGuideStep(3);
  187. },
  188. });
  189. }}
  190. >
  191. {pass}
  192. </Button>
  193. </Layout>
  194. </ConnectButton>
  195. )}
  196. </Layout>
  197. </ScrollPage>
  198. </>
  199. );
  200. }
  201. const styles = StyleSheet.create({
  202. container: {
  203. flex: 1,
  204. paddingBottom: 33,
  205. },
  206. tabContent: {
  207. backgroundColor: "#fff",
  208. marginTop: 20,
  209. },
  210. img: {
  211. width: 100,
  212. height: 100,
  213. alignSelf: "center",
  214. },
  215. img2: {
  216. width: 97,
  217. height: 21,
  218. alignSelf: "center",
  219. marginTop: 2,
  220. },
  221. text: {
  222. marginTop: 16,
  223. },
  224. layoutLeft: {
  225. // flexDirection: "row",
  226. paddingVertical: 10,
  227. justifyContent: "center",
  228. alignItems: "center",
  229. },
  230. form: {
  231. paddingHorizontal: 26,
  232. paddingVertical: 20,
  233. },
  234. textareaContainer: {
  235. backgroundColor: "#F0F0F0",
  236. height: 100,
  237. borderRadius: 4,
  238. },
  239. textarea: {
  240. textAlignVertical: "top", // hack android
  241. fontSize: 13,
  242. color: "#333",
  243. paddingHorizontal: 14,
  244. paddingVertical: 10,
  245. height: 100,
  246. },
  247. });