import React, { useState, useEffect } from 'react'
import { Select, Spin, Table, Button, Form, Input, Divider, Modal, Rate, Popconfirm } from 'antd'
import NavLink from 'umi/navlink'
import router from 'umi/router'
import { fetchList, apis, fetch } from '@/utils/request'
import Search from '../components/Search'
import List from '../components/List'

const lifeConsultantEvaluate = fetchList(apis.propUser.lifeConsultantEvaluate)

const Condition = props => {
  return (
    <Search
      onSearch={props.onSearch}
      onReset={props.onReset}
      render={form => {
        const { getFieldDecorator } = form
        
        return (
          <>
            <Form.Item label="月份">
            {
              getFieldDecorator('evaluateTime')(<Input placeholder="月份-格式202006" />)
            }
            </Form.Item>
          </>
        )
      }}
      actions={[
        <Button onClick={() => router.go(-1)}>返回</Button>
      ]}
    />
  )
}

export default props => {
  const [loading, setLoading] = useState(false)
  const [listData, setListData] = useState([])
  const [pagination, setPagination] = useState({})
  const [queryParams, setQueryParams] = useState({ pageNum: 1, pageSize: 10 })

  const { userId } = props.location.query

  const handleSearch = vals => {
    setQueryParams({
      ...queryParams,
      ...vals,
      pageNum: 1,
    })
  }

  const handlePageChange = (pageNum, pageSize) => {
    setQueryParams({
      ...queryParams,      
      pageNum,
      pageSize,
    })
  }

  useEffect(() => {
    setLoading(true)
    lifeConsultantEvaluate({...queryParams, userId}).then(res => {
      const [list, pageInfo] = res || {}
      setListData(list)
      setPagination(pageInfo)
      setLoading(false)
    }).catch(() => setLoading(false))
  }, [queryParams])

  return (
    <div>
      <Condition onSearch={handleSearch} onReset={handleSearch} />
      <div style={{ margin: '24px 0' }}>
        {/* <NavLink to={`/staff/editStaff`}>
          <Button type="primary">添加管家</Button>
        </NavLink> */}
      </div>
      <List dataSource={listData} loading={loading} pagination={pagination} onPageChange={handlePageChange} rowKey="id">
        <Table.Column title="评价人" dataIndex="personName" key="personName" />
        <Table.Column title="月份" dataIndex="evaluateTime" key="evaluateTime" />
        <Table.Column title="评分" dataIndex="score" key="score" render={t => <Rate disabled value={t} />} />
        <Table.Column title="评分时间" dataIndex="createDate" key="createDate" />
      </List>

    </div>
  )
}
