name: instance_relocate
is_enable: true
label: 重定位
'on': record_only
type: amis_button
visible: true
amis_schema: |-
  {
    "type": "service",
    "bodyClassName": "p-0",
    "regions": [
      "body"
    ],
    "body": [
      {
        "type": "button",
        "label": "重定位",
        "hiddenOn": "!(this.record.box === 'monitor' && this.record.state != 'draft' && this.flowPermissions.includes('admin'))",
        "onEvent": {
          "click": {
            "weight": 0,
            "actions": [
              {
                "dialog": {
                  "type": "dialog",
                  "title": "重定位",
                  "body": [
                    {
                      "type": "service",
                      "id": "u:fe0773fa3aa7",
                      "body": [
                        {
                          "type": "form",
                          "title": "表单",
                          "mode": "normal",
                          "body": [
                            {
                              "type": "tpl",
                              "tpl": "当前步骤: <p class='font-medium inline'>${record.currentStep.name}</p>",
                              "inline": true,
                              "wrapperComponent": "",
                              "id": "u:1f7dd93080d3"
                            },
                            {
                              "type": "select",
                              "label": "下一步",
                              "name": "relocate_step",
                              "id": "u:ee15214c1808",
                              "multiple": false,
                              "required": true,
                              "source": "${stepsOption}"
                            },
                            {
                              "type": "steedos-select-user",
                              "label": "处理人",
                              "name": "relocate_users",
                              "id": "u:c3ad733db360",
                              "multiple": true,
                              "mode": "normal",
                              "required": true,
                              "visibleOn": "this.relocate_step && !this.relocate_step.startsWith('start.') && !this.relocate_step.startsWith('end.')"
                            },
                            {
                              "type": "textarea",
                              "label": false,
                              "name": "reason",
                              "id": "u:bffe87a42168",
                              "minRows": 3,
                              "maxRows": 20,
                              "placeholder": "请填写重定位的理由"
                            }
                          ],
                          "id": "u:1779a48caedb",
                          "wrapWithPanel": false,
                          "debug": false,
                          "api": {
                            "url": "${context.rootUrl}/api/workflow/relocate",
                            "method": "post",
                            "messages": {
                              "success": "重定位成功",
                              "failed": "重定位失败"
                            },
                            "dataType": "json",
                            "requestAdaptor": "const { record, relocate_users, relocate_step, reason } = api.data;\napi.data = {\n  \"Instances\": [{\n    _id: record._id, relocate_next_step: relocate_step.split('.')[1], relocate_inbox_users: relocate_users, relocate_comment: reason\n  }]\n}\n\nreturn api;"
                          },
                          "onEvent": {
                            "submitFail": {
                              "weight": 0,
                              "actions": []
                            },
                            "submitSucc": {
                              "weight": 0,
                              "actions": [
                                {
                                  "args": {
                                    "eventName": "@data.@instanceDetail.changed"
                                  },
                                  "actionType": "broadcast",
                                  "data": {}
                                }
                              ]
                            }
                          }
                        }
                      ],
                      "messages": {},
                      "dataProvider": "const stepsOption = [];\n\n_.each(data.record.flowVersion.steps, (step) => {\n  stepsOption.push({\n    label: step.name,\n    value: `${step.step_type}.${step._id}`\n  })\n})\nsetData({ stepsOption })\n\n"
                    }
                  ],
                  "showCloseButton": true,
                  "showErrorMsg": true,
                  "showLoading": true,
                  "id": "u:13f325044bbc",
                  "closeOnEsc": false,
                  "dataMapSwitch": false
                },
                "actionType": "dialog"
              }
            ]
          }
        }
      }
    ],
    "id": "u:7080a6a5484e"
  }