import React, { useState, useEffect } from 'react';
import {connect,history,useModel,Loading} from 'umi';
import { Input ,Tabs,Table,Space, Button,Tooltip} from 'antd';
const { TabPane } = Tabs;

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

// import { objectColumns } from '@/utils/string'; 
import {timestampToTime3, timestampToTime} from '@/utils/time'

// 搜索框
import TitleSearch from '../../../components/TitleSearch/TitleSearch';


// communityNum: "A7"
// count: 0
// createTime: "Jul 8, 2020 7:38:37 PM"
// deleted: 0
// extend: ""
// id: "2f9b5e98a2ea4b79b75242b1b34301bd"
// noticEndTime: "Aug 23, 2020 7:38:29 PM"
// noticImageName: "3.jpg"
// noticScope: 0
// noticStartTime: "Aug 20, 2020 7:38:26 PM"
// noticText: "噶防范发更好覅单号梵蒂冈很反感辅导班梵蒂冈房管局覅北京饭店个法币发动机盖我甲方的GV第八届发第十九GIF大锅饭"
// noticTitlel: "大家好，今年端午节不放假"
// updateTime: "Jun 28, 2020 7:38:39 PM"


// import { RA } from '@/utils/method';

const goToAdd = () => {
  history.push("./CommunityAnnouncement/Add");
}
const module="CommunityAnnouncement"
const CommunityAnnouncement = (props:any) => {


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


  const columns = [
    {
      title:"community", 
      dataIndex:"communityNum",
      width: 400,
      ellipsis: {
        showTitle: false,
      },
    },
    {
      title:"Title", 
      dataIndex:"noticTitlel",
    },
    {
      title:"Publish Time", 
      dataIndex:"noticStartTime",
      render:(text: any, record: any) => (
        <Space size="middle">
          {text!=null? timestampToTime(text.time):null}
        </Space>
      )
    },
    {
      title:"noticScope", 
      dataIndex:"noticScope",
    },
    {
      title:"Actions", 
      render:(text: any, record: any) => (
        <Space size="middle"><a>Detail</a></Space>
      ),
    },
  ];
  useEffect(() => {
    RA(25,{communityNum: "", noticTitlel: "" , pageNum:1 },module,dispatch)
  },[1])


  // 
  
  const RA = (index:any,values: any) => { 
    dispatch({ 
      type: 'FacilityBookings/RA', 
      playload: {index:index, body:values } 
    }) 
  };


  const SA = (values: any) => { dispatch({ type: 'FacilityBookings/SA', playload: values }) };
  const QA = (values: any) => { dispatch({ type: 'FacilityBookings/QA', playload: values }) };
  
  const CA = () => { dispatch({ type: 'FacilityBookings/CA',  playload: null }) };

  // 点击搜索
  const CallBackTitleSearch= (comment: any) => {
    console.log(comment)

    if (curString.tab == 1) {  
      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 })
      }
    } else {
      if (comment.communityName != null || comment.facilityName != null) {
        var tmp = curString      
        tmp.communityNameList = comment.communityName
        tmp.facilityName = comment.facilityName
        tmp.curPage=1
        QA(tmp) 
        RA(8, {communityNameList: comment.communityName, facilityName: comment.facilityName, pageNum: "1"})
                                    
      }
    }
  }
  return (
    <div style={{ width: "100%", minWidth: 1020, padding: 34, backgroundColor: "#ffffff" }}>       
      {/* 搜索组件 */}
      {
        curString.tab == 1 ?
        <>
        <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} />
        </> :
        <>
        <TitleSearch
        listkey={['facilityName']}    list={['Facility name']}
        community={"communityName"}
        onSubmit={CallBackTitleSearch} />
        </>
      }  

      {Data!=null?
      <ProTable
        loading={loading}
        rowKey="id"
        style={{ marginTop: 16 }}
        dataSource={Data.rows}
        columns={columns}
        pagination={false}      // 隐藏默认分页
        search={false}
        toolBarRender={() => [
          <Button key="3" type="primary" onClick={goToAdd}>
            <PlusOutlined />Create new Announcement
          </Button>,
        ]}
        options={{
          density: true,
          fullScreen: true,
          reload: () => {
            // resetHandler();
          },
          setting: false,
        }}
        headerTitle="Announcement list"
      />:null}   
    </div>
  );
};

function map(state:any) {
  const loading = state.loading.models.FacilityBookings;
  const Data = state.FacilityBookings.NoticeList;
  const { curString } = state.FacilityBookings;
  return { Data,curString,loading }
}
export default connect(map)(CommunityAnnouncement);

// function mapStateToProps(state:any) {
//   const { Data, Data2,DataSave,curString,Result } = state.FacilityBookings;
//   const { token } = state.login;  
//   return {
//     Data,
//     Data2,
//     DataSave,
//     curString,
//     Result,
//     token
//   };
// }
// export default connect(mapStateToProps)(FacilityBookings);
//备注 发布人缺少 发布时间格式错误