king
2019-12-01 cf8e332b14ca79859fcd89f2ac097ed7c6aa66c5
src/tabviews/commontable/index.jsx
@@ -27,17 +27,16 @@
    searchlist: null,
    actions: null,
    columns: null,
    arr_field: '',
    setting: null,
    data: null,
    total: 0,
    loading: false,
    param: {
      pageIndex: 1,
      pageSize: 10,
      orderColumn: '',
      orderType: '',
      search: ''
    },
    pageIndex: 1,
    pageSize: 10,
    orderColumn: '',
    orderType: 'asc',
    search: '',
    fixed: {}
  }
@@ -67,14 +66,29 @@
          duration: 10
        })
      }
      let _search = Utils.mainjointsearchkey(config.search)
      let _arrField = []
      config.columns.forEach(col => {
        if (col.field) {
          _arrField.push(col.field)
        }
      })
      this.setState({
        config: config,
        setting: config.setting,
        searchlist: config.search,
        actions: config.action,
        columns: config.columns
        columns: config.columns,
        arr_field: _arrField.join(','),
        search: _search ? 'where (' + _search + ')' : '',
        orderColumn: config.setting.orderColumn,
        loading: true
      }, () => {
        this.improveSearch()
        this.loadmaindata()
      })
    } else {
      this.setState({
@@ -159,66 +173,82 @@
    })
  }
  async loadmaindata (pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search = '') {
  async loadmaindata () {
    const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
    // 获取列表数据
    let result = await Api.getMainTableData(this.props.MenuNo, pageIndex, pageSize, orderColumn, orderType, search)
    let param = {
      func: 'sPC_Get_TableData',
      obj_name: 'data',
      arr_field: arr_field
    }
    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderColumn} ${orderType}) as rows from ${setting.dataresource} ${search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
    let DateCount = `select count(1) as total from ${setting.dataresource} ${search}`
    console.log(LText)
    console.log(DateCount)
    param.LText = Utils.formatOptions(LText)
    param.DateCount = Utils.formatOptions(DateCount)
    let result = await Api.genericInterface(param)
    if (result.status) {
      this.setState({
        data: result.data.map((item, index) => {
          item.key = index
          item.rows = item.mkrows
          return item
        }),
        total: result.total,
        loading: false
      })
    } else {
      this.setState({
        loading: false
      })
      notification.error({
        top: 92,
        message: result.message,
        duration: 15
      })
    }
  }
  refreshbysearch = (searches) => {
    // 搜索条件变化
    console.log(searches)
    // searches = Utils.jointsearchkey(searches)
    // this.loadmaindata(this.state.param.pageIndex, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, searches)
    // let param = Object.assign({}, this.state.param, {
    //   search: searches
    // })
    // this.setState({
    //   loading: true,
    //   param: param
    // })
    let search = Utils.mainjointsearchkey(searches)
    this.refs.mainTable.resetTable()
    this.setState({
      loading: true,
      search: search ? 'where (' + search + ')' : ''
    }, () => {
      this.loadmaindata()
    })
  }
  refreshbytable = (pagination, filters, sorter) => {
    // 表格查询条件修改
    console.log(pagination)
    console.log(filters)
    console.log(sorter)
    // if (sorter.order) {
    //   let _chg = {
    //     ascend: 'asc',
    //     descend: 'desc'
    //   }
    //   sorter.order = _chg[sorter.order]
    // }
    // this.loadmaindata(pagination.current, pagination.pageSize, sorter.field, sorter.order, this.state.param.search)
    // let param = Object.assign({}, this.state.param, {
    //   pageIndex: pagination.current,
    //   pageSize: pagination.pageSize,
    //   orderColumn: sorter.field,
    //   orderType: sorter.order
    // })
    // this.setState({
    //   loading: true,
    //   param: param
    // })
    if (sorter.order) {
      let _chg = {
        ascend: 'asc',
        descend: 'desc'
      }
      sorter.order = _chg[sorter.order]
    }
    this.setState({
      loading: true,
      pageIndex: pagination.current,
      pageSize: pagination.pageSize,
      orderColumn: sorter.field || this.state.setting.orderColumn,
      orderType: sorter.order || 'asc'
    }, () => {
      this.loadmaindata()
    })
  }
  refreshbyaction = (btn, type) => {
    // 按钮操作后刷新表格,重置页码及选择项
    console.log(btn)
    console.log(type)
    // this.refs.mainTable.resetTable()
    this.refs.mainTable.resetTable()
    // this.loadmaindata(1, this.state.param.pageSize, this.state.param.orderColumn, this.state.param.orderType, this.state.param.search)
    // this.setState({
    //   loading: true
@@ -239,22 +269,22 @@
    this.loadconfig()
    // this.loadmaindata()
    this.setState({
      data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
        return {
          key: index,
          ID: item + 'mainkey',
          ExRateName: '$',
          SupplierName: '天猫' + item + '店',
          SupShortName: '天猫',
          SupplierCode: '201922' + item,
          OrgName: '阿里巴巴',
          OrgCode: '302999',
          PlanDate: '2019-11-' + (item < 10 ? '0' + item : item)
        }
      }),
      total: 329
    })
    // this.setState({
    //   data: [1,2,3,4,5,6,7,8,9,10].map((item, index) => {
    //     return {
    //       key: index,
    //       ID: item + 'mainkey',
    //       ExRateName: '$',
    //       SupplierName: '天猫' + item + '店',
    //       SupShortName: '天猫',
    //       SupplierCode: '201922' + item,
    //       OrgName: '阿里巴巴',
    //       OrgCode: '302999',
    //       PlanDate: '2019-11-' + (item < 10 ? '0' + item : item)
    //     }
    //   }),
    //   total: 329
    // })
  }
  shouldComponentUpdate (nextProps, nextState) {