<template>
	<view class="page">
		<navbar title="发布租房" leftClick @leftClick="$utils.navigateBack" />
		
		
		<view class="form">
			<view class="help-issue">
				<text>租房标题</text>
				<text style="color: #BD3624;">*</text>
			</view>
			<view class="form-sheet-cell">
				<input type="text" class="title-input"/>
			</view>
			
			<uv-cell
			title="租房地点"
			rightIconStyle="fontSize: 30rpx;"
			value="请选择租房地点"
			isLink
			></uv-cell>
			
			<uv-cell
			title="朝向"
			rightIconStyle="fontSize: 30rpx;"
			value="请选择朝向"
			isLink
			></uv-cell>
			
			<uv-cell
			title="装修"
			rightIconStyle="fontSize: 30rpx;"
			value="请选择装修"
			isLink
			></uv-cell>
			
			<uv-cell
			title="楼层"
			rightIconStyle="fontSize: 30rpx;"
			value="请选择楼层"
			isLink
			></uv-cell>
			
			<view class="form-sheet-cell">
				<view class="label">
					户型
				</view>
				<view class="price">
					<input placeholder="请输入户型（三室一厅）" v-model="form.home" />
				</view>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					付款方式
				</view>
				<view class="price">
					<input placeholder="请输入付款方式（押一付三）" v-model="form.price" />
				</view>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					租金/月
				</view>
				<view class="price">
					<input placeholder="请输入租金" type="number" v-model="form.money" />
				</view>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					面积
				</view>
				<view class="price">
					<input placeholder="请输入面积（米平方）" type="number" v-model="form.crm" />
				</view>
			</view>
			
			
			<view class="form-sheet-cell">
				<view class="label">
					看房
				</view>
				<uv-radio-group v-model="radiovalue">
					<view class="price">
						<uv-radio
							:customStyle="{margin: '8px'}" 
							iconSize="30rpx"
							size="40rpx"
							labelSize="26rpx"
							label="随时可看" 
							name="随时可看">
						</uv-radio>
						
						<uv-radio
							:customStyle="{margin: '8px'}" 
							iconSize="30rpx"
							size="40rpx"
							labelSize="26rpx"
							label="电话预约" 
							name="电话预约">
						</uv-radio>
						
					</view>
				</uv-radio-group>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					租房类型
				</view>
				<uv-radio-group v-model="form.type">
					<view class="price">
						<uv-radio
							:customStyle="{margin: '8px'}" 
							iconSize="30rpx"
							size="40rpx"
							labelSize="26rpx"
							label="整租" 
							name="整租">
						</uv-radio>
						
						<uv-radio
							:customStyle="{margin: '8px'}" 
							iconSize="30rpx"
							size="40rpx"
							labelSize="26rpx"
							label="合租" 
							name="合租">
						</uv-radio>
					</view>
				</uv-radio-group>
			</view>
			
			<view class="form-sheet-cell">
				<view class="label">
					联系电话
				</view>
				<input placeholder="请输入联系电话" v-model="form.phone" />
			</view>
			
			<view class="images box">
				<view class="">
					精选照片
				</view>
				<uv-upload 
				:fileList="fileList" 
				:maxCount="imageMax" 
				multiple 
				width="150rpx" 
				height="150rpx"
				@delete="deleteImage"
				@afterRead="afterRead"
				:previewFullImage="true"></uv-upload>
			</view>
			
			<view class="category">
				<view class="title">
					选择地区
				</view>
				<view class="tagList">
					<view 
					:class="{act : t.id == form.addId}"
					@click="form.addId = t.id"
					v-for="(t, i) in cityList"
					:key="i">
						{{ t.name }}
					</view>
				</view>
			</view>
			
			<!-- <view class="">
				<uv-textarea 
				v-model="form.content" 
				count 
				:maxlength="300" 
				autoHeight
				placeholder="请输入详细介绍"></uv-textarea>
			</view> -->
			
			<uv-picker ref="picker"
			:columns="columns" 
			@confirm="pickerConfirm"></uv-picker>
			
			<view class="uni-color-btn">
				发布
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		data() {
			return {
				form : {
					addId : '',//地区id
					address : '',//地址
					crm : '',//面积
				},
				radiovalue : '',
				priceType : [
					{
						name : '月付',
					},
					{
						name : '季付',
					},
					{
						name : '年付',
					},
				],
				radiolist : [
					{
						name : '日结',
					},
					{
						name : '月结',
					},
				],
				fileList : [],
				imageMax : 9,
				picker : {
					workYear : [
						'不限',
					],
					school : [
						'不限',
						'初中',
						'高中',
						'专科',
						'本科',
						'研究生',
						'博士',
					],
				},
			}
		},
		onLoad() {
			for (var i = 0; i < 30; i++) {
				this.picker.workYear.push((i + 1) + '年')
			}
			this.form.addId = this.cityList[0].id
		},
		computed : {
			columns(){
				return [this.picker[this.pickerKey]]
			},
			...mapState(['cityList', 'category']),
		},
		methods: {
			openPicker(key){
				this.pickerKey = key
				this.$refs.picker.open()
			},
			pickerConfirm(e){
				this.form[this.pickerKey] = e.value[0]
			},
			deleteImage(e){
				this.fileList.splice(e.index, 1)
			},
			afterRead(e){
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.fileList.push({
							url
						})
					})
				})
			},
			//地图上选择地址
			selectAddr() {
				Position.selectAddress(res => {
					//经纬度信息
					this.form.latitude = res.latitude
					this.form.longitude = res.longitude
					if (res.name) {
						return this.form.address = res.name
					}
					this.form.address = ''
				})
			},
			// 提交
			submit(){
				
				if(this.fileList.length == 0){
					return uni.showToast({
						title: '请上传精选照片',
						icon : 'none'
					})
				}
				
				if (this.$utils.verificationAll(this.form, {
						title: '请输入标题',
						address : '请选择租房地点',
						money : '请输入租金',
						phone: '请输入联系电话',
						titleSub : '请输入备注',
					})) {
					return
				}
				
				this.$api('publishJob', this.form, res => {
					if(res.code == 200){
						uni.showToast({
							title: '发布成功!',
							icon: 'none'
						})
						
						setTimeout(uni.navigateBack, 1000, -1)
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
.page{
	background-color: #fff;
	min-height: 100vh;
	box-sizing: border-box;
	color: #333333;
	font-size: 28rpx;
	/deep/ text{
		font-size: 28rpx !important;
	}
	.form{
		padding: 30rpx;
		.help-issue {
			margin: 20rpx;
		}
		.title-input{
			border: 1px solid $uni-color;
			width: 100%;
			border-radius: 10rpx;
			padding: 10rpx 20rpx;
			box-sizing: border-box;
			height: 65rpx;
		}
		.form-sheet-cell{
			display: flex;
			background-color: #fff;
			padding: 20rpx 30rpx;
			align-items: center;
			.label{
				width: 160rpx;
			}
			.price{
				display: flex;
				// text-align: center;
				input{
					width: 450rpx;
					// border: 1px solid $uni-color;
					margin: 0 10rpx;
				}
			}
			.right-icon{
				margin-left: auto;
			}
		}
		
		.images{
			padding: 30rpx;
			view{
				padding-bottom: 20rpx;
			}
		}
	}
	
	.category{
		padding: 20rpx;
		.title{
			// font-weight: 900;
			// font-size: 30rpx;
		}
		.tagList{
			display: flex;
			flex-wrap: wrap;
			padding: 10rpx 0;
			view{
				background: rgba($uni-color, 0.1);
				padding: 10rpx 20rpx;
				margin: 10rpx;
				border-radius: 10rpx;
				font-size: 26rpx;
			}
			.act{
				color: #fff;
				background: $uni-color;
			}
		}
	}
}
</style>
