index.tsx 7.2 KB

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