<template>
  <div class="NCC-preview-main">
    <div class="NCC-common-page-header">
      <el-page-header @back="goBack" content="接口预览" />
      <div class="options">
        <el-button @click="goBack">{{$t('common.cancelButton')}}</el-button>
      </div>
    </div>
    <el-form ref="dataForm" class="main" label-position="top" v-loading="formLoading">
      <el-form-item label="Request URL">
        <el-input v-model="url">
          <template slot="prepend">GET</template>
        </el-input>
      </el-form-item>
      <el-form-item label="Response body" class="value-item">
        <el-input v-model="responseData" type="textarea" :rows="30" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { previewDataInterface } from '@/api/systemData/dataInterface'
import NCCCodeEditor from '@/components/NCCEditor/monaco'

export default {
  components: {
    NCCCodeEditor
  },
  data() {
    return {
      title: '',
      formLoading: false,
      responseData: '',
      url: '',
      options: {
        readOnly: true,
        language: 'json'
      }
    }
  },
  methods: {
    goBack() {
      this.$emit('close')
    },
    init(id) {
      this.id = id || ''
      this.formLoading = true
      this.responseData = ''
      this.$nextTick(() => {
        this.url = `${this.define.comUrl}/api/system/DataInterface/${id}/Actions/Response`
        previewDataInterface(this.id).then(res => {
          this.responseData = JSON.stringify(res, null, 4)
          this.formLoading = false
        }).catch(() => {
          this.formLoading = false
        })
      })

    },
  }
}
</script>
<style lang="scss" scoped>
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  .value-item {
    flex: 1;
    margin-bottom: 0;
    >>> .el-form-item__content {
      height: calc(100% - 32px);
      .el-textarea {
        height: 100%;
        .el-textarea__inner {
          height: 100%;
        }
      }
    }
  }
}
</style>