/*! Copyright (c) REBUILD and/or its owners. All rights reserved. rebuild is dual-licensed under commercial and open source licenses (GPLv3). See LICENSE and COMMERCIAL in the project root for license information. */ /* eslint-disable no-unused-vars */ // 审批流程 class ApprovalProcessor extends React.Component { constructor(props) { super(props) this.state = { ...props } } render() { return (
{this.state.state === 1 && this.renderStateDraft()} {this.state.state === 2 && this.renderStateProcessing()} {this.state.state === 10 && this.renderStateApproved()} {this.state.state === 11 && this.renderStateRejected()} {this.state.state === 12 && this.renderStateCanceled()} {this.state.state === 13 && this.renderStateRevoked()}
) } renderStateDraft() { return (
{$L('当前记录尚未提交审批,请在信息完善后尽快提交')}
) } renderStateProcessing() { window.RbViewPage && window.RbViewPage.setReadonly(true) let aMsg = $L('当前记录正在审批中') let imApproverCurrent = false if (this.state.imApprover) { if (this.state.imApproveSatate === 1) { aMsg = $L('当前记录正在等待你审批') imApproverCurrent = true } else if (this.state.imApproveSatate === 10) aMsg = $L('你已审批同意,正在等待其他人审批') else if (this.state.imApproveSatate === 11) aMsg = $L('你已驳回审批') } return (
{this.state.imApprover && this.state.imApproveSatate === 1 && ( )} {this.state.canUrge && imApproverCurrent === false && ( )} {this.state.canCancel && ( )} {this.state.canCancel38 && ( )}
{aMsg}
) } renderStateApproved() { window.RbViewPage && window.RbViewPage.setReadonly(true) return (
{(rb.isAdminUser || this.state.canRevoke) && ( )}
{$L('当前记录已审批完成')}
) } renderStateRejected() { return (
{$L('审批被驳回,可在信息完善后再次提交')}
) } renderStateCanceled() { return (
{$L('审批已撤回,请在信息完善后再次提交')}
) } renderStateRevoked() { return (
{$L('审批已撤销,请在信息完善后再次提交')}
) } componentDidMount() { $.get(`/app/entity/approval/state?record=${this.props.id}`, (res) => { if (res.error_code === 0 && res.data) { this.setState(res.data) } else { RbHighbar.error($L('无法获取审批状态')) } }) } submit = () => { const that = this if (this._SubmitForm) { // this._SubmitForm.show(null, () => that._SubmitForm.reload()) this._SubmitForm.show() } else { renderRbcomp(, function () { that._SubmitForm = this }) } } approve = () => { const that = this if (this._ApproveForm) { // this._ApproveForm.show(null, () => that._ApproveForm.reload()) this._ApproveForm.show() } else { renderRbcomp(, function () { that._ApproveForm = this }) } } cancel = () => { const that = this RbAlert.create($L('将要撤回已提交审批。是否继续?'), { confirm: function () { this.disabled(true, true) $.post(`/app/entity/approval/cancel?record=${that.props.id}`, (res) => { if (res.error_code > 0) RbHighbar.error(res.error_msg) else _reloadAndTips(this, $L('审批已撤回')) this.disabled() }) }, }) } cancel38 = () => { const that = this RbAlert.create($L('将退回你的审批,退回后可重审。是否继续?'), { confirm: function () { this.disabled(true, true) $.post(`/app/entity/approval/cancel38?record=${that.props.id}`, (res) => { if (res.error_code > 0) RbHighbar.error(res.error_msg) else _reloadAndTips(this, $L('审批已退回')) this.disabled() }) }, }) } urge = () => { const that = this RbAlert.create($L('将向当前审批人发送催审通知。是否继续?'), { confirm: function () { this.disabled(true) $.post(`/app/entity/approval/urge?record=${that.props.id}`, (res) => { if (res.error_code > 0) { RbHighbar.create(res.error_msg) this.disabled() } else { RbHighbar.success($L('通知已发送')) this.hide() } }) }, }) } revoke = () => { const that = this RbAlert.create($L('将要撤销已通过审批。是否继续?'), { type: 'danger', confirm: function () { this.disabled(true, true) $.post(`/app/entity/approval/revoke?record=${that.props.id}`, (res) => { if (res.error_code > 0) RbHighbar.error(res.error_msg) else _reloadAndTips(this, $L('审批已撤销')) this.disabled() }) }, }) } viewSteps = () => { const that = this if (this._ApprovalStepViewer) { this._ApprovalStepViewer.show() } else { renderRbcomp(, function () { that._ApprovalStepViewer = this }) } } } // 审批人/抄送人选择 class ApprovalUsersForm extends RbFormHandler { renderUsers() { if (!this.state.isLoaded) return null if (this.state.hasError) { return (
) } const approverHas = (this.state.nextApprovers || []).length > 0 || this.state.approverSelfSelecting const ccHas = (this.state.nextCcs || []).length > 0 || this.state.ccSelfSelecting return ( {approverHas ? (
{(this.state.nextApprovers || []).map((item) => { return })}
{this.state.approverSelfSelecting && (
(this._approverSelector = c)} />
)}
) : ( !this.state.isLastStep && (
) )} {ccHas && (
{(this.state.nextCcs || []).map((item) => { return })}
{this.state.ccSelfSelecting && (
(this._ccSelector = c)} />
)} {(this.state.nextCcAccounts || []).length > 0 && (
{$L('及以下外部人员')} {this.state.nextCcAccounts.map((me) => { return {me} })}
)}
)}
) } getSelectUsers() { const selectUsers = { selectApprovers: this.state.approverSelfSelecting ? this._approverSelector.getSelected() : [], selectCcs: this.state.ccSelfSelecting ? this._ccSelector.getSelected() : [], } if (!this.state.isLastStep) { if ((this.state.nextApprovers || []).length === 0 && selectUsers.selectApprovers.length === 0) { RbHighbar.create($L('请选择审批人')) return false } } return selectUsers } getNextStep(approval) { $.get(`/app/entity/approval/fetch-nextstep?record=${this.props.id}&approval=${approval || this.props.approval}`, (res) => { this.setState({ isLoaded: true }) if (res.error_code === 0) { this.setState({ ...res.data, hasError: null }) } else { this.setState({ hasError: res.error_msg }) } }) } } // 审批提交 class ApprovalSubmitForm extends ApprovalUsersForm { constructor(props) { super(props) this._ccLabel = $L('本次提交将抄送给') this._approverLabel = $L('审批人') this.state.approvals = [] } render() { const approvals = this.state.approvals || [] return ( (this._dlg = c)} title={$L('提交审批')}>
{!this.state.approvals && (

{$L('无适用流程')} {rb.isAdminUser && ( {$L('点击添加')} )}

)} {approvals.map((item) => { return ( ) })}
{approvals.length > 0 && this.renderUsers()}
(this._btns = c)}>
) } componentDidMount = () => this.reload() reload() { $.get(`/app/entity/approval/workable?record=${this.props.id}`, (res) => { if (res.data && res.data.length > 0) { this.setState({ approvals: res.data, useApproval: res.data[0].id }, () => { this.getNextStep(res.data[0].id) }) } else { this.setState({ approvals: null, useApproval: null }) } }) } handleChangeAfter(id, val) { if (id === 'useApproval') this.getNextStep(val) } post() { if (!this.state.useApproval) return RbHighbar.create($L('请选择审批流程')) const selectUsers = this.getSelectUsers() if (!selectUsers) return this.disabled(true) $.post(`/app/entity/approval/submit?record=${this.props.id}&approval=${this.state.useApproval}`, JSON.stringify(selectUsers), (res) => { if (res.error_code > 0) RbHighbar.error(res.error_msg) else _reloadAndTips(this, $L('审批已提交')) this.disabled() }) } } // 审批 class ApprovalApproveForm extends ApprovalUsersForm { render() { return ( (this._dlg = c)} title={$L('审批')}>
{this.state.bizMessage && (
this.setState({ bizMessage: null })} />
)} {(this.state.aform || this.state.aform_details) && this.renderLiteForm()} {this.state.editableMode === 1 && this.renderEditable()}