NewList.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import React, { useState, useEffect } from 'react';
  2. import { Table, Divider } from 'antd';
  3. import { connect } from 'dva';
  4. import router from 'umi/router';
  5. import FlowModal from '../Detail/FlowModal';
  6. import { queryBoomFlowDetail, queryRecordSheet } from '@/services/boom';
  7. import { async } from '@antv/x6/es/registry/marker/async';
  8. import { getToken } from '@/utils/utils';
  9. function List(props) {
  10. const { excel, loading, project, dispatch } = props;
  11. const [flowVisible, setFlowVisible] = useState(false);
  12. const [version, setVersion] = useState({});
  13. const [versionVisible, setVersionVisible] = useState(false);
  14. const [flowDetail, setFlowDetail] = useState();
  15. let token = getToken();
  16. const columns = [
  17. {
  18. title: '流程名称',
  19. width: '35%',
  20. render: item => item.version_name || item.name,
  21. },
  22. {
  23. title: '所属项目',
  24. width: '35%',
  25. render: item => {
  26. if (!item.is_parent) return '';
  27. return project.list.find(p => p.ID == item.project_id)?.Name;
  28. },
  29. },
  30. {
  31. title: '操作',
  32. render: record => {
  33. if (record.is_parent) return null;
  34. return (
  35. <a
  36. onClick={async () => {
  37. localStorage.excelId = record.id;
  38. const data = await queryBoomFlowDetail({ id: record.template_id });
  39. setFlowDetail(data);
  40. setVersion(record);
  41. setFlowVisible(true);
  42. // router.push(`/home/detail/${record.project_id}/${record.template_id}`);
  43. }}
  44. >
  45. 查看
  46. </a>
  47. );
  48. },
  49. },
  50. ];
  51. const queryList = page => {
  52. console.log(page);
  53. dispatch({
  54. type: 'newList/queryProjectRecord',
  55. payload: {
  56. ...page,
  57. currentPage: page.current,
  58. },
  59. });
  60. };
  61. useEffect(() => {
  62. dispatch({
  63. type: 'newList/queryProjectRecord',
  64. payload: {
  65. pageSize: 20,
  66. },
  67. });
  68. dispatch({
  69. type: 'newList/queryProject',
  70. });
  71. }, []);
  72. const changeVersion = item => {
  73. if (typeof item == 'object') {
  74. localStorage.excelId = item.id;
  75. }
  76. router.push(`/home/detail/${item.project_id}/${item.template_id}`);
  77. };
  78. const getLoading = () => {
  79. let effects = loadingVersion.effects;
  80. return !loadingVersion.effects['detail/queryComment'] && loadingVersion.models.detail;
  81. };
  82. const onCommit = async (values, id) => {
  83. let currentNode = flowDetail.nodes.find?.(item => item.Id == version.template_node_id);
  84. let sheets = await queryRecordSheet({ gridKey: version.id, 'JWT-TOKEN': token });
  85. if (!currentNode.muti_version) {
  86. // audit_status=4 表示为清单推进后留存的副本.不计入多清单计算
  87. let serviceVersion = versionList.find(
  88. item => item.audit_status != 4 && item.template_node_id == currentNode.Id
  89. );
  90. if (serviceVersion) {
  91. message.error(`新建清单失败!业务节点【${currentNode.label}】只能有一个清单!`);
  92. return;
  93. }
  94. }
  95. let params = {
  96. ...values,
  97. id: id,
  98. project_id: version.project_id,
  99. name: version.name,
  100. guid: version.guid,
  101. template_id: version.template_id,
  102. template_node_id: version.template_node_id,
  103. flow_id: version.flow_id,
  104. node_id: version.node_id,
  105. new_version: '0',
  106. audit_status: 0,
  107. data: sheets,
  108. base_id: version.id,
  109. };
  110. dispatch({
  111. type: 'newList/commitSheet',
  112. payload: params,
  113. callback: async newVersion => {
  114. // 更新flow流程图
  115. const data = await queryBoomFlowDetail({ id: newVersion.template_id });
  116. console.log(data);
  117. setFlowDetail(data);
  118. },
  119. });
  120. };
  121. return (
  122. <div>
  123. <Table
  124. loading={loading}
  125. rowKey="id"
  126. dataSource={excel.list}
  127. pagination={excel.pagination}
  128. columns={columns}
  129. onChange={queryList}
  130. />
  131. <FlowModal
  132. isOut={true}
  133. flowDetail={flowDetail}
  134. visible={flowVisible}
  135. onClose={() => setFlowVisible(false)}
  136. version={version}
  137. onCommit={onCommit}
  138. onChangeVersion={version => changeVersion(version)}
  139. />
  140. {/* <VersionModal
  141. loading={getLoading()}
  142. visible={versionVisible}
  143. onClose={() => setVersionVisible(false)}
  144. onOk={values => onCommit(values)}
  145. /> */}
  146. </div>
  147. );
  148. }
  149. export default connect(({ newList, loading }) => ({
  150. excel: newList.excel,
  151. project: newList.project,
  152. loading: loading.models.newList,
  153. loadingVersion: loading,
  154. }))(List);