chenhaozhe
2025-11-10 1f0bc7f2cf56b601595410ebf4d4bdc00ba9314c
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
<template>
  <div class="print-container">
    <!-- 报表显示区域将由JS动态创建 -->
  </div>
</template>
 
<script>
import '@/utils/print/CreateControl.js'
import '@/utils/print/GRInstall.js'
import '@/utils/print/GRUtility.js'
 
export default {
  name: 'HBarPlanPrint',
  data() {
    return {
      PrintCount: 0,
      params: {},
      value: '',
      type: '',
      openTmp: ''
    }
  },
  mounted() {
    this.params = this.getUrlVars()
    this.initParams()
    this.createDisplayViewer()
    window.addEventListener('load', this.windowOnload)
  },
  beforeUnmount() {
    window.removeEventListener('load', this.windowOnload)
  },
  methods: {
    getUrlVars() {
      const vars = {}
      const hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')
      for (let i = 0; i < hashes.length; i++) {
        const hash = hashes[i].split('=')
        vars[hash[0]] = hash[1]
      }
      return vars
    },
    initParams() {
      // 解析参数,根据实际参数结构调整
      const paramKeys = Object.keys(this.params)
      this.value = this.params[paramKeys[0]] || ''
      this.type = this.params[paramKeys[1]] || ''
      this.openTmp = this.params[paramKeys[2]] || ''
    },
    windowOnload() {
      const ReportViewer = document.getElementById('ReportViewer')
      if (ReportViewer) {
        const Report = ReportViewer.Report
        Report.OnPrintBegin = this.onPrintBegin
        Report.OnPrintEnd = this.onPrintEnd
        ReportViewer.Start()
      }
    },
    onPrintBegin() {
      // 打印开始时的逻辑
    },
    onPrintEnd() {
      // 打印结束时的逻辑
      if (this.PrintCount === 0) {
        const LCStatus = sessionStorage.getItem('LCStatus')
        if (LCStatus === 'Print') {
          // 调用保存打印记录的方法,此处假设SaveLabelPrint已全局定义
          if (window.SaveLabelPrint) {
            window.SaveLabelPrint(sessionStorage.getItem('LabelJson'))
          }
          this.PrintCount = 1
        }
      }
    },
    createDisplayViewer() {
      switch (this.type) {
        case 'HProcessReport':
          window.CreateDisplayViewerEx('100%', '100%', '../../grf/' + this.openTmp + '.grf', 'xmlLBM_ProcessReport.aspx?linterid=' + this.value, true, '')
          break
        case 'HDepartMent':
          window.CreateDisplayViewerEx('100%', '100%', 'grf/' + this.openTmp + '.grf', 'xmlLBM_Gy_Department_Edit.aspx?linterid=' + this.value, true, '')
          break
        case 'HMaterial':
          window.CreateDisplayViewerEx('100%', '100%', '../../grf/' + this.openTmp + '.grf', 'xmlLBM_Gy_Material.aspx?linterid=' + this.value, true, '')
          break
        // 其他case省略,保持与原html中switch逻辑一致
        case 'HCustTag':
          const listTrue = this.value.split('@')
          if (listTrue.length > 1) {
            window.CreateDisplayViewerEx('100%', '100%', '../../grf/' + this.openTmp + '.grf', `xmlLBM_Sc_CustTagBarCodeList.aspx?linterid=${listTrue[0]}&entryid=${listTrue[1]}`, true, '')
          } else {
            window.CreateDisplayViewerEx('100%', '100%', '../../grf/' + this.openTmp + '.grf', 'xmlLBM_Sc_CustTagBarCodeList_Select.aspx?linterid=' + listTrue[0], true, '')
          }
          break
        // 更多case请参照原代码补充
        default:
          break
      }
    }
  }
}
</script>
 
<style scoped>
.print-container {
  width: 100%;
  height: 100%;
  margin: 0;
}
</style>