index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import BreadTit from "@/components/BreadTit";
  2. import ImageLazy from "@/components/ImageLazy";
  3. import LookModal from "@/components/LookObjTable/LookModal";
  4. import { RootState } from "@/store";
  5. import { object5infoOutAPI } from "@/store/action/object5";
  6. import { goodsChangeObj, statusObj } from "@/utils/dataChange";
  7. import history, { urlParameter } from "@/utils/history";
  8. import { Button, Table } from "antd";
  9. import React, {
  10. useCallback,
  11. useEffect,
  12. useMemo,
  13. useRef,
  14. useState,
  15. } from "react";
  16. import { useDispatch, useSelector } from "react-redux";
  17. import { useLocation } from "react-router-dom";
  18. import styles from "./index.module.scss";
  19. function LookObject5() {
  20. const dispatch = useDispatch();
  21. // 获取地址栏参数
  22. const location = useLocation();
  23. const urlParamRef = useRef<any>({});
  24. useEffect(() => {
  25. urlParamRef.current = urlParameter(location.search);
  26. // console.log("地址栏参数", urlParamRef.current);
  27. }, [location]);
  28. const { info, list: tableList } = useSelector(
  29. (state: RootState) => state.object5Store.lookInfo
  30. );
  31. const getInfo = useCallback(async () => {
  32. const id = urlParamRef.current.id;
  33. const res = await object5infoOutAPI(id);
  34. const info = res.data;
  35. // 表格信息的整理
  36. const list = [] as any;
  37. const oldData = JSON.parse(res.data.before_json);
  38. const newData = JSON.parse(res.data.after_json);
  39. console.log(123, oldData, newData);
  40. for (const k in newData) {
  41. if (k !== "fileIds" && k !== "fileIdsName") {
  42. if (k === "size") {
  43. const oldValArr = oldData[k].split(",");
  44. const newValArr = oldData[k].split(",");
  45. list.push({
  46. label: goodsChangeObj[k],
  47. oldVal: `通长:${oldValArr[0]}cm,通宽:${oldValArr[1]}cm,通高:${oldValArr[2]}cm`,
  48. newVal: `通长:${newValArr[0]}cm,通宽:${newValArr[1]}cm,通高:${newValArr[2]}cm`,
  49. });
  50. } else if (k === "display") {
  51. list.push({
  52. label: goodsChangeObj[k],
  53. oldVal: oldData[k] === 1 ? "是" : "否",
  54. newVal: newData[k] === 1 ? "是" : "否",
  55. });
  56. } else {
  57. list.push({
  58. label: goodsChangeObj[k],
  59. oldVal: oldData[k],
  60. newVal: newData[k],
  61. });
  62. }
  63. } else if (k === "fileIdsName") {
  64. list.push({
  65. label: "附件信息",
  66. oldVal: oldData[k],
  67. newVal: newData[k],
  68. });
  69. }
  70. }
  71. info.statusTxt = statusObj[info.status];
  72. dispatch({ type: "object5/getLookInfo", payload: { info, list } });
  73. }, [dispatch]);
  74. useEffect(() => {
  75. getInfo();
  76. }, [getInfo]);
  77. // 控制弹窗的显示隐藏
  78. const [show, setShow] = useState(false);
  79. // 点击表格里面的查看
  80. const lookIdRef = useRef(-1);
  81. const lookGoods = useCallback((id: number) => {
  82. lookIdRef.current = id;
  83. setShow(true);
  84. }, []);
  85. // 点击返回
  86. const cancelFu = useCallback(() => {
  87. history.push({
  88. pathname: `/object/5`,
  89. state: {
  90. k: urlParamRef.current.k ? urlParamRef.current.k : "1",
  91. d: urlParamRef.current.d,
  92. },
  93. });
  94. }, []);
  95. // 表格格式
  96. const columns = useMemo(() => {
  97. const tempArr = [
  98. {
  99. title: "修改内容",
  100. dataIndex: "label",
  101. },
  102. {
  103. title: "修改前",
  104. render: (item: any) => {
  105. return item.label === "藏品图片" && item.oldVal ? (
  106. <ImageLazy width={120} height={70} src={item.oldVal} />
  107. ) : item.oldVal ? (
  108. item.oldVal
  109. ) : (
  110. "-"
  111. );
  112. },
  113. },
  114. {
  115. title: "修改后",
  116. render: (item: any) => {
  117. return item.label === "藏品图片" && item.newVal ? (
  118. <ImageLazy width={120} height={70} src={item.newVal} />
  119. ) : item.newVal ? (
  120. item.newVal
  121. ) : (
  122. "-"
  123. );
  124. },
  125. },
  126. ];
  127. return tempArr;
  128. }, []);
  129. return (
  130. <div className={styles.LookObject5}>
  131. <div className="breadTit">
  132. <BreadTit>
  133. <div className="breadTitRow">藏品修改</div>
  134. <div className="splitStr">/</div>
  135. <div className="breadTitRow active">查看</div>
  136. </BreadTit>
  137. </div>
  138. <div className="objectSonMain">
  139. <div className="topTit">修改信息</div>
  140. <div className="topInfo">
  141. <div className="topInfoRow">
  142. <div>
  143. <div className="one">藏品名称:</div>
  144. <div>{info.name}</div>
  145. </div>
  146. <div>
  147. <div className="one">藏品编号:</div>
  148. <div>{info.dictNum}</div>
  149. </div>
  150. </div>
  151. <div className="topInfoRow">
  152. <div>
  153. <div className="one">登记人员:</div>
  154. <div>{info.creatorName}</div>
  155. </div>
  156. <div>
  157. <div className="one">创建日期:</div>
  158. <div>{info.create_time}</div>
  159. </div>
  160. </div>
  161. <div className="topInfoTex">
  162. <span>审核结果:</span>
  163. {info.statusTxt}
  164. </div>
  165. <div className="topInfoTex" title={info.reason}>
  166. <span>审核说明:</span>
  167. {info.reason ? info.reason : "-"}
  168. </div>
  169. </div>
  170. <br />
  171. <div className="topTit topTit2">
  172. 修改记录
  173. <div className="titBtn">
  174. <Button onClick={() => lookGoods(info.goods_ids)}>查看</Button>
  175. </div>
  176. </div>
  177. <div className="goodsInfo">
  178. {/* 表格信息 */}
  179. <Table
  180. size="small"
  181. scroll={{ y: 340 }}
  182. dataSource={tableList}
  183. columns={columns}
  184. rowKey="label"
  185. pagination={false}
  186. />
  187. </div>
  188. <div className="backBtn">
  189. <Button onClick={cancelFu}>返回</Button>
  190. </div>
  191. </div>
  192. {/* 点击查看出来的对话框 */}
  193. {show ? (
  194. <LookModal
  195. id={lookIdRef.current}
  196. show={show}
  197. closeShow={() => setShow(false)}
  198. />
  199. ) : null}
  200. </div>
  201. );
  202. }
  203. const MemoLookObject5 = React.memo(LookObject5);
  204. export default MemoLookObject5;