king
2022-04-25 9e716f3bd30820a08757845b592db73363faa48c
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
import React, { Component } from 'react'
import { is, fromJS } from 'immutable'
import { Col, Row, Spin, notification, Button } from 'antd'
import moment from 'moment'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import options, { styles } from '@/store/options.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import UtilsDM from '@/utils/utils-datamanage.js'
import NotFount from '@/components/404'
import asyncComponent from '@/utils/asyncComponent'
 
import './index.scss'
 
// 通用组件
const AntvBarAndLine = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-bar-line'))
const AntvPie = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-pie'))
const AntvDashboard = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-dashboard'))
const AntvScatter = asyncComponent(() => import('@/tabviews/custom/components/chart/antv-scatter'))
const DataCard = asyncComponent(() => import('@/tabviews/custom/components/card/data-card'))
const PropCard = asyncComponent(() => import('@/tabviews/custom/components/card/prop-card'))
const TableCard = asyncComponent(() => import('@/tabviews/custom/components/card/table-card'))
const NormalTable = asyncComponent(() => import('@/tabviews/custom/components/table/normal-table'))
const SandBox = asyncComponent(() => import('@/tabviews/custom/components/code/sand-box'))
const TimeLine = asyncComponent(() => import('@/tabviews/custom/components/timeline/normal-timeline'))
const Balcony = asyncComponent(() => import('@/tabviews/custom/components/card/balcony'))
 
