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

import {connect,history} from 'umi';



import { RA, SA } from '@/utils/method';
import { objectColumns, stringTab } from '@/utils/string';
import { timestampToTime } from '@/utils/time';
const module="CommunityService"
const Renovation = (props:any) => {

  //  const decoration_status = [[0, "待处理"], [1, "已批准"], [2, "已拒绝"]]
  const decoration_status = [[0, "Pending"], [1, "Approved"], [2, "Rejected"]]

  const columns = objectColumns([
    ["Community", "community_name"],
    ["Applicant", "applyfor_name"],
    ["Unit", null, (text: any, record: any) => (<div>{record.community_build_decorate}#{record.community_floor_decorate}-{record.community_room_decoate}</div>)],
    ["Content", "decoration_content", (text: any) => (<div>{stringTab(text)}</div>)],
    ["Request Time", "create_time",(text: any) => (<div>{timestampToTime(text.time)}</div>)],
    ["status", "decoration_status",(text: any) => (<div>{decoration_status[parseInt(text)][1]}</div>)],
    ["Actions",null, (text: any, record: any) => (<Space size="middle"> <a onClick={goToDetail.bind(this,record)}>Detail</a></Space>)],
  ])

  const { dispatch, Data8 } = props;
  const formRef = useRef(null)

  useEffect(()=>{
    RA(23, { serviceType: "6", id: "" }, module, dispatch)

// applyfor_name: "jack-小白白"
// communityId: "7e5c6fd2f4ba497a90e64535df6e9088"
// community_build_decorate: "01"
// community_floor_decorate: "00"
// community_name: "A4"
// community_room_decoate: "767"
// contact_name: "15626274096"
// contact_phone: "jack-小白白"
// create_time: {date: 10, day: 4, hours: 19, minutes: 39, month: 8, …}
// decorationBegin_time: {date: 10, day: 4, hours: 0, minutes: 0, month: 8, …}
// decorationEnd_time: {date: 10, day: 4, hours: 0, minutes: 0, month: 8, …}
// decoration_content: "滚滚滚"
// decoration_status: 0
// deleted: 0
// id: "977591272158003200"
// ownerId: "c4da40676d044487b37e7a1bdc6dd045"
//     update_time: {
//       date: 10, day: 4, hours: 19, minutes:

  }, [])

  const goToDetail = (values: any, e: any) => {
      SA(values,module,dispatch)
      history.push('./RenovationApplication/Detail')
  }
  return (
    <div style={{ width: "100%", minWidth: 1020, padding: 34, backgroundColor: "#ffffff" }}>
      {
                Data8 != null ?
                <>
                  <Table loading={false} rowKey="id" style={{ marginTop: 16 }}
                  dataSource={Data8.data.rows}
                  columns={columns}
                  pagination={{ defaultCurrent: 1, total: Data8.total }} />
                </>
          : null
      }
    </div>
  );
};

function map(state:any) {
  const { Data8} = state[module]
  return { Data8}
}
export default connect(map)(Renovation);
