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

import { connect, history } from 'umi';

const orderStatus = [[0, "已发单"], [1, "待上门"], [2, "进行中"], [3, "已完成"], [4, "已取消"]]
const goToDetail = () => {
  
}
const columns = objectColumns([
  ["OrderNumber", "orderNumber"],
  ["Community", "communityName"],
  ["Owner Name", "ownerName"], 
  ["type", null, (text: any, record: any) => (<div>{orderStatus[record.orderStatus][1]}</div>)],
  ["Content", "serviceContent"], 
  ["Order Time", null, (text: any, record: any) => (<div>{getStringToTime(record.orderSendTime)}</div>)],  
  ["Booking Time", null, (text: any, record: any) => (<div>{getStringToTime(record.orderReserveTime)}</div>)],  
  ["Actions",null, (text: any, record: any) => (<Space size="middle"> <a onClick={goToDetail.bind(this,record)}>Detail</a></Space>)],
])

import { RA } from '@/utils/method';
import { objectColumns } from '@/utils/string';
import TitleSearch from '@/components/TitleSearch/TitleSearch';
import { timestampToTime, getStringToTime } from '@/utils/time';


const module="OrderManagement"
const Order = (props:any) => {

  const { dispatch, Data } = props;
  const formRef = useRef(null)
  useEffect(() => {
    RA(30, {orderNumber:"",serviceType:"0"}, module, dispatch)
  }, [])
  // useEffect(() => {
  //   if (Data != null) {
  //     console.log("首页信息")
  //     console.log(Data)
  //   }
  // },[Data])
  const CallBackTitleSearch = (value: any) => {
    if (value.orderNumber != null || value.serviceType != null) {
      RA(30, value, module, dispatch)
    }
  }
  return (
    <div style={{ width: "100%", minWidth: 1020, padding: 34, backgroundColor: "#ffffff" }}>      

      {
        Data != null ? <>
          <TitleSearch
            status={[{
              name: ["serviceType", "订单状态"],
              data: orderStatus
            }]}
            listkey={['orderNumber']}
            list={['订单号']}
            onSubmit={CallBackTitleSearch}
          ></TitleSearch>

             <Table loading={false} rowKey="id" style={{ marginTop: 16 }}
            dataSource={Data.data.rows}
            columns={columns}
            pagination={{ current: 1, total: Data.total }} />    
          
          </>:null
      }

    </div>
  );
};

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

// 订单管理模块的order_status  int(11) NULL 
// /tos/tosOrder/get
// {
//  "orderNumber":"123",
// "serviceType":"0"
// }

// 返回的数据
// communityAddress: "TianHeStreet"
// communityId: "0166bd9a1e6f4efca1b867699a649e1d"
// communityName: "A Garden"
// count: 0
// deleted: 0
// extend: ""
// id: "0166bd9a1e6f4efca1b867699a649e1d"
// orderAcceptTime: "Jul 2, 2020 12:00:00 AM"
// orderFinishTime: "Jul 3, 2020 12:00:00 AM"
// orderNumber: "123"
// orderReserveTime: "Jul 3, 2020 12:00:00 AM"
// orderSendTime: "Jul 1, 2020 12:00:00 AM"
// orderStatus: "0"
// ownerId: "0166bd9a1e6f4efca1b867699a649e1d"
// ownerName: "张三"
// ownerPhone: "18817676732"
// serviceContent: "家具维修"
// serviceType: "0"

// order_send_time 发单时间
// order_accept_time 接单时间
// order_reserve_time 预约时间