| | |
| | | import React, { Component } from 'react' |
| | | import { is, fromJS } from 'immutable' |
| | | import { connect } from 'react-redux' |
| | | import { Col, Row, Spin, notification } from 'antd' |
| | | import { Col, Row, Spin, notification, Button } from 'antd' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | |
| | | import zhCN from '@/locales/zh-CN/main.js' |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import options from '@/store/options.js' |
| | | import UtilsDM from '@/utils/utils-datamanage.js' |
| | | import NotFount from '@/components/404' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | |
| | |
| | | class BillPrint extends Component { |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | loadingview: true, |
| | | dataManager: false, |
| | | BID: '', |
| | | data: '', |
| | | tempId: '', |
| | |
| | | UNSAFE_componentWillMount() { |
| | | try { |
| | | let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param))) |
| | | |
| | | this.setState({ |
| | | BID: param.id || '', |
| | | tempId: param.tempId, |
| | | dataManager: param.dataManager |
| | | }, () => { |
| | | this.getMenuParam() |
| | | }) |
| | |
| | | } |
| | | |
| | | getMenuParam = () => { |
| | | const { tempId, BID } = this.state |
| | | const { tempId, BID, dataManager } = this.state |
| | | |
| | | let param = { |
| | | func: 's_PrintTemplateMGetData', |
| | | Type: 'Y', |
| | | PrintTempNO: tempId |
| | | let _param = { |
| | | func: 'sPC_Get_LongParam', |
| | | MenuID: tempId |
| | | } |
| | | |
| | | if (window.GLOB.mainSystemApi) { // 从单点登录服务器取打印配置信息 |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | _param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | |
| | | Api.getLocalConfig(param).then(result => { |
| | | Api.getLocalConfig(_param).then(result => { |
| | | if (result.status) { |
| | | let config = '' |
| | | |
| | | try { |
| | | config = JSON.parse(window.decodeURIComponent(window.atob(result.ConfigParam))) |
| | | config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) |
| | | } catch (e) { |
| | | console.warn('Parse Failure') |
| | | config = '' |
| | | } |
| | | |
| | | setTimeout(() => { // 延时加载状态 |
| | | this.setState({ |
| | | loadingview: false |
| | | }) |
| | | }, 1500) |
| | | |
| | | // 页面配置解析错误时提示 |
| | | if (!config) { |
| | | this.setState({ |
| | | viewlost: true |
| | | viewlost: true, |
| | | loadingview: false |
| | | }) |
| | | return |
| | | } |
| | |
| | | if (!config.enabled) { |
| | | this.setState({ |
| | | viewlost: true, |
| | | loadingview: false, |
| | | lostmsg: this.state.dict['main.view.unenabled'] |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let params = [] |
| | | config.components = config.components.map(component => { |
| | | if (['tabs', 'search'].includes(component.type)) return null |
| | | let _pars = [] |
| | | |
| | | config.components = config.components.filter(item => !['tabs', 'search'].includes(item.type) && item.subtype !== 'tablecard') |
| | | config.components = config.components.map(component => { |
| | | if (component.action) component.action = [] |
| | | if (component.search) component.search = [] |
| | | |
| | |
| | | component.setting.dataresource = '(' + component.setting.dataresource + ') tb' |
| | | } |
| | | |
| | | if (this.props.dataManager) { // 数据权限 |
| | | if (dataManager) { // 数据权限 |
| | | component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*') |
| | | component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') |
| | | _customScript = _customScript.replace(/\$@/ig, '/*') |
| | |
| | | // pageable 是否分页,组件属性,不分页的组件才可以统一查询 |
| | | if (component.dataName && component.setting.sync === 'true') { |
| | | let param = this.getDefaultParam(component) |
| | | params.push(param) |
| | | _pars.push(param) |
| | | } else { |
| | | component.setting.sync = 'false' |
| | | let arr_field = component.columns.map(col => col.field).join(',') |
| | | let param = UtilsDM.getQueryDataParams(component.setting, arr_field, [], component.setting.order || '', 1, 1000, BID, '', dataManager) |
| | | |
| | | 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({ |
| | | setting: config.setting, |
| | | config |
| | | }, () => { |
| | | if (params.length === 0) { |
| | | this.setState({loadingview: false}) |
| | | } else { |
| | | this.loadmaindata(params) |
| | | } |
| | | }) |
| | | } else { |
| | | notification.warning({ |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 主表数据加载 |
| | | */ |
| | | loadmaindata = (params) => { |
| | | if (!params || params.length === 0) return |
| | | getFormatParam = (params) => { |
| | | if (!params || params.length === 0) return '' |
| | | let LText_field = [] |
| | | let LText = params.map((item, index) => { |
| | | let _sql = item.sql |
| | |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | Api.getLocalConfig(param).then(result => { |
| | | if (result.status) { |
| | | delete result.status |
| | | delete result.message |
| | | delete result.ErrMesg |
| | | delete result.ErrCode |
| | | return param |
| | | } |
| | | |
| | | this.setState({ |
| | | data: result, |
| | | loading: false |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | data: '', |
| | | loading: false |
| | | }) |
| | | notification.error({ |
| | | /** |
| | | * @description 主表数据加载 |
| | | */ |
| | | loadmaindata = (params) => { |
| | | 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: result.message, |
| | | duration: 10 |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | resolve(false) |
| | | } else { |
| | | res.componentId = componentId |
| | | resolve(res) |
| | | } |
| | | }) |
| | | }) |
| | | }) |
| | | |
| | | Promise.all(deffers).then(results => { |
| | | let _results = results.filter(Boolean) |
| | | |
| | | this.setState({loadingview: false}) |
| | | |
| | | if (_results.length === results.length) { |
| | | console.log(_results) |
| | | } |
| | | |
| | | // delete result.ErrCode |
| | | // delete result.ErrMesg |
| | | // delete result.message |
| | | // delete result.status |
| | | }) |
| | | } |
| | | |
| | | print = () => { |
| | | 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 |
| | | |
| | | try { |
| | | if (window.ActiveXObject) { |
| | | let hkeyRoot |
| | | let hkeyPath |
| | | let hkeyKey |
| | | // eslint-disable-next-line |
| | | let RegWsh = new ActiveXObject('WScript.Shell') |
| | | |
| | | hkeyRoot = 'HKEY_CURRENT_USER' |
| | | hkeyPath = '\\Software\\Microsoft\\Internet Explorer\\PageSetup\\' |
| | | |
| | | // 设置页眉/脚的字体样式 |
| | | hkeyKey = 'font' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, 'font-size: 12px; font-family: 黑体; line-height: 24px') |
| | | |
| | | // 设置页眉 |
| | | hkeyKey = 'header' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '打印编号') |
| | | |
| | | // 设置页脚 |
| | | hkeyKey = 'footer' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '&b第 &p 页/共 &P 页') |
| | | |
| | | // 设置页边距(0.6 要乘以 2.5为实际打印的尺寸) |
| | | hkeyKey = 'margin_bottom' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') |
| | | |
| | | hkeyKey = 'margin_left' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') |
| | | |
| | | hkeyKey = 'margin_right' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') |
| | | |
| | | hkeyKey = 'margin_top' |
| | | RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') |
| | | |
| | | window.print() |
| | | } else { |
| | | window.print() |
| | | } |
| | | } catch (e) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '打印异常!', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | |
| | | window.document.body.innerHTML = bdhtml |
| | | window.location.reload() |
| | | } |
| | | |
| | | getComponents = () => { |
| | | const { dataManager } = this.props |
| | | const { config, BID, data } = this.state |
| | | |
| | | if (!config || !config.components) return |
| | | const { config, BID, data, dataManager } = this.state |
| | | |
| | | return config.components.map(item => { |
| | | if (!item) return null |
| | |
| | | const { loadingview, viewlost, config } = this.state |
| | | |
| | | return ( |
| | | <div className="custom-page-wrap" id={this.state.ContainerId} style={config ? config.style : null}> |
| | | <div className="bill-print-wrap" > |
| | | {loadingview && <Spin size="large" />} |
| | | <Row>{this.getComponents()}</Row> |
| | | {config ? <div id="bill-print" style={config.style}><Row>{this.getComponents()}</Row></div> : null} |
| | | {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} |
| | | {!loadingview && !viewlost ? <div className="print-button"><Button onClick={this.print}>打印</Button></div> : null} |
| | | </div> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | dataManager: state.dataManager |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(BillPrint) |
| | | export default BillPrint |