<template>
	<view class='container'>
		<view style="background: linear-gradient( 180deg, #1FCA7C 0%, #1FCAA7 100%);">
			<u-navbar :autoBack="true" placeholder="true" :title="title" bgColor="transparent" leftIconColor="#FFF"
				:title-style="{color: '#FFF'}">
			</u-navbar>
		</view>
		<view class="mar-20">
			<view class="flex-column-center">
				<image class="w-30 h-30" src="/static/icon_home_dw.png"></image>
				<text>{{userinfo.communityName}}</text>
			</view>
			<view class="flex-column-center fs-32 fw-700  mt-30 ml-10">
				<image class="w-10 h-40 mr-15" style="background-color: #1FCA7C;"></image>
				<text>业主信息</text>
			</view>
			<view class="flex-column br-12 fs-28 mt-30" style="box-shadow: 0px 0px 15px 1px rgba(142,142,142,0.16);">
				<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
					<text style="color: #999999;">业主姓名</text>
					<text>{{$wskj.isNullStr(userinfo.name)}}</text>
				</view>
				<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
					<text style="color: #999999;">业主房间号</text>
					<text>{{$wskj.isNullStr(userinfo.room)}}</text>
				</view>
				<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
					<text style="color: #999999;">业主手机号</text>
					<text>{{userinfo.mobile}}</text>
				</view>
			</view>
			<view class="flex-column-center fs-32 fw-700  mt-30">
				<image class="w-10 h-40 mr-15" style="background-color: #1FCA7C;"></image>
				<text>{{type==1?'报修信息':'报事信息'}}</text>
			</view>
			<view class="flex-column br-12 fs-28 mt-30 pad-30"
				style="box-shadow: 0px 0px 15px 1px rgba(142,142,142,0.16);">
				<u-textarea v-model="reason" height="260rpx" maxlength="100" placeholder="填写下详细报修内容，有助于工作人员快速帮您解决问题"
					count border="border" ref="textarea"></u-textarea>
				<view class="mt-30">
					<upload-image @upload="upload" v-model="imgurl" maxCount="3" width="70" height="70"
						type="fullurl"></upload-image>
				</view>
			</view>

		</view>
		<view @click="onSubmit" class="fullscreen-btn">
			<text>提交</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '居家报修',
				type: 0,
				reason: '',
				images: '',
				userinfo: '',
			};
		},
		onLoad(e) {
			this.type = e.type
			if (e.type == 1) {
				this.title = "居家报修"
			} else {
				this.title = "公区报事"
			}
			this.userinfo = uni.getStorageSync("userInfo")
		},
		onReady() {
			// 如果需要兼容微信小程序的话，需要用此写法
			this.$refs.textarea.setFormatter((value) => {
				if (value.length >= 100) {
					return value.substr(0, 100)
				} else {
					return value
				}
			})
		},
		methods: {
			upload(e) {
				this.images = e
			},
			onSubmit() {
				console.log(this.images)
				if (!this.reason) {
					this.$wskj.toast('请输入报修信息');
					return
				}
				if (!this.images) {
					this.$wskj.toast('请上传图片');
					return
				}
				const params = {
					url: '/api/repairs/add',
					loadingTip: '加载中...',
					data: {
						repairsDescription: this.reason,
						repairsImg: this.images,
						type: this.type
					}
				}
				this.$request(params).then(res => {
					this.$wskj.redirectTo("/pagesMain/pages/tjsq?type=" + this.type)
				})
			}
		},
	};
</script>

<style scoped>
	.container {
		display: flex;
		flex-direction: column;
		background: #fff;
	}
</style>