king
2019-12-18 977ce3d348f898d64ea240c8397b83d3e1cc5bb4
src/tabviews/commontable/mainAction/index.jsx
@@ -1,7 +1,7 @@
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'
@@ -14,8 +14,7 @@
    MenuID: PropTypes.string,
    actions: PropTypes.array, // 搜索条件列表
    dict: PropTypes.object, // 字典项
    setting: PropTypes.any,
    configMap: PropTypes.object
    setting: PropTypes.any
  }
  state = {
@@ -24,14 +23,17 @@
    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() || []
@@ -77,21 +79,13 @@
        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,
@@ -317,7 +311,6 @@
        }).then(res => {
          if (!res) return
          // 外部请求
          console.log(res)
          return Api.genericInterface(res)
        }).then(response => {
          // 回调请求
@@ -504,7 +497,7 @@
    notification.success({
      top: 92,
      message: this.props.dict['main.action.confirm.success'],
      duration: 5
      duration: 2
    })
    if (btn.OpenType === 'pop') {
      this.setState({
@@ -531,6 +524,164 @@
    })
  }
  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({
@@ -541,7 +692,6 @@
          confirmLoading: false
        })
      }, res)
      console.log(res)
    }, () => {})
  }
@@ -584,7 +734,7 @@
        <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}
        />
@@ -593,7 +743,7 @@
  }
  render() {
    const { loadingUuid } = this.state
    const { loadingUuid, btnloading } = this.state
    if (this.props.setting.actionfixed) { // 按钮是否固定在头部
      return (
@@ -622,6 +772,7 @@
              }
            })}
            {this.getModels()}
            {btnloading && <Spin size="large" />}
          </div>
        </Affix>
      )
@@ -651,6 +802,7 @@
            }
          })}
          {this.getModels()}
          {btnloading && <Spin size="large" />}
        </div>
      )
    }