HomeScreenPage3.js 7.2 KB

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