// 核心库
import React from 'react'
import { connect } from 'dva'
// 组件库
import { Form ,Input} from 'antd'
import { LocalSearch } from '@woowalker/feui'
import ListPage from '../../Table/ListPage'
// 工具库

class BDEquipmentListPage extends React.Component {
  constructor (props) {
    super(props)
    this.state = {
      appName: "",
      appCode: ""
    }
    this.refOfTable = null
  }
  onChangeApp = (value) => {
    this.setState({
      appName: value
    })
  }
  onChangeCode = (value) => {
    this.setState({
      appCode: value
    })
  }

 handleSearch = (value) => {
    const {data } = this.props
    value.rules.push({
      field: 'appCode',
      operator: 0,
      value: this.state.appCode,
      isCustom: true,
      isSysParam: false,
    })
    value.rules.push({
      field: 'appName',
      operator: 0,
      value: this.state.appName,
      isCustom: true,
      isSysParam: false,
    })
    value.rules.push({
      field: 'deptId',
      operator: 0,
      value: data.id,
      isCustom: true,
      isSysParam: false,
    })

    // 搜索动作由 LocalSearch DidMount 之后发起，这时候 refOfTable 还没被赋值，所以需要 setState 之后，再发起 table 的接口请求
    this.setState({ searchParams: value }, () => {
      this.refOfTable && this.refOfTable.loadData(this.state.searchParams)
    })
  }

  render () {
    return (
      <>    
      <LocalSearch
          isRemember
          shareKey='BDApplianceList'
          onSearch={this.handleSearch}
          extraSearch={[
            <Form.Item label='设备名称'>
            <Input placeholder="" value={this.state.appName} style={{ width: '100%' }} onChange={(evt) => this.onChangeApp(evt.target.value)} />
          </Form.Item>,
           <Form.Item label='设备编码'>
           <Input placeholder="" value={this.state.appCode} style={{ width: '100%' }} onChange={(evt) => this.onChangeCode(evt.target.value)} />
         </Form.Item>
          ]}
        >     
        </LocalSearch>
        <ListPage
          preventDefaultSearch
          formCode={'BD123'}
          onRef={ref => this.refOfTable = ref}
        />
      </>
    )
  }
}

export default connect(({ search }) => ({ search }))(BDEquipmentListPage)
