<script>
import { Message, Modal } from 'ant-design-vue'
import WorkbenchService from '@/workbench/workbench-service'
import toDoListService from '@/todo/todo-list-service'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import TableColumnTypes from '@/common/services/table-column-types'
import components from './_import-components/sd-flow-form-mixins-import'
// 流程管理
const progressFlowColums = [
  {
    title: '流程名称',
    dataIndex: 'flowName',
    sorter: true,
  },
  {
    title: '标题',
    dataIndex: 'title',
    sdClickable: true,
  },
  {
    title: '发起人',
    dataIndex: 'creatorName',
  },
  {
    title: '发起部门',
    dataIndex: 'creatorDeptName',
  },
  {
    title: '创建时间',
    dataIndex: 'startDate',
    sdRender: TableColumnTypes.dateTime,
    sorter: true,
  },
  {
    title: '当前状态',
    dataIndex: 'activeStepNames',
  },
  {
    title: '当前处理人',
    dataIndex: 'activeOperatorUsers',
  },
  {
    title: '接收时间',
    dataIndex: 'receiveDate',
    sdRender: TableColumnTypes.dateTime,
  },
]
export default {
  name: 'SdFlowFormMixins',
  metaInfo: {
    title: 'SdFlowFormMixins',
  },
  components,
  data() {
    return {
      progressFlowColums,
    }
  },
  methods: {
    // 删除此流程
    remove(keys) {
      Modal.confirm({
        title: '您确定删除这项内容吗？',
        content: '删除数据后，就无法恢复初始的状态。',
        okText: '删除',
        okType: 'danger',
        onOk: () => {
          const params = {
            flowCallbackBeanName: 'formBeanCleanerCallBack',
            processInstanceIds: keys.join(','),
          }
          WorkbenchService.removeFlowById(params)
            .then((res) => {
              if (res) {
                this.$refs.datatable.refresh(true)
                this.$refs.datatable.clearSelection()
              }
            })
            .catch((e) => {
              Message.error({ content: '调取删除服务失败' })
            })
        },
      })
    },
    // 查看详情
    rowClick(record) {
      const url = '/sd-webflow/' + toDoListService.makePath(record, 'processing')
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) this.$refs.datatable.refresh(true)
      })
    },
  },
}
</script>
