import React, { useState, useEffect } from 'react';
import { Input ,Tabs,Table,Space, Button ,Form ,message} from 'antd';
const { TabPane } = Tabs;

import {connect,history} from 'umi';

// 图标
import { SearchOutlined,ClearOutlined,PlusOutlined } from '@ant-design/icons';
import ProTable from '@ant-design/pro-table';


import TitleSearch from '@/components/TitleSearch/TitleSearch'
import SearchOptionsCommnity from '@/components/SearchOptions/SearchOptionsCommnity'
import { RA, SA } from '@/utils/method';
import { objectColumns } from '@/utils/string'; 
import { timestampToTime } from '@/utils/time';
import CommunitySearch from "@/components/CommunitySearch/CommunitySearch";
const module="CellList"

import './celllist.less'

const CellList = (props:any) => {

  const columns = objectColumns([
    ["Community", "residentialName"],
    ["Administrator", "residentialManagerUserName"],  
    ["Operation Hours", null, (text: any, record: any) => (<div></div>)],
    ["Office Tel", "residentialPhone"],
    ["Address", "residentialAddress"],    
    ["Actions", null, (text: any, record: any) => (<Space size="middle">
      <a onClick={goToDetail.bind(this, record)}>Edit</a>
      <a onClick={goToDetail.bind(this,record)}>Detail</a>
    </Space>)],
  ])
  

  const { dispatch, Data , loading  , curString} = props;


  const onChange = e => {
    e.persist();
    console.log("表单输入的值", e.target.value);
  };

  useEffect(() => {
    RA(24, {communityName: "" }, module, dispatch);
  }, [])
  useEffect(() => {
    if (Data != null) {
      //console.log(columnsVal)
    }
  }, [Data])
  const CallbackSearch = (values:any) => {    
    RA(24, {communityName: values }, module, dispatch);
  }
  const goToAdd = () => {
    history.push("./CellList/Add");
  }
  const goToDetail = (values: any, e: any) => {
    SA(values,module,dispatch)
    history.push("./CellList/Detail");
  }

  
  // 表单标识
  const [form] = Form.useForm()
  // 表单提交
  const onFinishContract = (value:any)=>{
    // console.log(value)
    if(!value.communityName&&!value.contractNumber&&!value.contractTitle){
      message.error('Please enter one of them!')
    }else{
      console.log(value)
      let payload = {
        index: 19,
        page:{
          pageNum:1,
          contractNumber:value.contractNumber,
          contractTitle:value.contractTitle,
          communityName:value.communityName
        }
      }
      // requst(payload);
    }
  }

  // 选择小区名字并赋值
  const opname = (value:any)=>{
    form.setFieldsValue({
      'communityName' : value
    })
  }
  // 重置
  const onReset = () => {
    form.resetFields();
    let payload = {
      index: 19,
      page:{
        pageNum:1
      }
    }
  };
  
  // 点击搜索
  
  const CallBackTitleSearch= (comment: any) => {
    console.log(comment)

    // if (comment.communityName != null || comment.key != null || comment.status != null) {  
    //   var tmp = curString      
    //   tmp.subscribeDate = comment.key
    //   if (comment.status == null||comment.status==undefined) {
    //     tmp.status = 0; 
    //   } else {
    //     tmp.status = comment.status
    //   }
    //   tmp.communityNameList = comment.communityName
    //   tmp.curPage=1
    //   QA(tmp) 
    //   console.log(tmp)
    //   //中断
    //   RA(9, { userToken: token, pageNum: "1", subscribeDate: tmp.subscribeDate, status: tmp.status,communityNameList:comment.communityName })
    // }
  }
  return (
    <div > 
    {
        Data != null ? <>
          {/* <TitleSearch listkey={['communityName']}   list={['Community Name']}  onSubmit={CallBackTitleSearch}/> */}
          <div className='contop'>
          <TitleSearch
              status={[{
                name: ["status", "Order status"],
                data: [[0, "All"], [1, "Applied"], [2, "Reserved"], [3, "Used"], [4, "Cancelled"]]
              }]}
        time={["key", "Booking time "]}
        community={"communityName"}  
        checklist={curString.communityNameList!=null?curString.communityNameList:null}
        onSubmit={CallBackTitleSearch} />
            {/* <Form
                autoComplete= "off"
                layout="inline"
                form={form}
                name="contract"
                onFinish={onFinishContract}
              >
                <Form.Item name="communityName">
                  <SearchOptionsCommnity 
                      // ubmit={extendName} 
                      opname={opname} />
                </Form.Item>
                <Form.Item name="contractNumber">
                  <Input allowClear  placeholder='Contract No'  />
                </Form.Item>
                <Form.Item name="contractTitle">
                  <Input allowClear  placeholder='Contract Title' />
                </Form.Item>
                <Form.Item>
                  <Button type="primary" htmlType="submit" icon={<SearchOutlined />} loading={loading}>Search </Button>
                  <Button htmlType="button" onClick={onReset} style={{marginLeft:'15px'}}  icon={<ClearOutlined />} loading={loading}> Reset</Button>
                </Form.Item>
              </Form> */}
          </div>
          <ProTable 
            // request={requestHeadl}
            pagination={false}      // 隐藏默认分页
            rowKey={"id"} 
            dataSource={Data.rows}
            columns={columns} 
            search={false}
            loading={loading}
            toolBarRender={() => [
              <Button key="3" type="primary" onClick={goToAdd}>
                <PlusOutlined />Create new Community
              </Button>,
            ]}
            options={{
              density: true,
              fullScreen: true,
              reload: () => {
                // resetHandler();
              },
              setting: false,
            }}
            headerTitle="Community List"
            // pagination={{ defaultCurrent: 1, total: Data.totalRow }} 
            />
          {/* <Table loading={false} rowKey="id" style={{ marginTop: 16 }}
            dataSource={Data.rows}
            columns={columns}
            pagination={{ defaultCurrent: 1, total: Data.total}} />   */}
          
        </> : null
    }  
      
    </div>
  );
};

function map(state:any) {
  console.log(state)
  const loading = state.loading.models.CellList
  const { Data ,curString } = state[module]
  return { Data , loading ,curString}
}
export default connect(map)(CellList);