import { message, Modal } from '@/common/one-ui'
import FlowService from '../flow-service'

export default function({ button }) {
  const duration = 1
  const key = 'key'
  return new Promise((resolve) => {
    Modal.confirm({
      title: '您确定终止此条数据？',
      content: '终止这条数据后，数据状态就会修改为终止。',
      okText: '终止',
      okType: 'danger',
      onOk: () => {
        const terminateParams = {
          flowCallbackBeanName: 'formBeanCleanerCallBack',
          processInstanceIds: this.FlowData.instId,
        }
        FlowService.terminateFlowById(terminateParams).then(
          () => {
            message.success({ content: '终止流程成功', key, duration })
            this.updateFlow()
            resolve()
          },
          (res) => {
            if (res.response.data?.code === '10205001') {
              message.info({
                content: '该流程目前处于暂停状态，无法执行终止，请先恢复，再操作',
                key,
                duration,
              })
            } else {
              message.error({ content: '终止流程失败', key, duration })
            }
            resolve()
          }
        )
      },
      onCancel: () => resolve(),
    })
  })
}
