<template>
	<view class="se-p-40 se-bgc-white">
		<uv-form labelPosition="left" :model="form" :rules="rules" ref="form" labelWidth="60" labelStyle="font-size:26rpx;">
			<uv-form-item label="标题" prop="title" >
				<uv-input v-model="form.title" type="text" placeholder="请输入标题" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="价格" prop="price">
				<uv-input v-model="form.price" type="text" placeholder="请输入价格" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="户型" prop="house">
				<uv-input v-model="form.house" type="text" placeholder="请输入户型" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="面积" prop="proportion">
				<uv-input v-model="form.proportion" type="text" placeholder="请输入面积" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="所属位置" prop="address" @click="handleAreaChange()">
				<uv-input v-model="form.address" @click="handleAreaChange()" disabled disabledColor="#ffffff" placeholder="所属位置" border="none">
				</uv-input>
				<template v-slot:right>
					<uv-icon name="arrow-right"></uv-icon>
				</template>
			</uv-form-item>
			<uv-form-item label="编号" prop="number">
				<uv-input v-model="form.number" type="text" placeholder="请输入编号" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="房屋周边" prop="perimeter">
				<uv-input v-model="form.perimeter" type="text" placeholder="请输入房屋周边" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="房间数量" prop="housesNumber">
				<uv-number-box v-model="form.housesNumber" :min="1" :max="10"></uv-number-box>
			</uv-form-item>
			<uv-form-item label="房屋主体是否改造"  labelWidth="200" prop="revamp">
				<uv-radio-group v-model="form.revamp" placement="row">
					<uv-radio name="1" label="是"></uv-radio>
					<uv-radio name="0" customStyle="margin-left:30rpx;" label="否"></uv-radio>
				</uv-radio-group>
			</uv-form-item>
			<uv-form-item label="是否经过安置"  labelWidth="200" prop="resettle">
				<uv-radio-group v-model="form.resettle" placement="row">
					<uv-radio name="1" label="是"></uv-radio>
					<uv-radio name="0" customStyle="margin-left:30rpx;" label="否"></uv-radio>
				</uv-radio-group>
			</uv-form-item>
			<uv-form-item label="院子总面积"  labelWidth="100" prop="yardProportion">
				<uv-input v-model="form.yardProportion" type="text" placeholder="请输入院子总面积" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="坟包及电塔工厂噪音" labelWidth="150" prop="noise">
				<uv-input v-model="form.noise" type="text" placeholder="请输入坟包及电塔工厂噪音" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="水电气网" prop="net">
				<uv-input v-model="form.net" type="text" placeholder="请输入水电气网" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="停车" prop="park">
				<uv-input v-model="form.park" type="text" placeholder="请输入停车" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="付款方式及押金" labelWidth="120" prop="deposit">
				<uv-input v-model="form.deposit" type="text" placeholder="请输入押金" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="天府市民云房屋信息档案查询" labelWidth="100" prop="archival" labelPosition="top">
				<uv-input v-model="form.archival" type="text" placeholder="请输入天府市民云房屋信息档案查询" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="租期" prop="tenancy">
				<uv-input v-model="form.tenancy" type="text" placeholder="请输入租期" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="邻居对房东的评价" labelWidth="120" prop="evaluate">
				<uv-input v-model="form.evaluate" type="text" placeholder="请输入邻居对房东的评价" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="非正常死亡" labelWidth="80" prop="death">
				<uv-input v-model="form.death" type="text" placeholder="请输入非正常死亡" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="钥匙" prop="key">
				<uv-input v-model="form.key" type="text" placeholder="请输入钥匙" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="佣金" prop="commission">
				<uv-input v-model="form.commission" type="text" placeholder="请输入佣金" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="报建手续" prop="procedures">
				<uv-input v-model="form.procedures" type="text" placeholder="请输入报建手续" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item label="产权证照片" labelWidth="250" prop="isOwnershipList" labelPosition="top">
				<uv-upload customStyle="margin-top:20rpx;" :fileList="form.ownershipList" @afterRead="afterOwnershipRead" @delete="deleteOwnershipPic" name="1"
					multiple :maxCount="10"></uv-upload>
			</uv-form-item>
			<uv-form-item label="房屋照片/视频" labelWidth="250" prop="isHouseList" labelPosition="top">
				<uv-upload customStyle="margin-top:20rpx;" :fileList="form.houseList" @afterRead="afterHouseRead" @delete="deleteHousePic" name="1"
					multiple :maxCount="10"></uv-upload>
			</uv-form-item>
			<uv-form-item label="备注" prop="remark" labelPosition="top">
				<uv-input v-model="form.remark" type="text" placeholder="请输入备注" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
			</uv-form-item>
			<uv-form-item>
				<uv-button type="primary" text="确认发布" customStyle="margin-top: 30px;background-color: #1EC77A;border-radius: 30px;" @click="submit"></uv-button>
			</uv-form-item>
		</uv-form>
		<!-- 地址 -->
		<citySelect ref="citySelectRef" :zIndex="0" @city-change="handleCityChange"></citySelect>
	</view>
