NewList.js 4.7 KB

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