山西督察-superintend-distribute-web react
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
5.4 KiB

  1. import React, { useState, useEffect } from 'react';
  2. import { connect } from 'umi';
  3. import { Button, Table, Popconfirm, message } from 'antd';
  4. import { CzqkList } from '@/utils/constants';
  5. import FormModal from './FormModal';
  6. import styles from './index.less';
  7. const CZBtn = (props) => {
  8. const {
  9. id,
  10. sysToken,
  11. fetchAJCZtable,
  12. fetchAddAJCZ,
  13. fetchDeleteAJCZ,
  14. fetchDownloadFile,
  15. fetchOrgTreeData,
  16. fetchOrgDataByName,
  17. CZLX,
  18. onlyRead,
  19. loading,
  20. } = props;
  21. const [visible, setVisible] = useState(false);
  22. const [tableData, setTableData] = useState([]);
  23. // const [CZLX, setCZLX] = useState([]);
  24. const handleOpenModal = () => {
  25. // fetchDictCZLX(sysToken).then((res) => {
  26. // if (res && res.resCode === 0) {
  27. // setCZLX(res.data);
  28. // setVisible(true);
  29. // }
  30. // });
  31. setVisible(true);
  32. };
  33. const handleCloseModal = () => {
  34. setVisible(false);
  35. };
  36. const handleGetTable = () => {
  37. fetchAJCZtable({ id, sysToken }).then((res) => {
  38. setTableData(res);
  39. });
  40. };
  41. const handleDelete = (id) => {
  42. fetchDeleteAJCZ({ id, sysToken }).then((res) => {
  43. if (res && res.resCode === 0) {
  44. message.success(res.resMsg);
  45. handleGetTable();
  46. } else {
  47. message.error(res.resMsg);
  48. }
  49. });
  50. };
  51. useEffect(() => {
  52. handleGetTable();
  53. // fetchCzlx();
  54. }, []);
  55. // 下载文件
  56. const handleDownload = (file) => {
  57. const params = {
  58. mc: file.wjMc,
  59. path: file.wjPath,
  60. url: file.wjUrl,
  61. };
  62. fetchDownloadFile({ params, sysToken });
  63. };
  64. const getCZLXMc = (text) => {
  65. const p = [];
  66. CZLX?.forEach((item) => {
  67. if (item.id === Number(text)) {
  68. p.push(item.mc);
  69. }
  70. });
  71. return p[0];
  72. };
  73. const columns = [
  74. {
  75. title: '处置类型',
  76. dataIndex: 'czlx',
  77. key: '',
  78. render: (text) => {
  79. return <span>{getCZLXMc(text)}</span>;
  80. },
  81. },
  82. {
  83. title: '处置情况',
  84. dataIndex: 'czqk',
  85. width: '10%',
  86. render: (text) => CzqkList.filter((i) => i.value === String(text))[0]?.text,
  87. },
  88. {
  89. title: '情况说明',
  90. dataIndex: 'qksm',
  91. width: '15%',
  92. },
  93. {
  94. title: '姓名',
  95. dataIndex: 'czMc',
  96. key: 'czMc',
  97. },
  98. {
  99. title: '身份证号',
  100. dataIndex: 'czSfz',
  101. key: 'czSfz',
  102. },
  103. {
  104. title: '警号',
  105. dataIndex: 'czJh',
  106. key: 'czJh',
  107. },
  108. {
  109. title: '单位',
  110. dataIndex: 'czDw',
  111. key: 'czDw',
  112. },
  113. {
  114. title: '法律文书',
  115. dataIndex: 'flwsMc',
  116. key: 'flwsMc',
  117. render: (text, record) => {
  118. return record?.wjList?.map((file, index) => {
  119. return (
  120. <a key={file.id} onClick={() => handleDownload(file)}>
  121. {file.wjMc}
  122. {index === record?.wjList?.length - 1 ? '' : ';'}
  123. </a>
  124. );
  125. });
  126. },
  127. },
  128. {
  129. title: '操作',
  130. key: 'action',
  131. render: (text, record) => {
  132. if (onlyRead) {
  133. return (
  134. <a type="text" disabled={onlyRead}>
  135. 删除
  136. </a>
  137. );
  138. } else {
  139. return (
  140. <Popconfirm
  141. placement="left"
  142. title="确定删除吗?"
  143. onConfirm={() => handleDelete(record.id)}
  144. okText="确定"
  145. cancelText="取消"
  146. >
  147. <a type="text" disabled={onlyRead}>
  148. 删除
  149. </a>
  150. </Popconfirm>
  151. );
  152. }
  153. },
  154. },
  155. ];
  156. return (
  157. <div>
  158. <div className={styles.titleAndButton}>
  159. <div className={styles.title}>处置明细</div>
  160. {!onlyRead && (
  161. <div className={styles.button}>
  162. <Button onClick={handleOpenModal} type="primary" disabled={onlyRead} loading={loading}>
  163. 添加处置信息
  164. </Button>
  165. </div>
  166. )}
  167. </div>
  168. <div>
  169. <Table
  170. rowKey="id"
  171. columns={columns}
  172. dataSource={tableData || []}
  173. pagination={false}
  174. scroll={{ x: 1400 }}
  175. />
  176. </div>
  177. {visible && (
  178. <FormModal
  179. id={id}
  180. sysToken={sysToken}
  181. visible={visible}
  182. CZLXList={CZLX}
  183. handleClose={handleCloseModal}
  184. getTable={handleGetTable}
  185. fetchAddAJCZ={fetchAddAJCZ}
  186. fetchOrgTreeData={fetchOrgTreeData}
  187. fetchOrgDataByName={fetchOrgDataByName}
  188. loading={loading}
  189. />
  190. )}
  191. </div>
  192. );
  193. };
  194. const mapStateToProps = ({ doing, global, loading }) => ({
  195. ...doing,
  196. ...global,
  197. loading: loading.effects['doing/fetchAddAJCZ'] || false,
  198. });
  199. const mapDispatchToProps = (dispatch) => ({
  200. fetchAJCZtable(params) {
  201. return dispatch({ type: 'doing/fetchAJCZtable', payload: { ...params } });
  202. },
  203. fetchAddAJCZ(params) {
  204. return dispatch({ type: 'doing/fetchAddAJCZ', payload: { ...params } });
  205. },
  206. fetchDeleteAJCZ(params) {
  207. return dispatch({ type: 'doing/fetchDeleteAJCZ', payload: { ...params } });
  208. },
  209. fetchDownloadFile(params) {
  210. return dispatch({ type: 'doing/fetchDownloadFile', payload: { ...params } });
  211. },
  212. fetchOrgTreeData(params) {
  213. return dispatch({ type: 'global/fetchOrgTreeData', payload: { ...params } });
  214. },
  215. fetchOrgDataByName(params) {
  216. return dispatch({ type: 'global/fetchOrgDataByName', payload: { ...params } });
  217. },
  218. });
  219. export default connect(mapStateToProps, mapDispatchToProps)(CZBtn);