<template>
  <div>
    <Modal v-model="showDiagramModalSampleLook" title="原始记录" width="1300" class="footer-hidden">
      <div id="iframeSampleLookThree" style="text-align:center;align-content:center;width: 100%;height: 790px">
      </div>
      <div slot="footer">
      </div>
    </Modal>
  </div>
</template>
<script>
/**
 * 详情
 */
import { drugItem } from '../../../../../api'
export default {
  data() {
    return {
      showDiagramModalSampleLook: false,
      templateId: '',
      formId: '',
      again: true,
      itemIds: [],
      name: ''
    }
  },
  mounted() {
    // 监听原始记录消息
    window.addEventListener('message', this._saveOriginal)
  },
  methods: {
    async _saveOriginal(data) {
      console.log('data11111', data)
      console.log('formId', this.formId)
      console.log('itemIds: [],', this.itemIds)
      console.log('data.data.msg,', data.data.msg)
      if (this.again) {
        this.again = false
        if (
          undefined !== this.formId &&
          this.formId !== '' &&
          this.itemIds !== undefined
        ) {
          await drugItem.originalRecordsEdit({
            ids: this.itemIds,
            formId: this.formId
          })
        }
        if (data.data.msg === true) {
          this._cancel()
        } else {
          this._cancel()
        }
      }
    },
    _cancel() {
      this.showDiagramModalSampleLook = false
      this.$emit('on-result-change')
    },
    _open(formId, name, itemIds) {
      console.log(itemIds)
      console.log(formId)
      console.log(name)
      this.again = true
      this.formId = formId
      this.showDiagramModalSampleLook = true
      this.itemIds = itemIds
      this.name = name
      let url = ''
      url =
        name !== 'only'
          ? 'http://record.patzn.com:7000/print/v1/eln/form_' + 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>'
      )
    }
  }
}
</script>
