name: instance_new
amis_schema: |-
  {
      "type": "service",
      "body": [
          {
              "type": "button",
              "label": "新建",
              "id": "u:instance_new",
              "className": "instance-new-btn",
              "onEvent": {
                  "click": {
                      "actions": [
                          {
                              "actionType": "dialog",
                              "dialog": {
                                  "type": "dialog",
                                  "title": "请选择流程",
                                  "body": [
                                      {
                                          "type": "steedos-select-flow",
                                          "id": "instanceNewFlowSelect",
                                          "showIcon": true,
                                          "showRadio": false,
                                          "onlyLeaf": true,
                                          "name": "flow",
                                          "action": "new",
                                          "onEvent": {
                                                "change": {
                                                    "weight": 0,
                                                    "actions": [
                                                        {
                                                            "args": {
                                                                "api": {
                                                                    "url": "${context.rootUrl}/api/workflow/v2/draft",
                                                                    "method": "post",
                                                                    "dataType": "json",
                                                                    "data": {
                                                                        "instance":{
                                                                            "applicant": "${context.userId}",
                                                                            "space": "${context.tenantId}",
                                                                            "flow": "$event.data.value"
                                                                        }
                                                                    },
                                                                    "headers": {
                                                                        "Authorization": "Bearer ${context.tenantId},${context.authToken}"
                                                                    }
                                                                },
                                                                "messages": {
                                                                    "success": "创建成功!"
                                                                }
                                                            },
                                                            "actionType": "ajax"
                                                        },
                                                        {
                                                            "actionType": "custom",
                                                            "script": "\nconst {instance, appId, objectName} = event.data;\nconsole.log(`instance===`);if(window.Meteor){\ndoAction({\n  actionType: 'link',\n  args: {\n    blank: false,\n    url: `/workflow/space/${instance.space}/draft/${instance._id}?side_object=instances&side_listview_id=draft`\n  }\n});\n return ;}\ndoAction({\n  actionType: 'link',\n  args: {\n    blank: false,\n    url: `/app/${appId}/instances/view/${instance._id}?side_object=instances&side_listview_id=draft`\n  }\n});\n"
                                                        },
                                                        {
                                                        "componentId": "",
                                                        "args": {
                                                        },
                                                        "actionType": "closeDrawer"
                                                        }
                                                    ]
                                                }
                                            }

                                      }
                                  ],
                                  "id": "u:0a98fff55554",
                                  "closeOnEsc": true,
                                  "closeOnOutside": false,
                                  "showCloseButton": true,
                                  "size": "lg",
                                  "actions": false
                              }
                          }
                      ],
                      "weight": 0
                  }
              }
          }
      ],
      "regions": [
          "body"
      ],
      "bodyClassName": "p-0",
      "id": "u:b9ad8e8df0b0"
  }
is_enable: true
label: 新建
'on': list
type: amis_button
visible: true
