| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import moment from 'moment' |
| | | import {connect} from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message, Icon } from 'antd' |
| | | import { Button, Modal, notification, message } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | import asyncSpinComponent from '@/utils/asyncSpinComponent' |
| | | import { updateForm } from '@/utils/utils-update.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | import MkIcon from '@/components/mk-icon' |
| | | // import './index.scss' |
| | | |
| | | const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform')) |
| | | const { confirm } = Modal |
| | |
| | | |
| | | class PrintButton extends Component { |
| | | static propTpyes = { |
| | | show: PropTypes.any, // 按钮显示样式控制 |
| | | position: PropTypes.any, // 按钮位置,工具栏为toolbar |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | selectedData: PropTypes.any, // 子表中选择数据 |
| | |
| | | btn: PropTypes.object, // 按钮 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | ContainerId: PropTypes.any, // tab页面ID,用于弹窗控制 |
| | | disabled: PropTypes.any, // 行按钮禁用 |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | visible: false, |
| | | formdata: null, |
| | | tabledata: null, |
| | | selines: null, |
| | | btnconfig: null, |
| | | confirmLoading: false, |
| | | loading: false, |
| | | disabled: false, |
| | | loadingNumber: '' |
| | | hidden: false, |
| | | autoMatic: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { btn, selectedData } = this.props |
| | | const { btn, selectedData, BData } = this.props |
| | | let disabled = false |
| | | |
| | | if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | selectedData.forEach(item => { |
| | | let s = item[btn.controlField] + '' |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | this.setState({disabled}) |
| | | this.setState({hidden: disabled && btn.control === 'hidden'}) |
| | | } else if (btn.control === 'parent') { |
| | | if (!BData || !BData.hasOwnProperty(btn.controlField)) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | let s = BData[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | this.setState({hidden: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (this.props.disabled || disabled) { |
| | | this.setState({disabled: true}) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { position } = this.props |
| | | const { btn } = this.props |
| | | |
| | | if (position === 'toolbar') { |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | |
| | | if (btn.autoMatic) { |
| | | MKEmitter.addListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit) |
| | | } |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { btn, selectedData } = this.props |
| | | const { btn, selectedData, BData } = this.props |
| | | |
| | | let disabled = false |
| | | if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) { |
| | | let disabled = false |
| | | |
| | | if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | nextProps.selectedData.forEach(item => { |
| | | let s = item[btn.controlField] + '' |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | } |
| | | this.setState({disabled}) |
| | | this.setState({disabled, hidden: disabled && btn.control === 'hidden'}) |
| | | } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) { |
| | | if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | let s = nextProps.BData[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | this.setState({hidden: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nextProps.disabled || disabled) { |
| | | this.setState({disabled: true}) |
| | | } else { |
| | | this.setState({disabled: false}) |
| | | } |
| | | } |
| | | |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('triggerBtnId', this.actionTrigger) |
| | | MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit) |
| | | } |
| | | |
| | | /** |
| | | * @description 按钮状态改变 |
| | | */ |
| | | updateStatus = (type) => { |
| | | if (type === 'start') { |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | } else if (type === 'over') { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | } |
| | | triggerBtnPopSubmit = (id) => { |
| | | const { btn } = this.props |
| | | |
| | | if (btn.uuid !== id) return |
| | | |
| | | this.handleOk() |
| | | } |
| | | |
| | | /** |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record) => { |
| | | actionTrigger = (triggerId, record, type) => { |
| | | const { Tab, BID, btn, selectedData, setting } = this.props |
| | | const { loading } = this.state |
| | | const { loading, disabled } = this.state |
| | | |
| | | if ((triggerId && btn.uuid !== triggerId) || loading) return |
| | | if (loading || disabled) return |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | notification.warning({ |
| | |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) { |
| | | return |
| | | } |
| | | |
| | | this.setState({autoMatic: type === 'autoMatic'}) |
| | | |
| | | let _this = this |
| | | let data = record || selectedData || [] |
| | |
| | | return |
| | | } |
| | | |
| | | this.setState({ |
| | | selines: data |
| | | }) |
| | | |
| | | if (btn.execMode === 'pop') { |
| | | this.updateStatus('start') |
| | | let modal = this.state.btnconfig |
| | | if (!modal && btn.modal) { |
| | | modal = this.handleModelConfig(btn.modal) |
| | | } |
| | | |
| | | this.setState({ |
| | | tabledata: data, |
| | | loading: true, |
| | | btnconfig: modal |
| | | }, () => { |
| | | this.improveAction() |
| | | }) |
| | | } else if (btn.execMode === 'prompt') { |
| | | this.updateStatus('start') |
| | | this.setState({ loading: true }) |
| | | confirm({ |
| | | title: this.state.dict['main.action.confirm.tip'], |
| | | onOk() { |
| | | _this.triggerPrint(data) |
| | | }, |
| | | onCancel() { |
| | | _this.updateStatus('over') |
| | | _this.setState({ loading: false }) |
| | | } |
| | | }) |
| | | } else { |
| | |
| | | triggerPrint = (data, formlist = []) => { |
| | | const { btn } = this.props |
| | | let formdata = {} |
| | | let baseCount = 1 |
| | | let baseType = '' |
| | | let baseTemp = btn.verify.Template || '' |
| | | |
| | | formlist.forEach(_data => { |
| | | formdata[_data.key] = _data.value |
| | | |
| | | if (!_data.value) return |
| | | |
| | | if (_data.key.toLowerCase() === 'printcount') { |
| | | baseCount = +_data.value |
| | | } else if (_data.key.toLowerCase() === 'printtype') { |
| | | baseType = _data.value |
| | | } else if (_data.key.toLowerCase() === 'templateid') { |
| | | baseTemp = _data.value |
| | | } |
| | | }) |
| | | |
| | | let printlist = [] |
| | | let templates = [] |
| | | let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1) |
| | | |
| | | if (isNaN(printCount) || printCount < 1) { |
| | | printCount = 1 |
| | | if (isNaN(baseCount) || baseCount < 1) { |
| | | baseCount = 1 |
| | | } |
| | | |
| | | new Promise(resolve => { |
| | | if (btn.intertype === 'system') { // 使用系统时,直接从表格或表单中选取数据 |
| | | let printcell = {} |
| | | |
| | | printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' |
| | | printcell.printCount = printCount |
| | | printcell.templateID = btn.verify.Template || '' |
| | | |
| | | if (btn.Ot === 'notRequired') { |
| | | let printcell = {} |
| | | |
| | | printcell.printType = baseType |
| | | printcell.printCount = baseCount |
| | | printcell.templateID = baseTemp |
| | | printcell.data = [formdata] |
| | | |
| | | templates.push(printcell.templateID) |
| | | |
| | | printlist.push(printcell) |
| | | } else { |
| | | printcell.data = data.map(cell => { |
| | | return {...cell, ...formdata} |
| | | data.forEach(cell => { |
| | | let _cell = {...cell, ...formdata} |
| | | |
| | | let printcell = {data: [_cell]} |
| | | |
| | | printcell.templateID = baseTemp |
| | | printcell.printType = baseType |
| | | printcell.printCount = 0 |
| | | |
| | | Object.keys(_cell).forEach(key => { |
| | | if (!_cell[key]) return |
| | | |
| | | let _key = key.toLowerCase() |
| | | |
| | | if (_key === 'templateid') { |
| | | printcell.templateID = _cell[key] |
| | | } else if (_key === 'printtype') { |
| | | printcell.printType = _cell[key] |
| | | } else if (_key === 'printcount') { |
| | | printcell.printCount = +_cell[key] |
| | | } |
| | | }) |
| | | |
| | | if (isNaN(printcell.printCount) || printcell.printCount < 1) { |
| | | printcell.printCount = baseCount |
| | | } |
| | | |
| | | templates.push(printcell.templateID) |
| | | |
| | | printlist.push(printcell) |
| | | }) |
| | | } |
| | | |
| | | templates.push(printcell.templateID) |
| | | |
| | | printlist.push(printcell) |
| | | |
| | | resolve(true) |
| | | } else { |
| | |
| | | // 系统打印数据,校验data字段 |
| | | if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return |
| | | |
| | | cell.templateID = cell.templateID || cell.TemplateID || cell.Templateid || cell.templateid || btn.verify.Template |
| | | cell.printType = cell.printType || cell.PrintType || cell.printtype || cell.Printtype || formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' |
| | | let templateID = baseTemp |
| | | let printType = baseType |
| | | let printCount = 0 |
| | | |
| | | let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0) |
| | | Object.keys(cell).forEach(key => { |
| | | if (!cell[key]) return |
| | | |
| | | if (isNaN(_printCount) || _printCount < 1) { |
| | | _printCount = printCount |
| | | let _key = key.toLowerCase() |
| | | |
| | | if (_key === 'templateid') { |
| | | templateID = cell[key] |
| | | } else if (_key === 'printtype') { |
| | | printType = cell[key] |
| | | } else if (_key === 'printcount') { |
| | | printCount = +cell[key] |
| | | } |
| | | }) |
| | | |
| | | cell.templateID = templateID |
| | | cell.printType = printType |
| | | cell.printCount = printCount |
| | | |
| | | if (isNaN(cell.printCount) || cell.printCount < 1) { |
| | | cell.printCount = baseCount |
| | | } |
| | | |
| | | cell.printCount = _printCount |
| | | |
| | | templates.push(cell.templateID) |
| | | |
| | |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | |
| | | Api.getLocalConfig(param).then(result => { |
| | | Api.genericInterface(param).then(result => { |
| | | result.tempId = tempId |
| | | resolve(result) |
| | | }) |
| | |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('data', 'form', 'printer', 'notification', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification) |
| | | let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) |
| | | |
| | | // 自定义打印示例 |
| | | // let defaultPrinter = printer.defaultPrinter || 'lackprinter' |
| | |
| | | // for (let i = 0; i < 32; i++) { |
| | | // uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1)) |
| | | // } |
| | | // uuid = uuid.join('') |
| | | // return uuid |
| | | // return uuid.join('') |
| | | // } |
| | | // if (printer.printerTypeList && printer.printerTypeList.length > 0) { |
| | | // printer.printerTypeList.forEach(cell => { |
| | |
| | | // }) |
| | | // } |
| | | |
| | | // let jdList = [] |
| | | // let otherList = [] |
| | | // data.forEach(item => { |
| | | // if (item.CustomData) { |
| | | // item.CustomData = JSON.parse(item.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) |
| | | // } |
| | | // if (item.PrintData) { |
| | | // item.PrintData = JSON.parse(item.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) |
| | | // item.PrintData.data = {...form, ...item.PrintData.data} |
| | | // } |
| | | // let jdList = []; |
| | | // let jdNewList = []; |
| | | // let otherList = []; |
| | | // let _map = new Map() |
| | | // data.forEach(m => { |
| | | // if (!m.print_data || m.print_data.length === 0) return |
| | | |
| | | // if (!item.PrintData) { |
| | | // return |
| | | // } |
| | | // m.print_data.forEach(n => { |
| | | // if (n.InsideBill) { |
| | | // if (_map.has(n.InsideBill)) { |
| | | // return |
| | | // } |
| | | // _map.set(n.InsideBill, true) |
| | | // } |
| | | // if (n.CustomData) { |
| | | // n.CustomData = JSON.parse(n.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) |
| | | // } |
| | | |
| | | // if (item.PrintData.ectype === 'jdpop') { |
| | | // jdList.push(item) |
| | | // } else { |
| | | // otherList.push(item) |
| | | // } |
| | | // if (n.hasOwnProperty('StdTemplate')) { |
| | | // jdNewList.push(n); |
| | | // return |
| | | // } else if (!n.PrintData) { |
| | | // return |
| | | // } |
| | | |
| | | // n.PrintData = JSON.parse(n.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r")) |
| | | // n.PrintData.data = {...form, ...n.PrintData.data} |
| | | |
| | | // if (n.PrintData.ectype === 'jdpop') { |
| | | // jdList.push(n) |
| | | // } else { |
| | | // otherList.push(n) |
| | | // } |
| | | // }) |
| | | // }) |
| | | |
| | | // if (jdList.length === 0 && otherList.length === 0) { |
| | | // if (jdList.length === 0 && otherList.length === 0 && jdNewList.length === 0) { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: '无打印数据!', |
| | |
| | | // return |
| | | // } |
| | | |
| | | // let execPrint = (list, linkUrl) => { |
| | | // let printdata = {} |
| | | // let execPrint = (list, linkUrl, type) => { |
| | | // let printdata = {}; |
| | | // let printerList = []; |
| | | |
| | | // list.forEach(res => { |
| | | // let _printer = defaultPrinter |
| | | // if (type === 'jd') { |
| | | // printerList = list.map(m => { |
| | | // let _printer = defaultPrinter; |
| | | |
| | | // if (res.printType && printers[res.printType]) { |
| | | // _printer = printers[res.printType] |
| | | // } |
| | | |
| | | // printdata[_printer] = printdata[_printer] || [] |
| | | |
| | | // printdata[_printer].push(res) |
| | | // }) |
| | | |
| | | // let printerList = [] |
| | | |
| | | // Object.keys(printdata).forEach(printer => { |
| | | // let _documents = [] |
| | | // printdata[printer].forEach(item => { |
| | | // let _cell = { |
| | | // documentID: getuuid(), |
| | | // contents: [] |
| | | // if (m.printType && printers[m.printType]) { |
| | | // _printer = printers[m.printType]; |
| | | // } |
| | | |
| | | // if (item.PrintData) { |
| | | // _cell.contents.push(item.PrintData) |
| | | // return { |
| | | // orderType: "print", |
| | | // parameters: { |
| | | // printName: _printer === 'lackprinter' ? '' : _printer, |
| | | // tempUrl: m.StdTemplate, |
| | | // customTempUrl: m.CusTemplate, |
| | | // customData: [m.CustomData], |
| | | // printData: [m.PrintData] |
| | | // } |
| | | // } |
| | | // if (item.CustomData) { |
| | | // _cell.contents.push(item.CustomData) |
| | | // }) |
| | | // } else { |
| | | // list.forEach(res => { |
| | | // let _printer = defaultPrinter |
| | | |
| | | // if (res.printType && printers[res.printType]) { |
| | | // _printer = printers[res.printType] |
| | | // } |
| | | |
| | | // for (let i = 0; i < item.printCount; i++) { |
| | | // printdata[_printer] = printdata[_printer] || [] |
| | | |
| | | // printdata[_printer].push(res) |
| | | // }) |
| | | |
| | | // Object.keys(printdata).forEach(printer => { |
| | | // let _documents = [] |
| | | // printdata[printer].forEach(item => { |
| | | // let _cell = { |
| | | // documentID: getuuid(), |
| | | // contents: [] |
| | | // } |
| | | |
| | | // if (item.PrintData) { |
| | | // _cell.contents.push(item.PrintData) |
| | | // } |
| | | // if (item.CustomData) { |
| | | // _cell.contents.push(item.CustomData) |
| | | // } |
| | | |
| | | // _documents.push(_cell) |
| | | // } |
| | | // }) |
| | | // printerList.push({ |
| | | // cmd: 'print', |
| | | // requestID: '', |
| | | // version: '', |
| | | // task: { |
| | | // taskID: getuuid(), |
| | | // preview: false, |
| | | // printer: printer === 'lackprinter' ? '' : printer, |
| | | // documents: _documents |
| | | // } |
| | | // }) |
| | | // }) |
| | | // printerList.push({ |
| | | // cmd: 'print', |
| | | // requestID: '', |
| | | // version: '', |
| | | // task: { |
| | | // taskID: getuuid(), |
| | | // preview: false, |
| | | // printer: printer, |
| | | // documents: _documents |
| | | // } |
| | | // }) |
| | | // }) |
| | | |
| | | // let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0] |
| | | // } |
| | | |
| | | // let socket = new WebSocket('ws://' + linkUrl) |
| | | |
| | | // // 打开Socket |
| | | // socket.onopen = () =>{ |
| | | // if (lackItems) { |
| | | // let request = { |
| | | // requestID: '', |
| | | // version: '', |
| | | // cmd: 'getPrinters' |
| | | // } |
| | | // socket.send(JSON.stringify(request)) |
| | | // } else { |
| | | // printerList.forEach(cell => { |
| | | // socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n")) |
| | | // }) |
| | | // printerList.forEach((cell, i) => { |
| | | // setTimeout(() => { |
| | | // socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n")) |
| | | // }, 1000 * i) |
| | | // }); |
| | | |
| | | // notification.success({ |
| | | // top: 92, |
| | | // message: '打印请求已发出。', |
| | | // duration: 2 |
| | | // }) |
| | | // } |
| | | // } |
| | | // // 监听消息 |
| | | // socket.onmessage = (event) => { |
| | |
| | | // } |
| | | // } |
| | | |
| | | // if (data && data.cmd === 'getPrinters' && data.status) { |
| | | // printerList.forEach(cell => { |
| | | // if (cell.task.printer === 'lackprinter') { |
| | | // cell.task.printer = data.defaultPrinter |
| | | // } |
| | | // socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n")) |
| | | // }) |
| | | |
| | | // notification.success({ |
| | | // top: 92, |
| | | // message: '打印请求已发出。', |
| | | // duration: 2 |
| | | // }) |
| | | // } else if (data && data.message && !data.status) { |
| | | // if (data && data.message && !data.status) { |
| | | // notification.warning({ |
| | | // top: 92, |
| | | // message: data.message, |
| | |
| | | // } |
| | | // } |
| | | |
| | | // if (jdNewList.length > 0) { |
| | | // execPrint(jdNewList, '127.0.0.1:9113', 'jd'); |
| | | // } |
| | | // if (jdList.length > 0) { |
| | | // execPrint(jdList, '127.0.0.1:13529') |
| | | // } |
| | |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let evalfunc = eval('(true && function (data, form, printer, notification) {' + btn.verify.printFunc + '})') |
| | | evalfunc(printlist, formdata, btn.verify, notification) |
| | | let evalfunc = eval('(true && function (data, form, printer, notification, Api, systemType) {' + btn.verify.printFunc + '})') |
| | | evalfunc(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) |
| | | } catch (error) { |
| | | console.warn(error) |
| | | notification.warning({ |
| | |
| | | _param[setting.primaryKey] = cell[setting.primaryKey] |
| | | } |
| | | |
| | | let _cell = {} |
| | | if (index !== 0) { |
| | | Object.keys(cell).forEach(key => { |
| | | _cell[key.toLowerCase()] = cell[key] |
| | | }) |
| | | } |
| | | |
| | | formlist.forEach(_data => { |
| | | if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) { |
| | | _param[_data.key] = cell[_data.key] |
| | | if (index !== 0 && _data.readin && _cell.hasOwnProperty(_data.key.toLowerCase())) { |
| | | _param[_data.key] = _cell[_data.key.toLowerCase()] |
| | | } else { |
| | | _param[_data.key] = _data.value |
| | | } |
| | |
| | | // 外部请求 |
| | | _outParam = JSON.parse(JSON.stringify(res)) |
| | | |
| | | if (this.props.menuType === 'HS') { |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | res.rduri = options.cloudServiceApi |
| | | res.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | res.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | |
| | | res.rduri = btn.proInterface |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | |
| | | let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') |
| | | if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) { |
| | | res.$login = true |
| | | } |
| | | } |
| | | } |
| | |
| | | if (!configParam) { |
| | | error = '打印模板解析错误!' |
| | | } else { |
| | | let control = configParam.elements.map(element => { |
| | | let control = [] |
| | | let rotate = configParam.rotate || 0 |
| | | let offsetTop = 0 |
| | | let offsetLeft = 0 |
| | | |
| | | if (rotate === 90) { |
| | | offsetTop = configParam.width - configParam.height |
| | | } else if (rotate === 270) { |
| | | offsetLeft = configParam.height - configParam.width |
| | | } |
| | | |
| | | configParam.elements.forEach(element => { |
| | | let _field = element.field |
| | | |
| | | if (_field === 'other_field') { |
| | |
| | | Type: element.type, |
| | | Value: element.value || '', |
| | | Field: _field, |
| | | Left: element.left, |
| | | Top: element.top, |
| | | Left: element.left + offsetLeft, |
| | | Top: element.top + offsetTop, |
| | | Width: element.width, |
| | | Height: element.height, |
| | | Rotate: element.rotate, |
| | | Rotate: rotate, |
| | | // Rotate: element.rotate, |
| | | BorderSize: element.borderSize / 10, |
| | | BorderColor: element.borderColor, |
| | | Align: element.align, |
| | |
| | | item.Trimming = '' |
| | | if (!item.Width) { |
| | | item.Width = item.BorderSize |
| | | item.Left = item.Left - item.Width |
| | | item.Left = item.Left - item.Width + 0.1 |
| | | } else if (!item.Height) { |
| | | item.Height = item.BorderSize |
| | | item.Top = item.Top - item.Height |
| | | item.Top = item.Top - item.Height + 0.1 |
| | | } |
| | | item.BackColor = element.borderColor |
| | | item.BorderSize = 0 |
| | | } else if (item.Type === 'image') { |
| | | item.ImageWidth = element.imgWidth |
| | |
| | | } |
| | | } |
| | | |
| | | return item |
| | | control.push(item) |
| | | }) |
| | | |
| | | let down = false |
| | | |
| | | if (rotate === 90 || rotate === 270) { |
| | | down = true |
| | | } |
| | | |
| | | _configparam = { |
| | | Version: '', |
| | |
| | | Description: configParam.remark, |
| | | PrintTempNO: configParam.PrintTempNO, |
| | | PageSetting: { |
| | | Width: configParam.width, |
| | | Height: configParam.height, |
| | | Width: down ? configParam.height : configParam.width, |
| | | Height: down ? configParam.width : configParam.height, |
| | | Left: '0', |
| | | Right: '0', |
| | | Top: '0', |
| | |
| | | }) |
| | | |
| | | if (list.length === 0) { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '未获取到打印信息!', |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | if (btn.verify.emptyTip === 'false') { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '未获取到打印信息!', |
| | | ErrMesg: '', |
| | | status: true |
| | | }) |
| | | } else { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '未获取到打印信息!', |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | } |
| | | return |
| | | } else if (_errors.length > 0) { |
| | | let lackerror = [] |
| | |
| | | */ |
| | | execSuccess = (res) => { |
| | | const { btn } = this.props |
| | | const { autoMatic, btnconfig } = this.state |
| | | |
| | | if (res && res.ErrCode === 'S') { // 执行成功 |
| | | if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 执行成功 |
| | | notification.success({ |
| | | top: 92, |
| | | message: res.ErrMesg || this.state.dict['main.action.confirm.success'], |
| | | duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2 |
| | | }) |
| | | } else if (res && res.ErrCode === 'Y') { // 执行成功 |
| | | } else if (res.ErrCode === 'Y') { // 执行成功 |
| | | Modal.success({ |
| | | title: res.ErrMesg || this.state.dict['main.action.confirm.success'] |
| | | }) |
| | | } else if (res && res.ErrCode === '-1') { // 完成后不提示 |
| | | } else if (res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | | } |
| | | |
| | | |
| | | if (autoMatic || !btnconfig || btnconfig.setting.finish !== 'unclose') { |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: false |
| | | loading: false, |
| | | confirmLoading: false |
| | | }) |
| | | |
| | | if (autoMatic) { |
| | | MKEmitter.emit('autoExecOver', btn.uuid, 'success') |
| | | return |
| | | } |
| | | |
| | | if (btn.execSuccess !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn) |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines) |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | execError = (res) => { |
| | | const { btn } = this.props |
| | | const { btnconfig, autoMatic } = this.state |
| | | |
| | | if (res.ErrCode === 'E') { |
| | | if (res.ErrCode === 'E' && !autoMatic) { |
| | | Modal.error({ |
| | | title: res.message || res.ErrMesg, |
| | | }) |
| | | } else if (res.ErrCode === 'N') { |
| | | } else if (res.ErrCode === 'N' || autoMatic) { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: false |
| | | loading: false, |
| | | confirmLoading: false |
| | | }) |
| | | |
| | | if (autoMatic) { |
| | | MKEmitter.emit('autoExecOver', btn.uuid, 'error') |
| | | return |
| | | } |
| | | |
| | | if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) { |
| | | MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus) |
| | | } |
| | | |
| | | if (btn.execError !== 'never') { |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn) |
| | | MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines) |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | improveAction = () => { |
| | | const { btn } = this.props |
| | | const { btnconfig } = this.state |
| | | const { btnconfig, autoMatic } = this.state |
| | | |
| | | if (btnconfig) { |
| | | if (btnconfig.setting.display === 'prompt') { // 如果表单以是否框展示 |
| | | if (!autoMatic && (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec')) { // 如果表单以是否框展示 |
| | | this.modelconfirm() |
| | | } else { |
| | | this.setState({ |
| | |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | this.updateStatus('over') |
| | | this.setState({ loading: false }) |
| | | } else if (!_LongParam || (btn.execMode === 'pop' && _LongParam.type !== 'Modal')) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到按钮配置信息!', |
| | | duration: 5 |
| | | }) |
| | | this.updateStatus('over') |
| | | this.setState({ loading: false }) |
| | | } else { |
| | | _LongParam = updateForm(_LongParam) |
| | | _LongParam = this.handleModelConfig(_LongParam) |
| | |
| | | this.setState({ |
| | | btnconfig: _LongParam |
| | | }, () => { |
| | | if (_LongParam.setting.display === 'prompt') { // 如果表单以是否框展示 |
| | | if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 如果表单以是否框展示 |
| | | this.modelconfirm() |
| | | } else { |
| | | this.setState({ |
| | |
| | | * @description 模态框(表单),确认 |
| | | */ |
| | | handleOk = () => { |
| | | if (!this.formRef) return |
| | | |
| | | this.formRef.handleConfirm().then(res => { |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | this.triggerPrint(this.state.tabledata, res) |
| | | this.setState({ confirmLoading: true }) |
| | | this.triggerPrint(this.state.selines, res) |
| | | }) |
| | | } |
| | | |
| | |
| | | */ |
| | | handleCancel = () => { |
| | | this.setState({ |
| | | visible: false |
| | | loading: false, |
| | | visible: false, |
| | | confirmLoading: false |
| | | }) |
| | | this.updateStatus('over') |
| | | } |
| | | |
| | | modelconfirm = () => { |
| | | const { BData } = this.props |
| | | const { btnconfig, tabledata } = this.state |
| | | const { btnconfig, selines } = this.state |
| | | let _this = this |
| | | let result = [] |
| | | let _data = {} |
| | | let BData = {} |
| | | |
| | | if (selines[0]) { |
| | | Object.keys(selines[0]).forEach(key => { |
| | | _data[key.toLowerCase()] = selines[0][key] |
| | | }) |
| | | } |
| | | if (this.props.BData) { |
| | | Object.keys(this.props.BData).forEach(key => { |
| | | BData[key.toLowerCase()] = this.props.BData[key] |
| | | }) |
| | | } |
| | | |
| | | btnconfig.fields.forEach(item => { |
| | | if (!item.field) return |
| | |
| | | _readin = false |
| | | } |
| | | |
| | | if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) { |
| | | _initval = BData[item.field] |
| | | } else if (_readin && tabledata[0] && tabledata[0].hasOwnProperty(item.field)) { |
| | | _initval = tabledata[0][item.field] |
| | | if (item.type === 'linkMain' && BData.hasOwnProperty(item.field.toLowerCase())) { |
| | | _initval = BData[item.field.toLowerCase()] |
| | | } else if (_readin && _data.hasOwnProperty(item.field.toLowerCase())) { |
| | | _initval = _data[item.field.toLowerCase()] |
| | | } else if (item.type === 'date' && _initval) { |
| | | _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD') |
| | | } else if (item.type === 'datemonth' && _initval) { |
| | |
| | | _fieldlen = item.fieldlength || 512 |
| | | } else if (item.type === 'number') { |
| | | _fieldlen = item.decimal ? item.decimal : 0 |
| | | } else if (item.type === 'rate') { |
| | | item.rateCount = item.rateCount || 5 |
| | | let allowHalf = item.allowHalf === 'true' |
| | | |
| | | if (allowHalf) { |
| | | _initval = parseFloat(_initval) |
| | | if (_initval % 0.5 !== 0) { |
| | | _initval = parseInt(_initval) |
| | | } |
| | | } else { |
| | | _initval = parseInt(_initval) |
| | | } |
| | | |
| | | if (isNaN(_initval) || _initval < 0) { |
| | | _initval = 0 |
| | | } else if (_initval > item.rateCount) { |
| | | _initval = item.rateCount |
| | | } |
| | | } |
| | | |
| | | if (_initval === undefined) { |
| | |
| | | result.push({ |
| | | key: item.field, |
| | | readonly: item.readonly === 'true', |
| | | readin: _readin, |
| | | readin: item.readin !== 'false' && item.readin !== 'top', |
| | | fieldlen: _fieldlen, |
| | | type: item.type, |
| | | value: _initval |
| | | }) |
| | | }) |
| | | |
| | | confirm({ |
| | | title: this.state.dict['main.action.confirm.tip'], |
| | | onOk() { |
| | | _this.triggerPrint(tabledata, result) |
| | | }, |
| | | onCancel() { |
| | | _this.updateStatus('over') |
| | | } |
| | | }) |
| | | if (btnconfig.setting.display === 'exec') { |
| | | this.execSubmit(selines, () => {}, result) |
| | | } else { |
| | | confirm({ |
| | | title: this.state.dict['main.action.confirm.tip'], |
| | | onOk() { |
| | | _this.triggerPrint(selines, result) |
| | | }, |
| | | onCancel() { |
| | | _this.setState({ loading: false }) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | if (!this.state.visible || !btnconfig || !btnconfig.setting) return null |
| | | |
| | | let title = btnconfig.setting.title |
| | | let width = btnconfig.setting.width + 'vw' |
| | | let title = btn.label |
| | | let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw' |
| | | let clickouter = false |
| | | let container = document.body |
| | | |
| | |
| | | (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) || |
| | | (btnconfig.setting.container === 'tab' && btn.ContainerId) |
| | | ) { |
| | | width = btnconfig.setting.width + '%' |
| | | width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%' |
| | | container = () => document.getElementById(this.props.ContainerId || btn.ContainerId) |
| | | } |
| | | |
| | |
| | | getContainer={container} |
| | | wrapClassName='action-modal' |
| | | visible={this.state.visible} |
| | | confirmLoading={this.state.confirmLoading} |
| | | width={width} |
| | | onOk={this.handleOk} |
| | | onCancel={this.handleCancel} |
| | |
| | | <MutilForm |
| | | BID={BID} |
| | | dict={this.state.dict} |
| | | menuType={this.props.menuType} |
| | | action={btnconfig} |
| | | inputSubmit={this.handleOk} |
| | | data={this.state.tabledata[0]} |
| | | data={this.state.selines[0]} |
| | | BData={this.props.BData} |
| | | wrappedComponentRef={(inst) => this.formRef = inst} |
| | | /> |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { btn, show } = this.props |
| | | const { loadingNumber, loading, disabled } = this.state |
| | | const { btn } = this.props |
| | | const { loading, disabled, hidden } = this.state |
| | | |
| | | if (show === 'actionList') { |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | icon={btn.icon} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | className={'mk-btn mk-' + btn.class} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button> |
| | | {this.getModels()} |
| | | </div> |
| | | } else { // icon、text、 all 卡片 |
| | | let label = '' |
| | | let icon = '' |
| | | if (hidden) return null |
| | | |
| | | if (show === 'button') { |
| | | label = btn.label |
| | | icon = btn.icon || '' |
| | | } else if (show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> |
| | | icon = '' |
| | | } else if (show === 'icon') { |
| | | icon = btn.icon || '' |
| | | // } else if (show === 'text') { |
| | | } else { |
| | | label = btn.label |
| | | } |
| | | let label = '' |
| | | let icon = '' |
| | | let type = 'link' |
| | | let className = '' |
| | | |
| | | return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> |
| | | <Button |
| | | type="link" |
| | | title={show === 'icon' ? btn.label : ''} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style} |
| | | icon={icon} |
| | | onClick={() => {this.actionTrigger()}} |
| | | >{label}</Button> |
| | | {this.getModels()} |
| | | </div> |
| | | if (btn.show === 'button') { |
| | | label = btn.label |
| | | icon = btn.icon || '' |
| | | } else if (btn.show === 'link') { |
| | | label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> |
| | | icon = '' |
| | | } else if (btn.show === 'icon') { |
| | | icon = btn.icon || '' |
| | | } else if (!btn.$toolbtn) { |
| | | icon = btn.icon || '' |
| | | label = btn.label |
| | | className = 'mk-btn mk-' + btn.class |
| | | } else { |
| | | type = '' |
| | | icon = btn.icon || '' |
| | | label = btn.label |
| | | className = 'mk-btn mk-' + btn.class |
| | | } |
| | | |
| | | return <> |
| | | <Button |
| | | type={type} |
| | | title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} |
| | | loading={loading} |
| | | disabled={disabled} |
| | | style={btn.style || null} |
| | | icon={icon} |
| | | className={className} |
| | | onClick={(e) => {e.stopPropagation(); this.actionTrigger()}} |
| | | >{label}</Button> |
| | | <span onClick={(e) => {e.stopPropagation()}}>{this.getModels()}</span> |
| | | </> |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | tabviews: state.tabviews, |
| | | menuType: state.editLevel |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(PrintButton) |
| | | export default PrintButton |