<template>
  <div>
    <div class="i-layout-page-header">
      <PageHeader :title="$route.meta.title" :content="$route.meta.description" hidden-breadcrumb />
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <view-form ref="form" view-code="SystemData"></view-form>
      <div style="text-align: center">
        <Button type="info" custom-icon="fa fa-cloud-download-alt" @click="exportFile()">{{ $t('Front_Btn_Export') }}</Button>
        <file-upload url="api/System/importFile" accept=".syd" @on-success="importFileSuccess" style="display: inline-block; margin-left: 8px; margin-right: 8px">
          <template #>
            <Button type="primary" custom-icon="fa fa-cloud-upload-alt">{{ $t('Front_Btn_Import') }}</Button>
          </template>
        </file-upload>
      </div>
    </Card>
  </div>
</template>
<script>
  import mixinPage from '../../mixins/page';
  import systemApi from '../../api/system';

  export default {
    name: 'system-systemData',
    mixins: [mixinPage],
    components: {},
    data() {
      return {};
    },
    computed: {},
    created() {},
    methods: {
      // 导出文件
      exportFile() {
        let types = this.$refs.form.data.types;
        if (types && types.length > 0) {
          systemApi.exportFile(JSON.parse(types));
        } else {
          this.error('Front_Msg_Please_Select_Export_Item');
        }
      },
      // 导入成功
      importFileSuccess(res) {
        if (res.code == 0) {
          this.success('Front_Msg_Success');
        } else {
          this.error(res.message);
        }
      }
    }
  };
</script>
