name: instance_terminate
amis_schema: |-
  {
      "type": "service",
      "body": [
          {
              "type": "button",
              "label": "取消申请",
              "id": "u:instance_terminate",
              "className": "  ",
              "onEvent": {
                  "click": {
                      "actions": [
                          {
                              "actionType": "dialog",
                              "dialog": {
                                  "type": "dialog",
                                  "title": "取消申请",
                                  "body": [
                                      {
                                          "type": "tpl",
                                          "tpl": "<p>&nbsp;请填写取消申请的理由</p>",
                                          "inline": false,
                                          "id": "u:0a1847d1d018",
                                          "className": "m-b-sm"
                                      },
                                      {
                                          "type": "form",
                                          "title": "表单",
                                          "body": [
                                              {
                                                  "label": false,
                                                  "type": "textarea",
                                                  "name": "terminate_reason",
                                                  "id": "u:0f956b433712",
                                                  "minRows": 3,
                                                  "maxRows": 20,
                                                  "required": true
                                              }
                                          ],
                                          "id": "u:7a36d573eb51",
                                          "api": {
                                                "url": "${context.rootUrl}/api/workflow/v2/instance/terminate",
                                                "method": "post",
                                                "data": {
                                                    "&": "$$",
                                                    "record": "${record}"
                                                },
                                                "requestAdaptor": "\nconsole.log(\"api.data\", api.data)\nconst { record, terminate_reason } = api.data;\napi.data = {\n  terminate_reason: terminate_reason,\n  instance_id: record._id\n}\nreturn api;",
                                                "headers": {
                                                    "Authorization": "Bearer ${context.tenantId},${context.authToken}"
                                                },
                                                "messages": {
                                                    "success": "取消申请成功!",
                                                    "failed": "取消申请失败"
                                                }
                                            },
                                            "onEvent": {
                                                "submitSucc": {
                                                    "actions": [
                                                        {
                                                          "componentId": "",
                                                          "args": {},
                                                          "actionType": "closeDialog"
                                                        },
                                                        {
                                                            "componentId": "",
                                                            "args": {
                                                                "blank": false,
                                                                "url": "/app/${appId}/instance_tasks/grid/${side_listview_id}"
                                                            },
                                                            "actionType": "url"
                                                        }
                                                    ]
                                                }
                                            }
                                      }
                                  ],
                                  "id": "u:9af240735397",
                                  "actions": [
                                      {
                                          "type": "button",
                                          "label": "取消",
                                          "onEvent": {
                                              "click": {
                                                  "actions": [
                                                      {
                                                          "componentId": "",
                                                          "args": {},
                                                          "actionType": "closeDialog"
                                                      }
                                                  ]
                                              }
                                          },
                                          "id": "u:d953ce5ace05"
                                      },
                                      {
                                          "type": "button",
                                          "label": "确定",
                                          "onEvent": {
                                              "click": {
                                                  "actions": [
                                                      {
                                                          "args": {},
                                                          "actionType": "validate",
                                                          "componentId": "u:7a36d573eb51"
                                                      },
                                                      {
                                                        "componentId": "u:7a36d573eb51",
                                                        "args": {
                                                        },
                                                        "actionType": "submit"
                                                       }
                                                  ]
                                              }
                                          },
                                          "id": "u:9cbc7515d223",
                                          "level": "primary"
                                      }
                                  ]
                              }
                          }
                      ],
                      "weight": 0
                  }
              },
              "hiddenOn": "!((record.box == \"pending\" || record.box == \"inbox\") && record.state == \"pending\" && record.applicant == context.user.userId)"
          }
      ],
      "regions": [
          "body"
      ],
      "data": {
      },
      "bodyClassName": "p-0",
      "id": "u:441b481ccdeb"
  }
is_enable: true
label: 取消申请
'on': record_only
type: amis_button
visible: true
