<template>
	<view class="container">
		<view class="form-box">
			<view class="item">
				<view class="label">地址</view>
				<view class="input">
					<u-input height="102" type="text" input-align="right" v-model="form.address" placeholder="请输入地址"></u-input>
				</view>
			</view>
			<view class="item">
				<view class="label">操作人</view>
				<view class="input">
					<u-input height="102" type="text" input-align="right" v-model="form.person" placeholder="请输入操作人"></u-input>
				</view>
			</view>
			<view class="item" style="border:0">
				<view class="label">上传图片</view>
			</view>
			<u-upload upload-text="添加图片" ref="uUpload" :show-progress="false" max-count="6" @on-uploaded="upload" :action="action" :auto-upload="true" ></u-upload>
		</view>
		<view class="submit-btn" @click="openModal">提交</view>
		<u-modal v-model="modalShow" content="您确认提交吗？" :show-cancel-button="true" confirm-color="#FF6D25" title="确认操作" @confirm="submit" ref="uModal" :async-close="false"></u-modal>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				modalShow: false,
				action: 'https://erpx.2weisou.com/sjjy/file/upload.do',
				form: {
					address: '',
					person: '',
				},
				customStyle:{
					maxHeight:'200rpx',
					padding: '20rpx',
					fontSize: '30rpx',
					borderBottom:'1px solid #e0e0e0'
				},
			};
		},
		onLoad(options) {
			this.mediacyId = options.mediacyId;
			this.masterHouseId = options.masterHouseId;
			let user = uni.getStorageSync('user')
			this.form.person = user.name||user.userName||''
			this.form.address = options.address;
		},
		methods: {
			upload(lists, name){
				console.log(lists)
			},
			openModal(){
				if(this.form.address==''){
					uni.showToast({
						title: '请输入地址',
						icon: 'none'
					})
					return;
				}
				if(this.form.person==''){
					uni.showToast({
						title: '请输入操作人',
						icon: 'none'
					})
					return;
				}
				let	files = this.$refs.uUpload.lists
				let fileList = files.length&&files.map(item=>{
					return {
						url: item.response&&item.response.result.FilePath || item.url,
						webUrl: item.response&&item.response.result.FilePath|| item.url,
					}
				})
				if(fileList&&fileList.length){
					this.picList = fileList
					this.modalShow = true
				}else{
					uni.showToast({
						title: '请上传图片',
						icon: 'none'
					})
					return;
				}
			},
			submit() {
				let params = {
          "masterHouseId": this.masterHouseId,
          "mediacyId": this.mediacyId,
					"imageDetails": this.picList
        }
        this.$u.api.visit({body:params}).then((res)=>{
					if(res.ErrNo=='0000'){
						wx.navigateBack()
					}
        })
			},
		},
	};
</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{
				width: 380rpx;
				display: flex;
				align-items: center;
				justify-content: flex-end;
				.path{
					width: 14rpx;
					height: 30rpx;
					margin-left: 20rpx;
				}
				.calendar{
					width: 40rpx;
					height: 40rpx;
					margin-left: 20rpx;
				}

			}
		}
		.last-item{
			display: flex;
			.label{
				line-height: 102rpx;
				font-size: 30rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
				margin-right: 150rpx;
			}

		}
	}
	.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>
