<template>
	<view class="content">
		<!-- <image src="../../static/img/yuyue.png" mode="widthFix" style="width: 750rpx;"></image> -->
		<view class="hotgoods">
			<view class="hotgoods-item" v-for="item in goodList" :key="item.id"
				@click="navto('/pages/product/product?id=' + item.id)" style="height: 480rpx;">
				<view class="image-wrapper">
					<image class="image" :src="item.image" mode="scaleToFill"></image>
				</view>
				<view class="flex"
					style="flex-direction: column;justify-content: space-between;align-items: flex-start;height:120rpx;">
					<view class="title clamp">{{item.store_name}}</view>
					<view class="hot-price">
						<view class="price">
							<text class="font-size-sm"></text>
							￥{{ item.price * 1 }}
						</view>
						<view class="yuanPrice" v-if="item.ot_price*1 > item.price*1">￥{{ item.ot_price*1 }}</view>
					</view>
				</view>
			</view>
		</view>
		<empty v-if="loaded && goodList.length === 0"></empty>
		<uni-load-more v-else :status="loadingType"></uni-load-more>
		<!-- <view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">服务项目</text>
				<picker @change="bindPickerChange" :range="typeArray" range-key="lable" :value="state">
					<view class="desc">{{typeArray[state].lable}}</view>
				</picker>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">上门日期</text>
				<picker mode="date" :value="date" @change="bindDateChange">
					<view class="desc">{{date||'上门日期'}}</view>
				</picker>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">上门时间</text>
				<view class="desc" @click="open">{{timeArea||'请选择上门时间'}}</view>
			</view>
		</view> -->
		<buuug7-simple-datetime-picker ref="myPicker" @submit="handleSubmit"
			:time-hide="[true, true, true, true, true, false]" :time-label="['年', '月', '日', '时', '分']" />
		<uni-popup ref="popupkf" type="bottom">
			<smh-time-range @confrim="confrim" @cancel="cancel"></smh-time-range>
		</uni-popup>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from '@/components/empty';
	import {
		getDefaultAddress,
		createSubscribe
	} from '@/api/user.js'
	import {
		groomList,
		getProducts
	} from '@/api/product.js';

	export default {
		components: {
			empty,
			uniLoadMore
		},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				mark: '',
				date: currentDate,
				addressImg: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAu4AAAAFCAYAAAAaAWmiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6Rjk3RjkzMjM2NzMxMTFFOUI4RkU4OEZGMDcxQzgzOEYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6Rjk3RjkzMjQ2NzMxMTFFOUI4RkU4OEZGMDcxQzgzOEYiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpGOT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				state: 2,
				typeArray: [
					// {
					// 	value: 1,
					// 	lable: '洗衣'
					// },
					{
						value: 2,
						lable: '家政'
					},
					{
						value: 3,
						lable: '维修'
					}
				],
				birthday: '',
				timeArea: "",
				yyTime: '', //预约时间
				loading: false,
				goodList: [],
				loadingType: 'more',
				limit: 10,
				page: 1,
				loaded: false
			}
		},
		onLoad(opt) {
			if (opt.state) {
				this.state = opt.state
				if(this.state == 2) {
					uni.setNavigationBarTitle({
						title:'家政预约'
					})
				}else if(this.state == 3){
					uni.setNavigationBarTitle({
						title:'维修预约'
					})
				}else if(this.state == 1) {
					uni.setNavigationBarTitle({
						title:'商品列表'
					})
				}
			}
			this.getList()
		},
		onShow() {},
		onReachBottom() {
			this.getList()
		},
		onReady() {
			
		},
		methods: {
			navto(url) {
				uni.navigateTo({
					url,
					fail() {
						uni.switchTab({
							url
						})
					}
				})
			},
			getList() {
				let that = this
				if (that.loadingType == 'loading' || that.loadingType == 'noMore') return;
				that.loadingType = 'loading'
				getProducts({
					page: that.page,
					limit: that.limit,
					is_housekeeping:that.state == 2?1:0,
					is_maintenance: that.state == 3? 1:0
				}).then(res => {
					let data = res.data
					this.goodList = this.goodList.concat(data)
					if (data.length == that.limit) {
						that.page++
						that.loadingType = 'more'
					} else {
						that.loadingType = 'noMore'
					}
					that.loaded = true
				})
			},
			open() {
				this.$refs.popupkf.open()
			},
			confrim(e) {
				console.log(e.time) //确定事件 =>12:30-17:30
				this.timeArea = e.time
				this.$refs.popupkf.close()
			},
			cancel(e) {
				console.log(e.time) //取消事件 =>12:30-17:30
				this.$refs.popupkf.close()
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			getDefaultAddress() {
				getDefaultAddress().then(res => {
					if (res.data.id) {
						this.addressData = res.data
					} else {
						this.addressData = {
							real_name: ''
						}
					}
				})
			},
			bindPickerChange(e) {
				console.log(e)
				this.state = e.detail.value
			},
			// 打开picker
			openDatetimePicker() {
				this.$refs.myPicker.show();
			},
			// 关闭picker
			closeDatetimePicker() {
				this.$refs.myPicker.hide();
			},
			handleSubmit(e) {
				this.birthday = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`;
				this.yyTime = Date.parse(this.birthday)
			},
			gonow() {
				if (this.addressData.real_name == '') {
					return this.$api.msg('请选择上门地址')
				}
				if (!this.date) {
					return this.$api.msg('请选择上门时间')
				}
				if (!this.timeArea) {
					return this.$api.msg('请选择上门时间')
				}
				createSubscribe({
					type: this.typeArray[this.state].lable,
					addressId: this.addressData.id,
					subscribe_day: this.date,
					subscribe_time: this.timeArea,
					mark: this.mark
				}).then(res => {
					console.log();
					uni.showToast({
						title: '提交成功',
						duration: 2000
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding-top: 20rpx;
	}

	.address-section {
		padding: 30rpx 0;
		background: #fff;
		position: relative;
		border-top: 1px solid $border-color-light;

		.order-content {
			min-height: 100rpx;
			display: flex;
			align-items: center;

			.addAddress {
				text-align: center;
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;

				.iconaddition {
					font-size: 55rpx;
					line-height: 1;
					border-radius: 100rpx;
					margin-right: 20rpx;
				}
			}
		}

		.iconlocation {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90rpx;
			color: #888;
			font-size: 44rpx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28rpx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34rpx;
			margin-right: 24rpx;
		}

		.address {
			margin-top: 16rpx;
			margin-right: 20rpx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32rpx;
			color: $font-color-light;
			margin-right: 30rpx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5rpx;
		}
	}

	.yt-list {
		margin-top: 16rpx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10rpx 30rpx 10rpx 40rpx;
		line-height: 70rpx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30rpx;
		}

		.cell-icon {
			height: 32rpx;
			width: 32rpx;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 32rpx;
			background: #f85e52;
			border-radius: 4rpx;
			margin-right: 12rpx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}
		}

		.cell-more {
			align-self: center;
			font-size: 24rpx;
			color: $font-color-light;
			margin-left: 8rpx;
			margin-right: -10rpx;
		}

		.cell-tit {
			flex: 1;
			font-size: 30rpx;
			color: #222222;
			margin-right: 10rpx;

		}

		.desc {
			flex: 1;
			min-width: 300rpx;
			text-align: right;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

	.bz {
		padding: 30rpx;
		margin-top: 20rpx;
		background-color: #fff;
		margin-bottom: 50rpx;
	}

	#bzinfo {
		padding: 20rpx 10rpx 10rpx;
		width: 100%;
	}

	.hotgoods {
		// margin-top: 38rpx;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		padding: 0 20rpx 30rpx;
		justify-content: space-between;

		.hotgoods-item {
			width: 345rpx;
			background-color: #ffffff;
			border-radius: 12rpx;
			box-shadow: 0 0 15rpx rgba(0, 0, 0, 0.2);
			margin-bottom: 15rpx;

			.image-wrapper {
				width: 345rpx;
				height: 345rpx;
				border-radius: 3px;
				overflow: hidden;
				position: relative;

				.image-bg {
					position: absolute;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					width: 100%;
					height: 100%;
					opacity: 1;
					border-radius: 12rpx 12rpx 0 0;
					z-index: 2;
				}

				.image {
					width: 100%;
					height: 100%;
					opacity: 1;
					border-radius: 12rpx 12rpx 0 0;
				}
			}

			.title {
				width: 320rpx;
				margin-top: 24rpx;
				padding: 0 20rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: #333333;
			}

			.hot-price {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				// padding: 14rpx 0 30rpx;

				.hotPrice-box {
					padding: 2rpx 6rpx;

					background: linear-gradient(90deg, #c79a4c, #f9df7f);
					border-radius: 5rpx;
					text-align: center;
					line-height: 28rpx;
					font-size: 20rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #ffffff;
				}

				.price {
					margin-left: 10rpx;
					font-size: 40rpx;
					color: #ff0000;
					font-weight: 500;

					.jf {
						font-size: 20rpx;
					}
				}

				.yuanPrice {
					margin-left: 10rpx;
					font-size: 20rpx;
					font-family: PingFang SC;
					font-weight: 500;
					text-decoration: line-through;
					color: #999999;
				}

				.cart-icon {
					image {
						width: 44rpx;
						height: 44rpx;
					}
				}
			}
		}
	}
</style>