HomeScreen.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. import * as WebBrowser from "expo-web-browser";
  2. import * as React from "react";
  3. import {
  4. Image,
  5. StyleSheet,
  6. TouchableOpacity,
  7. ImageBackground,
  8. View,
  9. } from "react-native";
  10. import { ScrollView } from "react-native-gesture-handler";
  11. import { useModel } from "flooks";
  12. import {
  13. Layout,
  14. Text,
  15. useTheme,
  16. Button,
  17. Card,
  18. Icon,
  19. MenuItem,
  20. OverflowMenu,
  21. TopNavigation,
  22. TopNavigationAction,
  23. } from "@ui-kitten/components";
  24. import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";
  25. import { useFocusEffect } from "@react-navigation/native";
  26. import Badge from "../components/Badge";
  27. import HomePage1 from "./HomeScreenPage1";
  28. import HomePage2 from "./Comment";
  29. import HomePage3 from "./HomeScreenPage3";
  30. import * as RootNavigation from "../navigation/RootNavigation";
  31. const styles = StyleSheet.create({
  32. container: {
  33. flex: 1,
  34. backgroundColor: "#F0F0F0",
  35. },
  36. touch: {
  37. width: 53,
  38. height: 53,
  39. position: "absolute",
  40. left: 10,
  41. top: 10,
  42. zIndex: 2,
  43. },
  44. icon: {
  45. width: 53,
  46. height: 53,
  47. backgroundColor: "#E5E5E5",
  48. borderRadius: 3,
  49. },
  50. text: {
  51. fontWeight: "500",
  52. marginBottom: 7,
  53. },
  54. button: {
  55. marginTop: 19,
  56. },
  57. banner: {
  58. height: 100,
  59. backgroundColor: "#E5E5E5",
  60. position: "absolute",
  61. left: 0,
  62. right: 0,
  63. top: 0,
  64. zIndex: 1,
  65. },
  66. FlexRow: {
  67. flexDirection: "row",
  68. alignItems: "center",
  69. marginTop: 2,
  70. },
  71. zanImg: {
  72. width: 12,
  73. height: 12,
  74. marginRight: 3,
  75. },
  76. layItem: {
  77. width: 40,
  78. marginRight: 10,
  79. },
  80. cardMain: {
  81. alignItems: "center",
  82. zIndex: 1,
  83. },
  84. cardTop: {
  85. minHeight: 53,
  86. alignItems: "center",
  87. justifyContent: "center",
  88. paddingBottom: 10,
  89. },
  90. allBadges1: {
  91. marginHorizontal: 10,
  92. },
  93. allBadges: {
  94. overflow: "hidden",
  95. height: 20,
  96. marginHorizontal: 10,
  97. },
  98. more: {
  99. position: "absolute",
  100. right: 5,
  101. top: 57,
  102. },
  103. badges: {
  104. flexDirection: "row",
  105. flexWrap: "wrap",
  106. alignSelf: "center",
  107. backgroundColor: "rgba(0,0,0,0)",
  108. },
  109. badge: {
  110. marginRight: 15,
  111. marginTop: 3,
  112. },
  113. labelText: {
  114. textAlign: "left",
  115. fontSize: 13,
  116. paddingHorizontal: 10,
  117. minWidth: 120,
  118. maxWidth: "100%",
  119. },
  120. homeCard: {
  121. zIndex: 2,
  122. marginHorizontal: 15,
  123. marginTop: 80,
  124. },
  125. mainContent: {
  126. marginTop: 0,
  127. backgroundColor: "transparent",
  128. },
  129. tab: {
  130. backgroundColor: "#eee",
  131. },
  132. tabContainer: {
  133. backgroundColor: "transparent",
  134. },
  135. tabIndicator: {
  136. backgroundColor: "#FFC21C",
  137. },
  138. btn: {
  139. maxWidth: "100%",
  140. overflow: "hidden",
  141. paddingLeft: 30,
  142. },
  143. });
  144. const Tab = createMaterialTopTabNavigator();
  145. const labelText = (focused, title) => (
  146. <Text category="s1" status={focused ? "primary" : ""}>
  147. {title}
  148. </Text>
  149. );
  150. const NextIcon = props => <Icon {...props} name="arrow-ios-downward" />;
  151. const SearchIcon = props => <Icon {...props} name="search-outline" />;
  152. const MailIcon = props => <Icon {...props} name="email-outline" />;
  153. const ShareIcon = props => <Icon {...props} name="share-outline" />;
  154. const MenuIcon = props => <Icon {...props} name="more-vertical" />;
  155. const LogoutIcon = props => <Icon {...props} name="log-out" />;
  156. const img1 = require("../assets/images/zan.png");
  157. const img2 = require("../assets/images/cai.png");
  158. export default function HomeScreen({ navigation, route }) {
  159. const theme = useTheme();
  160. const { changeBackground } = useModel("barModel");
  161. const {
  162. showName,
  163. logo,
  164. proclamation,
  165. updateMerchant,
  166. banner,
  167. userLogout,
  168. monthSales,
  169. goodNum,
  170. badNum,
  171. firstOrder,
  172. } = useModel("userModel");
  173. const {
  174. homeBar,
  175. homeTip1,
  176. homeTitle3,
  177. homeTip2,
  178. homeTip3,
  179. homeTab1,
  180. homeTab2,
  181. homeTab3,
  182. fullReduction2,
  183. fullReduction1,
  184. ABSYHA,
  185. HXRNYH,
  186. MPSFFU,
  187. changeLocal,
  188. local,
  189. } = useModel("wordsModel");
  190. const [fullReductions, changeFllReduction] = React.useState([]);
  191. const { showDialog } = useModel("dialogModel", true);
  192. const { httpGet } = useModel("httpModel", true);
  193. const { getPlaf } = useModel("couponModel", true);
  194. const [showMore, changeShow] = React.useState(false);
  195. const [couponList, setCouponList] = React.useState([]);
  196. // const couponTips = React.useMemo(() => {
  197. // if (couponList.length > 0) {
  198. // return couponList
  199. // .map(item => {
  200. // return item.name;
  201. // })
  202. // .join(",");
  203. // }
  204. // return "";
  205. // }, [couponList]);
  206. useFocusEffect(
  207. React.useCallback(() => {
  208. changeBackground(theme["color-primary-500"]);
  209. httpGet("/fullReduction/my").then(res => {
  210. changeFllReduction(res);
  211. });
  212. getPlaf().then(res => {
  213. setCouponList(res);
  214. });
  215. }, [])
  216. );
  217. const [menuVisible, setMenuVisible] = React.useState(false);
  218. const toggleMenu = () => {
  219. setMenuVisible(!menuVisible);
  220. };
  221. const renderMenuAction = () => (
  222. <TopNavigationAction icon={MenuIcon} onPress={toggleMenu} />
  223. );
  224. const renderRightActions = () => (
  225. <>
  226. <TopNavigationAction
  227. icon={SearchIcon}
  228. onPress={() => {
  229. RootNavigation.navigate("Search");
  230. }}
  231. />
  232. <TopNavigationAction
  233. icon={MailIcon}
  234. onPress={() => {
  235. RootNavigation.navigate("SystemEmail");
  236. }}
  237. />
  238. <TopNavigationAction icon={ShareIcon} />
  239. <OverflowMenu
  240. anchor={renderMenuAction}
  241. visible={menuVisible}
  242. onBackdropPress={toggleMenu}
  243. >
  244. <MenuItem
  245. accessoryLeft={LogoutIcon}
  246. title={MPSFFU}
  247. onPress={() => {
  248. toggleMenu();
  249. userLogout();
  250. }}
  251. />
  252. <MenuItem title="0904版本" />
  253. <MenuItem title={`切换语言(${local})`} onPress={changeLocal} />
  254. </OverflowMenu>
  255. </>
  256. );
  257. const renderBackAction = () => <Text category="h6">{homeBar}</Text>;
  258. const badgeList = list => {
  259. return list.map(item => {
  260. return (
  261. <Badge style={styles.badge} key={item.id}>
  262. {fullReduction1}
  263. {item.fullAmount}
  264. {fullReduction2}
  265. {item.minusAmount}
  266. </Badge>
  267. );
  268. });
  269. };
  270. const CoupnbadgeList = list => {
  271. return list.map((item, index) => {
  272. return (
  273. <Badge style={styles.badge} key={`coupon${index}`}>
  274. {item.name}
  275. </Badge>
  276. );
  277. });
  278. };
  279. const [scrollRef, setScroll] = React.useState();
  280. React.useEffect(() => {
  281. const unsubscribe = navigation.addListener("tabPress", () => {
  282. if (route.name === "Home") {
  283. navigation.jumpTo("homeTab1");
  284. if (scrollRef) {
  285. scrollRef.scrollTo({ x: 0, y: 0, animated: true });
  286. }
  287. }
  288. });
  289. return unsubscribe;
  290. }, [navigation]);
  291. return (
  292. <>
  293. <TopNavigation
  294. appearance="homeBar"
  295. alignment="center"
  296. accessoryLeft={renderBackAction}
  297. accessoryRight={renderRightActions}
  298. />
  299. <ScrollView contentContainerStyle={{ flexGrow: 1 }} ref={setScroll}>
  300. <Layout style={styles.container}>
  301. <ImageBackground source={{ uri: banner }} style={styles.banner}>
  302. <Button
  303. appearance="bannerButton"
  304. onPress={() =>
  305. RootNavigation.navigate("EditBanner", {
  306. type: "banner",
  307. })
  308. }
  309. >
  310. {homeTip1}
  311. </Button>
  312. </ImageBackground>
  313. <Card disabled appearance="homeCard" style={styles.homeCard}>
  314. <TouchableOpacity
  315. style={styles.touch}
  316. onPress={() =>
  317. RootNavigation.navigate("EditBanner", {
  318. type: "logo",
  319. })
  320. }
  321. >
  322. <Image source={{ uri: logo }} style={styles.icon} />
  323. </TouchableOpacity>
  324. <Layout style={styles.cardMain}>
  325. <Layout style={styles.cardTop}>
  326. <Text>{showName}</Text>
  327. <Layout style={[styles.FlexRow]}>
  328. <Layout style={[styles.FlexRow, styles.layItem]}>
  329. <Image source={img1} style={styles.zanImg} />
  330. <Text category="c1" status="primary">
  331. {goodNum || 0}
  332. </Text>
  333. </Layout>
  334. <Layout style={[styles.FlexRow, styles.layItem]}>
  335. <Image source={img2} style={styles.zanImg} />
  336. <Text category="c1" status="info">
  337. {badNum || 0}
  338. </Text>
  339. </Layout>
  340. <Layout>
  341. <Text category="c1" status="info">
  342. {`${homeTip2} :`}
  343. {monthSales || 0}
  344. </Text>
  345. </Layout>
  346. </Layout>
  347. </Layout>
  348. <View style={styles.more}>
  349. <Icon
  350. fill="#000"
  351. style={{ width: 10, height: 10 }}
  352. name="arrow-ios-downward"
  353. />
  354. </View>
  355. <TouchableOpacity
  356. key="event"
  357. style={[showMore ? styles.allBadges1 : styles.allBadges]}
  358. onPress={() => {
  359. changeShow(!showMore);
  360. }}
  361. >
  362. <Layout style={styles.badges}>
  363. {badgeList(fullReductions)}
  364. {firstOrder !== 0 &&
  365. firstOrder !== null &&
  366. firstOrder !== "" && (
  367. <Badge style={styles.badge} key="firstOrder">
  368. {HXRNYH}
  369. {firstOrder}
  370. </Badge>
  371. )}
  372. {CoupnbadgeList(couponList)}
  373. </Layout>
  374. </TouchableOpacity>
  375. </Layout>
  376. <Button
  377. style={styles.btn}
  378. key="boad"
  379. appearance="ghost"
  380. status="info"
  381. accessoryRight={NextIcon}
  382. onPress={() => {
  383. showDialog({
  384. pla: "",
  385. maxLength: 50,
  386. defaultValue: proclamation,
  387. isEdit: true,
  388. title: homeTitle3,
  389. cancelable: true,
  390. confirmCallback: info => {
  391. updateMerchant({ proclamation: info });
  392. },
  393. });
  394. }}
  395. >
  396. <Text
  397. style={styles.labelText}
  398. numberOfLines={1}
  399. ellipsizeMode="tail"
  400. >
  401. {`${homeTip3}:`}
  402. {proclamation || ABSYHA}
  403. </Text>
  404. </Button>
  405. </Card>
  406. <Layout style={styles.mainContent}>
  407. <Tab.Navigator
  408. initialRouteName="homeTab1"
  409. lazy
  410. backBehavior="initialRoute"
  411. unmountOnBlur
  412. tabBarOptions={{
  413. activeTintColor: "#FFC21C",
  414. inactiveTintColor: "#000",
  415. style: styles.tab,
  416. indicatorStyle: styles.tabIndicator,
  417. labelStyle: styles.tab,
  418. }}
  419. >
  420. <Tab.Screen
  421. name="homeTab1"
  422. component={HomePage1}
  423. options={{
  424. tabBarLabel: ({ focused }) => labelText(focused, homeTab1),
  425. }}
  426. />
  427. <Tab.Screen
  428. name="homeTab2"
  429. component={HomePage2}
  430. options={{
  431. tabBarLabel: ({ focused }) => labelText(focused, homeTab2),
  432. }}
  433. />
  434. <Tab.Screen
  435. name="homeTab3"
  436. component={HomePage3}
  437. options={{
  438. tabBarLabel: ({ focused }) => labelText(focused, homeTab3),
  439. }}
  440. />
  441. </Tab.Navigator>
  442. </Layout>
  443. </Layout>
  444. </ScrollView>
  445. </>
  446. );
  447. }