<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-table ref="table" view-code="ApiOutLog">
        <template #command="{ row }">
          <Button size="small" :title="$t('Front_Btn_Request')" type="info" custom-icon="fa fa-cloud-upload-alt" @click="openRequest(row)"></Button>
          <Button size="small" :title="$t('Front_Btn_Response')" type="info" custom-icon="fa fa-cloud-download-alt" @click="openResponse(row)"></Button>
        </template>
      </view-table>
    </Card>
    <Modal v-model="isShow" scrollable :mask-closable="layout.maskClosable" :draggable="layout.draggable" :sticky="true" :reset-drag-position="true" :width="800">
      <template #header>
        <div>
          <slot name="header">
            <span class="title">{{ title }}</span>
            <span class="description">{{ description }}</span>
          </slot>
        </div>
      </template>
      <div class="ivu-ml-8 ivu-mr-8">
        <Row :gutter="24" type="flex">
          <Col span="12">
            <pre>{{ json }}</pre>
          </Col>
        </Row>
      </div>
      <template #footer>
        <div>
          <Button type="default" custom-icon="fa fa-times" @click="isShow = false">{{ $t('Front_Btn_Close') }}</Button>
        </div>
      </template>
    </Modal>
  </div>
</template>
<script>
  import mixinPage from '../../mixins/page';

  export default {
    name: 'system-apiOutLog',
    mixins: [mixinPage],
    components: {},
    data() {
      return {
        isShow: false,
        json: null,
        title: null,
        description: null
      };
    },
    computed: {},
    created() {},
    methods: {
      openRequest(row) {
        try {
          this.json = JSON.stringify(JSON.parse(row.requestBody), null, 2);
        } catch {
          this.json = row.requestBody;
        }

        this.title = this.$t('Front_Label_Request');
        this.description = this.$t('Front_Label_Request_Desc');
        this.isShow = true;
      },
      openResponse(row) {
        try {
          this.json = JSON.stringify(JSON.parse(row.responseBody), null, 2);
        } catch {
          this.json = row.responseBody;
        }

        this.title = this.$t('Front_Label_Response');
        this.description = this.$t('Front_Label_Response_Desc');
        this.isShow = true;
      }
    }
  };
</script>
