HomeScreenPage3.js 8.8 KB

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