| | |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | loadingview: true, |
| | | dataManager: false, |
| | | pages: null, |
| | | BID: '', |
| | | data: '', |
| | | tempId: '', |
| | |
| | | return |
| | | } |
| | | |
| | | config.style = config.style || {} |
| | | |
| | | if (config.pageSize === 'A0') { |
| | | if (config.pageLayout === 'horizontal') { |
| | | config.style.height = 1305 |
| | | } else { |
| | | config.style.height = 1305 |
| | | } |
| | | } else if (config.pageSize === 'A1') { |
| | | if (config.pageLayout === 'horizontal') { |
| | | config.style.height = 1305 |
| | | } else { |
| | | config.style.height = 1305 |
| | | } |
| | | } else if (config.pageSize === 'A2') { |
| | | if (config.pageLayout === 'horizontal') { |
| | | config.style.height = 1305 |
| | | } else { |
| | | config.style.height = 1305 |
| | | } |
| | | } else if (config.pageSize === 'A3') { |
| | | if (config.pageLayout === 'horizontal') { |
| | | config.style.height = 1305 |
| | | } else { |
| | | config.style.height = 1305 |
| | | } |
| | | } else if (config.pageSize === 'A5') { |
| | | if (config.pageLayout === 'horizontal') { |
| | | config.style.height = 1305 |
| | | } else { |
| | | config.style.height = 1305 |
| | | } |
| | | } else { |
| | | if (config.pageLayout === 'horizontal') { |
| | | config.style.height = 895 |
| | | } else { |
| | | config.style.height = 1305 |
| | | } |
| | | } |
| | | |
| | | // config.style.height = 895 |
| | | |
| | | let params = [] |
| | | let _pars = [] |
| | | |
| | |
| | | config.components = config.components.map(component => { |
| | | if (component.action) component.action = [] |
| | | if (component.search) component.search = [] |
| | | component.data = [] // 初始化数据为空 |
| | | |
| | | if (!component.setting) return component // 不使用系统函数时 |
| | | if (!component.format || (component.subtype === 'propcard' && component.wrap.datatype === 'static')) return component // 没有动态数据 数据格式 array 或 object |
| | |
| | | config |
| | | }, () => { |
| | | if (params.length === 0) { |
| | | this.setState({loadingview: false}) |
| | | this.setState({loadingview: false, pages: [config.components]}) |
| | | } else { |
| | | this.loadmaindata(params) |
| | | } |
| | |
| | | * @description 主表数据加载 |
| | | */ |
| | | loadmaindata = (params) => { |
| | | const { components, everyPCount, firstCount, lastCount } = this.state.config |
| | | |
| | | let deffers = params.map(item => { |
| | | let componentId = item.componentId |
| | | delete item.componentId |
| | |
| | | Promise.all(deffers).then(results => { |
| | | let _results = results.filter(Boolean) |
| | | |
| | | this.setState({loadingview: false}) |
| | | let comps = components.map(item => { |
| | | if (item.subtype === 'propcard' && item.wrap.datatype === 'static') return item |
| | | |
| | | if (_results.length === results.length) { |
| | | console.log(_results) |
| | | _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}) |
| | | } |
| | | |
| | | // delete result.ErrCode |
| | | // delete result.ErrMesg |
| | | // delete result.message |
| | | // delete result.status |
| | | // everyPCount, firstCount, lastCount |
| | | 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 (item.wrap && item.wrap.printType === 'headerOrfooter') { // 页眉页脚 |
| | | page.push(item) |
| | | } else if (_pageover) { |
| | | return |
| | | } else if (item.type === 'card' && item.subtype === 'datacard') { |
| | | if (!_item.dataArray || _item.dataArray.length === 0) return |
| | | |
| | | item.data = [] |
| | | |
| | | while (count < limit && _item.dataArray.length > 0) { |
| | | item.data.push(_item.dataArray.shift()) |
| | | count++ |
| | | } |
| | | |
| | | if (count >= limit) { |
| | | _pageover = true |
| | | } |
| | | page.push(item) |
| | | } else { |
| | | 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.type === 'card' && item.subtype === 'datacard') { |
| | | if (!_item.dataArray || _item.dataArray.length === 0) return |
| | | |
| | | item.data = [] |
| | | |
| | | while (count < limit && _item.dataArray.length > 0) { |
| | | item.data.push(_item.dataArray.shift()) |
| | | count++ |
| | | } |
| | | |
| | | if (count >= limit) { |
| | | _pageover = true |
| | | } |
| | | page.push(item) |
| | | } else { |
| | | page.push(item) |
| | | } |
| | | |
| | | if (index + 1 === length && !_pageover) { |
| | | pagesover = true |
| | | } |
| | | }) |
| | | } |
| | | |
| | | pages.push(page) |
| | | pageIndex++ |
| | | |
| | | if (pageIndex >= 2000 || pagesover) { |
| | | over = true |
| | | } |
| | | } |
| | | |
| | | this.setState({loadingview: false, pages}) |
| | | }) |
| | | } |
| | | |
| | |
| | | let bdhtml = window.document.body.innerHTML |
| | | let jubuData = document.getElementById('bill-print').innerHTML |
| | | window.document.body.innerHTML = jubuData |
| | | // document.getElementsByTagName('body')[0].style.zoom = 0.7 |
| | | document.getElementsByTagName('body')[0].style.zoom = 0.8 |
| | | |
| | | try { |
| | | if (window.ActiveXObject) { |
| | |
| | | window.location.reload() |
| | | } |
| | | |
| | | getComponents = () => { |
| | | const { config, BID, data, dataManager } = this.state |
| | | getComponents = (components) => { |
| | | const { dataManager } = this.state |
| | | |
| | | return config.components.map(item => { |
| | | if (!item) return null |
| | | |
| | | return components.map(item => { |
| | | if (item.type === 'bar' || item.type === 'line') { |
| | | return ( |
| | | <Col span={item.width} key={item.uuid}> |
| | | <AntvBarAndLine config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | <AntvBarAndLine config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'pie') { |
| | | return ( |
| | | <Col span={item.width} key={item.uuid}> |
| | | <AntvPie config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | <AntvPie config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'card' && item.subtype === 'datacard') { |
| | | return ( |
| | | <Col span={item.width} key={item.uuid}> |
| | | <DataCard config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | <DataCard config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'card' && item.subtype === 'propcard') { |
| | | return ( |
| | | <Col span={item.width} key={item.uuid}> |
| | | <PropCard config={item} data={data} BID={BID} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | <PropCard config={item} initdata={item.data} mainSearch={[]} menuType="" dataManager={dataManager} /> |
| | | </Col> |
| | | ) |
| | | } else { |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { loadingview, viewlost, config } = this.state |
| | | const { loadingview, viewlost, config, pages } = this.state |
| | | |
| | | return ( |
| | | <div className="bill-print-wrap" > |
| | | {loadingview && <Spin size="large" />} |
| | | {config ? <div id="bill-print" style={config.style}><Row>{this.getComponents()}</Row></div> : null} |
| | | {pages ? <div id="bill-print"> |
| | | {pages.map((components, index) => (<div className="print-page" key={index} style={config.style}><Row>{this.getComponents(components)}</Row></div>))} |
| | | </div> : null} |
| | | {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} |
| | | {!loadingview && !viewlost ? <div className="print-button"><Button onClick={this.print}>打印</Button></div> : null} |
| | | {pages && !loadingview && !viewlost ? <div className="print-button"><Button icon="printer" size="large" shape="circle" onClick={this.print}></Button></div> : null} |
| | | </div> |
| | | ) |
| | | } |