<template>
  <a-card>
    <sd-data-table-ex
      ref="table"
      form-id="weRemoteCallFail"
      page-id="extracirc/fail/weRemoteCallFail"
      :columns="columns"
      :actions="actions"
      :modal-props="{ class: $style.table }"
      :search-fields="['sysName', 'sysCode']"
    >
      <template v-slot:form>
        <sd-form-item name="title" />
        <sd-form-item name="sysCode" />
        <sd-form-item name="sysName" />
        <sd-form-item name="instId" />
        <sd-form-item name="beanId" />
        <sd-form-item name="formId" />
        <sd-form-item name="sendTime" />
        <sd-form-item name="creatorCode" />
        <sd-form-item name="creatorName" />
        <sd-form-item name="errMsg" />
        <sd-form-item name="belongedOrgId" />
      </template>
    </sd-data-table-ex>
  </a-card>
</template>

<script>
import axios from '@/common/services/axios-instance'
import { message } from 'ant-design-vue'
import TableActionTypes from '@/common/services/table-action-types'
import components from './_import-components/sd-log-fail-record-import'

export default {
  name: 'SdLogFailRecord',
  metaInfo: {
    title: '审批中心失败记录',
  },
  components,
  data() {
    return {
      columns: [
        {
          title: '标题',
          sdClickable: true,
          dataIndex: 'title',
        },
        {
          title: '系统code',
          dataIndex: 'sysCode',
        },
        {
          title: '系统名称',
          dataIndex: 'sysName',
        },
        {
          title: '流程实例ID',
          dataIndex: 'instId',
        },
      ],
      actions: [
        {
          label: '推送',
          id: 'push',
          permission: null,
          type: TableActionTypes.inline,
          callback: (record) => {
            axios
              .post(
                `api/framework/v1/extra-process-drive/process-instance/send?instId=${record.instId}`
              )
              .then((res) => {
                if (res.data.success) {
                  message.success('已推送')
                  this.$refs.table.refresh()
                } else {
                  message.error(res.data.errMsg || '推送失败')
                }
              })
              .catch((e) => {
                message.error(e.response?.data?.message || '推送失败')
              })
          },
        },
      ],
    }
  },
  methods: {},
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.table {
  :global .ant-modal-footer {
    display: none;
  }
}
</style>
