index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. import React, { useCallback, useEffect, useRef, useState } from "react";
  2. import styles from "./index.module.scss";
  3. import {
  4. Button,
  5. Cascader,
  6. DatePicker,
  7. Form,
  8. FormInstance,
  9. Input,
  10. InputNumber,
  11. Popconfirm,
  12. Select,
  13. } from "antd";
  14. import mapDataAll from "./data";
  15. import dayjs from "dayjs";
  16. import TextArea from "antd/es/input/TextArea";
  17. import Z1upImgs from "@/components/Z1upImgs";
  18. import Z2upVideos from "@/components/Z2upVideos";
  19. import { MessageFu } from "@/utils/message";
  20. import Z3upFiles from "@/components/Z3upFiles";
  21. import classNames from "classnames";
  22. const { RangePicker } = DatePicker;
  23. const eeeeArr = [
  24. {
  25. value: "项目状态1",
  26. label: "项目状态1",
  27. },
  28. {
  29. value: "项目状态2",
  30. label: "项目状态2",
  31. },
  32. ];
  33. type LinkType = {
  34. id: number;
  35. name: string;
  36. link: string;
  37. };
  38. type Props = {
  39. pageType: { txt: string; id: number };
  40. closeFu: () => void;
  41. addFu: () => void;
  42. editFu: () => void;
  43. };
  44. function A1Add({ pageType, closeFu, addFu, editFu }: Props) {
  45. useEffect(() => {
  46. console.log("进来编辑和新增项目的页面~~~~~~~");
  47. }, []);
  48. // 表单的ref
  49. const FormBoxRef = useRef<FormInstance>(null);
  50. // 图片数组的ref
  51. const imgsRef = useRef<any>(null);
  52. // 视频数组的ref
  53. const videosRef = useRef<any>(null);
  54. // 有关 项目链接
  55. const [linkArr, setLinkArr] = useState<LinkType[]>([]);
  56. const addLinkFu = useCallback(() => {
  57. if (linkArr.length >= 10) return;
  58. setLinkArr([...linkArr, { id: Date.now(), name: "", link: "" }]);
  59. }, [linkArr]);
  60. const delLinkFu = useCallback(
  61. (id: number) => {
  62. setLinkArr(linkArr.filter((v) => v.id !== id));
  63. },
  64. [linkArr]
  65. );
  66. const linkChangeFu = useCallback(
  67. (id: number, val: string, type: "name" | "link") => {
  68. setLinkArr(
  69. linkArr.map((v) => ({
  70. ...v,
  71. [type]: v.id === id ? val.replace(/\s+/g, "") : v[type],
  72. }))
  73. );
  74. },
  75. [linkArr]
  76. );
  77. // 没有通过校验
  78. const onFinishFailed = useCallback(() => {}, []);
  79. // 通过校验点击确定
  80. const onFinish = useCallback(
  81. async (value: any) => {
  82. console.log("通过校验", value);
  83. if (value.ffff) {
  84. console.log(
  85. "修改日期格式",
  86. dayjs(value.ffff[0]).format("YYYY-MM-DD"),
  87. dayjs(value.ffff[1]).format("YYYY-MM-DD")
  88. );
  89. }
  90. // 获取图片地址
  91. const imgsRes = imgsRef.current.imgIdsRes();
  92. console.log("获取图片地址", imgsRes);
  93. // 获取视频地址
  94. const videosRes = videosRef.current.videoIdsRes();
  95. console.log("获取视频地址", videosRes);
  96. // 检查链接填写完整情况
  97. const linkArrFlag = linkArr.some((v) => !v.name || !v.link);
  98. if (linkArrFlag) return MessageFu.warning("请完整填写 项目链接 !");
  99. console.log("项目链接", linkArr);
  100. // 项目成功
  101. const filesRes = filesRef.current.filesIdRes();
  102. console.log("获取项目成果文件", filesRes);
  103. if (pageType.txt === "add") {
  104. MessageFu.success("新增成功!");
  105. addFu();
  106. } else if (pageType.txt === "edit") {
  107. MessageFu.success("编辑成功!");
  108. editFu();
  109. }
  110. closeFu();
  111. },
  112. [addFu, closeFu, editFu, linkArr, pageType.txt]
  113. );
  114. // 项目成功的 ref
  115. const filesRef = useRef<any>(null);
  116. return (
  117. <div className={styles.A1Add}>
  118. <div
  119. className={classNames(
  120. "A1AddMain",
  121. pageType.txt === "look" ? "A1AddMainLook" : ""
  122. )}
  123. >
  124. <Form
  125. scrollToFirstError={true}
  126. ref={FormBoxRef}
  127. name="basic"
  128. onFinish={onFinish}
  129. onFinishFailed={onFinishFailed}
  130. autoComplete="off"
  131. >
  132. <Form.Item
  133. label="项目编号"
  134. name="aaaa"
  135. rules={[{ required: true, message: "请输入项目编号!" }]}
  136. getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
  137. >
  138. <Input
  139. style={{ width: 600 }}
  140. disabled={pageType.txt === "edit"}
  141. maxLength={30}
  142. showCount
  143. placeholder="请输入内容,不能重复"
  144. />
  145. </Form.Item>
  146. <Form.Item
  147. label="项目名称"
  148. name="bbbb"
  149. rules={[{ required: true, message: "请输入项目名称!" }]}
  150. getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
  151. >
  152. <Input
  153. style={{ width: 600 }}
  154. maxLength={30}
  155. showCount
  156. placeholder="请输入内容"
  157. />
  158. </Form.Item>
  159. <Form.Item label="建设单位" name="cccc">
  160. <Input
  161. style={{ width: 600 }}
  162. maxLength={30}
  163. showCount
  164. placeholder={pageType.txt === "look" ? "(空)" : "请输入内容"}
  165. />
  166. </Form.Item>
  167. <Form.Item label="项目地点" name="dddd">
  168. <Cascader
  169. style={{ width: 300 }}
  170. options={mapDataAll}
  171. placeholder={pageType.txt === "look" ? "(空)" : "请选择省/市"}
  172. />
  173. </Form.Item>
  174. <Form.Item
  175. label="项目状态"
  176. name="eeee"
  177. rules={[{ required: true, message: "请选择项目状态!" }]}
  178. >
  179. <Select
  180. placeholder="请选择"
  181. style={{ width: 300 }}
  182. options={eeeeArr}
  183. />
  184. </Form.Item>
  185. {pageType.txt === "look" ? (
  186. <div className="e_row">
  187. <div className="e_rowL">
  188. <span> </span>项目日期:
  189. </div>
  190. <div className="e_rowR e_rowRLook">日期日期日期日期</div>
  191. </div>
  192. ) : (
  193. <Form.Item label="项目日期" name="ffff">
  194. <RangePicker style={{ width: 300 }} />
  195. </Form.Item>
  196. )}
  197. <Form.Item label="项目简介" name="gggg">
  198. <TextArea
  199. style={{ width: 600 }}
  200. autoSize
  201. placeholder={pageType.txt === "look" ? "(空)" : "请输入内容"}
  202. showCount
  203. maxLength={500}
  204. />
  205. </Form.Item>
  206. {pageType.txt === "look" ? (
  207. <div className="e_row">
  208. <div className="e_rowL">
  209. <span> </span>项目金额:
  210. </div>
  211. <div className="e_rowR e_rowRLook">1000000 ¥</div>
  212. </div>
  213. ) : (
  214. <Form.Item label="项目金额" name="hhhh">
  215. <InputNumber
  216. style={{ width: 300 }}
  217. addonAfter="¥"
  218. maxLength={10}
  219. placeholder="请输入数字,最多10位"
  220. />
  221. </Form.Item>
  222. )}
  223. <div className="e_row">
  224. <div className="e_rowL">
  225. <span> </span>项目图片:
  226. </div>
  227. <div className="e_rowR">
  228. <Z1upImgs
  229. max={50}
  230. isLook={pageType.txt === "look"}
  231. ref={imgsRef}
  232. fileCheck={false}
  233. size={10}
  234. isCoverShow={true}
  235. dirCode="aaaaaaaaa"
  236. myUrl="cms/goods/upload"
  237. />
  238. </div>
  239. </div>
  240. <div className="e_row">
  241. <div className="e_rowL e_rowL2">
  242. <span> </span>项目视频:
  243. </div>
  244. <div className="e_rowR">
  245. <Z2upVideos
  246. max={10}
  247. isLook={pageType.txt === "look"}
  248. ref={videosRef}
  249. fileCheck={false}
  250. size={500}
  251. dirCode="aaaaaaaaa"
  252. myUrl="cms/goods/upload"
  253. />
  254. </div>
  255. </div>
  256. <div className="e_row">
  257. <div className="e_rowL e_rowL2">
  258. <span> </span>项目链接:
  259. </div>
  260. <div className="e_rowR">
  261. {pageType.txt === "look" && linkArr.length <= 0 ? (
  262. <div className="lookNoneOne">(空)</div>
  263. ) : (
  264. <div className="erLinkTop">
  265. <Button onClick={addLinkFu} disabled={linkArr.length >= 10}>
  266. 新&emsp;增
  267. </Button>
  268. <span className="e_rowRtit">&emsp;最多支持10条链接</span>
  269. </div>
  270. )}
  271. <div className="erLinkMain">
  272. {linkArr.map((v) => (
  273. <div className="erLinkRow" key={v.id}>
  274. <Input
  275. value={v.name}
  276. onChange={(e) =>
  277. linkChangeFu(v.id, e.target.value, "name")
  278. }
  279. style={{ width: 240 }}
  280. maxLength={10}
  281. showCount
  282. placeholder="请输入链接标题"
  283. />
  284. &emsp;
  285. <Input
  286. value={v.link}
  287. onChange={(e) =>
  288. linkChangeFu(v.id, e.target.value, "link")
  289. }
  290. style={{ width: 800 }}
  291. maxLength={100}
  292. showCount
  293. placeholder="请输入链接"
  294. />
  295. &emsp;
  296. <Popconfirm
  297. title="删除后无法恢复,是否删除?"
  298. okText="删除"
  299. cancelText="取消"
  300. onConfirm={() => delLinkFu(v.id)}
  301. okButtonProps={{ loading: false }}
  302. >
  303. <Button>删除</Button>
  304. </Popconfirm>
  305. </div>
  306. ))}
  307. </div>
  308. </div>
  309. </div>
  310. <br />
  311. <div className="e_row">
  312. <div className="e_rowL e_rowL2">
  313. <span> </span>项目成果:
  314. </div>
  315. <div className="e_rowR">
  316. <Z3upFiles
  317. max={10}
  318. isLook={pageType.txt === "look"}
  319. ref={filesRef}
  320. fileCheck={false}
  321. dirCode="aaaaaaaaa"
  322. myUrl="cms/goods/upload"
  323. />
  324. </div>
  325. </div>
  326. {/* 确定和取消按钮 */}
  327. <div className="A1AddBtn">
  328. {pageType.txt === "look" ? null : ( // <Button onClick={closeFu}>关 闭</Button>
  329. <>
  330. <Popconfirm
  331. title="放弃编辑后,信息将不会保存!"
  332. okText="放弃"
  333. cancelText="取消"
  334. onConfirm={closeFu}
  335. okButtonProps={{ loading: false }}
  336. >
  337. <Button>取消</Button>
  338. </Popconfirm>{" "}
  339. &emsp;&emsp;
  340. <Button type="primary" htmlType="submit">
  341. 保存
  342. </Button>
  343. </>
  344. )}
  345. </div>
  346. </Form>
  347. </div>
  348. </div>
  349. );
  350. }
  351. const MemoA1Add = React.memo(A1Add);
  352. export default MemoA1Add;