import { message } from 'ant-design-vue'
import XmSingleDataService from './xm-single-data-service'

export default function({ button, eventScript, context: { args, dataList, fieldInfos } }) {
  return new Promise((resolve) => {
    const wid = fieldInfos?.find((item) => item.name === 'id').value
    const projectId = fieldInfos?.find((item) => item.name === 'PROJECT_ID').value
    if (wid) {
      // 调用接口
      const param = []
      param.push(wid)
      XmSingleDataService.againFlow(param, projectId)
        .then((res) => {
          if (res.status === 200) {
            message.success('重新起草成功')
            resolve()
            // 刷新
            setTimeout(() => {
              dataList.refresh()
            }, 1000)
          }
        })
        .catch((e) => {
          message.error('重新起草失败，请联系管理员')
          resolve()
        })
    }
  })
}
