<script>
import download from '@/common/services/download'
import axios from '@/common/services/axios-instance'
import { Modal } from 'ant-design-vue'
import components from './_import-components/xm-law-team-export-handler-import'

export default {
  name: 'XmLawTeamExportHandler',
  components,
  data() {
    return {}
  },
  methods: {
    run({ button, eventScript, context: { args, dataList } }) {
      // 导出
      const fe = dataList.filterExpressions
      const exs = fe.find((i) => {
        return i.name === 'OWNER_ORG_ID'
      })
      const params = {
        configId: '251',
        selectIds: [],
        expressions: exs || [],
      }
      return axios({
        method: 'post',
        url: 'api/xcoa-mobile/v1/iam-excel-export/excelExport',
        data: params,
        responseType: 'blob',
      }).then((res) => {
        if (res.status === 200) {
          const url = URL.createObjectURL(res.data)
          const filename = res.headers['content-disposition']
          const fname = filename.substring(filename.indexOf('filename=') + 9, filename.length)
          download(url, decodeURI(fname))
        } else {
          Modal.warning({
            title: '提示',
            content: '导出报错，请联系管理员!',
          })
          return false
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
