| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import moment from 'moment' |
| | | import { Button, Affix, Modal, notification } from 'antd' |
| | | import { Button, Affix, Modal, notification, Spin } from 'antd' |
| | | import MutilForm from '../mutilform' |
| | | import Utils from '@/utils/utils.js' |
| | | import Api from '@/api' |
| | |
| | | MenuID: PropTypes.string, |
| | | actions: PropTypes.array, // 搜索条件列表 |
| | | dict: PropTypes.object, // 字典项 |
| | | setting: PropTypes.any, |
| | | configMap: PropTypes.object |
| | | setting: PropTypes.any |
| | | } |
| | | |
| | | state = { |
| | |
| | | tabledata: null, |
| | | confirmLoading: false, |
| | | execAction: null, |
| | | loadingUuid: '' |
| | | loadingUuid: '', |
| | | btnloading: false, |
| | | configMap: {} |
| | | } |
| | | |
| | | refreshdata = (item, type) => { |
| | | this.props.refreshdata(item, type) |
| | | } |
| | | actionTrigger = (item) => { |
| | | const { setting, configMap } = this.props |
| | | const { setting } = this.props |
| | | |
| | | let _this = this |
| | | let data = this.props.gettableselected() || [] |
| | | |
| | |
| | | this.setState({loadingUuid: ''}) |
| | | }) |
| | | } else if (item.OpenType === 'pop') { |
| | | let param = configMap[item.uuid] |
| | | |
| | | if (!param || param.type !== 'Modal') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到按钮配置信息!', |
| | | duration: 10 |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | visible: true, |
| | | execAction: {...param, ...item}, |
| | | tabledata: data |
| | | }) |
| | | } |
| | | this.setState({ |
| | | execAction: item, |
| | | tabledata: data, |
| | | btnloading: true |
| | | }, () => { |
| | | this.improveAction(item) |
| | | }) |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | |
| | | }).then(res => { |
| | | if (!res) return |
| | | // 外部请求 |
| | | console.log(res) |
| | | return Api.genericInterface(res) |
| | | }).then(response => { |
| | | // 回调请求 |
| | |
| | | notification.success({ |
| | | top: 92, |
| | | message: this.props.dict['main.action.confirm.success'], |
| | | duration: 5 |
| | | duration: 2 |
| | | }) |
| | | if (btn.OpenType === 'pop') { |
| | | this.setState({ |
| | |
| | | }) |
| | | } |
| | | |
| | | improveAction = (action) => { |
| | | const { configMap, execAction } = this.state |
| | | |
| | | let _config = configMap[action.uuid] |
| | | |
| | | if (_config) { |
| | | this.setState({ |
| | | execAction: {..._config, ...execAction} |
| | | }, () => { |
| | | this.improveActionForm() |
| | | }) |
| | | } else { |
| | | Api.getSystemCacheConfig({ |
| | | func: 'sPC_Get_LongParam', |
| | | MenuID: action.uuid |
| | | }).then(res => { |
| | | let _LongParam = '' |
| | | |
| | | if (res.status && res.LongParam) { |
| | | _LongParam = window.decodeURIComponent(window.atob(res.LongParam)) |
| | | try { |
| | | _LongParam = JSON.parse(_LongParam) |
| | | } catch (e) { |
| | | _LongParam = '' |
| | | } |
| | | } |
| | | |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 10 |
| | | }) |
| | | this.setState({ |
| | | execAction: null, |
| | | tabledata: null, |
| | | btnloading: false |
| | | }) |
| | | } else if (!_LongParam || (action.OpenType === 'pop' && _LongParam.type !== 'Modal')) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到按钮配置信息!', |
| | | duration: 10 |
| | | }) |
| | | this.setState({ |
| | | execAction: null, |
| | | tabledata: null, |
| | | btnloading: false |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | configMap: {...configMap, [action.uuid]: _LongParam}, |
| | | execAction: {..._LongParam, ...execAction} |
| | | }, () => { |
| | | this.improveActionForm() |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | |
| | | improveActionForm = () => { |
| | | const { configMap, execAction } = this.state |
| | | let subfields = [] |
| | | |
| | | if (execAction.groups.length > 0) { |
| | | execAction.groups.forEach(group => { |
| | | group.sublist.forEach(field => { |
| | | if ((field.type === 'select' || field.type === 'link') && field.resourceType === '1') { |
| | | subfields.push(field) |
| | | } |
| | | }) |
| | | }) |
| | | } else { |
| | | execAction.fields.forEach(field => { |
| | | if ((field.type === 'select' || field.type === 'link') && field.resourceType === '1') { |
| | | subfields.push(field) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | if (subfields.length === 0) { |
| | | this.setState({ |
| | | visible: true, |
| | | btnloading: false |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let deffers = subfields.map(item => { |
| | | let arrfield = item.valueField + ',' + item.valueText |
| | | |
| | | if (item.type === 'link') { |
| | | arrfield = arrfield + ',' + item.linkField |
| | | } |
| | | |
| | | let param = { |
| | | func: 'sPC_Get_SelectedList', |
| | | LText: item.dataSourceSql, |
| | | obj_name: 'data', |
| | | arr_field: arrfield |
| | | } |
| | | |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | return new Promise(resolve => { |
| | | Api.getSystemCacheConfig(param).then(res => { |
| | | res.search = item |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | }) |
| | | |
| | | let _field = {} |
| | | let error = '' |
| | | Promise.all(deffers).then(result => { |
| | | result.forEach(res => { |
| | | if (res.status) { |
| | | let options = res.data.map(cell => { |
| | | let item = { |
| | | key: Utils.getuuid(), |
| | | Value: cell[res.search.valueField], |
| | | Text: cell[res.search.valueText] |
| | | } |
| | | |
| | | if (res.search.type === 'link') { |
| | | item.parentId = cell[res.search.linkField] |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | _field[res.search.uuid] = options |
| | | } else { |
| | | error = res |
| | | } |
| | | }) |
| | | |
| | | if (error) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: error.message, |
| | | duration: 10 |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | configMap: {...configMap, ..._field} |
| | | }, () => { |
| | | this.setState({ |
| | | visible: true, |
| | | btnloading: false |
| | | }) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | handleOk = () => { |
| | | this.formRef.handleConfirm().then(res => { |
| | | this.setState({ |
| | |
| | | confirmLoading: false |
| | | }) |
| | | }, res) |
| | | console.log(res) |
| | | }, () => {}) |
| | | } |
| | | |
| | |
| | | <MutilForm |
| | | dict={this.props.dict} |
| | | action={execAction} |
| | | configMap={this.props.configMap} |
| | | configMap={this.state.configMap} |
| | | data={this.state.tabledata[0]} |
| | | wrappedComponentRef={(inst) => this.formRef = inst} |
| | | /> |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { loadingUuid } = this.state |
| | | const { loadingUuid, btnloading } = this.state |
| | | |
| | | if (this.props.setting.actionfixed) { // 按钮是否固定在头部 |
| | | return ( |
| | |
| | | } |
| | | })} |
| | | {this.getModels()} |
| | | {btnloading && <Spin size="large" />} |
| | | </div> |
| | | </Affix> |
| | | ) |
| | |
| | | } |
| | | })} |
| | | {this.getModels()} |
| | | {btnloading && <Spin size="large" />} |
| | | </div> |
| | | ) |
| | | } |