</template>

<script>
	import { saveOrUpdateHouse } from "@/common/api.js"
	import citySelect from "@/components/cityselect/index.vue"
	export default{
		components:{
			citySelect
		},
		data(){
			return{
				id:"",
				form:{
					title:"",//标题
					price:"",//价格
					house:"",//户型
					proportion:"",//面积
					address:"",//所属位置
					number:"",//编号
					perimeter:"",//房屋周边
					housesNumber:1,//房间数量
					revamp:0,//房屋主体是否改造
					resettle:0,//是否经过安置
					yardProportion:"",//院子总面积
					noise:"",//噪音
					net:"",//水电气网
					park:"",//停车
					deposit:"",//押金
					archival:"",//档案查询
					tenancy:"",//租期
					evaluate:"",//评价
					death:"",//非正常死亡
					key:"",//钥匙
					commission:"",//佣金
					procedures:"",//手续
					isOwnershipList:"",
					ownershipList:[],
					isHouseList:"",
					houseList:[],
					remark:""
				},
				rules:{
					title:[
						{
							type: 'string',
							required: true,
							message: '请输入账号',
							trigger: ['blur', 'change']
						}
					],
					price:[
						{
							type: 'string',
							required: true,
							message: '请输入价格',
							trigger: ['blur', 'change']
						}
					],
					house:[
						{
							type: 'string',
							required: true,
							message: '请输入户型',
							trigger: ['blur', 'change']
						}
					],
					proportion:[
						{
							type: 'string',
							required: true,
							message: '请输入面积',
							trigger: ['blur', 'change']
						}
					],
					number:[
						{
							type: 'string',
							required: true,
							message: '请输入编号',
							trigger: ['blur', 'change']
						}
					],
					perimeter:[
						{
							type: 'string',
							required: true,
							message: '请输入房屋周边',
							trigger: ['blur', 'change']
						}
					],
					yardProportion:[
						{
							type: 'string',
							required: true,
							message: '请输入院子总面积',
							trigger: ['blur', 'change']
						}
					],
					noise:[
						{
							type: 'string',
							required: true,
							message: '请输入坟包及电塔工厂噪音',
							trigger: ['blur', 'change']
						}
					],
					net:[
						{
							type: 'string',
							required: true,
							message: '请输入水电气网',
							trigger: ['blur', 'change']
						}
					],
					park:[
						{
							type: 'string',
							required: true,
							message: '请输入停车',
							trigger: ['blur', 'change']
						}
					],
					deposit:[
						{
							type: 'string',
							required: true,
							message: '请输入押金',
							trigger: ['blur', 'change']
						}
					],
					archival:[
						{
							type: 'string',
							required: true,
							message: '请输入天府市民云房屋信息档案查询',
							trigger: ['blur', 'change']
						}
					],
					tenancy:[
						{
							type: 'string',
							required: true,
							message: '请输入租期',
							trigger: ['blur', 'change']
						}
					],
					evaluate:[
						{
							type: 'string',
							required: true,
							message: '请输入邻居对房东的评价',
							trigger: ['blur', 'change']
						}
					],
					death:[
						{
							type: 'string',
							required: true,
							message: '请输入非正常死亡',
							trigger: ['blur', 'change']
						}
					],
					key:[
						{
							type: 'string',
							required: true,
							message: '请输入钥匙',
							trigger: ['blur', 'change']
						}
					],
					commission:[
						{
							type: 'string',
							required: true,
							message: '请输入佣金',
							trigger: ['blur', 'change']
						}
					],
					procedures:[
						{
							type: 'string',
							required: true,
							message: '请输入报建手续',
							trigger: ['blur', 'change']
						}
					],
				}
			}
		},
		watch: {
			'form.ownershipList'(newValue, oldValue) {
			    if (newValue.length > 0) {
			    	this.form.isOwnershipList = '有'
			    } else {
			    	this.form.isOwnershipList = ''
			    }
			},
			'form.houseList'(newValue, oldValue) {
			    if (newValue.length > 0) {
			    	this.form.isHouseList = '有'
			    } else {
			    	this.form.isHouseList = ''
			    }
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onLoad(options) {
			this.id = options.id
		},
		mounted() {
			
		},
		methods:{
			deleteHousePic(event) {
				this.form.houseList.splice(event.index, 1)
			},
			async afterHouseRead(e) {
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.form.houseList.push({
							url
						})
					})
				})
			},
			deleteOwnershipPic(event) {
				this.form.ownershipList.splice(event.index, 1)
			},
			async afterOwnershipRead(e) {
				let self = this
				e.file.forEach(file => {
					self.$Oss.ossUpload(file.url).then(url => {
						self.form.ownershipList.push({
							url
						})
					})
				})
			},
			handleAreaChange(){
				this.$refs.citySelectRef.open()
			},
			handleCityChange(e) {
				this.form.address = e.province.label + '-' + e.city.label + '-' + e.area.label;
			},
			submit() {
				
				// price:"",//价格
				// house:"",//户型
				// proportion:"",//面积
				// address:"",//所属位置
				// number:"",//编号
				// perimeter:"",//房屋周边
				// housesNumber:1,//房间数量
				// revamp:0,//房屋主体是否改造
				// resettle:0,//是否经过安置
				// yardProportion:"",//院子总面积
				// noise:"",//噪音
				// net:"",//水电气网
				// park:"",//停车
				// deposit:"",//押金
				// archival:"",//档案查询
				// tenancy:"",//租期
				// evaluate:"",//评价
				// death:"",//非正常死亡
				// key:"",//钥匙
				// commission:"",//佣金
				// procedures:"",//手续
				// isOwnershipList:"",
				// ownershipList:[],
				// isHouseList:"",
				// houseList:[],
				// remark:""
				this.$refs.form.validate().then(res => {
					let params={
						userId:"",
						id:"",
						classId:"",//分类标识
						commonClass:"",//所属分类
						address:that.form.address,//地址
						homeAge:"",//户主年龄
						homeAz:"",//是否经过安置
						
						homeBian:"",//房屋周边
						homeBjsx:"",//报建手续
						homeCai:"",//菜地
						homeCat:that.form.park,//停车
						homeGz:that.form.revamp,//房屋主体是否改造
						homeHb:"",//房屋朝向及海拔
						homeBz:that.form.remark,//备注
						homeJg:"",//房屋结构
						homeJl:"",//距离场镇距离
						homeJt:"",//交通
						homeJtzy:"",//户主家庭职业
						homeMi:"",//面积
						homeMj:that.form.proportion,//房屋面积
						homeMoney:that.form.commission,//佣金
						homeNo:"",//房屋编号
						homeNum:that.form.housesNumber,//房间数量
						homePay:that.form.deposit,//付款方式及押金
						homePj:that.form.evaluate,//邻居对房东评价
						homeSd:that.form.net,//水电气网
						homeShjl:"",//距离成都西三环
						homeSw:that.form.death,//非正常死亡
						homeTf:"",//府市民云房屋信息档案查询
						homeTime:that.form.tenancy,//租期
						homeType:that.form.house,//户型
						homeYs:that.form.key,//钥匙
						homeYzmj:that.form.yardProportion,//院子总面积
						homeZy:that.form.noise,//坟包及电塔 工厂噪音
						iconName:"",//热点名称
						iconTitle:"",//标签
						num:"",//浏览量
						price:that.form.price,//价格
						timeGo:"",//年限
						title:that.form.title,//标题
						unit:"",//单位
						
						
						image:"",//图片
						iconImage:"",//左上角图标
						homeImage:"",//产权证照片
						homeMp4:"",//视频
					}
					saveOrUpdateHouse(params).then(response=>{
						console.info('response',response)
					}).catch(error=>{
						
					})
				}).catch(errors => {
					
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #f5f5f5;
		
	}
</style>