class BillPrint extends Component {
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    loadingview: true,
    printing: false,
    pages: null,
    BID: '',
    data: '',
    tempId: '',
    config: null,
    auto: true
  }
 
  UNSAFE_componentWillMount() {
    const { params } = this.props.match
 
    if (params.menuId) {
      this.setState({
        BID: params.id || '',
        tempId: params.menuId
      }, () => {
        this.getTouristMsg()
      })
    } else {
      try {
        let param = JSON.parse(window.decodeURIComponent(window.atob(params.param)))
  
        sessionStorage.setItem('dataM', param.dataM || '')
        sessionStorage.setItem('localDataM', param.dataM || '')
        this.setState({
          BID: param.id || '',
          tempId: param.tempId
        }, () => {
          this.getMenuParam()
        })
      } catch (e) {
        notification.warning({
          top: 92,
          message: '菜单信息解析错误!',
          duration: 5
        })
      }
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  getTouristMsg = () => {
    Api.getTouristMsg().then(result => {
      if (result.status) {
        sessionStorage.setItem('UserID', result.UserID || '')
        sessionStorage.setItem('LoginUID', result.LoginUID || '')
        sessionStorage.setItem('dataM', 'false')
 
        this.getMenuParam()
 
        // 获取系统信息
        let _param = {
          func: 's_Get_style',
          TypeCharOne: 'PC',
          LText: `select '${window.GLOB.appkey}'`,
        }
 
        _param.userid = result.UserID
        _param.LoginUID = result.LoginUID
        _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
 
        Api.getSystemConfig(_param).then(res => {
          if (res.status) {
            window.GLOB.style = res.CSS
            document.title = res.titleName
        
            if (window.GLOB.style && styles[window.GLOB.style]) {
              document.body.className = styles[window.GLOB.style] + ' ' + (res.split_line_show === 'false' ? 'hidden-split-line' : '')
            }
 
            if (res.titlelogo) {
              let link = document.querySelector("link[rel*='icon']") || document.createElement('link')
              link.type = 'image/x-icon'
              link.rel = 'shortcut icon'
              link.href = res.titlelogo
              document.getElementsByTagName('head')[0].appendChild(link)
            }
          }
        })
      } else {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
 
  getMenuParam = () => {
    const { tempId, BID } = this.state
 
    let _param = {
      func: 'sPC_Get_LongParam',
      MenuID: tempId
    }
 
    window.GLOB.dataFormat = false // 打印去除水印
 
    if (window.GLOB.mainSystemApi) { // 从单点登录服务器取打印配置信息
      _param.rduri = window.GLOB.mainSystemApi
    }
 
    Api.getLocalConfig(_param).then(result => {
      if (result.status) {
        let config = ''
 
        try {
          config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
        } catch (e) {
          console.warn('Parse Failure')
          config = ''
        }
 
        // 页面配置解析错误时提示
        if (!config) {
          this.setState({
            viewlost: true,
            loadingview: false
          })
          return
        }
 
        // 页面未启用时,显示未启用页面
        if (!config.enabled) {
          this.setState({
            viewlost: true,
            loadingview: false,
            lostmsg: this.state.dict['main.view.unenabled']
          })
          return
        }
 
        config.style = config.style || {}
        config.pageSize = ['A4', 'A3', 'A5'].includes(config.pageSize) ? config.pageSize : 'A4'
        config.pageLayout = config.pageLayout !== 'horizontal' ? 'vertical' : 'horizontal'
        config.pagePadding = config.pagePadding !== 'without' ? 'default' : 'without'
 
        let pageParam = {
          A4: {
            vertical: 980,
            horizontal: 1200,
            verticaldefault: 1.455,
            verticalwithout: 1.411,
            horizontaldefault: 0.679,
            horizontalwithout: 0.701,
          },
          A3: {
            vertical: 1200,
            horizontal: 1600,
            verticaldefault: 1.441,
            verticalwithout: 1.410,
            horizontaldefault: 0.688,
            horizontalwithout: 0.703,
          },
          A5: {
            vertical: 700,
            horizontal: 1000,
            verticaldefault: 1.478,
            verticalwithout: 1.413,
            horizontaldefault: 0.669,
            horizontalwithout: 0.700,
          }
        }
 
        config.width = pageParam[config.pageSize][config.pageLayout]
        config.style.height = Math.floor(config.width * pageParam[config.pageSize][config.pageLayout + config.pagePadding])
 
        if (config.printCustom === 'true' && config.printWidth && config.printHeight) {
          config.width = config.printWidth
          config.style.height = config.printHeight
        }
 
        let params = []
        let _pars = []
 
        config.components = config.components.filter(item => !['tabs', 'search'].includes(item.type))
 
        let userName = sessionStorage.getItem('User_Name') || ''
        let fullName = sessionStorage.getItem('Full_Name') || ''
        let city = sessionStorage.getItem('city') || ''
 
        if (sessionStorage.getItem('isEditState') === 'true') {
          userName = sessionStorage.getItem('CloudUserName') || ''
          fullName = sessionStorage.getItem('CloudFullName') || ''
        }
 
        let regs = [
          { reg: /@userName@/ig, value: `'${userName}'` },
          { reg: /@fullName@/ig, value: `'${fullName}'` },
          { reg: /@login_city@/ig, value: `'${city}'` }
        ]
        
        if (window.GLOB.externalDatabase !== null) {
          regs.push({
            reg: /@db@/ig,
            value: window.GLOB.externalDatabase
          })
        }
 
        config.components = config.components.map(component => {
          if (component.action) component.action = []
          if (component.search) component.search = []
          component.data = [] // 初始化数据为空
 
          if (component.type === 'table' && component.subtype === 'normaltable') {
            let getColumns = (cols) => {
              return cols.map(item => {
                if (item.type === 'colspan') {
                  item.subcols = getColumns(item.subcols)
                } else {
                  item.IsSort = 'false'
                }
          
                return item
              })
            }
            component.cols = getColumns(component.cols)
          }
 
          if (component.wrap.datatype === 'static') {
            component.format = ''
          }
    
          if (!component.setting) return component // 不使用系统函数时
          if (!component.format) return component  // 没有动态数据  数据格式 array 或 object
          if (component.setting.interType !== 'system') { // 不使用系统函数时
            component.setting.sync = 'false'
            return component
          }
    
          let _customScript = ''
          component.scripts && component.scripts.forEach(script => {
            if (script.status !== 'false') {
              _customScript += `
              ${script.sql}
              `
            }
          })
          delete component.scripts
    
          component.setting.execute = component.setting.execute !== 'false'  // 默认sql是否执行,转为boolean 统一格式
          component.setting.laypage = false   // 是否分页,转为boolean 统一格式
          component.setting.onload = 'true'   // 默认加载
    
          if (!component.setting.execute) {
            component.setting.dataresource = ''
          }
          if (/\s/.test(component.setting.dataresource)) {
            component.setting.dataresource = '(' + component.setting.dataresource + ') tb'
          }
      
          if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
            component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*')
            component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/')
            _customScript = _customScript.replace(/\$@/ig, '/*')
            _customScript = _customScript.replace(/@\$/ig, '*/')
          } else {
            component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '')
            _customScript = _customScript.replace(/@\$|\$@/ig, '')
          }
 
          regs.forEach(cell => {
            component.setting.dataresource = component.setting.dataresource.replace(cell.reg, cell.value)
            _customScript = _customScript.replace(cell.reg, cell.value)
          })
    
          component.setting.customScript = _customScript // 整理后自定义脚本
    
          // floor    组件的层级
          // dataName 系统生成的数据源名称
          // pageable 是否分页,组件属性,不分页的组件才可以统一查询
          if (component.dataName && component.setting.sync === 'true') {
            let param = this.getDefaultParam(component)
            _pars.push(param)
          } else {
            let arr_field = component.columns.map(col => col.field).join(',')
            let param = UtilsDM.getQueryDataParams(component.setting, arr_field, [], component.setting.order || '', 1, 1000, BID, '')
            
            param.componentId = component.uuid
 
            params.push(param)
          }
          component.setting.sync = 'true'
    
          return component
        })
 
        _pars = this.getFormatParam(_pars)
 
        if (_pars) {
          _pars.componentId = 'union'
          params.unshift(_pars)
        }
 
        this.setState({
          config
        }, () => {
          if (params.length === 0) {
            this.setState({loadingview: false, pages: [config.components]})
          } else {
            this.loadmaindata(params)
          }
        })
      } else {
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
 
  reload = () => {
    this.setState({
      loadingview: true,
      pages: null,
      data: '',
      config: null
    }, () => {
      this.getMenuParam()
    })
  }
 
  /**
   * @description 获取系统存储过程参数
   */
  getDefaultParam = (component) => {
    const { columns, setting, dataName, format } = component
    
    let arr_field = columns.map(col => col.field)
    let _dataresource = setting.dataresource
    let _customScript = setting.customScript
 
    if (setting.order && _dataresource) {
      _dataresource = `select top 1000 ${arr_field.join(',')} from (select ${arr_field.join(',')} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
    } else if (_dataresource) {
      _dataresource = `select top 1000 ${arr_field.join(',')} from ${_dataresource} `
    }
 
    // 测试系统打印查询语句
    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
      _customScript &&  console.info(`${_dataresource ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      _dataresource &&  console.info(_dataresource)
    }
 
    return {
      name: dataName,
      columns: columns,
      par_tablename: '',
      type: format === 'array' ? format : '',
      primaryKey: setting.primaryKey || '',
      foreign_key: '',
      sql: _dataresource,
      script: _customScript,
      transaction: setting.transaction === 'true'
    }
  }
 
  getFormatParam = (params) => {
    const { BID } = this.state
 
    if (!params || params.length === 0) return ''
    let LText_field = []
    let transaction = false
 
    let userName = sessionStorage.getItem('User_Name') || ''
    let fullName = sessionStorage.getItem('Full_Name') || ''
    let RoleID = sessionStorage.getItem('role_id') || ''
    let departmentcode = sessionStorage.getItem('departmentcode') || ''
    let organization = sessionStorage.getItem('organization') || ''
    let city = sessionStorage.getItem('city') || ''
  
    if (sessionStorage.getItem('isEditState') === 'true') {
      userName = sessionStorage.getItem('CloudUserName') || ''
      fullName = sessionStorage.getItem('CloudFullName') || ''
    }
 
    let LText = params.map((item, index) => {
      let _sql = item.sql
      let _script = item.script
 
      if (index === 0) {
        _script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(50),@mk_organization nvarchar(50),@login_city nvarchar(50)
          select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @login_city='${city}'
          ${_script}
        `
      }
      if (item.transaction) {
        transaction = true
      }
 
      item.columns.forEach(cell => {
        LText_field.push(`Select '${item.name}' as tablename,'${cell.field}' as fieldname,'${cell.datatype}' as field_type`)
      })
      return `Select '${item.name}' as tablename,'${window.btoa(window.encodeURIComponent(_sql))}' as LText,'${window.btoa(window.encodeURIComponent(_script))}' as Lcustomize,'${item.type}' as table_type,'${item.primaryKey}' as primary_key,'${item.par_tablename}' as par_tablename,'${item.foreign_key}' as foreign_key,'${index}' as Sort`
    })
 
    let param = {
      func: 'sPC_Get_structured_data',
      LText: LText.join(' union all '),
      LText_field: LText_field.join(' union all '),
      BID: BID || ''
    }
 
    if (transaction) {
      param.func = 'sPC_Get_structured_data_try'
    }
 
    param.LText = Utils.formatOptions(param.LText)
    param.LText_field = Utils.formatOptions(param.LText_field)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
    return param
  }
 
  /**
   * @description 主表数据加载
   */ 
  loadmaindata = (params) => {
    const { components, everyPCount, firstCount, lastCount } = this.state.config
 
    let deffers = params.map(item => {
      let componentId = item.componentId
      delete item.componentId
      return new Promise(resolve => {
        Api.getLocalConfig(item).then(res => {
          if (!res.status) {
            notification.warning({
              top: 92,
              message: res.message,
              duration: 5
            })
            resolve(false)
          } else {
            res.componentId = componentId
            resolve(res)
          }
        })
      })
    })
 
    Promise.all(deffers).then(results => {
      let _results = results.filter(Boolean)
 
      let comps = components.map(item => {
        if (!item.format) return item
 
        _results.forEach(res => {
          if (res.componentId === item.uuid && res.data) {
            item.data = res.data
            item.dataArray = fromJS(res.data).toJS()
          } else if (res.componentId === 'union' && res[item.dataName]) {
            item.data = res[item.dataName]
            item.dataArray = fromJS(res[item.dataName]).toJS()
          }
        })
 
        return item
      })
 
      let length = comps.length
      let pageIndex = 1
      let pages = []
      let over = false
 
      if (length === 0) {
        this.setState({loadingview: false, pages})
      }
 
      let auto = true
 
      if (comps[comps.length - 1].wrap && comps[comps.length - 1].wrap.printHeight) {
        auto = false
      }
 
      while (!over) {
        let page = []
        let count = 0
        let _pageover = false
        let pagesover = false
 
        let limit = pageIndex === 1 ? (firstCount || 20) : (everyPCount || 20)
 
        comps.forEach((_item, index) => {
          let item = fromJS(_item).toJS()
 
          if (index + 1 >= length && !_pageover) {
            pagesover = true
          }
 
          if (item.wrap && item.wrap.printType === 'headerOrfooter') { // 页眉页脚
            page.push(item)
          } else if (_pageover) {
            return
          } else if (item.subtype === 'datacard' || item.type === 'table') {
            if (_item.dataArray && _item.dataArray.length > 0) {
              if (item.subtype === 'datacard' && item.wrap.layout === 'flex') {
                if (!item.added && item.wrap.printHeight) {
                  count += item.wrap.printHeight
                  if (count >= limit) {
                    _pageover = true
                  }
                  if (count <= limit) {
                    _item.added = true
                    page.push(item)
                  }
                } else if (!item.added) {
                  _item.added = true
                  page.push(item)
                }
              } else {
                item.data = []
  
                while (count + 1 <= limit && _item.dataArray.length > 0) {
                  item.data.push(_item.dataArray.shift())
                  count++
                }
    
                if (count >= limit) {
                  _pageover = true
                }
                page.push(item)
              }
              _item.added = true
            } else if (!item.added) {
              _item.added = true
              page.push(item)
            }
          } else if (!item.added && item.wrap && item.wrap.printHeight) {
            if (item.wrap.empty === 'hidden' && (!item.data || item.data.length === 0)) {
              _item.added = true
              return
            }
 
            count += item.wrap.printHeight
            if (count >= limit) {
              _pageover = true
            }
            if (count <= limit) {
              _item.added = true
              page.push(item)
            }
          } else if (!item.added) {
            _item.added = true
            page.push(item)
          }
          
          if (index + 1 >= length && !_pageover) {
            pagesover = true
          }
        })
 
        if (pagesover && lastCount && count > lastCount) {
          pagesover = false
          page = []
          count = 0
          _pageover = false
 
          if (pageIndex === 1) {
            limit = (everyPCount - firstCount) + (everyPCount - lastCount)
 
            if (limit <= 0) {
              limit = firstCount
            }
          } else {
            limit = lastCount
          }
 
          comps.forEach((_item, index) => {
            let item = fromJS(_item).toJS()
            if (item.wrap && item.wrap.printType === 'headerOrfooter') { // 页眉页脚
              page.push(item)
            } else if (_pageover) {
              return
            } else if (item.subtype === 'datacard' || item.type === 'table') {
              if (_item.dataArray && _item.dataArray.length > 0) {
                if (item.subtype === 'datacard' && item.wrap.layout === 'flex') {
                  if (!item.added && item.wrap.printHeight) {
                    count += item.wrap.printHeight
                    if (count >= limit) {
                      _pageover = true
                    }
                    if (count <= limit) {
                      _item.added = true
                      page.push(item)
                    }
                  } else if (!item.added) {
                    _item.added = true
                    page.push(item)
                  }
                } else {
                  item.data = []
 
                  while (count + 1 <= limit && _item.dataArray.length > 0) {
                    item.data.push(_item.dataArray.shift())
                    count++
                  }
      
                  if (count >= limit) {
                    _pageover = true
                  }
                  page.push(item)
                }
                _item.added = true
              } else if (!item.added) {
                _item.added = true
                page.push(item)
              }
            } else if (!item.added && item.wrap && item.wrap.printHeight) {
              if (item.wrap.empty === 'hidden' && (!item.data || item.data.length === 0)) {
                _item.added = true
                return
              }
              count += item.wrap.printHeight
              if (count >= limit) {
                _pageover = true
              }
              if (count <= limit) {
                _item.added = true
                page.push(item)
              }
            } else if (!item.added) {
              _item.added = true
              page.push(item)
            }
  
            if (index + 1 === length && !_pageover) {
              pagesover = true
            }
          })
        }
 
        pages.push(page)
        pageIndex++
 
        if (pageIndex >= 200 || pagesover) {
          over = true
        }
      }
 
      this.setState({loadingview: false, pages, auto})
    })
  }
 
  print = () => {
    const { config, printing } = this.state
 
    if (printing) return
 
    let jubuData = document.getElementById('bill-print').innerHTML
 
    this.setState({printing: true})
    
    try {
      let iframe = document.createElement('IFRAME')
      let linkList = document.getElementsByTagName('link')     // 获取父窗口link标签对象列表
      let styleList = document.getElementsByTagName('style')   // 获取父窗口style标签对象列表
 
      iframe.style.marginTop = '600px'
      document.body.appendChild(iframe)
      let doc = iframe.contentWindow.document
      
      doc.open()
      doc.write(`<!DOCTYPE html><html lang="en"><head>`)
      for (let i = 0;i < linkList.length;i++) {
        if (linkList[i].type === 'text/css') {
          doc.write(`<LINK rel="stylesheet" type="text/css" href="${linkList[i].href}">`)
        }
      }
      doc.write(`<style>body{width: ${config.width}px!important;}*{border-style: solid;border-width: 0;}.ant-table-placeholder{display: none;}.ant-empty{display: none;}</style>`)
      for (let i = 0;i < styleList.length;i++) {
        doc.write('<style>' + styleList[i].innerHTML + '</style>')
      }
      doc.write(`</head><body>`)
      doc.write(jubuData)
      doc.write(`</body></html>`)
      doc.close()
 
      setTimeout(() => {
        iframe.contentWindow.focus()
        iframe.contentWindow.print()
 
        document.body.removeChild(iframe)
 
        setTimeout(() => {
          window.close()
        }, 2000)
      }, 500)
    } catch (e) {
      notification.warning({
        top: 92,
        message: '打印异常!',
        duration: 5
      })
    }
  }
 
  getComponents = (components) => {
    return components.map(item => {
      if (item.type === 'bar' || item.type === 'line') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvBarAndLine config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'pie') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvPie config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'scatter') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvScatter config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'dashboard') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvDashboard config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'datacard') {
        return (
          <Col span={item.width} key={item.uuid}>
            <DataCard config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'propcard') {
        return (
          <Col span={item.width} key={item.uuid}>
            <PropCard config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'tablecard') {
        return (
          <Col span={item.width} key={item.uuid}>
            <TableCard config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'normaltable') {
        return (
          <Col span={item.width} key={item.uuid}>
            <NormalTable config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'code') {
        return (
          <Col span={item.width} key={item.uuid}>
            <SandBox config={item} initdata={item.data} mainSearch={[]} menuType="" />
          </Col>
        )
      } else if (item.type === 'balcony') {
        return (
          <Col span={item.width} key={item.uuid}>
            <Balcony config={item} initdata={item.data} menuType="" />
          </Col>
        )
      } else if (item.type === 'timeline') {
        return (
          <Col span={item.width} key={item.uuid}>
            <TimeLine config={item} initdata={item.data} menuType="" />
          </Col>
        )
      } else {
        return null
      }
    })
  }
 
  render() {
    const { loadingview, viewlost, config, pages, auto } = this.state
 
    return (
      <div className="bill-print-wrap" >
        {loadingview && <Spin size="large" />}
        {pages ? <div id="bill-print">
          {pages.map((components, index) => (<div className={'print-page' + (auto ? ' auto' : '')} key={index} style={{...config.style, overflow: 'hidden', boxSizing: 'border-box'}}><Row>{this.getComponents(components)}</Row></div>))}
        </div> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
        {pages && !loadingview && !viewlost ? <div className="print-button"><Button icon="printer" size="large" shape="circle" onClick={this.print}></Button></div> : null}
        {!loadingview && !viewlost ? <div className="refresh-button"><Button icon="reload" size="large" shape="circle" onClick={this.reload}></Button></div> : null}
      </div>
    )
  }
}
 
export default BillPrint