/*!
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('提交')}
{$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 && (
{$L('审批')}
)}
{this.state.canUrge && imApproverCurrent === false && (
{$L('催审')}
)}
{this.state.canCancel && (
{$L('撤回')}
)}
{this.state.canCancel38 && (
{$L('退回')} (LAB)
)}
{$L('详情')}
{aMsg}
)
}
renderStateApproved() {
window.RbViewPage && window.RbViewPage.setReadonly(true)
return (
{(rb.isAdminUser || this.state.canRevoke) && (
{$L('撤销')}
)}
{$L('详情')}
{$L('当前记录已审批完成')}
)
}
renderStateRejected() {
return (
{$L('再次提交')}
{$L('详情')}
{$L('审批被驳回,可在信息完善后再次提交')}
)
}
renderStateCanceled() {
return (
{$L('再次提交')}
{$L('详情')}
{$L('审批已撤回,请在信息完善后再次提交')}
)
}
renderStateRevoked() {
return (
{$L('再次提交')}
{$L('详情')}
{$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._approverLabel || $L('下一审批人')} (${this.state.signMode === 'AND' ? $L('会签') : $L('或签')})`}
{(this.state.nextApprovers || []).map((item) => {
return
})}
{this.state.approverSelfSelecting && (
(this._approverSelector = c)} />
)}
) : (
!this.state.isLastStep && (
)
)}
{ccHas && (
{this._ccLabel || $L('本次审批结果将抄送给')}
{(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('提交审批')}>
{$L('选择审批流程')}
{!this.state.approvals && (
{$L('无适用流程')}
{rb.isAdminUser && (
{$L('点击添加')}
)}
)}
{approvals.map((item) => {
return (
)
})}
{approvals.length > 0 && this.renderUsers()}
(this._btns = c)}>
{$L('取消')}
this.post()}>
{$L('提交')}
)
}
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()}
{$L('批注')}
{this.state.expiresTime > 0 && ({$L('已超时 %s', $sec2Time(this.state.expiresTime))}) }
{this.state.expiresTime < 0 && ({$L('%s 后超时', $sec2Time(Math.abs(this.state.expiresTime)))}) }
{this.renderUsers()}
(this._btns = c)}>
{this.props.$$$parent && (
{
this.props.$$$parent.viewSteps()
// this.hide()
}}>
{$L('审批详情')}
)}
{(this.state.allowReferral || this.state.allowCountersign) && (
)}
this.post(10)} disabled={!!this.state.hasError}>
{$L('同意')}
this.post(11)} disabled={!!this.state.hasError}>
{$L('驳回')}
)
}
renderLiteForm() {
return (
{$L('信息完善 (驳回时无需填写)')}
(this._EditableFieldForms = c)} />
)
}
renderEditable() {
return (
{$L('信息完善')}
{
$fetchMetaInfo(this.props.entity, (res) => {
const editProps = {
entity: res.entity,
title: $L('编辑%s', res.entityLabel),
icon: res.icon,
id: this.props.id,
postAfter: (recordId, next, formObject) => {
// 刷新列表
const rlp = window.RbListPage || parent.RbListPage
if (rlp) rlp.reload(recordId)
RbAlert.create($L('数据可能已更改,是否需要刷新页面?'), {
onConfirm: () => {
// 刷新视图
if (window.RbViewPage) window.RbViewPage.reload()
},
})
},
}
RbFormModal.create(editProps, true)
})
}}>
{$L('编辑')}
)
}
componentDidMount = () => this.getNextStep()
reload = () => this.getNextStep()
post(state) {
const that = this
if (state === 11 && this.state.isRejectStep) {
this.disabled(true)
$.get(`/app/entity/approval/fetch-backsteps?record=${this.props.id}`, (res) => {
this.disabled()
const ss = res.data || []
RbAlert.create(
{$L('请选择驳回方式')}
0 ? ss[ss.length - 1].node : '0'}>
{$L('整体驳回')}
{ss.length > 0 && (
{ss.map((s) => {
return (
{s.nodeName}
)
})}
)}
,
{
onConfirm: function () {
this.disabled(true, true)
const node = $(this._element).find('select').val()
const s = that._post(state, node === '0' ? null : node, this)
if (s === false) this.disabled() // reset
},
onRendered: function () {
$(this._element).find('select').select2({
allowClear: false,
})
},
}
)
})
} else {
this._post(state, null)
}
}
_post(state, rejectNode, _alert, weakMode) {
let aformData = []
if ((this.state.aform || this.state.aform_details) && state === 10) {
// aformData = this._LiteForm.buildFormData()
aformData = this._EditableFieldForms.buildFormsData()
if (aformData === false) return false
}
let selectUsers
if (state === 10) {
selectUsers = this.getSelectUsers()
if (!selectUsers) return false
}
const data = {
remark: this.state.remark || null,
selectUsers: selectUsers,
aformData: aformData,
useGroup: this.state.useGroup,
}
// v4.0
if (this.state.remarkReq >= 1 && $empty(data.remark)) {
RbHighbar.createl('请输入批注')
return false
}
_alert && _alert.disabled(true, true)
this.disabled(true)
let url = `/app/entity/approval/approve?record=${this.props.id}&state=${state}&rejectNode=${rejectNode || ''}`
if (weakMode) url += '&weakMode=' + weakMode
$.post(url, JSON.stringify(data), (res) => {
_alert && _alert.disabled()
this.disabled()
if (res.error_code === 498) {
this.setState({ bizMessage: res.error_msg })
this.getNextStep()
} else if (res.error_code === 497) {
// 弱校验
const that = this
const msg_id = res.error_msg.split('$$$$')
RbAlert.create(msg_id[0], {
onConfirm: function () {
this.hide()
that._post(state, rejectNode, _alert, msg_id[1])
},
})
} else if (res.error_code > 0) {
RbHighbar.error(res.error_msg)
} else {
_alert && _alert.hide(true)
_reloadAndTips(this, state === 10 ? $L('审批已同意') : rejectNode ? $L('审批已退回') : $L('审批已驳回'))
typeof this.props.call === 'function' && this.props.call()
}
})
}
_handleReferral() {
renderRbcomp(
{
_alert.disabled(true)
$.post(`/app/entity/approval/referral?record=${this.props.id}&to=${s[0]}`, (res) => {
_alert.disabled()
if (res.error_code === 0) {
_alert.hide()
_reloadAndTips(this, $L('已转审'))
typeof this.props.call === 'function' && this.props.call()
} else {
RbHighbar.error(res.error_msg)
}
})
}}
/>
)
}
_handleCountersign() {
renderRbcomp(
{
_alert.disabled(true)
$.post(`/app/entity/approval/countersign?record=${this.props.id}&to=${s.join(',')}`, (res) => {
_alert.disabled()
if (res.error_code === 0) {
_alert.hide()
_reloadAndTips(this, $L('已加签'))
typeof this.props.call === 'function' && this.props.call()
} else {
RbHighbar.error(res.error_msg)
}
})
}}
/>
)
}
}
class ApproveFormExtAction extends RbAlert {
renderContent() {
return (
)
}
}
const STATE_NAMES = {
10: $L('审批同意'),
11: $L('审批驳回'),
12: $L('审批撤回'),
13: $L('审批撤销'),
21: $L('退回'),
}
// 已审批步骤查看
class ApprovalStepViewer extends React.Component {
constructor(props) {
super(props)
this.state = { ...props }
}
render() {
const stepsLen = (this.state.steps || []).length
let stateLast = 0
return (
(this._dlg = c)} style={{ zIndex: 1051 }}>
{!this.state.steps &&
}
{(this.state.steps || []).map((item, idx) => {
if (item.submitter) stateLast = item.approvalState
return idx === 0 || item.submitter ? this.renderSubmitter(item, idx) : this.renderApprover(item, stateLast, stepsLen === idx + 1)
})}
{stateLast >= 10 && (
{stateLast === 13 || stateLast === 12 ? $L('重审') : $L('结束')}
)}
{this.state.steps && (
)}
)
}
renderSubmitter(s, idx) {
return (
{idx > 0 && {$L('再次提交')} }
{this._formatTime(s.createdOn)}
{$L('由 %s 提交审批', s.submitter === rb.currentUser ? $L('你') : s.submitterName)}
{s.approvalName && (
{s.approvalName}
)}
)
}
renderApprover(s, stateLast, isLast) {
const stepsGroup = []
let nodeState = 0
if (s[0].signMode === 'OR') {
s.forEach((item) => {
if (item.state >= 10) nodeState = item.state
})
}
s.forEach((item) => {
const approverName = item.approver === rb.currentUser ? $L('你') : item.approverName
let aMsg = $L('等待 %s 审批', approverName)
if (item.state >= 10) aMsg = $L('由 %s %s', approverName, STATE_NAMES[item.state] || item.state)
if ((nodeState >= 10 || stateLast >= 10) && item.state < 10) aMsg = `${approverName} ${$L('未进行审批')}`
// 待我审批
if (item.approver === rb.currentUser && item.state === 1 && stateLast === 2) {
aMsg = (
{$L('等待 你 ')}
{
$stopEvent(e, true)
if (this.props.$$$parent) {
this.props.$$$parent.approve()
this.hide()
}
}}>
{$L('审批')}
)
}
const state1w = item.state === 1 && isLast && stateLast < 10
stepsGroup.push(
{this._formatTime(item.approvedTime || item.createdOn)}
{aMsg}
{item.referralFrom && (
{$L('转审')}
)}
{item.countersignFrom && (
{$L('加签')}
)}
{item.batchMode && (
{$L('批量')}
)}
{(item.druation || item.druation === 0) && (
{$sec2Time(item.druation)}
)}
{item.remark && (
{item.remark}
)}
{item.state >= 10 && (item.ccUsers || []).length + (item.ccAccounts || []).length > 0 && (
{$L('已抄送')}
{(item.ccUsers || []).map((item) => {
return {item}
})}
{(item.ccAccounts || []).map((item) => {
return (
{item}
)
})}
)}
)
})
if (stepsGroup.length < 2) {
return (
{s[0].nodeName && {s[0].nodeName} }
{stepsGroup}
)
}
const sm = s[0].signMode
const clazz = sm === 'OR' || sm === 'AND' ? 'joint' : 'no-joint'
return (
{s[0].nodeName && {s[0].nodeName} }
{stepsGroup}
)
}
_formatTime(time) {
time = time.split(' ')
return (
)
}
componentDidMount() {
this.show()
this._load()
}
_load(his) {
$.get(`/app/entity/approval/fetch-workedsteps?record=${this.props.id}&his=${!!his}`, (res) => {
if (!res.data || res.data.length === 0) {
RbHighbar.create($L('未查询到流程详情'))
this.hide()
this.__noStepFound = true
} else {
this.setState({ steps: res.data })
}
})
}
hide = () => $(this._dlg).modal('hide')
show = () => {
if (this.__noStepFound === true) {
RbHighbar.create($L('未查询到流程详情'))
this.hide()
} else {
$(this._dlg).modal({ show: true, keyboard: true })
}
}
}
class EditableFieldForms extends React.Component {
constructor(props) {
super(props)
this._fakeParent = {
state: { id: props._this.props.id },
}
this._LiteForms = {}
}
render() {
const _this = this.props._this
const _details = _this.state.aform_details
console.log(_details)
return (
{_this.state.aform && this.renderLiteForm(_this.props.entity, _this.props.id, _this.state.aform)}
{_details && this.renderDetails(_details)}
)
}
renderLiteForm(entity, id, aform) {
// @see rb-forms.append.js LiteFormModal#create
return (
(this._LiteForms[id] = c)} key={id}>
{aform.map((item) => {
item.isFull = true
delete item.referenceQuickNew // v35
// eslint-disable-next-line no-undef
return detectElement(item)
})}
)
}
renderDetails(details) {
return details.map((d) => {
return (
{d.aentityLabel} ({d.aforms.length})
{d.aforms.map((aform) => {
const c = [...aform]
const id = c[c.length - 1] // Last is ID
c.pop()
return this.renderLiteForm(d.aentity, id, c)
})}
)
})
}
buildFormsData() {
let datas = []
for (let key in this._LiteForms) {
const aformData = this._LiteForms[key].buildFormData()
if (aformData === false) {
datas = false
break
}
datas.push(aformData)
}
return datas
}
}
// 刷新页面
const _reloadAndTips = function (dlg, msg) {
dlg && dlg.hide(true)
msg && RbHighbar.success(msg)
// 保持当前视图
const keepViewId = dlg && parent && parent.RbViewModal && parent.RbViewModal.mode === 2 ? dlg.props.id : null
setTimeout(() => {
if (window.RbViewPage) window.RbViewPage.reload()
if (window.RbListPage) window.RbListPage.reload()
else if (parent.RbListPage) parent.RbListPage.reload(keepViewId)
}, 1000)
}