<template>
	<view class="content">
		<image src="../../static/img/yuyue.png" mode="widthFix" style="width: 750rpx;"></image>
		<navigator class="address-section" url="/pages/set/address?source=1&tit=1">
			<view class="order-content" v-if="addressData.real_name">
				<text class="iconfont iconlocation"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{ addressData.real_name }}</text>
						<text class="mobile">{{ addressData.phone }}</text>
					</view>
					<text class="address">{{ addressData.province + addressData.city + addressData.district }}
						{{ addressData.detail }}</text>
				</view>
				<text class="iconfont iconenter"></text>
			</view>
			<view class="order-content" v-if="!addressData.real_name">
				<view class="addAddress">
					<text class="iconfont iconaddition"></text>
					<text>选择上门地址</text>
				</view>
			</view>

			<image class="a-bg" :src="addressImg"></image>
		</navigator>
		<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">
					<view class="desc">{{typeArray[state].lable}}</view>
				</picker>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">上门时间</text>
				<view class="desc" @click="openDatetimePicker">{{birthday|| '选择上门时间'}}</view>
			</view>

		</view>
		<view class="bz">
			<view class="tit">
				备注说明<text>(选填)</text>
			</view>
			<textarea name="" id="bzinfo" cols="30" rows="10" placeholder="请输入备注说明" maxlength="140"></textarea>
		</view>
		<buuug7-simple-datetime-picker ref="myPicker" @submit="handleSubmit"
			:time-hide="[true, true, true, true, true, false]" :time-label="['年', '月', '日', '时', '分']" />
		<view class="base-btn" @click="gonow">
			立即预约
		</view>
	</view>
</template>

<script>
	import {
		getDefaultAddress
	} from '@/api/user.js'
	export default {
		data() {
			return {
				addressImg: 'data:image/png;base64, ',
				// 收货地址
				addressData: {real_name:''},
				state: 0,
				typeArray: [{
						value: 1,
						lable: '洗衣'
					},
					{
						value: 2,
						lable: '家政'
					},
					{
						value: 3,
						lable: '维修'
					}
				],
				birthday: '',
				yyTime: '',//预约时间
				loading: false,
			}
		},
		onLoad(opt) {
			if(opt.state) {
				this.state = opt.state*1 -1
			}
		},
		onShow() {
			this.getDefaultAddress()
		},
		onReachBottom() {

		},
		onReady() {

		},
		methods: {
			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.birthday) {
					return this.$api.msg('请选择上门时间')
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.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%;
	}
</style>