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

export default function({ button }) {
  const name = button.buttonName
  const duration = 1
  const key = 'key'
  return new Promise((resolve) => {
    Modal.confirm({
      title: `您确定${name}此条数据？`,
      content: `${name}这条数据后，数据状态就会修改为${name}。`,
      okText: `${name}`,
      okType: 'danger',
      onOk: () => {
        const suppendParams = {
          flowCallbackBeanName: 'formBeanCleanerCallBack',
          processInstanceIds: this.FlowData.instId,
        }
        FlowService.suspendFlowById(suppendParams).then(
          (res) => {
            message.success({ content: `${name}流程成功`, key, duration })
            this.updateFlow()
            resolve()
          },
          () => {
            message.error({ content: `${name}流程失败`, key, duration })
            resolve()
          }
        )
      },
      onCancel: () => resolve(),
    })
  })
}
