dialogIframe.vue 4.42 KB
Newer Older
何虹's avatar
何虹 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
<template>
  <el-dialog
    title="导入"
    :visible.sync="dialogVisible"
    width="90%"
    :before-close="handleClose"
    :close-on-click-modal='false'
    @open='open'
    :append-to-body='true'
  >
    <iframe
      name="zi"
      :src='pageSrc'
      style="width:100%;height:500px;padding-top:10px"
      sandbox="allow-same-origin allow-scripts allow-forms allow-top-navigation allow-popups"
    ></iframe>
  </el-dialog>
</template>
<script>
export default {
  name: 'hsDialogIframe',
  props: {
    value: {
      type: Boolean,
      default: false
    },
    src: {
      type: String,
      default: ''
    },
    entityConfig: {},
    currentImportItem: {},
    entityManger: {}
  },
  watch: {
    value(val) {
      this.dialogVisible = val
    },
    dialogVisible(val) {
      this.$emit('input', val)
    }
  },
  data() {
    return {
      dialogVisiblePage: false,
      pageSrc: '',
      dialogVisible: false
    }
  },
  beforeDestroy() {
    window.removeEventListener('message', this.listenerMessageFun, false)
  },
  mounted() {
    window.addEventListener(
      'message',
      this.listenerMessageFun,
      false
    )
  },
  methods: {
    listenerMessageFun(event) {
      const data_ = event.data
      const { innerType, data, main, close } = data_
      if (close) {
        this.$emit('closeDialog')
      } else {
        if (innerType) {
          switch (innerType) {
            case 'dataImport':
            case 'dataImportHdrDtl':
              this.dataImport(data, this.entityConfig, main)
              break
            case 'selectPlugin':
              this.selectPlugin(data)
              break
          }
        }
      }
    },
    // 参照弹出选择
    selectPlugin(data) {
      this.$emit('linkBtnUiBack', data)
    },
    // 单一列表的数据导入
    async dataImport(data, config, main) {
      if (!config) return
      const type = this.entityManger.type // 实体类型
      if (type === 'mainDtl') { // 详情的导入
        this.dtlImport(data, config, main)
      } else { // 列表上的导入
        const ids = data.reduce((prve, curr) => {
          prve.push(curr.id)
          return prve
        }, [])
        const { table_name } = config
        const { import_name, saveParms, _parms } = this.currentImportItem
        const url_table_name = this.currentImportItem.table_name || table_name
        let queryParms = saveParms || {}
        if (_parms) {
          queryParms = Object.assign({}, saveParms, _parms)
        }
        const data_ = {
          ids: ids.join(),
          data,
          main,
          type: 'import'
        }
        const parms_ = {
          table_name: url_table_name,
          import_name: import_name,
          queryParms: queryParms
        }
        this.$API.importDataIframe(data_, parms_).then(res => {
          this.$message.success('导入成功!')
          this.$emit('importSuccess')
        })
      }
    },
    // 详情中的导入
    async dtlImport(data, config, main) {
      if (!config) return
      const mainEntity = this.entityManger.mainEntity
      const config_ = mainEntity.config
      const primaryKey = config_.primaryKey
      const mainData = mainEntity.data
      if (mainData) {
        const iUpdateStatus = mainData.iUpdateStatus
        if (iUpdateStatus === 1) {
          await mainEntity.save(true)
        }
        const ids = data.reduce((prve, curr) => {
          prve.push(curr.id)
          return prve
        }, [])
        const { table_name } = config
        const { import_name, saveParms, _parms } = this.currentImportItem
        const url_table_name = this.currentImportItem.table_name || table_name
        let queryParms = saveParms || {}
        if (_parms) {
          queryParms = Object.assign({}, saveParms, _parms)
        }
        const data_ = {
          ids: ids.join(),
          data,
          main,
          type: 'import'
        }
        queryParms.bill_id = mainData[primaryKey]
        const parms_ = {
          table_name: url_table_name,
          import_name: import_name,
          queryParms: queryParms
        }
        this.$API.importDataIframe(data_, parms_).then(res => {
          this.$message.success('导入成功!')
          this.handleClose()
          this.$emit('importSuccess', {
            bill_id: mainData[primaryKey]
          })
        })
      }
    },
    open() {
      this.pageSrc = this.src
    },
    handleClose() {
      this.dialogVisible = false
    }
  }
}
</script>