import React, { useState, useEffect } from 'react';
import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, Radio, Modal, Descriptions, notification } from 'antd';
import moment from 'moment';
import request from '../../../../utils/request';
import apis from '../../../../services/apis';
import Styles from '../style.less';


const { Option } = Select;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { Meta } = Card;

/**
 * 推荐客户
 *
 * @param {*} props
 * @returns
 */
class ModalRecommendRecord extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
       dataSource: [],
       visibleData: { visible: false, customerId: '' },
    }
  }

  // 挂载之后
  componentDidMount() {
    this.getList({ pageNumber: 1, pageSize: 5 })
  }

  componentDidUpdate(preProps, preState) {
    // console.log('this.props.visibleData', this.props.visibleData)
    if (this.props.visibleData.customerId !== preState.visibleData.customerId) {
      this.getList({ pageNumber: 1, pageSize: 5 })
      this.setState({ visibleData: this.props.visibleData });
    }
  }

  // 弹框确定按钮
  // eslint-disable-next-line react/sort-comp
  handleOk() {
    this.props.onCancel()
  }

  // 弹框取消按钮
  handleCancel() {
    this.props.onCancel()
  }

  openNotificationWithIcon = (type, message) => {
    notification[type]({
      message,
      description:
        '',
    });
  }

  getList(params) {
    const { customerId } = this.state.visibleData
    if (customerId === '' || customerId === undefined) {
      return
    }
    console.log('customerId', customerId)
    // 网路请求
    // 网路请求
    request({ ...apis.customer.recommendClient, urlData: { id: customerId }, params: { ...params } }).then(res => {
      this.setState({ dataSource: res })
    }).catch(err => {
      this.openNotificationWithIcon('error', err)
    })
  }

   // 分页
  onChange(pageNum) {
    this.getList({ pageNumber: pageNum, pageSize: 5 })
  }

  render() {
    const columns = [
      {
        title: '头像',
        // eslint-disable-next-line jsx-a11y/alt-text
        render: (text, records) => <img src={records.picture} width={50} height={50} />,
      },
      {
        title: '用户名',
        dataIndex: 'name',
        key: 'name',
      },
      {
        title: '电话',
        dataIndex: 'phone',
        key: 'phone',
      },
      {
        title: '性别',
        dataIndex: 'sex',
        key: 'sex',
        render: (text, records) => <span>{records.sex === 1 ? '男' : '女'}</span>,
      },
      {
        title: '意向项目',
        dataIndex: 'intention',
        key: 'intention',
      },
      {
        title: '推荐时间',
        dataIndex: 'createDate',
        key: 'createDate',
        render: (_, record) => <><span>{ record.createDate && moment(record.createDate).format('YYYY-MM-DD HH:mm:ss') }</span></>,
      },
      {
        title: '状态',
        // eslint-disable-next-line consistent-return
        render: (text, records) => {
          if (records.verifyStatus === 0) { return '未审核' }
          if (records.verifyStatus === 1) {
            if (records.reportRecommendStatus === 1) { return '报备' }
            if (records.reportRecommendStatus === 2) { return '推荐' }
           }
          if (records.verifyStatus === 2) { return '审核不通过' }
        },
      },
    ]
    return (
      <>
        <Modal
            title="推荐客户"
            width={800}
            destroyOnClose="true"
            footer={null}
            visible={this.state.visibleData.visible}
            // onOk={() => this.handleOk()}
            onCancel={(e) => this.handleCancel(e)}
          >
            {console.log('this.state.dataSource11111111111', this.state.dataSource.total)}
            <Table dataSource={this.state.dataSource.records} rowKey="integralrecord" columns={columns} pagination={{ total: this.state.dataSource.total, pageSize: this.state.dataSource.size, onChange: e => this.onChange(e) }} />
          </Modal>
      </>
    );
  }
}

export default ModalRecommendRecord
