index.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import AuthButton from "@/components/AuthButton";
  2. import BreadTit from "@/components/BreadTit";
  3. import ImageLazy from "@/components/ImageLazy";
  4. import LookModal from "@/components/LookObjTable/LookModal";
  5. import { RootState } from "@/store";
  6. import { object4infoOutAPI, returnObject4API } from "@/store/action/object4";
  7. import { statusObjCK2 } from "@/utils/dataChange";
  8. import history, { urlParameter } from "@/utils/history";
  9. import { MessageFu } from "@/utils/message";
  10. import { Button, Popconfirm, Table } from "antd";
  11. import React, {
  12. useCallback,
  13. useEffect,
  14. useMemo,
  15. useRef,
  16. useState,
  17. } from "react";
  18. import { useDispatch, useSelector } from "react-redux";
  19. import { useLocation } from "react-router-dom";
  20. import styles from "./index.module.scss";
  21. function LookObject4() {
  22. const dispatch = useDispatch();
  23. // 获取地址栏参数
  24. const location = useLocation();
  25. const urlParamRef = useRef<any>({});
  26. useEffect(() => {
  27. urlParamRef.current = urlParameter(location.search);
  28. // console.log("地址栏参数", urlParamRef.current);
  29. }, [location]);
  30. const getInfo = useCallback(async () => {
  31. const id = urlParamRef.current.id;
  32. const res1 = await object4infoOutAPI(id);
  33. const info = res1.data.entity;
  34. const list = res1.data.child;
  35. info.statusTxt = statusObjCK2[info.status];
  36. dispatch({ type: "object4/getLookInfo", payload: { info, list } });
  37. }, [dispatch]);
  38. useEffect(() => {
  39. getInfo();
  40. }, [getInfo]);
  41. const { info, list: tableList } = useSelector(
  42. (state: RootState) => state.object4Store.lookInfo
  43. );
  44. // 点击返回
  45. const cancelFu = () => {
  46. history.push({
  47. pathname: `/object/4`,
  48. state: {
  49. k: urlParamRef.current.k ? urlParamRef.current.k : "1",
  50. d: urlParamRef.current.d,
  51. },
  52. });
  53. };
  54. // 控制弹窗的显示隐藏
  55. const [show, setShow] = useState(false);
  56. // 点击表格里面的查看
  57. const lookIdRef = useRef(-1);
  58. const lookGoods = useCallback((id: number) => {
  59. lookIdRef.current = id;
  60. setShow(true);
  61. }, []);
  62. // 表格格式
  63. const columns = useMemo(() => {
  64. const tempArr = [
  65. {
  66. title: "缩略图",
  67. render: (item: any) => (
  68. <ImageLazy width={120} height={70} src={item.thumb} />
  69. ),
  70. },
  71. {
  72. title: "藏品编号名称",
  73. dataIndex: "dictNum",
  74. },
  75. {
  76. title: "藏品编号",
  77. render: (item: any) => (item.num ? item.num : "-"),
  78. },
  79. {
  80. title: "藏品名称",
  81. dataIndex: "name",
  82. },
  83. {
  84. title: "类别",
  85. dataIndex: "dictGoodType",
  86. },
  87. {
  88. title: "完残程度",
  89. dataIndex: "complete",
  90. },
  91. {
  92. title: "出库位置",
  93. dataIndex: "outLocation",
  94. },
  95. {
  96. title: "出库状态",
  97. render: (item: any) =>
  98. item.storageStatus === "out"
  99. ? "待归还"
  100. : item.storageStatus === "in"
  101. ? "已归还"
  102. : "-",
  103. },
  104. {
  105. title: "操作",
  106. render: (item: any) => (
  107. <>
  108. <Button type="text" danger onClick={() => lookGoods(item.id)}>
  109. 查看
  110. </Button>
  111. </>
  112. ),
  113. },
  114. ];
  115. return tempArr;
  116. }, [lookGoods]);
  117. // 选中的表格数据
  118. const [tableSelectList, setTableSelectList] = useState([]);
  119. // 表格的多选和禁选
  120. const rowSelection = {
  121. selectedRowKeys: tableSelectList,
  122. onChange: (selectedRowKeys: any) => {
  123. setTableSelectList(selectedRowKeys);
  124. },
  125. getCheckboxProps: (record: any) => ({
  126. disabled: record.storageStatus === "in" || info.status !== 3, // 已归还的禁止选中
  127. }),
  128. };
  129. // 点击归还
  130. const returnGoodsFu = useCallback(async () => {
  131. console.log("---------点击了归还", tableSelectList);
  132. const obj = {
  133. goodsIds: tableSelectList.join(","),
  134. id: info.id,
  135. };
  136. const res: any = await returnObject4API(obj);
  137. if (res.code === 0) {
  138. MessageFu.success("归还成功!");
  139. // 清空表格选中状态和数据
  140. setTableSelectList([]);
  141. getInfo();
  142. }
  143. }, [getInfo, info.id, tableSelectList]);
  144. return (
  145. <div className={styles.LookObject4}>
  146. <div className="breadTit">
  147. <BreadTit>
  148. <div className="breadTitRow">出库管理</div>
  149. <div className="splitStr">/</div>
  150. <div className="breadTitRow active">
  151. {info.status === 3 ? "查看-归还" : "查看"}
  152. </div>
  153. </BreadTit>
  154. </div>
  155. <div className="objectSonMain">
  156. <div className="topTit">出库信息</div>
  157. <div className="topInfo">
  158. <div className="topInfoRow">
  159. <div>
  160. <div className="one">出库编号:</div>
  161. <div>{info.num}</div>
  162. </div>
  163. <div>
  164. <div className="one">出库人员:</div>
  165. <div>{info.creatorName}</div>
  166. </div>
  167. <div>
  168. <div className="one">出库类型:</div>
  169. <div>{info.outType}</div>
  170. </div>
  171. <div>
  172. <div className="one">审核结果:</div>
  173. <div>{info.statusTxt}</div>
  174. </div>
  175. </div>
  176. <div className="topInfoTex" title={info.description}>
  177. <span>登记说明:</span>
  178. {info.description ? info.description : "-"}
  179. </div>
  180. <div className="topInfoTex" title={info.reason}>
  181. <span>审核说明:</span>
  182. {info.reason ? info.reason : "-"}
  183. </div>
  184. </div>
  185. <br />
  186. <div className="topTit topTit2">
  187. 藏品信息
  188. {info.status === 3 ? (
  189. <div className="titBtn">
  190. <Popconfirm
  191. disabled={tableSelectList.length === 0}
  192. title="确定归还吗?"
  193. okText="确定"
  194. cancelText="取消"
  195. onConfirm={returnGoodsFu}
  196. >
  197. <AuthButton id={406} disabled={tableSelectList.length === 0}>
  198. 归还
  199. </AuthButton>
  200. </Popconfirm>
  201. </div>
  202. ) : null}
  203. </div>
  204. <div className="goodsInfo">
  205. {/* 表格信息 */}
  206. <Table
  207. size="small"
  208. scroll={{ y: 360 }}
  209. rowSelection={{
  210. type: "checkbox",
  211. ...rowSelection,
  212. }}
  213. dataSource={tableList}
  214. columns={columns}
  215. rowKey="id"
  216. pagination={false}
  217. />
  218. </div>
  219. <div className="backBtn">
  220. {info.status === 2 ? (
  221. <AuthButton
  222. id={402}
  223. type="primary"
  224. onClick={() =>
  225. history.push(
  226. `/object/4/add?k=${urlParamRef.current.k}&d=${urlParamRef.current.d}&id=${urlParamRef.current.id}`
  227. )
  228. }
  229. >
  230. 编辑
  231. </AuthButton>
  232. ) : null}
  233. &emsp;
  234. <Button onClick={cancelFu}>返回</Button>
  235. </div>
  236. </div>
  237. {/* 点击查看出来的对话框 */}
  238. {show ? (
  239. <LookModal
  240. id={lookIdRef.current}
  241. show={show}
  242. closeShow={() => setShow(false)}
  243. />
  244. ) : null}
  245. </div>
  246. );
  247. }
  248. const MemoLookObject4 = React.memo(LookObject4);
  249. export default MemoLookObject4;