Calendar.js 5.0 KB
import React,{PropTypes} from 'react';  
import calendarUtil from '../../utils/calendarUtil';  
import { Button, Icon ,Badge} from 'antd';
import moment from 'moment';
import cx from 'classnames';
import s from './calendarLess.les';

const solarFestivalData = {
	'd0101':'元旦节',  
	'd0214':'情人节', 
	'd0308':'妇女节',
	'd0312':'植树节',     
	'd0401':'愚人节',  
	'd0501':'劳动节',
	'd0504':'青年节',      
	'd0601':'儿童节',       
	'd0801':'建军节',      
	'd1001':'国庆节',          
	'd1224':'平安夜',
	'd1225':'圣诞节' 
	};


class Calendar extends React.Component {
	constructor (props, context) {
		super(props, context); 
		this.preMonth=this.preMonth.bind(this);
		this.nextMonth=this.nextMonth.bind(this); 
	}
	static propTypes={
		onChange: PropTypes.func,
		choseDay:PropTypes.object 
	}  
	static defaultProps = {  
		current:moment(new Date()),
        onChange:(choseDay)=>{
         	console.log(choseDay.format('YYYY-MM-DD'));
        },
        todoList:{}
    } 
    componentDidMount() {  
	}

	componentWillReceiveProps(nextProps){
		
	}
	clickDay(day){ 
		this.props.onChange(moment(day.year+"-"+day.month+"-"+day.day));
	}
	preMonth(){
		const {current} = this.props;  
		this.props.onChange(current.subtract(1, 'months'));
	}
	nextMonth(){
		const {current} = this.props;  
		this.props.onChange(current.add(1,'months'));
	}
	render(){  
		const {current,todoList}=this.props;
		const months=calendarUtil.getMonths(current.format('YYYY'),current.format('MM'));    
		const renderDayName=(day)=>{
			if(day){
				if(day.lunarFestival){
					return day.lunarFestival;
				}else if(day.solarFestival){
					return day.solarFestival;
				}else if(day.lunarDayName&&'初一'==day.lunarDayName){
					return day.lunarMonthName;
				}else{
					return day.lunarDayName;
				} 
			}else{
				return "";
			} 
		}
		return(
			<div>	
				<div></div>
				<div>
					<table className={cx(s.calendar_wrap,s.lg)}>
					  <thead>
						<tr className={s.calendar_week_head}>
							<td className={s.week_day}></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td></td>
							<td className={s.week_day}></td>
						</tr> 
					  </thead>
					  <tbody>
						{months.map((week,i)=>{
							return (
								<tr key={i}> 
									{
										week.map((day,j)=>{ 
											let currentDay=false
											if(current.format('M-D')==(day.month+"-"+day.day)){
												currentDay=true
											} 
											const state=todoList[""+day.year+day.month+day.day]
											if(state&&state.color=='Warning'){
												return (
													<td className={day.week==0||day.week==6?s.week_day:null} key={j}>
														<div className={cx("dayInfo-2Vtsl_0",s.week_day_td_wrap)}>
															<Badge  status="warning" style={{ backgroundColor: '#ffbf00',position: 'absolute',right:0}} > 
																<p onClick={this.clickDay.bind(this,day)} className={s.day_nmuber_wrap}>  
																	<span className={cx(currentDay?s.current_day:null,s.day_wrap)}>{day&&day.day} </span> 
																</p> 
															</Badge>
						 									<p className={cx(s.week_day_nongli_wrap)}>{renderDayName(day)}</p>
						 									
						 								</div>
						 							</td> 
												)
											}else if(state&&state.color){
												return (
													<td className={day.week==0||day.week==6?s.week_day:null} key={j}>
														<div className={cx("dayInfo-2Vtsl_0",s.week_day_td_wrap)}>
															<Badge status="warning" style={{ backgroundColor: '#d9d9d9',position: 'absolute',right:0}} > 
																<p onClick={this.clickDay.bind(this,day)} className={s.day_nmuber_wrap}>  
																	<span className={cx(currentDay?s.current_day:null,s.day_wrap)}>{day&&day.day} </span> 
																</p> 
															</Badge>
						 									<p  className={cx(s.week_day_nongli_wrap)}>{renderDayName(day)}</p>
						 									
						 								</div>
						 							</td> 
												)
											}else{
												return (
													<td className={day.week==0||day.week==6?s.week_day:null} key={j}>
														<div  className={cx("dayInfo-2Vtsl_0",s.week_day_td_wrap)}> 
															<p onClick={this.clickDay.bind(this,day)} className={s.day_nmuber_wrap}>  
																<span className={cx(currentDay?s.current_day:null,s.day_wrap)}>{day&&day.day} </span> 
															</p>  
						 									<p  className={cx(s.week_day_nongli_wrap)}>{renderDayName(day)}</p>
						 									
						 								</div>
						 							</td> 
												)
											} 
										})
									}  
		                        </tr>
							)
						})}
					  </tbody>
					</table>
				</div>{/*
				<div className={s.bottom_wrap}>
					<Button.Group size={'small'}>
			          <Button onClick={this.preMonth}>
			           	<Icon type="left" />
			          </Button>
			          <Button onClick={this.nextMonth}>
			           	<Icon type="right" />
			          </Button>
			        </Button.Group>
				</div>*/}
        	</div>

		); 
	}
}
 


export default Calendar;