From bde2916433c7830e2879e6524e32b9f6c8bd0bab Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 02 一月 2022 16:31:32 +0800 Subject: [PATCH] 2022-01-02 --- src/tabviews/zshare/actionList/printbutton/index.jsx | 172 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 132 insertions(+), 40 deletions(-) diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx index ef3fe55..0e0ceb7 100644 --- a/src/tabviews/zshare/actionList/printbutton/index.jsx +++ b/src/tabviews/zshare/actionList/printbutton/index.jsx @@ -3,7 +3,7 @@ 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' @@ -13,7 +13,8 @@ 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 @@ -22,7 +23,6 @@ class PrintButton extends Component { static propTpyes = { show: PropTypes.any, // 鎸夐挳鏄剧ず鏍峰紡鎺у埗 - position: PropTypes.any, // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar BID: PropTypes.string, // 涓昏〃ID BData: PropTypes.any, // 涓昏〃鏁版嵁 selectedData: PropTypes.any, // 瀛愯〃涓�夋嫨鏁版嵁 @@ -31,21 +31,24 @@ 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, loading: false, disabled: false, - loadingNumber: '' + hidden: false, + loadingNumber: '', + 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) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� @@ -55,7 +58,22 @@ 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}) } } @@ -64,15 +82,20 @@ } componentDidMount () { + const { btn } = this.props + 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] + '' @@ -81,7 +104,24 @@ } }) } - 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}) } } @@ -90,6 +130,15 @@ return } MKEmitter.removeListener('triggerBtnId', this.actionTrigger) + MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit) + } + + triggerBtnPopSubmit = (id) => { + const { btn } = this.props + + if (btn.uuid !== id) return + + this.handleOk() } /** @@ -113,6 +162,8 @@ return } } + + this.setState({autoMatic: type === 'autoMatic'}) let _this = this let data = record || selectedData || [] @@ -150,6 +201,10 @@ return } + this.setState({ + selines: data + }) + if (btn.execMode === 'pop') { let modal = this.state.btnconfig if (!modal && btn.modal) { @@ -158,7 +213,6 @@ this.setState({ loading: true, - tabledata: data, btnconfig: modal }, () => { this.improveAction() @@ -1206,8 +1260,9 @@ */ execSuccess = (res) => { const { btn } = this.props + const { autoMatic } = this.state - if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛 + if ((res && res.ErrCode === 'S') || autoMatic) { // 鎵ц鎴愬姛 notification.success({ top: 92, message: res.ErrMesg || this.state.dict['main.action.confirm.success'], @@ -1220,13 +1275,18 @@ } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず } - + this.setState({ loading: 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) } } @@ -1238,13 +1298,13 @@ */ execError = (res) => { const { btn } = this.props - const { btnconfig } = this.state + 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, @@ -1265,12 +1325,17 @@ loading: 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) } } @@ -1313,10 +1378,10 @@ */ 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({ @@ -1360,7 +1425,7 @@ this.setState({ btnconfig: _LongParam }, () => { - if (_LongParam.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず + if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず this.modelconfirm() } else { this.setState({ @@ -1377,14 +1442,17 @@ * @description 妯℃�佹锛堣〃鍗曪級锛岀‘璁� */ handleOk = () => { - const { btnconfig } = this.state + const { btnconfig, autoMatic } = this.state + + if (!this.formRef) return + this.formRef.handleConfirm().then(res => { - if (btnconfig.setting.finish !== 'unclose') { + if (btnconfig.setting.finish !== 'unclose' || autoMatic) { this.setState({ visible: false }) } - this.triggerPrint(this.state.tabledata, res) + this.triggerPrint(this.state.selines, res) }) } @@ -1400,7 +1468,7 @@ modelconfirm = () => { const { BData } = this.props - const { btnconfig, tabledata } = this.state + const { btnconfig, selines } = this.state let _this = this let result = [] @@ -1415,8 +1483,8 @@ 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] + } else if (_readin && selines[0] && selines[0].hasOwnProperty(item.field)) { + _initval = selines[0][item.field] } else if (item.type === 'date' && _initval) { _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD') } else if (item.type === 'datemonth' && _initval) { @@ -1430,6 +1498,24 @@ _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) { @@ -1446,15 +1532,19 @@ }) }) - confirm({ - title: this.state.dict['main.action.confirm.tip'], - onOk() { - _this.triggerPrint(tabledata, result) - }, - onCancel() { - _this.setState({ loading: false }) - } - }) + 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 }) + } + }) + } } /** @@ -1501,7 +1591,7 @@ 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} /> @@ -1511,7 +1601,9 @@ render() { const { btn, show } = this.props - const { loadingNumber, loading, disabled } = this.state + const { loadingNumber, loading, disabled, hidden } = this.state + + if (hidden) return null if (show === 'actionList') { return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> @@ -1532,7 +1624,7 @@ label = btn.label icon = btn.icon || '' } else if (show === 'link') { - label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> + label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> icon = '' } else if (show === 'icon') { icon = btn.icon || '' -- Gitblit v1.8.0