|
1 | 1 | import React from "react"; |
2 | 2 | import {Button, Divider, Form, message, Modal, Row, Space, Tabs} from "antd"; |
3 | | -import {detail, postponed, recall, saveFlow, submitFlow, transfer} from "@/api/flow"; |
| 3 | +import {custom, detail, postponed, recall, saveFlow, submitFlow, transfer, trySubmitFlow} from "@/api/flow"; |
4 | 4 | import { |
5 | 5 | ModalForm, |
6 | 6 | ProDescriptions, |
@@ -40,6 +40,67 @@ const FlowView: React.FC<FlowViewProps> = (props) => { |
40 | 40 |
|
41 | 41 | const [transferForm] = Form.useForm(); |
42 | 42 |
|
| 43 | + const handlerTool = (key:string,buttonId:string) =>{ |
| 44 | + switch (key) { |
| 45 | + case 'SAVE': |
| 46 | + handlerSaveFlow(); |
| 47 | + break; |
| 48 | + case 'SUBMIT': |
| 49 | + handleSubmitFlow(true); |
| 50 | + break; |
| 51 | + case 'TRY_SUBMIT': |
| 52 | + handleTrySubmitFlow(); |
| 53 | + break; |
| 54 | + case 'REJECT': |
| 55 | + handleSubmitFlow(false); |
| 56 | + break; |
| 57 | + case 'TRANSFER': |
| 58 | + setTransferVisible(true); |
| 59 | + break; |
| 60 | + case 'POSTPONED': |
| 61 | + setPostponedVisible(true); |
| 62 | + break; |
| 63 | + case 'RECALL': |
| 64 | + handleRecallFlow(); |
| 65 | + break; |
| 66 | + case 'SPECIFY_SUBMIT': |
| 67 | + handleSubmitFlow(true); |
| 68 | + break; |
| 69 | + case 'CUSTOM': |
| 70 | + handleCustomFlow(buttonId); |
| 71 | + break; |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + const ToolButtons = () => { |
| 76 | + if(!data){ |
| 77 | + return null; |
| 78 | + } |
| 79 | + return ( |
| 80 | + <Space> |
| 81 | + {data.flowNode.buttons && data.flowNode.buttons.map((item:any)=>{ |
| 82 | + const style = item.style && { |
| 83 | + ...JSON.parse(item.style), |
| 84 | + color:"white", |
| 85 | + } || {}; |
| 86 | + return ( |
| 87 | + <Button |
| 88 | + key={item.id} |
| 89 | + onClick={()=>{ |
| 90 | + handlerTool(item.type,item.id); |
| 91 | + }} |
| 92 | + style={{ |
| 93 | + ...style |
| 94 | + }} |
| 95 | + > |
| 96 | + {item.name} |
| 97 | + </Button> |
| 98 | + ) |
| 99 | + })} |
| 100 | + </Space> |
| 101 | + ) |
| 102 | + } |
| 103 | + |
43 | 104 | const handlerSaveFlow = () => { |
44 | 105 | const advice = opinionForm.getFieldValue('advice'); |
45 | 106 | const recordId = props.id; |
@@ -113,6 +174,54 @@ const FlowView: React.FC<FlowViewProps> = (props) => { |
113 | 174 | }); |
114 | 175 | } |
115 | 176 |
|
| 177 | + const handleCustomFlow = (buttonId:string) => { |
| 178 | + const recordId = props.id; |
| 179 | + const advice = opinionForm.getFieldValue('advice'); |
| 180 | + const binData = viewForm.getFieldsValue(); |
| 181 | + const clazzName = data.flowRecord.bindClass; |
| 182 | + const body = { |
| 183 | + recordId, |
| 184 | + buttonId, |
| 185 | + advice: advice, |
| 186 | + formData: { |
| 187 | + ...binData, |
| 188 | + clazzName |
| 189 | + } |
| 190 | + } |
| 191 | + custom(body).then(res => { |
| 192 | + if (res.success) { |
| 193 | + message.success(res.data).then(); |
| 194 | + } |
| 195 | + }) |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + const handleTrySubmitFlow = () => { |
| 200 | + const advice = opinionForm.getFieldValue('advice'); |
| 201 | + const recordId = props.id; |
| 202 | + const binData = viewForm.getFieldsValue(); |
| 203 | + const clazzName = data.flowRecord.bindClass; |
| 204 | + const body = { |
| 205 | + recordId, |
| 206 | + advice: advice, |
| 207 | + success: true, |
| 208 | + formData: { |
| 209 | + ...binData, |
| 210 | + clazzName |
| 211 | + } |
| 212 | + } |
| 213 | + trySubmitFlow(body).then(res => { |
| 214 | + if (res.success) { |
| 215 | + const operators = res.data.operators; |
| 216 | + const usernames = operators.map((item:any)=>{ |
| 217 | + return item.name; |
| 218 | + }); |
| 219 | + const messageText = `下级节点:${res.data.flowNode.name},下一流程审批人:${usernames.join(',')}`; |
| 220 | + message.success(messageText).then(); |
| 221 | + } |
| 222 | + }) |
| 223 | + } |
| 224 | + |
116 | 225 | const handleSubmitFlow = (success: boolean) => { |
117 | 226 | const advice = opinionForm.getFieldValue('advice'); |
118 | 227 | const recordId = props.id; |
@@ -208,62 +317,9 @@ const FlowView: React.FC<FlowViewProps> = (props) => { |
208 | 317 | > |
209 | 318 | <Row justify="end"> |
210 | 319 | <Space> |
211 | | - {!props.review && ( |
212 | | - <Button |
213 | | - onClick={() => { |
214 | | - handlerSaveFlow(); |
215 | | - }} |
216 | | - >保存</Button> |
217 | | - )} |
218 | | - |
219 | | - |
220 | | - {!props.review && ( |
221 | | - <Button |
222 | | - type={"primary"} |
223 | | - onClick={() => { |
224 | | - handleSubmitFlow(true); |
225 | | - }} |
226 | | - >同意</Button> |
227 | | - )} |
228 | | - |
229 | | - |
230 | | - {!props.review && ( |
231 | | - <Button |
232 | | - type={"primary"} |
233 | | - onClick={() => { |
234 | | - handleSubmitFlow(false); |
235 | | - }} |
236 | | - danger={true} |
237 | | - >拒绝</Button> |
238 | | - )} |
239 | 320 |
|
240 | 321 | {!props.review && ( |
241 | | - <Button |
242 | | - type={"primary"} |
243 | | - onClick={()=>{ |
244 | | - setTransferVisible(true); |
245 | | - }} |
246 | | - >转办</Button> |
247 | | - )} |
248 | | - |
249 | | - {!props.review && ( |
250 | | - <Button |
251 | | - type={"primary"} |
252 | | - onClick={() => { |
253 | | - setPostponedVisible(true); |
254 | | - }} |
255 | | - danger={true} |
256 | | - >延期</Button> |
257 | | - )} |
258 | | - |
259 | | - {!props.review && ( |
260 | | - <Button |
261 | | - type={"primary"} |
262 | | - onClick={() => { |
263 | | - handleRecallFlow(); |
264 | | - }} |
265 | | - danger={true} |
266 | | - >撤销</Button> |
| 322 | + <ToolButtons/> |
267 | 323 | )} |
268 | 324 |
|
269 | 325 | <Button |
|
0 commit comments