calendar.js 2.72 KB
import util from '../../../../utils/util';
import App from '../../../../utils/api';
Component({
	properties:{
		seller:Object,
		date:{
			type:String,
			value:util.unixtoTime(new Date()/1000,'YYYY-MM-DD'),
		},
		setroom:{
			type:Object,
			value:{}
		}
	},
	data:{
		marklist:[]
	},
	attached(){
		this.marklist=[];
		this.setData({
			date:util.unixtoTime(new Date()/1000,'YYYY-MM-DD')
		})
		this.showYearMonth=this.getshowmonth();
		this.gethousefulldate(this.data.seller,this.showYearMonth);
		this.triggerEvent('tellselectdate',{date:util.unixtoTime(new Date()/1000,'YYYY-MM-DD'),action:'defalut'});
	},
	observers: {
		'setroom'(newsetroom){
			console.log('calendar-room',newsetroom)
			if(newsetroom && newsetroom.id){
				this.marklist=[];
				this.gethousefulldate(this.data.seller,this.showYearMonth);
			}
		}
	},
	methods:{
		//获取当前选中日期
		getshowmonth(){
			let datearr=this.data.date.split('-');
			return{
				showyear:Number(datearr[0]),
				showmonth:Number(datearr[1]),
			}
		},
		//切换月份
		getmonth(e){
			console.log('tellmonth',e)
			this.showYearMonth=e.detail;
			if(e.detail.action='click'){
				this.gethousefulldate(this.data.seller,this.showYearMonth);
			}
		},
		//根据指定年份月份获取当月满房的日期
		gethousefulldate(seller,showYearMonth){
			let parmdata={
				sid:seller.id,
				type:'month',
				date:showYearMonth.showyear+'-'+(showYearMonth.showmonth<10 ? '0'+showYearMonth.showmonth : showYearMonth.showmonth)
			}
			App.Customer.GetHouseFullDate(parmdata).then((json)=>{
				console.log(json)
				if(json.ret==200){
					let marklist=[];
					console.log(marklist)
					if(json.data && json.data.length>0){
						json.data.forEach((v,i)=>{
							marklist.push({
								date:v,
								mark:'满'
							})
						})
						this.marklist=marklist;
					}
					this.getFillDate(seller,showYearMonth);
				}
			})
		},
		getFillDate(seller,showYearMonth){
			let parmdata={
				sid:seller.id,
				type:'month',
				date:showYearMonth.showyear+'-'+(showYearMonth.showmonth<10 ? '0'+showYearMonth.showmonth : showYearMonth.showmonth)
			}
			App.Customer.GetTableFillUpDate(parmdata).then((json)=>{
				if(json.ret==200){
					let marklist=this.marklist;
					let templist=[];
					marklist.forEach((v,i)=>{
						templist.push(v.date)
					})
					json.data.forEach((v,i)=>{
						if(templist.length>0){
							if(templist.indexOf(v)==-1){
								marklist.push({
									date:v,
									mark:'置'
								})
							}
						}else{
							marklist.push({
								date:v,
								mark:'置'
							})
						}
					})
					this.marklist=marklist;
					this.setData({
						marklist:this.marklist
					})
				}
				
			})
		},
		tellselectdate(e){
			this.triggerEvent('tellselectdate',e.detail);
		}
	}
})