<template>
  <div>
<!--    <Modal v-model="showDiagramModalSampleLook" title="检定（校准）证书" width="100%" class="footer-hidden iframeSampleLookThree">-->
<!--      <div id="iframeSampleLookThree" style="text-align:center;align-content:center;width: 100%;height: 790px">-->
<!--      </div>-->
<!--      <div slot="footer">-->
<!--      </div>-->
<!--    </Modal>-->
    <div v-show="showDiagramModalSampleLook">
      <RecordIframe ref="iframeModal"></RecordIframe>
    </div>
  </div>
</template>
<script>
/**
 * 详情
 */
import { meterSample } from '../../api'
import RecordIframe from '../meter-out/personal-task/RecordIframe'
export default {
  components: {
    RecordIframe
  },
  data() {
    return {
      showDiagramModalSampleLook: false,
      templateId: '',
      formId: '',
      again: true,
      sampleId: '',
      name: ''
    }
  },
  mounted() {
    // 监听原始记录消息
    window.addEventListener('message', this._saveOriginal)
  },
  methods: {
    async _saveOriginal(data) {
      console.log('data11111', data)
      console.log('formId', this.formId)
      console.log('sampleId: [],', this.sampleId)
      console.log('data.data.msg,', data.data.msg)
      if (this.again) {
        this.again = false
        if (
          undefined !== this.formId &&
          this.formId !== '' &&
          this.sampleId !== undefined
        ) {
          await meterSample.certificateEdit({
            sampleId: this.sampleId,
            formId: this.formId
          })
        }
        if (data.data.msg === true) {
          this._cancel()
        } else {
          this._cancel()
        }
      }
    },
    _cancel() {
      this.$refs.iframeModal._closeIframe()
      this.showDiagramModalSampleLook = false
      this.$emit('on-result-change')
    },
    _open(formId, name, sampleId) {
      console.log(sampleId)
      console.log(formId)
      console.log(name)
      this.again = true
      this.formId = formId
      this.showDiagramModalSampleLook = true
      this.sampleId = sampleId
      this.name = name
      let url = ''
      url =
        name !== 'only'
          ? 'http://record.patzn.com:7000/print/v1/eln/form_meter_' + formId
          : 'http://record.patzn.com:7000/print/v1/form/' + formId
      // $('#iframeSampleLookThree').html(
      //   '<iframe style="padding: 0px;width:100%;height:100%" frameborder="0" src=' +
      //     encodeURI(url) +
      //     '></iframe>'
      // )
      this.$refs.iframeModal._createIframe(url)
    }
  }
}
</script>
<style>
.iframeSampleLookThree .ivu-modal {
  position: relative !important;
  top: 0px !important;
}
</style>
