name: instance_forward
amis_schema: |-
  {
      "type": "service",
      "body": [
          {
              "type": "button",
              "label": "转发",
              "id": "u:instance_forward",
              "onEvent": {
                  "click": {
                      "actions": [
                          {
                              "actionType": "dialog",
                              "dialog": {
                                  "type": "dialog",
                                  "title": {
                                      "type": "tpl",
                                      "id": "u:4733f85da58b",
                                      "tpl": "<p>转发&nbsp;<a href=\"https://www.steedos.cn/docs/user/workflow#%E5%A6%82%E4%BD%95%E8%BD%AC%E5%8F%91\" target=\"_blank\" rel=\"noopener\">?</a></p>"
                                  },
                                  "body": [
                                      {
                                          "type": "tpl",
                                          "tpl": "<div class=\"box-title\">将当前选中的文件转发到新的流程，继续执行审批操作</div>",
                                          "inline": false,
                                          "id": "u:cf94d83ee7a8",
                                          "className": "m-b-sm"
                                      },
                                      {
                                          "type": "form",
                                          "id": "u:64543b9b5f6d",
                                          "title": "表单",
                                          "body": [
                                              {
                                                  "label": "流程名称",
                                                  "type": "steedos-select-flow",
                                                  "mode": "tree-select",
                                                  "name": "flow_id",
                                                  "id": "instanceForwardFlow",
                                                  "options": [],
                                                  "multiple": false,
                                                  "required": true,
                                                  "searchable": true,
                                                  "autoFill": {},
                                                  "onlyLeaf": true
                                              },
                                              {
                                                  "type": "textarea",
                                                  "label": "备注",
                                                  "name": "description",
                                                  "id": "u:bb3fcb0c4e8c",
                                                  "minRows": 3,
                                                  "maxRows": 20
                                              },
                                              {
                                                  "type": "checkbox",
                                                  "name": "hasSaveInstanceToAttachment",
                                                  "id": "u:da17af0371f8",
                                                  "option": "将原表单存储为附件"
                                              }
                                          ],
                                          "mode": "normal",
                                          "api": {
                                                "url": "${context.rootUrl}/api/workflow/v2/instance/forward",
                                                "method": "post",
                                                "data": {
                                                    "&": "$$",
                                                    "record": "${record}",
                                                    "context": "${context}"
                                                },
                                                "requestAdaptor": "console.log('====', api);const { record, flow_id, description, hasSaveInstanceToAttachment, context: contextData } = api.data; var from_approve_id = null; if(record.approve && record.approve._id){from_approve_id = record.approve._id}else if(window.InstanceManager && window.InstanceManager.getCurrentApprove()?._id){from_approve_id = window.InstanceManager.getCurrentApprove()._id} \napi.data = {\n  \"instance_id\": record._id,\n  \"space_id\": record.space,\n  \"flow_id\": flow_id,\n  \"hasSaveInstanceToAttachment\": hasSaveInstanceToAttachment || false,\n  \"description\": description,\n  \"isForwardAttachments\": true,\n  \"selectedUsers\": [contextData.userId],\n  \"action_type\": \"forward\",\n  \"related\": false,\n  \"from_approve_id\": from_approve_id\n};\nreturn api;",
                                                "headers": {
                                                    "Authorization": "Bearer ${context.tenantId},${context.authToken}"
                                                },
                                                "messages": {
                                                    "success": "转发成功!",
                                                    "failed": "转发失败"
                                                }
                                            },
                                          "onEvent": {
                                                "submitSucc": {
                                                    "actions": [
                                                        {
                                                          "componentId": "",
                                                          "args": {},
                                                          "actionType": "closeDialog"
                                                        },
                                                        {
                                                          "actionType": "custom",
                                                          "script": "/* 自定义JS使用说明： \n * 1.动作执行函数doAction，可以执行所有类型的动作\n * 2.通过上下文对象context可以获取当前组件实例，例如context.props可以获取该组件相关属性\n * 3.事件对象event，在doAction之后执行event.stopPropagation = true;可以阻止后续动作执行\n*/\nconsole.log('doAction context', context)\nconsole.log('doAction event', event)\n_.each(event.data.result.data, (item) => {\n  let url = `/app/${event.data.app_id}/instance_tasks/view/${item.instanceTasksId}?side_object=instance_tasks&side_listview_id=inbox`;\n   if(window.Meteor && false){url=`/workflow/space/${context.props.scope.context.tenantId}/inbox/${item.instanceId}`}\n   doAction({\n actionType: 'url',\n    args: {\n      url: url,\n      blank: true\n    }\n  });\n});\n\n"
                                                        }
                                                    ]
                                                }
                                            }
                                      }
                                  ],
                                  "id": "u:dde7a246d6ee",
                                  "actions": [
                                      {
                                          "type": "button",
                                          "label": "取消",
                                          "onEvent": {
                                              "click": {
                                                  "actions": [
                                                      {
                                                          "componentId": "",
                                                          "args": {},
                                                          "actionType": "closeDialog"
                                                      }
                                                  ]
                                              }
                                          },
                                          "id": "u:2202552cf5bb"
                                      },
                                      {
                                          "type": "button",
                                          "label": "确定",
                                          "onEvent": {
                                              "click": {
                                                  "actions": [
                                                      {
                                                          "componentId": "u:64543b9b5f6d",
                                                          "args": {},
                                                          "actionType": "validate"
                                                      },
                                                      {
                                                        "componentId": "u:64543b9b5f6d",
                                                        "args": {
                                                        },
                                                        "actionType": "submit"
                                                       }
                                                  ]
                                              }
                                          },
                                          "id": "u:0ff222ae9546",
                                          "level": "primary"
                                      }
                                  ]
                              }
                          }
                      ],
                      "weight": 0
                  }
              },
              "hiddenOn": "!( record.state != \"draft\" )"
          }
      ],
      "regions": [
          "body"
      ],
      "data": {
      },
      "bodyClassName": "p-0",
      "id": "u:61148479a181"
  }
is_enable: true
label: 转发
'on': record_only
type: amis_button
visible: true
