<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="ApiLog">
        <template slot-scope="{ row }" slot="command">
          <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"
      :styles="{ top: '4vh' }"
    >
      <div slot="header">
        <slot name="header">
          <span class="title">{{ title }}</span>
          <span class="description">{{ description }}</span>
        </slot>
      </div>
      <div class="ivu-ml-8 ivu-mr-8">
        <Row :gutter="24" type="flex">
          <Col span="12">
            <pre>{{ json }}</pre>
          </Col>
        </Row>
      </div>
      <div slot="footer">
        <Button type="default" custom-icon="fa fa-times" @click="isShow = false">{{ $t('Front_Btn_Close') }}</Button>
      </div>
    </Modal>
  </div>
</template>
<script>
  import mixinPage from '../../mixins/page';

  export default {
    name: 'system-apiLog',
    mixins: [mixinPage],
    components: {},
    data() {
      return {
        isShow: false,
        json: null,
        title: null,
        description: null
      };
    },
    computed: {},
    created() {},
    methods: {
      openRequest(row) {
        this.json = JSON.stringify(JSON.parse(row.requestBody), null, 2);
        this.title = this.$t('Front_Label_Request');
        this.description = this.$t('Front_Label_Request_Desc');
        this.isShow = true;
      },
      openResponse(row) {
        this.json = JSON.stringify(JSON.parse(row.responseBody), null, 2);
        this.title = this.$t('Front_Label_Response');
        this.description = this.$t('Front_Label_Response_Desc');
        this.isShow = true;
      }
    }
  };
</script>
