import React, { useState, useEffect } from 'react';
import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Radio, Tag, Tooltip, Tabs, Table, notification, Modal,message } from 'antd';
import moment from 'moment';
import request from '../../../../../utils/request';
import apis from '../../../../../services/apis';
import Styles from './style.less';
import { router } from 'umi';
import BlockSelect from '../../../../../components/HouseSelect/BlockSelect'
import UnitSelect from '../../../../../components/HouseSelect/UnitSelect'
import FloorSelect from '../../../../../components/HouseSelect/FloorSelect'
import RoomSelect from '../../../../../components/HouseSelect/RoomSelect'
import ApartmentSelect from '../../../../../components/HouseSelect/ApartmentSelect';
import BasicHeat from './BasicHeat';
import Navigate from '@/components/Navigate';
/**
 *图片设置
 *
 * @param {*} props
 * @returns
 */
function RaiseHouse(props) {
  // eslint-disable-next-line react-hooks/rules-of-hooks
  const [data, setData] = useState([])
  const [basicHeat, setBasicHeat] = useState({visable:false, houseId:'', salesBatchId:''})
  const [houseId, setHouseId] = useState('')
  const raiseId = props.raiseId.raiseId
  const buildingId = props.buildingId
  const salesBatchId = props.salesBatchId
  console.log(salesBatchId,'updateNameupdateNameupdateName');
  useEffect(() => {
    getList()
  }, [])

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

  function getList(params) {
    // 网路请求
    request({ ...apis.house.houseRaise, params: { ...params,raiseId:raiseId, salesBatchId: salesBatchId, buildingId: buildingId} }).then(res => {
      console.log(res,"resresres")
      setData(res)
    }).catch(err => {
      openNotificationWithIcon('error', err.message)
    })
  }

    // 重置搜索
    function handleReset () {
      props.form.resetFields();
      getList({ pageNumber: 1, pageSize: 10 })
    }

    function showEdi(e) {
      props.onSuccess(e);
    }
    
  // 分页
  const changePageNum = (pageNumber) => {
    getList({ pageNumber: pageNumber, pageSize: 10,raiseId:raiseId, salesBatchId: salesBatchId, buildingId: buildingId, ...props.form.getFieldsValue() })
  }

  const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      setHouseId(selectedRows)
    },
  };

  // 提交事件
  const handleSubmit = e => {
    e.preventDefault();
    props.form.validateFields((err, values) => {
      if (!err) {
        console.log('提交数据: ', values)
        getList({ pageNumber: 1, pageSize: 10, ...values })
      }
    });
  }

  function showBaseModal(e){
    if (houseId.length <=0){
      message.info("请选择数据");
      return;
    }
    setBasicHeat(e);
  }

  const columns = [
    {
      title: '房源编号',
      dataIndex: 'houseId',
      key: 'houseId',
    },
    {
        title: '房源',
        dataIndex: 'roomInfo',
        key: 'roomInfo',
        render: (text, records) => <span>{records.termName}/{records.blockName}/{records.unitName}/{records.floorName}/{records.roomName}</span>,
    },
    {
        title: '价格(万元)',
        dataIndex: 'price',
        key: 'price',
      },
    {
      title: '对应户型',
      dataIndex: 'apartmentName',
      key: 'apartmentName',
    },
    {
      title: '发布状态',
      dataIndex: 'status',
      key: 'status',
      render: (text, records) => <span>{records.status === 1 ? '已发布':'未发布'}</span>,
    },
    {
        title: '认筹基础热度',
        dataIndex: 'raiseHeat',
        key: 'raiseHeat',
    },
    {
        title: '认筹实际热度',
        dataIndex: 'raiseRealHeat',
        key: 'raiseRealHeat',
        render:  (x, row) => <Navigate onClick={() => showEdi({type: "identifyingChips",houseId: row.houseId})}>{row.raiseRealHeat}</Navigate>,
    },
    {
      title: '锁定状态',
      dataIndex: 'houseLockingStatus',
      key: 'houseLockingStatus',
      render: (text, records) => <span>{records.houseLockingStatus === 'locked' ? '已锁定':'未锁定'}</span>,
    },
    {
      title: '锁定认筹单编号',
      dataIndex: 'raiseRecordId',
      key: 'raiseRecordId',
    },
    {
        title: '最后修改人',
        dataIndex: 'updateName',
        key: 'updateName',
    },
    {
        title: '最后修改时间',
        dataIndex: 'updateDate',
        key: 'updateDate',
        render: (x, row) => <><span>{row.updateDate == null ? null : `${moment(row.updateDate).format('YYYY-MM-DD HH:mm:ss')}`}</span></>,
    },
  ]
  const { getFieldDecorator } = props.form
  return (
    <>
    <Form layout="inline" onSubmit={e => handleSubmit(e)}>
        <Form.Item>
          {getFieldDecorator('termname')(
            <Input placeholder="期区"/>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('blockName')(
            <Input placeholder="楼栋"/>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('unitName')(
            <Input placeholder="单元"/>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('floorName')(
            <Input placeholder="层"/>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('roomName')(
            <Input placeholder="房号"/>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('apartmentId')(
             <ApartmentSelect buildingId={props.buildingId} />
          )}
        </Form.Item>        
        <Form.Item>
          {getFieldDecorator('status')(
             <Select placeholder="发布状态" style={{width: '120px'}}>
             <Option value="0">否</Option>
             <Option value="1">是</Option>
           </Select>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('lockingStatus')(
             <Select placeholder="锁定状态" style={{width: '120px'}}>
             <Option value="unlocked">未锁定</Option>
             <Option value="locked">已锁定</Option>
           </Select>,
          )}
        </Form.Item>
        <Form.Item>
          {getFieldDecorator('houseId')(
            <Input placeholder="房源编号"/>,
          )}
        </Form.Item>
        <Form.Item>
          <Button type="primary" htmlType="submit" >
            搜索
          </Button>
          <Button style={{ marginLeft: 8 }} onClick={handleReset}>
            重置
            </Button>
        </Form.Item>

      </Form>
      <Button type="primary" onClick={() => showBaseModal({visable:true, houseId: houseId, salesBatchId:salesBatchId})} style={{ marginTop: '20px', marginRight:'20px'}}>批量修改基础热度</Button>
      <div style={{marginTop:'20px', marginBottom:'20px'}}><span>共筛选出{data.total}条数据</span></div>
      <Table rowSelection={rowSelection} dataSource={data.records} columns={columns} pagination={false} rowKey="carouseFigureList"/>
      <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
        <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current}/>
      </div>   
      <BasicHeat visible={basicHeat.visable} houseId={basicHeat.houseId} salesBatchId={basicHeat.salesBatchId} onCancel={() => setBasicHeat({visable:false, salesBatchId:'',houseId:[]})} onSuccess={()=>getList()}/>   
    </>
  )
}
const WrappedHeader = Form.create({ name: 'RaiseHouse' })(RaiseHouse);
export default WrappedHeader
