index.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. import AuthButton from "@/components/AuthButton";
  2. import BreadTit from "@/components/BreadTit";
  3. import ImageLazy from "@/components/ImageLazy";
  4. import ObjectAdd from "@/components/ObjectAdd";
  5. import { RootState } from "@/store";
  6. import history, { urlParameter } from "@/utils/history";
  7. import { Button, Cascader, message, Modal, Select, Table } from "antd";
  8. import React, {
  9. useCallback,
  10. useEffect,
  11. useMemo,
  12. useRef,
  13. useState,
  14. } from "react";
  15. import { useDispatch, useSelector } from "react-redux";
  16. import { useLocation } from "react-router-dom";
  17. import styles from "./index.module.scss";
  18. import "./index.css";
  19. import LookObject2Log from "./table";
  20. import { baseURL } from "@/utils/http";
  21. import classNames from "classnames";
  22. import { editObj2StoresAPI, getObj2InfoInAPI } from "@/store/action/object2";
  23. import { obj3InStorage, storageStatusObj } from "@/utils/dataChange";
  24. import { getStores1ListAPI } from "@/store/action/stores1";
  25. function LookObject2() {
  26. const dispatch = useDispatch();
  27. // 获取地址栏参数
  28. const location = useLocation();
  29. const urlParamRef = useRef<any>({});
  30. useEffect(() => {
  31. urlParamRef.current = urlParameter(location.search);
  32. // console.log("地址栏参数", urlParamRef.current);
  33. }, [location]);
  34. // 进页面通过id获取单个藏品详情
  35. const getObj2InfoInAPIFu = useCallback(async () => {
  36. const id = urlParamRef.current.id;
  37. const res = await getObj2InfoInAPI(id);
  38. const info = res.data.entity;
  39. const fileList = {
  40. img: [],
  41. video: [],
  42. audio: [],
  43. model: [],
  44. doc: [],
  45. } as any;
  46. res.data.file.forEach((v: any) => {
  47. fileList[v.type].push(v);
  48. });
  49. dispatch({
  50. type: "object2/getOneGoodsInfo",
  51. payload: { info, fileList },
  52. });
  53. }, [dispatch]);
  54. // 申请编辑和申请移库之后需要重新发送请求来更新按钮状态
  55. const upInfoAPIFu = useCallback(() => {
  56. getObj2InfoInAPIFu();
  57. }, [getObj2InfoInAPIFu]);
  58. useEffect(() => {
  59. getObj2InfoInAPIFu();
  60. return () => {
  61. // 退出页面的时候初始化仓库数据
  62. dispatch({
  63. type: "object2/getOneGoodsInfo",
  64. payload: {
  65. info: {},
  66. fileList: {
  67. img: [],
  68. video: [],
  69. audio: [],
  70. model: [],
  71. doc: [],
  72. },
  73. },
  74. });
  75. };
  76. }, [dispatch, getObj2InfoInAPIFu]);
  77. // 点击返回
  78. const cancelFu = () => {
  79. history.push({
  80. pathname: `/object/2`,
  81. state: {
  82. k: urlParamRef.current.k ? urlParamRef.current.k : "1",
  83. d: urlParamRef.current.d,
  84. },
  85. });
  86. };
  87. // 附件类型下拉框
  88. const fileSelectList = useMemo(() => {
  89. return [
  90. { id: 1, value: "img", label: "高清图片" },
  91. { id: 2, value: "video", label: "视频文件" },
  92. { id: 3, value: "audio", label: "音频文件" },
  93. { id: 4, value: "model", label: "三维模型" },
  94. { id: 5, value: "doc", label: "文档资料" },
  95. ];
  96. }, []);
  97. const [fileSelect, setFileSelect] = useState("img");
  98. const fileSelectChangeFu = (value: string) => {
  99. setFileSelect(value);
  100. };
  101. // 从仓库中获取信息
  102. const { info, fileList } = useSelector(
  103. (state: RootState) => state.object2Store.oneGoodsInfo
  104. );
  105. // 外形尺寸和具体质量
  106. let sizeRes = "";
  107. if (info.size && info.size.length) {
  108. const sizeArr = info.size.split(",");
  109. sizeRes = `(通长)${sizeArr[0]}cm&emsp;(通宽)${sizeArr[1]}cm&emsp;(通高)${sizeArr[2]}cm`;
  110. }
  111. let qualityRes = "-";
  112. if (info.quality && info.quality.length) {
  113. const qualityArr = info.quality.split(",");
  114. qualityRes = qualityArr[0] + qualityArr[1];
  115. }
  116. // 里面表格格式
  117. const columns = useMemo(() => {
  118. const tempArr = [
  119. {
  120. title: "附件名称",
  121. dataIndex: "name",
  122. },
  123. {
  124. title: "上传人",
  125. dataIndex: "creatorName",
  126. },
  127. {
  128. title: "上传时间",
  129. dataIndex: "updateTime",
  130. },
  131. {
  132. title: "操作",
  133. render: (item: any) => (
  134. <a
  135. target="_blank"
  136. href={baseURL + item.filePath}
  137. download
  138. rel="noreferrer"
  139. >
  140. 下载
  141. </a>
  142. ),
  143. },
  144. ] as any;
  145. if (fileSelect === "img") {
  146. tempArr.unshift({
  147. title: "缩略图",
  148. render: (item: any) => (
  149. <ImageLazy width={80} height={50} src={item.filePath} />
  150. ),
  151. });
  152. }
  153. return tempArr;
  154. }, [fileSelect]);
  155. // 关于 申请编辑 申请移库 操作记录
  156. const [titCut, setTitCut] = useState("");
  157. const titCutFu = useCallback(
  158. (val: string) => {
  159. if (val === "2") {
  160. dispatch(getStores1ListAPI());
  161. }
  162. setTitCut(val);
  163. },
  164. [dispatch]
  165. );
  166. // 从仓库中获取库房总信息
  167. const moveOptions = useSelector(
  168. (state: RootState) => state.stores1Store.infoList
  169. );
  170. const moveLocRef = useRef("");
  171. const [moveLoc, setMoveLoc] = useState<any>([]);
  172. const moveLocChangeFu = (val: any, names: any) => {
  173. setMoveLoc(val);
  174. let temp = "";
  175. names.forEach((v: any, i: number) => {
  176. if (i < names.length - 1) temp += v.name + "/";
  177. else temp += v.name;
  178. });
  179. moveLocRef.current = temp;
  180. };
  181. const moveBtnOk = useCallback(async () => {
  182. const oldLoc = info.storageAncestor;
  183. const newLoc = moveLoc.join(",");
  184. if (!newLoc) return message.warning("请选择移库位置!");
  185. if (oldLoc === newLoc) return message.warning("位置不能相同!");
  186. const obj = {
  187. beforeJson: { id: oldLoc, name: obj3InStorage(info.storageAncestor) },
  188. afterJson: { id: newLoc, name: moveLocRef.current },
  189. goodsIds: info.id,
  190. };
  191. const res: any = await editObj2StoresAPI(obj);
  192. if (res.code === 0) {
  193. message.success("申请移库成功!");
  194. // 更新页面
  195. getObj2InfoInAPIFu();
  196. setTitCut("");
  197. }
  198. console.log("移库点击提交", oldLoc, newLoc);
  199. }, [getObj2InfoInAPIFu, info.id, info.storageAncestor, moveLoc]);
  200. return (
  201. <div className={styles.LookObject2}>
  202. <div className="breadTit">
  203. <BreadTit>
  204. <div className="breadTitRow">藏品总账</div>
  205. <div className="splitStr">/</div>
  206. <div className="breadTitRow active">查看</div>
  207. </BreadTit>
  208. </div>
  209. <div className="objectSonMain">
  210. {/* 上面的信息 */}
  211. <div className="topInfoBox">
  212. <div className="topInfoBoxL">
  213. {/* 解决有图片进页面显示 加载失败 图片 问题 */}
  214. {info.id ? (
  215. <ImageLazy src={info.thumb} width={300} height={300} />
  216. ) : null}
  217. </div>
  218. <div className="topInfoBoxR">
  219. <div className="topInfoBoxRTit">
  220. <div>
  221. <h1>{info.name}</h1>
  222. <div
  223. className={classNames(
  224. "bs",
  225. info.storageStatus === "0"
  226. ? "bs1"
  227. : info.storageStatus === "in"
  228. ? "bs2"
  229. : info.storageStatus === "otu"
  230. ? "bs3"
  231. : "bs4"
  232. )}
  233. >
  234. {storageStatusObj[info.storageStatus]}
  235. </div>
  236. </div>
  237. <div>
  238. <AuthButton
  239. id={202}
  240. disabled={info.tempEdit !== 0}
  241. size="small"
  242. type="primary"
  243. onClick={() => titCutFu("1")}
  244. >
  245. 申请编辑
  246. </AuthButton>
  247. &emsp;
  248. {info.storageStatus !== "0" && info.storageStatus !== "temp" ? (
  249. <>
  250. <AuthButton
  251. id={205}
  252. disabled={info.tempMove !== 0||info.storageStatus==='out'}
  253. size="small"
  254. type="primary"
  255. onClick={() => titCutFu("2")}
  256. >
  257. 申请移库
  258. </AuthButton>
  259. &emsp;
  260. </>
  261. ) : null}
  262. <Button size="small" onClick={() => titCutFu("3")}>
  263. 操作记录
  264. </Button>
  265. </div>
  266. </div>
  267. <div className="topInfoBoxRTxt">
  268. <div className="row">
  269. <div title={info.name}>
  270. <span>藏品名称:</span>
  271. <p>{info.name}</p>
  272. </div>
  273. <div title={info.namePrimitive}>
  274. <span>原名:</span>
  275. <p>{info.namePrimitive ? info.namePrimitive : "-"}</p>
  276. </div>
  277. </div>
  278. <div className="row">
  279. <div title={info.dictNum}>
  280. <span>藏品编号名称:</span>
  281. <p>{info.dictNum}</p>
  282. </div>
  283. <div title={info.num}>
  284. <span>藏品编号:</span>
  285. <p>{info.num ? info.num : "-"}</p>
  286. </div>
  287. </div>
  288. <div className="row">
  289. <div title={info.dictAge}>
  290. <span>年代:</span>
  291. <p>{info.dictAge}</p>
  292. </div>
  293. <div title={info.dictTexture}>
  294. <span>文物质地:</span>
  295. <p>{info.dictTexture}</p>
  296. </div>
  297. </div>
  298. <div className="row">
  299. <div title={info.ageSpecific}>
  300. <span>具体年代:</span>
  301. <p>{info.ageSpecific ? info.ageSpecific : "-"}</p>
  302. </div>
  303. <div title={info.dictGoodType}>
  304. <span>文物类别:</span>
  305. <p>{info.dictGoodType}</p>
  306. </div>
  307. </div>
  308. <div className="row">
  309. <div title={info.pcs}>
  310. <span>实际数量:</span>
  311. <p>{info.pcs}</p>
  312. </div>
  313. <div title={info.dictLevel}>
  314. <span>文物级别:</span>
  315. <p>{info.dictLevel}</p>
  316. </div>
  317. </div>
  318. <div className="row">
  319. <div title={sizeRes.replaceAll("&emsp;", " ")}>
  320. <span>外形尺寸:</span>
  321. <p dangerouslySetInnerHTML={{ __html: sizeRes }}></p>
  322. </div>
  323. <div title={info.sizeSpecific}>
  324. <span>具体尺寸:</span>
  325. <p>{info.sizeSpecific}</p>
  326. </div>
  327. </div>
  328. <div className="row">
  329. <div title={info.dictQualityScope}>
  330. <span>质量范围:</span>
  331. <p>{info.dictQualityScope}</p>
  332. </div>
  333. <div title={qualityRes}>
  334. <span>具体质量:</span>
  335. <p>{qualityRes}</p>
  336. </div>
  337. </div>
  338. <div className="row">
  339. <div title={info.complete}>
  340. <span>完残程度:</span>
  341. <p>{info.complete}</p>
  342. </div>
  343. <div title={info.repair}>
  344. <span>保存状态:</span>
  345. <p>{info.repair ? info.repair : "-"}</p>
  346. </div>
  347. </div>
  348. <div className="row">
  349. <div title={info.dictCheckInScope}>
  350. <span>入藏时间范围:</span>
  351. <p>{info.dictCheckInScope}</p>
  352. </div>
  353. <div title={info.checkInYear}>
  354. <span>入藏年度:</span>
  355. <p>{info.checkInYear ? info.checkInYear : "-"}</p>
  356. </div>
  357. </div>
  358. <div className="row">
  359. <div title={info.author}>
  360. <span>著者:</span>
  361. <p>{info.author ? info.author : "-"}</p>
  362. </div>
  363. <div title={info.vision}>
  364. <span>版本:</span>
  365. <p>{info.vision ? info.vision : "-"}</p>
  366. </div>
  367. </div>
  368. <div className="row">
  369. <div title={info.onFile}>
  370. <span>存卷:</span>
  371. <p>{info.onFile ? info.onFile : "-"}</p>
  372. </div>
  373. <div title={info.description}>
  374. <span>来源说明:</span>
  375. <p>{info.description ? info.description : "-"}</p>
  376. </div>
  377. </div>
  378. <div className="row">
  379. <div
  380. title={
  381. info.storageStatus !== "0" &&
  382. info.storageStatus !== "temp" &&
  383. info.storageAncestor
  384. ? obj3InStorage(info.storageAncestor)
  385. : ""
  386. }
  387. >
  388. <span>入库位置:</span>
  389. <p>
  390. {info.storageStatus !== "0" &&
  391. info.storageStatus !== "temp" &&
  392. info.storageAncestor
  393. ? obj3InStorage(info.storageAncestor)
  394. : "-"}
  395. </p>
  396. </div>
  397. <div title={info.outLocation}>
  398. <span>出库位置:</span>
  399. <p>{info.outLocation ? info.outLocation : "-"}</p>
  400. </div>
  401. </div>
  402. </div>
  403. </div>
  404. </div>
  405. {/* 下面的表格 */}
  406. <div className="tableInfoBox">
  407. <div className="tableInfoBoxTit">
  408. <div className="rowTit">数字资源:</div>
  409. <div className="rowRr">
  410. <Select
  411. style={{ width: 150 }}
  412. value={fileSelect}
  413. onChange={fileSelectChangeFu}
  414. options={fileSelectList}
  415. />
  416. </div>
  417. </div>
  418. {/* 表格主体 */}
  419. <Table
  420. size="small"
  421. scroll={{ y: 190 }}
  422. dataSource={fileList[fileSelect]}
  423. columns={columns}
  424. rowKey="id"
  425. pagination={false}
  426. />
  427. </div>
  428. <div className="backBtn">
  429. <Button onClick={cancelFu}>返回</Button>
  430. </div>
  431. </div>
  432. {/* 点击上面的编辑 移库 操作记录出来的弹窗 */}
  433. {/* 申请编辑 */}
  434. {titCut === "1" ? (
  435. <ObjectAdd
  436. upInfoAPIFu={upInfoAPIFu}
  437. dirCode={info.dirCode}
  438. id={urlParamRef.current.id}
  439. colsePage={() => setTitCut("")}
  440. editId="edit"
  441. />
  442. ) : (
  443. <Modal
  444. wrapClassName="LookObject2Model"
  445. destroyOnClose
  446. open={!!titCut}
  447. title={titCut === "2" ? "申请移库" : "操作记录"}
  448. onCancel={() => setTitCut("")}
  449. footer={
  450. [] // 设置footer为空,去掉 取消 确定默认按钮
  451. }
  452. >
  453. {/* 申请移库 */}
  454. {titCut === "2" ? (
  455. <div className="moveLocBox">
  456. <div>
  457. <span>当前位置:</span>
  458. <p>{obj3InStorage(info.storageAncestor)}</p>
  459. </div>
  460. <div>
  461. <span>移库位置:</span>
  462. <Cascader
  463. style={{ width: 300 }}
  464. allowClear={false}
  465. value={moveLoc}
  466. onChange={moveLocChangeFu}
  467. fieldNames={{
  468. label: "name",
  469. value: "id",
  470. children: "children",
  471. }}
  472. options={moveOptions}
  473. placeholder="请选择"
  474. />
  475. </div>
  476. <br />
  477. <br />
  478. <div className="moveBtn">
  479. <Button type="primary" onClick={moveBtnOk}>
  480. 提交
  481. </Button>
  482. </div>
  483. </div>
  484. ) : null}
  485. {/* 操作记录 */}
  486. {titCut === "3" ? (
  487. <div className="logBox">
  488. {/* 表格 */}
  489. <LookObject2Log id={info.id} />
  490. </div>
  491. ) : null}
  492. </Modal>
  493. )}
  494. </div>
  495. );
  496. }
  497. const MemoLookObject2 = React.memo(LookObject2);
  498. export default MemoLookObject2;