calendar.js 2.04 KB
import util from '../../../utils/util';
import App from '../../../utils/api';
let date=new Date();
Component({
	properties:{
		seller:Object,
		//选中日期
		date:{
			type:String,
			value:util.unixtoTime(date/1000,'YYYY-MM-DD'),
		}
	},
	data: {
		curYear: date.getFullYear(), // 年份
		curMonth: date.getMonth() + 1,// 月份 1-12
		day:date.getDate(),
		header_show: true, // 主标题是否显示
		next: true, // 下一个月按钮是否显示
		closelaststyle:true,
		speciallist: [],
		nextNum:0,
  },
  attached(){
	//默认标记特殊日期
	this.getspeciallist();
	this.gethousefulldate();
  },
  ready(){
	  this.triggerEvent('selectdate',{date:this.data.date,action:'defalut'})
  },
  methods:{
	//默认标记特殊日期
	getspeciallist(){
		let speciallist = [
		  {date: util.unixtoTime(date/1000, 'YYYY-MM-DD'), background: '', text: '今'},
		  {date: util.unixtoTime(date + 86400, 'YYYY-MM-DD'), background: '', text: '明'}
		];
		this.setData({
			speciallist:speciallist
		})
	},
	//根据指定年份月份获取当月满房的日期
	gethousefulldate(){
		let parmdata={
			sid:this.data.seller.id,
			date:this.data.date
		}
		App.Customer.GetHouseFullDate(parmdata).then((json)=>{
			console.log(json)
			if(json.ret==200){
				if(json.data.length>0){
					this.changespeciallist(json.data)	
				}
				
			}
		})
	},
	//修改标记特殊日期
	changespeciallist(houseFullDate){
		let speciallist=this.data.speciallist;
		let newspeciallist=[];
		houseFullDate.forEach((v,i)=>{
			newspeciallist.push({
				date:v,
				background:'',
				text:'满'
			})
		})
		speciallist.forEach((v,i)=>{
			if(houseFullDate.indexOf(v.date)==-1){
				newspeciallist.push(v)
			}
		})
		this.setData({
			speciallist:newspeciallist
		})
	},
	//下一月
	nextMonth(e){
		this.setData({
			nextNum:this.data.nextNum+1
		})
	},
	//上一月
	prevMonth(e){
		this.setData({
			nextNum:this.data.nextNum-1
		})
	},
	//点击日期
	selectDate(e){
		this.setData({
			date:e.detail.date
		})
		this.triggerEvent('selectdate',{date:this.data.date,action:'click'})
	}
  }
  
})