/*! 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. */ const wpc = window.__PageConfig const bProps = { sourceEntity: wpc.referenceEntity, targetEntity: wpc.entityName, field: wpc.fieldName } $(document).ready(() => { $('.J_add-rule').click(() => renderRbcomp()) loadRules() }) const loadRules = () => { $.get(`../auto-fillin-list?field=${wpc.fieldName}`, (res) => { const $tbody = $('#dataList tbody').empty() $(res.data).each(function () { const $tr = $('').appendTo($tbody) $(`
${this.targetFieldLabel}
`).appendTo($tr) $(`${this.sourceFieldLabel}`).appendTo($tr) if (!this.extConfig.whenCreate && !this.extConfig.whenUpdate) { $(`(${$L('未启用')})`).appendTo($tr) } else { const ruleLabels = [] if (this.extConfig.whenCreate) ruleLabels.push($L('新建时')) if (this.extConfig.whenUpdate) ruleLabels.push($L('编辑时')) if (this.extConfig.fillinForce) ruleLabels.push($L('强制回填')) if (this.extConfig.readonlyTargetField) ruleLabels.push($L('自动设置目标字段为只读')) $(`${ruleLabels.join(', ')}`).appendTo($tr) } const $btns = $('').appendTo($tr) $btns.find('a:eq(0)').click(() => { renderRbcomp() }) const cfgid = this.id $btns.find('a:eq(1)').click(() => { RbAlert.create($L('确认删除此回填规则?'), { type: 'danger', confirm: function () { this.disabled(true) $.post(`/app/entity/common-delete?id=${cfgid}`, (res) => { if (res.error_code === 0) { RbHighbar.success($L('删除成功')) this.hide() loadRules() } else { RbHighbar.error(res.error_msg) } }) }, }) }) }) $('#dataList').parent().removeClass('rb-loading-active') if (res.data.length === 0) $('.list-nodata').removeClass('hide') else $('.list-nodata').addClass('hide') }) } class DlgRuleEdit extends RbFormHandler { constructor(props) { super(props) if (!props.id) this.state = { ...this.state, whenCreate: true } } render() { return ( (this._dlg = c)} disposeOnHide={true}>
(this._form = c)}>
(this._btns = c)}> {$L('取消')}
) } componentDidMount() { this.__select2 = [] // #1 $.get(`/commons/metadata/fields?entity=${this.props.targetEntity}`, (res) => { this.__targetFieldsCache = res.data const s2target = $(this._targetField).select2({ placeholder: $L('选择字段'), allowClear: false, }) this.__select2.push(s2target) // #2 $.get(`/commons/metadata/fields?entity=${this.props.sourceEntity}`, (res) => { this.__sourceFieldsCache = res.data this.setState({ sourceFields: res.data }, () => { const s2source = $(this._sourceField) .select2({ placeholder: $L('选择字段'), allowClear: false, }) .on('change', (e) => this._renderTargetFields(e.target.value)) this.__select2.push(s2source) if (this.props.sourceField) { s2source.val(this.props.sourceField).trigger('change') setTimeout(() => s2target.val(this.props.targetField).trigger('change'), 100) } else { s2source.trigger('change') } if (this.props.id && rb.env !== 'dev') { s2target.prop('disabled', true) s2source.prop('disabled', true) } }) }) }) $(this._form).find('[data-toggle="tooltip"]').tooltip() } _renderTargetFields(s) { const source = this.__sourceFieldsCache.find((x) => s === x.name) // 显示兼容的目标字段 const targetFields = [] $(this.__targetFieldsCache).each(function () { if (this.creatable && this.name !== wpc.fieldName && this.type !== 'SERIES' && $fieldIsCompatible(source, this)) { targetFields.push(this) } }) this.setState({ targetFields: targetFields }, () => { if (targetFields.length > 0) this.__select2[0].val(targetFields[0].name) }) } save = () => { const _data = { field: this.props.field, sourceField: $(this._sourceField).val(), targetField: $(this._targetField).val(), } if (!_data.targetField) return RbHighbar.create($L('请选择目标字段')) _data.extConfig = { whenCreate: this.state.whenCreate, whenUpdate: this.state.whenUpdate, fillinForce: this.state.fillinForce, readonlyTargetField: this.state.readonlyTargetField, } if (this.props.id) _data.id = this.props.id this.disabled(true) $.post('../auto-fillin-save', JSON.stringify(_data), (res) => { if (res.error_code === 0) { this.hide() loadRules() } else { RbHighbar.create(res.error_msg) } this.disabled() }) } }