EquipmentProcurementList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. import PageContent from '@/components/PageContent';
  2. import PreviewFile from '@/components/PreviewFile';
  3. import { subtypeDictionaries } from '@/utils/constants';
  4. import { GetTokenFromUrl, connectUserModel, getToken } from '@/utils/utils';
  5. import { connect } from '@umijs/max';
  6. import { Button, Card, Modal, Row, Table, Tabs, Upload, message } from 'antd';
  7. import dayjs from 'dayjs';
  8. import React, { Fragment } from 'react';
  9. import cardStyle from './Card.less';
  10. import styles from './index.less';
  11. const { TabPane } = Tabs;
  12. const { confirm } = Modal;
  13. const opsPermissionTabsMap = new Map([
  14. ['合同资料', 'func-01-ops-DeviceList-00-00'],
  15. ['监造资料', 'func-01-ops-DeviceList-01-00'],
  16. ['出厂检验', 'func-01-ops-DeviceList-01-01'],
  17. ['包装', 'func-01-ops-DeviceList-02-00'],
  18. ['装箱单', 'func-01-ops-DeviceList-02-01'],
  19. ['质量证书', 'func-01-ops-DeviceList-02-02'],
  20. ['原产地证明', 'func-01-ops-DeviceList-02-03'],
  21. ['安装手册', 'func-01-ops-DeviceList-02-04'],
  22. ['到货签收单', 'func-01-ops-DeviceList-03-00'],
  23. ['开箱报告', 'func-01-ops-DeviceList-03-01'],
  24. ['随机资料', 'func-01-ops-DeviceList-03-02'],
  25. ['安装指导资料', 'func-01-ops-DeviceList-04-00'],
  26. ['安装过程资料', 'func-01-ops-DeviceList-04-01'],
  27. ['调试指导资料', 'func-01-ops-DeviceList-05-00'],
  28. ['单体调试记录表', 'func-01-ops-DeviceList-05-01'],
  29. ['其它资料', 'func-01-ops-DeviceList-05-02'],
  30. ]);
  31. const buildPermissionTabsMap = new Map([
  32. ['合同资料', 'func-01-build-5-dev-00-00'],
  33. ['监造资料', 'func-01-build-5-dev-01-00'],
  34. ['出厂检验', 'func-01-build-5-dev-01-01'],
  35. ['包装', 'func-01-build-5-dev-02-00'],
  36. ['装箱单', 'func-01-build-5-dev-02-01'],
  37. ['质量证书', 'func-01-build-5-dev-02-02'],
  38. ['原产地证明', 'func-01-build-5-dev-02-03'],
  39. ['安装手册', 'func-01-build-5-dev-02-04'],
  40. ['到货签收单', 'func-01-build-5-dev-03-00'],
  41. ['开箱报告', 'func-01-build-5-dev-03-01'],
  42. ['随机资料', 'func-01-build-5-dev-03-02'],
  43. ['安装指导资料', 'func-01-build-5-dev-04-00'],
  44. ['安装过程资料', 'func-01-build-5-dev-04-01'],
  45. ['调试指导资料', 'func-01-build-5-dev-05-00'],
  46. ['单体调试记录表', 'func-01-build-5-dev-05-01'],
  47. ['其它资料', 'func-01-build-5-dev-05-02'],
  48. ]);
  49. // @connect(({ equipmentProcurementList, loading, user }) => ({
  50. // list: equipmentProcurementList.list,
  51. // folders: equipmentProcurementList.folders,
  52. // loading: loading.models.equipmentProcurementList,
  53. // permission: user.currentUser.Permission,
  54. // }))
  55. class Index extends React.Component {
  56. constructor(props) {
  57. super(props);
  58. const { fileType, list } = props;
  59. this.state = {
  60. typeNum:
  61. subtypeDictionaries[fileType] && subtypeDictionaries[fileType][0].type,
  62. subtypeMap: [],
  63. list,
  64. };
  65. }
  66. componentDidMount() {
  67. console.log(this.props);
  68. const { dispatch } = this.props;
  69. const { billId, projectId, deviceCode, fileType, ops } = this.props;
  70. if (ops == '1') {
  71. dispatch({
  72. type: 'equipmentProcurementList/getOpsFileType',
  73. projectId,
  74. fileType,
  75. callback: (res) => {
  76. let arr = [];
  77. res &&
  78. res.forEach((folder) => {
  79. subtypeDictionaries[fileType].forEach((element) => {
  80. if (
  81. folder.Type != 0 &&
  82. folder.Type == fileType &&
  83. element.type == folder.SubType
  84. )
  85. arr.push(element);
  86. });
  87. });
  88. // console.log(arr);
  89. this.setState({
  90. subtypeMap: arr,
  91. typeNum: arr[0].type || this.state.typeNum,
  92. });
  93. },
  94. });
  95. }
  96. dispatch({
  97. type: 'equipmentProcurementList/getFileList',
  98. payload: {
  99. billId: 0,
  100. deviceCode,
  101. fileType,
  102. projectId,
  103. ops: ops == '1' ? 1 : undefined,
  104. },
  105. });
  106. }
  107. componentWillReceiveProps(nextProps, prevState) {
  108. const { list } = nextProps;
  109. this.setState({
  110. list,
  111. });
  112. }
  113. OnDeleteFile = (fileId) => {
  114. const { dispatch } = this.props;
  115. const {
  116. match: {
  117. params: { billId, deviceCode, fileType, projectId, ops },
  118. },
  119. } = this.props;
  120. confirm({
  121. title: '提醒',
  122. content: '确认删除该文件,删除后无法复原',
  123. okText: '确认',
  124. cancelText: '取消',
  125. onOk() {
  126. dispatch({
  127. type: `equipmentProcurementList/removeFile`,
  128. payload: {
  129. FileId: fileId,
  130. billId: 0,
  131. deviceCode,
  132. fileType,
  133. projectId,
  134. ops: ops == '1' ? 1 : undefined,
  135. },
  136. });
  137. },
  138. });
  139. };
  140. OnDeletePurchaseBillFile = (fileId) => {
  141. const {
  142. dispatch,
  143. match: {
  144. params: { billId },
  145. },
  146. } = this.props;
  147. dispatch({
  148. type: 'purchaseBill/removeById',
  149. payload: {
  150. // ID: billId,
  151. ID: 0,
  152. FileId: fileId,
  153. },
  154. });
  155. };
  156. columns = [
  157. {
  158. title: '文件名称',
  159. dataIndex: 'Name',
  160. render: (text, item) => <PreviewFile name={item.Name} src={item.Url} />,
  161. },
  162. {
  163. title: '上传人',
  164. dataIndex: 'Creator',
  165. render: (text) => {
  166. return text && text.CName;
  167. },
  168. },
  169. {
  170. title: '上传时间',
  171. dataIndex: 'CreatedTime',
  172. render: (text) => {
  173. return text ? dayjs(text).format('YYYY年MM月DD日 HH:mm:ss') : null;
  174. },
  175. },
  176. {
  177. title: '操作',
  178. width: '20%',
  179. render: (record) => (
  180. <Fragment>
  181. <a
  182. style={{ color: '#7BFFFB' }}
  183. onClick={() => this.checkFile(record)}
  184. >
  185. 下载
  186. </a>
  187. {this.showJurisdiction('func-01-build-5-1-06') && (
  188. <>
  189. &nbsp;&nbsp;
  190. <a
  191. style={{ color: '#7BFFFB' }}
  192. onClick={() => this.OnDeleteFile(record.ID)}
  193. >
  194. 删除
  195. </a>
  196. </>
  197. )}
  198. </Fragment>
  199. ),
  200. },
  201. ];
  202. checkFile = (record) => {
  203. if (window.InvokeUnityFileOpener) {
  204. window.InvokeUnityFileOpener(record.Url);
  205. } else {
  206. window.location.href = `${record.Url}`;
  207. }
  208. };
  209. showJurisdiction = (item) => {
  210. if (item === undefined) {
  211. return false;
  212. }
  213. return this.props.user?.Permission[item];
  214. };
  215. callback = (key) => {
  216. this.setState({
  217. typeNum: key,
  218. });
  219. };
  220. GetOpsTabs = (subtype, fileType, folders) => {
  221. const { list, loading } = this.props;
  222. const { subtypeMap } = this.state;
  223. const typeNum = this.state.typeNum || -1;
  224. // const data = list && list.BillFiles && list.BillFiles.filter(each => each.Subtype == typeNum);
  225. return subtypeMap.map((item) => {
  226. if (!this.showJurisdiction(opsPermissionTabsMap.get(item.value)))
  227. return null;
  228. const num =
  229. list &&
  230. list.BillFiles &&
  231. list.BillFiles.filter((each) => each.Subtype == item.type);
  232. return (
  233. <TabPane
  234. tab={`${item.value} (${(num && num.length) || 0})`}
  235. key={item.type}
  236. >
  237. <Table
  238. bordered
  239. rowKey="ID"
  240. columns={this.columns}
  241. loading={loading}
  242. dataSource={num}
  243. pagination={false}
  244. />
  245. </TabPane>
  246. );
  247. });
  248. };
  249. render() {
  250. console.log('=--------', this.props);
  251. const { loading } = this.props;
  252. const { dispatch, billId, deviceCode, fileType, projectId, ops } =
  253. this.props;
  254. const { list, folders } = this.props;
  255. const token = getToken() || GetTokenFromUrl();
  256. const typeNum = this.state.typeNum || -1;
  257. // const data = list && list.BillFiles && list.BillFiles.filter(each => each.Subtype == typeNum);
  258. const uploadProps = {
  259. name: 'files',
  260. action: `/api/v1/purchase_bill/device_file/0/${deviceCode}/${fileType}/${typeNum}?projectId=${projectId}&${
  261. ops == '1' ? 'ops=1' : undefined
  262. }`,
  263. // action: `/api/v1/purchase_bill/device_file/${billId}/${deviceCode}/${fileType}/${typeNum}?projectId=${projectId}`,
  264. showUploadList: false,
  265. headers: {
  266. 'JWT-TOKEN': token,
  267. },
  268. onChange(info) {
  269. if (info.file.status !== 'uploading') {
  270. // console.log(info.file, info.fileList);
  271. }
  272. if (info.file.status === 'done') {
  273. var res = info.file.response;
  274. if (res.code !== 200) return message.error(res.msg);
  275. message.success(`${info.file.name} 文件上传成功`);
  276. dispatch({
  277. type: 'equipmentProcurementList/getFileList',
  278. payload: {
  279. billId: 0,
  280. deviceCode,
  281. fileType,
  282. projectId,
  283. ops: ops == '1' ? 1 : undefined,
  284. },
  285. });
  286. } else if (info.file.status === 'error') {
  287. message.error(`${info.file.name} 文件上传失败`);
  288. }
  289. },
  290. };
  291. return (
  292. <PageContent>
  293. <Card bordered={false} className={cardStyle.CardCon}>
  294. {(this.showJurisdiction('func-01-ops-1-5-06') ||
  295. this.showJurisdiction('func-01-build-5-1-05')) && (
  296. <Row>
  297. <Upload {...uploadProps} className={styles.upload}>
  298. <Button type="primary">上传</Button>
  299. </Upload>
  300. </Row>
  301. )}
  302. {subtypeDictionaries[fileType] ? (
  303. <Tabs
  304. animated={false}
  305. // activeKey={typeNum + ''}
  306. onChange={this.callback}
  307. style={{ paddingTop: -20 }}
  308. >
  309. {ops == '1'
  310. ? this.GetOpsTabs(subtypeDictionaries, fileType, folders)
  311. : subtypeDictionaries[fileType].map((item) => {
  312. if (
  313. !this.showJurisdiction(
  314. buildPermissionTabsMap.get(item.value),
  315. )
  316. )
  317. return null;
  318. const num =
  319. list &&
  320. list.BillFiles &&
  321. list.BillFiles.filter(
  322. (each) => each.Subtype == item.type,
  323. );
  324. return (
  325. <TabPane
  326. tab={`${item.value} (${(num && num.length) || 0})`}
  327. key={item.type}
  328. >
  329. <Table
  330. bordered
  331. rowKey="ID"
  332. columns={this.columns}
  333. loading={loading}
  334. dataSource={num}
  335. pagination={false}
  336. />
  337. </TabPane>
  338. );
  339. })}
  340. </Tabs>
  341. ) : (
  342. <Table
  343. bordered
  344. rowKey="ID"
  345. columns={this.columns}
  346. loading={loading}
  347. dataSource={
  348. list &&
  349. list.BillFiles &&
  350. list.BillFiles.filter((item) => item.Type == fileType)
  351. }
  352. pagination={false}
  353. style={{ paddingTop: 20 }}
  354. />
  355. )}
  356. </Card>
  357. </PageContent>
  358. );
  359. }
  360. }
  361. const HOCIndex = connect(({ equipmentProcurementList, loading }) => {
  362. return {
  363. list: equipmentProcurementList.list,
  364. folders: equipmentProcurementList.folders,
  365. loading: loading.models.equipmentProcurementList,
  366. };
  367. })(Index);
  368. export default connectUserModel('user', '@@initialState')(HOCIndex);