<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,[encoded data, 4176 characters]',
				// 收货地址
				addressData: {
					real_name: ''
				},
				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>