king
2019-11-28 213c70792e6af7f9ccef17d778c5f8806fbd513c
src/tabviews/commontable/index.jsx
@@ -10,7 +10,7 @@
import Loading from '@/components/loading'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
// import Utils from '@/utils/utils.js'
import Utils from '@/utils/utils.js'
import './index.scss'
export default class NormalTable extends Component {
@@ -27,7 +27,7 @@
    searchlist: null,
    actions: null,
    columns: null,
    select: null,
    setting: null,
    data: null,
    total: 0,
    loading: false,
@@ -67,8 +67,15 @@
          duration: 10
        })
      }
      this.setState({config})
      console.log(config.columns)
      this.setState({
        config: config,
        setting: config.setting,
        searchlist: config.search,
        actions: config.action,
        columns: config.columns
      }, () => {
        this.improveSearch()
      })
    } else {
      this.setState({
        loadingview: false,
@@ -80,6 +87,77 @@
        duration: 10
      })
    }
  }
  improveSearch = () => {
    let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
    let deffers = []
    searchlist.forEach(item => {
      if (item.type !== 'select' && item.type !== 'link') return
      let unloaded = item.options.length === 0
      if (item.setAll === 'true') {
        item.options.unshift({
          key: Utils.getuuid(),
          Value: '',
          Text: '全部'
        })
      }
      if (item.resourceType === '1' && item.dataSource && unloaded) {
        let param = {
          func: 'sPC_Get_SelectedList',
          // LText: item.dataSourceSql,
          LText: 'msltk * mfrmk sOrganization',
          obj_name: 'data',
          arr_field: item.valueField + ',' + item.valueText
        }
        let defer = new Promise(resolve => {
          Api.getSystemConfig(param).then(res => {
            res.search = item
            resolve(res)
          })
        })
        deffers.push(defer)
      } else if (item.resourceType === '1' && !item.dataSource) {
        notification.warning({
          top: 92,
          message: item.label + '数据源配置错误',
          duration: 10
        })
      }
    })
    this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
    if (deffers.length === 0) return
    Promise.all(deffers).then(result => {
      result.forEach(res => {
        if (res.status) {
          searchlist = searchlist.map(item => {
            if (item.uuid === res.search.uuid) {
              res.data.forEach(cell => {
                item.options.push({
                  key: Utils.getuuid(),
                  Value: cell[res.search.valueField],
                  Text: cell[res.search.valueText]
                })
              })
            }
            return item
          })
        } else {
          notification.warning({
            top: 92,
            message: res.search.label + ':' + res.message,
            duration: 10
          })
        }
      })
      this.setState({searchlist})
    })
  }
  async loadmaindata (pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search = '') {
@@ -150,6 +228,7 @@
    // 获取表格选择项
    let data = []
    this.refs.mainTable.state.selectedRowKeys.forEach(item => {
      console.log(item)
      data.push(this.refs.mainTable.props.data[item])
    })
    return data
@@ -166,8 +245,8 @@
          key: item,
          ID: item + 'mainkey',
          ExRateName: '$',
          SupplierName: '阿里巴巴' + item + '店',
          SupShortName: '阿里巴巴',
          SupplierName: '天猫' + item + '店',
          SupShortName: '天猫',
          SupplierCode: '201922' + item,
          OrgName: '阿里巴巴',
          OrgCode: '302999',
@@ -183,35 +262,35 @@
  }
  render() {
    const { config, loadingview, viewlost } = this.state
    const { setting, searchlist, actions, columns, loadingview, viewlost } = this.state
    return (
      <div className="commontable">
        {loadingview && <Loading />}
        {config.search && config.search.length > 0 ?
        {searchlist && searchlist.length > 0 ?
          <MainSearch
            refreshdata={this.refreshbysearch}
            searchlist={config.search}
            searchlist={searchlist}
            dict={this.state.dict}
          /> : null
        }
        {config.action &&
        {actions &&
          <MainAction
            MenuID={this.props.MenuID}
            fixed={config.setting && config.setting.actionfixed}
            fixed={setting && setting.actionfixed}
            refreshdata={this.refreshbyaction}
            gettableselected={this.gettableselected}
            actions={config.action}
            actions={actions}
            dict={this.state.dict}
          />
        }
        {config.columns &&
        {columns &&
          <MainTable
            ref="mainTable"
            MenuID={this.props.MenuID}
            setting={config.setting}
            setting={setting}
            refreshdata={this.refreshbytable}
            columns={config.columns}
            columns={columns}
            data={this.state.data}
            total={this.state.total}
            loading={this.state.loading}