<template>
	<view class="container">
		<view class="form-box">
			<view class="item">
				<view class="label">房源地址</view>
				<view class="input">
					<u-input height="102" style="width: 350rpx"  disabled input-align="right" v-model="form.address"  @click="topage"  placeholder="请选择房源地址"></u-input>
					<image class="path" src="/static/path.png" mode="" />
				</view>
			</view>
			<view class="item">
				<view class="label">带看时间</view>
				<view class="input">
					<u-input height="102" disabled input-align="right" v-model="form.date"  @click="calendarShow = true"  placeholder="请选择带看时间"></u-input>
					<image class="calendar" src="/static/kehu/calendar.png" mode="" />
					<u-picker mode="time" confirm-color="#FF6D25" :default-time="form.date" v-model="calendarShow" :params="params" @confirm="dateConfirm"></u-picker>
				</view>
			</view>
		</view>
		<view class="submit-btn" @click="submit">提交</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				calendarShow: false,
				form: {
					date: '',//带看时间
					address:'',//房源地址
				},
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				customStyle: {
					maxHeight:'200rpx',
					padding: '20rpx',
					fontSize: '30rpx',
					borderBottom:'1px solid #e0e0e0'
				},
				customerId: '',
				roomId: ''
			};
		},
		onLoad(options) {
			this.customerId = options.customerId;
		},
		onShow() {
			let houseSource = wx.getStorageSync('houseSource')
			if(houseSource&&houseSource.address){
				this.form.address = houseSource.address
				this.roomId = houseSource.houseId
				uni.removeStorageSync('houseSource')
			}
		},
		methods: {
			topage(){
				wx.navigateTo({
					url: '/pages/customer/selectHousesource'
				})
			},
			dateConfirm(e){
				console.log(e)
				this.form.date = e.year + '-'+e.month + '-'+e.day+ ' '+e.hour+':'+e.minute+':'+e.second
			},
			submit() {
				if(this.flag) return;
				this.flag = true;
				if(this.form.address==''){
					uni.showToast({
						title: '请选择房源地址',
						icon: 'none'
					})
					return ;
				}
					if(this.form.date==''){
					uni.showToast({
						title: '请选择带看时间',
						icon: 'none'
					})
					return ;
				}
				let body = {
					"viewTime": this.form.date,
					"customerId": this.customerId,
					"roomId": this.roomId,
					"houseAddress": this.form.address
				}
				this.$u.api.customerView({body:body}).then((res)=>{
					// console.log(res)
					this.flag = false;
					if(res.ErrNo=='0000'){
							wx.switchTab({
								url: '/pages/tabs/customer'
							})
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
.container {
	width: 750rpx;
	min-height: 100vh;
	background: #F8F8F8;
	padding-top: 20rpx;
	.form-box{
		background: #fff;
		padding: 0 30rpx;
		.item{
			height: 102rpx;
			font-size: 30rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			line-height: 102rpx;
			color: #333333;
			border-bottom: 1px solid #e0e0e0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.label{
				width: 120rpx;
				margin-right: 20rpx;
			}
			.input{
				display: flex;
				align-items: center;
				.path{
					width: 14rpx;
					height: 30rpx;
					margin-left: 20rpx;
				}
				.calendar{
					width: 40rpx;
					height: 40rpx;
					margin-left: 20rpx;
				}
			}
		}
	}
	.submit-btn{
		width: 690rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		background: #FF6D25;
		border-radius: 12rpx;
		margin-left: 30rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		position: fixed;
		bottom: 90rpx;
	}
}
</style>
