<template>
	<view class="subscribeTicket">
		<view>
			<calendar ref="calendar" :datePrice="datePrice" :curryear='curryear' :currmonth='currmonth'
				howManyMonth="6" mode="2" @changeDate="changeDate" @changeMonth="changeMonth"
				:defaultSelect="date"></calendar>
		</view>
	</view>
</template>

<script>
	import calender from './njzz-calendar/njzz-calendar.vue'
	export default {
		components: {
			calender
		},
		props: {
			date: {
				type: String,
				default: ""
			},
			TicketID: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				curryear: 0,
				currmonth: 0,
				datePrice: [

				],
			}
		},
		watch: {
			date(val, oldVal) {
				console.log(val, oldVal)
				let newMonth = val.split('-')[1]
				let oldMonth = oldVal.split('-')[1]
				if(newMonth!=oldMonth){
					console.log(newMonth!=oldMonth)
					this.getGoodsDateList()
				}
				
			}
		},
		mounted() {
			let year = new Date().getFullYear(); //年
			let month = new Date().getMonth() + 1; //月
			if(month<10){
				month = ('0' + month)
			}
			this.curryear= year
			this.currmonth= month
			console.log('sub')
			this.getGoodsDateList()
		},
		methods: {
			getGoodsDateList() {
				this.request2({
						url: '/api/AppletDining/GetMonthTicketList',
						data: {
							TicketID: this.TicketID,
							BuyDate: this.date
						}
					},

					res => {
						let data = res.data;
						let datePrice = [];
						data.forEach(x => {
								let obj = {}
								obj.date = x.Date;
								if(x.IsHavePrice===1){
									obj.price = x.HPriceB;
								}else{
									obj.price = "";
								}
								
								datePrice.push(obj)
						})
						this.datePrice = datePrice


					}
				);
			},
			changeMonth(nowMonth){
				let Month = nowMonth.year+'-'+nowMonth.month;
				this.getGoodsDateList(Month)
			},
		}

	}
</script>

<style lang="scss" scoped>
	.subscribeTicket {
		height: 70vh;
		padding: 45rpx 45rpx 90rpx;
	}
</style>
