HomeScreenPage3.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. import * as React from "react";
  2. import {
  3. Icon,
  4. useTheme,
  5. Text,
  6. Card,
  7. Layout,
  8. List,
  9. ListItem,
  10. Button,
  11. Menu,
  12. MenuItem,
  13. } from "@ui-kitten/components";
  14. import {
  15. Image,
  16. Platform,
  17. StyleSheet,
  18. TouchableOpacity,
  19. View,
  20. ImageBackground,
  21. Dimensions,
  22. } from "react-native";
  23. import { useFocusEffect } from "@react-navigation/native";
  24. import { useModel } from "flooks";
  25. import CommentCard from "../components/Comment";
  26. import Badge from "../components/Badge";
  27. import UpLoadImage from "../components/UpLoadImage";
  28. import Textarea from "react-native-textarea";
  29. import * as RootNavigation from "../navigation/RootNavigation.js";
  30. import OpenTimeUtil from "../Utils/OpenTimeUtil";
  31. import ListUtil from "../Utils/ListUtil";
  32. import ActionButton from "react-native-action-button";
  33. const Label = (props, title, value) => (
  34. <Layout style={[styles.lable]}>
  35. <Text {...props} style={[styles.lableName]}>
  36. {title}
  37. </Text>
  38. <Text
  39. {...props}
  40. style={[props.style, styles.lableText]}
  41. numberOfLines={1}
  42. ellipsizeMode='tail'
  43. >
  44. {value}
  45. </Text>
  46. </Layout>
  47. );
  48. export default function HomePage3(props) {
  49. const theme = useTheme();
  50. const { httpPost, httpGet } = useModel("httpModel", true);
  51. const [commentList, setCommentList] = React.useState([{}, {}, {}]);
  52. const [selectId, changeSelectId] = React.useState(0);
  53. const { showDialog } = useModel("dialogModel", true);
  54. const [text, changeText] = React.useState("");
  55. const {
  56. img,
  57. updateMerchant,
  58. introduction,
  59. name,
  60. phone,
  61. address,
  62. category,
  63. week,
  64. endTime,
  65. startTime,
  66. } = useModel("userModel");
  67. const categoryList = new ListUtil(category);
  68. const { loading, success } = useModel("loadingModel");
  69. const {
  70. editText,
  71. autoBackText,
  72. home3Title1,
  73. home3Title2,
  74. confirm,
  75. getWordsStr,
  76. weekWords,
  77. } = useModel("wordsModel");
  78. const imgList = React.useMemo(() => {
  79. let list = img ? img.split(",") : [];
  80. list.push("");
  81. console.log(list);
  82. return [...new Set(list)];
  83. }, [img]);
  84. const openTime = React.useMemo(() => {
  85. if (startTime && endTime && week && weekWords) {
  86. let _o = new OpenTimeUtil(startTime, endTime, week, weekWords());
  87. return _o.getShowStr();
  88. } else {
  89. return "";
  90. }
  91. }, [startTime, endTime, week, weekWords]);
  92. function changeImg(img, index) {
  93. let _imgs = [...imgList];
  94. _imgs.splice(index, 1, img);
  95. let _img1 = new Set(_imgs);
  96. updateMerchant({
  97. img: [..._img1].join(","),
  98. });
  99. }
  100. function delImg(index) {
  101. let _imgs = [...imgList];
  102. _imgs.splice(index, 1);
  103. let _img1 = new Set(_imgs);
  104. updateMerchant({
  105. img: [..._img1].join(","),
  106. });
  107. }
  108. const showImgList = list => {
  109. return list.map((item, index) => {
  110. return (
  111. <Layout key={index} style={styles.upload}>
  112. <UpLoadImage
  113. value={item}
  114. changeIcon={img => changeImg(img, index)}
  115. size={67}
  116. hasCancel={true}
  117. delEvent={() => {
  118. delImg(index);
  119. }}
  120. />
  121. </Layout>
  122. );
  123. });
  124. };
  125. function showChange(key, val, title, max, type) {
  126. showDialog({
  127. pla: "",
  128. maxLength: max || 50,
  129. defaultValue: val,
  130. InputType: type,
  131. isEdit: true,
  132. title: title,
  133. cancelable: true,
  134. confirmCallback: info => {
  135. updateMerchant({ [key]: info });
  136. },
  137. });
  138. }
  139. return (
  140. <Layout style={styles.tabContainer}>
  141. <Layout style={styles.top}>
  142. <Layout style={styles.imgList}>{showImgList(imgList)}</Layout>
  143. <Layout>
  144. <Text style={styles.text}>{home3Title1}</Text>
  145. <Textarea
  146. containerStyle={styles.textareaContainer}
  147. style={styles.textarea}
  148. onChangeText={changeText}
  149. defaultValue={introduction}
  150. maxLength={500}
  151. placeholder={home3Title2}
  152. placeholderTextColor={"#B4B4B4"}
  153. underlineColorAndroid={"transparent"}
  154. />
  155. <Button
  156. size='small'
  157. style={styles.button}
  158. onPress={() => {
  159. updateMerchant({
  160. introduction: text,
  161. }).then(res => {
  162. success("成功");
  163. });
  164. }}
  165. >
  166. {confirm}
  167. </Button>
  168. </Layout>
  169. </Layout>
  170. <Menu style={styles.menu}>
  171. <MenuItem
  172. title={props =>
  173. Label(props, getWordsStr("register_form_1"), name)
  174. }
  175. accessoryRight={ForwardIcon}
  176. style={styles.menuItem}
  177. onPress={() =>
  178. showChange(
  179. "name",
  180. name,
  181. getWordsStr("register_form_1"),
  182. 25,
  183. "text"
  184. )
  185. }
  186. />
  187. <MenuItem
  188. title={props =>
  189. Label(
  190. props,
  191. getWordsStr("guideHome_form_1"),
  192. categoryList.getKey("name")
  193. )
  194. }
  195. accessoryRight={ForwardIcon}
  196. style={styles.menuItem}
  197. onPress={() => {}}
  198. />
  199. <MenuItem
  200. title={props =>
  201. Label(props, getWordsStr("guideHome_form_2"), address)
  202. }
  203. accessoryRight={ForwardIcon}
  204. style={styles.menuItem}
  205. onPress={() =>
  206. showChange(
  207. "address",
  208. address,
  209. getWordsStr("guideHome_form_2")
  210. )
  211. }
  212. />
  213. <MenuItem
  214. title={props =>
  215. Label(props, getWordsStr("guideHome_form_3"), phone)
  216. }
  217. accessoryRight={ForwardIcon}
  218. style={styles.menuItem}
  219. onPress={() =>
  220. showChange(
  221. "phone",
  222. phone,
  223. getWordsStr("guideHome_form_3"),
  224. 11,
  225. "phone"
  226. )
  227. }
  228. />
  229. <MenuItem
  230. title={props =>
  231. Label(props, getWordsStr("guideHome_form_4"), openTime)
  232. }
  233. accessoryRight={ForwardIcon}
  234. style={styles.menuItem}
  235. onPress={() => {}}
  236. />
  237. <MenuItem
  238. title={getWordsStr("guideHome_form_5")}
  239. accessoryRight={ForwardIcon}
  240. style={styles.menuItem}
  241. onPress={() => {
  242. RootNavigation.navigate("EditBanner", {
  243. type: "qualification",
  244. });
  245. }}
  246. />
  247. </Menu>
  248. </Layout>
  249. );
  250. }
  251. const ForwardIcon = props => (
  252. <Icon
  253. {...props}
  254. name='arrow-ios-forward'
  255. fill='#B4B4B4'
  256. style={{ width: 15, height: 15, fontWeight: 500 }}
  257. />
  258. );
  259. const classificationItem = ({ item, index }) => <CommentCard />;
  260. const StarIcon = props => <Icon {...props} name='plus-outline' />;
  261. const goodsItem = ({ item, index }) => (
  262. <GoodsCardLarge appearance='classification' />
  263. );
  264. const styles = StyleSheet.create({
  265. tabContainer: {
  266. backgroundColor: "#fff",
  267. flex: 1,
  268. },
  269. top: {
  270. paddingVertical: 20,
  271. paddingHorizontal: 13,
  272. },
  273. imgList: {
  274. flexDirection: "row",
  275. },
  276. upload: {
  277. marginRight: 10,
  278. width: 67,
  279. width: 67,
  280. flexShrink: 0,
  281. },
  282. textareaContainer: {
  283. backgroundColor: "#F0F0F0",
  284. height: 100,
  285. alignSelf: "stretch",
  286. borderRadius: 4,
  287. },
  288. textarea: {
  289. textAlignVertical: "top", // hack android
  290. fontSize: 13,
  291. color: "#333",
  292. paddingHorizontal: 14,
  293. paddingVertical: 10,
  294. height: 100,
  295. },
  296. text: {
  297. paddingVertical: 10,
  298. },
  299. button: {
  300. alignSelf: "flex-end",
  301. marginTop: 10,
  302. marginRight: 14,
  303. },
  304. menu: {
  305. borderColor: "#EEEEEE",
  306. borderTopWidth: 6,
  307. backgroundColor: "#fff",
  308. paddingHorizontal: 15,
  309. },
  310. menuItem: {},
  311. lable: {
  312. flexDirection: "row",
  313. flex: 1,
  314. },
  315. lableName: {
  316. flexShrink: 0,
  317. flexBasis: "50%",
  318. marginHorizontal: 8,
  319. fontSize: 13,
  320. },
  321. lableText: {}
  322. });