// 核心库
import React from 'react'
// 组件库
import { Search } from '@woowalker/feui'
import EditListTable from '../../EditListTable'
// 工具库
import { isEqual } from 'lodash'

class EDProductUseListPage extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      searchParams: {},
      searchSize: undefined
    }
    this.refOfTable = null
  }

  handleSearch = (value) => {
    const { data } = this.props
    value.rules.push({
      field: 'Parameter4',
      operator: 0,
      value: data.selectedNodes ? data.selectedNodes[0].node.id : null,
      isCustom: true,
      isSysParam: false,
    })

    this.setState({ searchParams: value }, () => {
      this.refOfTable && this.refOfTable.loadData(this.state.searchParams)
    })
  }

  handleSize = (searchSize) => {
    !isEqual(searchSize, this.state.searchSize) && this.setState({ searchSize })
  }

  render () {
    const { formId, formCode } = this.props
    const { searchSize } = this.state
    return (
      <>
        <Search
          formId={formId}
          formCode={formCode}
          onSearch={this.handleSearch}
          onSize={this.handleSize}
        />
        <EditListTable
          preventDefaultSearch
          formCode={'ED045'}
          onRef={ref => this.refOfTable = ref}
          style={{ height: `calc(100% - ${searchSize?.fullHeight || 0}px)` }}
        />
      </>
    )
  }
}

export default EDProductUseListPage
