<template>
  <div class="app-container">
    <el-dialog
      class="tenantAppModal "
      :title="$t('ec.table.exportBase')"
      :close-on-click-modal="false"
      :visible.sync="visible"
      top="4%"
    >
      <el-form>
        <el-form-item>
          <ec-register-app v-model="appIds" multiple />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('ec.table.cancel') }}</el-button>
        <el-button type="primary" :loading="loading" @click="confirm">{{ $t('ec.table.confirm') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { download } from 'ecip-web/utils'

export default {
  name: 'AppExportModalVue',
  data() {
    return {
      visible: false,
      loading: false,
      baseExportUrl: `api/v1/app/sysrRegisterApp/exportBaseData`,
      appIds: ''
    }
  },
  methods: {
    init() {
      Object.assign(this.$data, this.$options.data())
      this.visible = true
      this.loading = false
    },
    async confirm() {
      this.loading = true
      const appIdList = this.appIds.split(',')
      if (!appIdList || appIdList.length === 0) {
        this.$notify.error(this.$t('ec.app.exportError'))
        return
      }
      await download({ url: this.baseExportUrl, method: 'post', data: appIdList.map(appId => parseInt(appId)) })
      this.loading = false
    }
  }
}
</script>

<style scoped>

</style>
