<template>
	<view class="book-month">
		<CalendarCard @nowDateList="nowDateList" ref="date" @click="(data)=>$emit('clickDate',data.date)">
			<template v-slot:default="slot">
				<view class="book-month-area_data">
					<template v-if="allDateInfo[slot.data.date]">
						<view class="iconfont iconxing2"
							v-if="allDateInfo[slot.data.date].importantDates&&allDateInfo[slot.data.date].importantDates.length>0"
							style="color: #e64340;font-size: 25rpx;transform: scale(0.8);width: 20rpx;">
						</view>
						<view class="flex-n fac" v-if="allDateInfo[slot.data.date].orderHouseTypeText01">
							<image class="icon" src="../../../static/c1.png"></image>
							<view class="num flex-1">{{allDateInfo[slot.data.date].orderHouseTypeText01}}</view>
						</view>
						<view class="flex-n fac" v-if="allDateInfo[slot.data.date].orderHouseTypeText03">
							<image class="icon" src="../../../static/c2.png"></image>
							<view class="num flex-1">{{allDateInfo[slot.data.date].orderHouseTypeText03}}</view>
						</view>
						<view class="flex-n fac" v-if="allDateInfo[slot.data.date].orderHouseTypeText02">
							<image class="icon" src="../../../static/c3.png"></image>
							<view class="num flex-1">{{allDateInfo[slot.data.date].orderHouseTypeText02}}</view>
						</view>
						<view class="flex-n fac" v-if="isDisplayPrein=='1'&&allDateInfo[slot.data.date].totalMoney">
							<image class="icon" src="../../../static/c4.png"></image>
							<view class="num flex-1 line-1">{{allDateInfo[slot.data.date].totalMoney}}</view>
						</view>
					</template>
				</view>
			</template>
		</CalendarCard>

		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	const app = getApp({
		allowDefault: true
	});
	export default {
		name: 'book-month',
		props: {
			refresh: Boolean
		},
		data() {
			return {
				current: 1,
				left: 0,
				right: 2,
				xqday: ['一', '二', '三', '四', '五', '六', '日'],
				monthList: [],
				ImpList: [], //重点日期
				orderTotalList: [], //订单总计数
				threeMonthList: ['', '', ''],
				// dataList: [],
				callPhone: '',
				column: -1,
				row: -1,
				disabletouch: false,
				monthday: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
				showDataAnimate: {},

				dx: 0,
				weekName: ['一', '二', '三', '四', '五', '六', '日'],
				showday: {}, //需要传入的值
				choose: 0,
				animateIn: '',
				timeout: '',
				date: '',

				total: 0,
				pageNum: 1,
				scrollTop: 0,
				showLoading: false,

				savedata: {},

				isDisplayPrein: '0',

				dateList: [],

				allDateInfo: {

				},
				nowChooseDate:'',//现在选中的日期

			}
		},
	
		methods: {
			nowDateList(dateList) {
				this.allDateInfo = {};
				this.dateList = dateList;
				console.error(2131234938985492843)
				this.$emit('changeDate', dateList[15].date)
				let k=-1;
				for(let i in dateList){
					//选择的日子在列表中的
					if(dateList[i].date==this.nowChooseDate&&dateList[15].mm==Number(this.nowChooseDate.substring(5,7))){
						k=i;
						break;
					}
				
				}
				if(k==-1){
					console.error(this.nowChooseDate,324213123)
					for(let i in dateList){
						if(dateList[i].dd==1){
							 this.$emit('changeDate', dateList[i].date)
							break;
						}
					}
					
				}
				this.orderCalendarTotal(dateList);
				this.bookImportantDate(dateList);
				this.getAuthState();
			},
			getDate(date) {
				console.log(date)
				this.nowChooseDate=date;
				this.$nextTick(() => {
					this.$refs.date.setDate(date);
				})
			},
			//重点日期
			bookImportantDate(dataList) {
				this.$axios.post("app/order/orderImportantDate", {
					"startTime": dataList[0].date,
					"endTime": dataList[dataList.length - 1].date,
					"storeId": uni.getStorageSync('storeId')
				}).then(res => {
					this.getOrderDateInfo(res.data.list);
				}).catch(err => {
					this.$refs.uToast.error(err.msg)
				})
			},
			//日历订单汇总
			orderCalendarTotal(dataList) {
				var houseTypeIds = uni.getStorageSync('searchField') || [];
				this.$axios.post("app/order/orderCalendarTotalCalc", {
					"startTime": dataList[0].date,
					"endTime": dataList[dataList.length - 1].date,
					"storeId": uni.getStorageSync('storeId'),
					"houseTypeIds": houseTypeIds,
				}).then(res => {
					this.getOrderDateInfo(res.data.list);
				}).catch(err => {
					this.$refs.uToast.error(err.msg)
				})
			},
			getOrderDateInfo(list) {
				let info = this.allDateInfo;
				for (let i in list) {
					if (info[list[i].orderDate]) {
						this.$set(info, [list[i].orderDate], Object.assign(info[list[i].orderDate], list[i]))
					} else {
						this.$set(info, [list[i].orderDate], list[i])
					}
				}
				for (let key in info) {
					if (info[key].houseOrderCalc) {
						let orderHouseTypeText01 = 0,
							orderHouseTypeText02 = 0,
							orderHouseTypeText03 = 0;
						for (let i in info[key].houseOrderCalc) {
							if (info[key].houseOrderCalc[i].houseTypeCode == '01') {
								orderHouseTypeText01 += info[key].houseOrderCalc[i].orderCount
							}
							if (info[key].houseOrderCalc[i].houseTypeCode == '02') {
								orderHouseTypeText02 += info[key].houseOrderCalc[i].orderCount
							}
							if (info[key].houseOrderCalc[i].houseTypeCode == '03') {
								orderHouseTypeText03 += info[key].houseOrderCalc[i].orderCount
							}
						}
						if (orderHouseTypeText01) {
							this.$set(info[key], 'orderHouseTypeText01', orderHouseTypeText01)
						}
						if (orderHouseTypeText02) {
							this.$set(info[key], 'orderHouseTypeText02', orderHouseTypeText02)
						}
						if (orderHouseTypeText03) {
							this.$set(info[key], 'orderHouseTypeText03', orderHouseTypeText03)
						}
					}
				}
				this.allDateInfo = Object.assign(this.allDateInfo, info)
			},
			//权限
			getAuthState() {
				this.$axios.post("storeAuth/findByRoleIdStoreId", {
					"roleId": uni.getStorageSync('roleId'),
					"storeId": uni.getStorageSync('storeId')
				}).then(res => {
					console.log(res.data)
					//不可编辑
					this.isDisplayPrein = res.data.auth.isDisplayPrein;

				}).catch(err => {
					this.$refs.uToast.error(err.msg);
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.book-month {
		.book-month-area_data {
			height: 100%;
			padding: 0 10rpx;
			position: relative;

			.iconxing2 {
				position: absolute;
				top: -32rpx;
				left: 34rpx;
			}

			.icon {
				width: 30rpx;
				min-width: 30rpx;
				height: 30rpx;
				margin-top: 4rpx;
			}

			.num {
				color: #666666;
				font-size: 20rpx;
				text-align: center;
			}
		}

	}

</style>
