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

export default function({ button }) {
  const name = button.buttonName
  return new Promise((resolve) => {
    Modal.confirm({
      title: `您确定${name}此条数据？`,
      content: `${name}这条数据后，就无法恢复初始的状态。`,
      okText: `${name}`,
      okType: 'danger',
      onOk: () => {
        const deleteParams = {
          flowCallbackBeanName: 'formBeanCleanerCallBack',
          processInstanceIds: this.FlowData.instId,
        }
        FlowService.removeFlowById(deleteParams).then(
          (res) => {
            message.success({
              content: `${name}流程成功`,
              duration: 1,
              onClose: () => {
                resolve()
                this.close(true)
              },
            })
          },
          (e) => {
            resolve()
            if (e.response?.data?.code === '20001009') {
              message.error({ content: e.response.data.message })
              this.updateFlow()
              return
            }
            throw e
          }
        )
      },
      onCancel: () => resolve(),
    })
  })
}
