<template>
	<view class="center">
		<view class="flex row form_css">
			<view class="left-text">被举报车队</view>
			<view class="right-text">
			     <u-avatar :src="formData.coverUrl" size="24" class="img_css"></u-avatar>
				 <view class="">
				 	{{formData.fleetName}}
				 </view>
			</view>
		</view>
		<!-- <view class="">被举报车队</view> -->
		<view class="">举报信息</view>
		<view class="textarea">
			<u--textarea v-model="reportInfo.content" placeholder="输入要举报的内容,10-300字" maxlength="300" height="100"></u--textarea>
		</view>
	     <u-upload class="uview-upload" :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic"
	     	name="1" multiple :maxCount="1" style="z-index: 9999;"></u-upload>
			<u-toast ref="uToast"></u-toast>
			<u-modal :show="tipsShow" :title="alertTitle" :closeOnClickOverlay='true' :showCancelButton='true'
				confirmColor='#2772FB' @confirm="confirmClick" @close="cancelClick" @cancel="cancelClick"></u-modal>
			<u-button type="primary" text="提交" class="btn_css" @click="submit"></u-button> 
	</view>
</template>

<script>
	import uploadImage from '@/components/ossutil/uploadFile.js';
	export default{
		data(){
			return{
				fileList1:[],
				content:"",
				textNumber:300,
				formData:{},
				fleetId:"",
				reportInfo:{},
				tipsShow:false,
				alertTitle:""
			}
		},
		onShow(){},
		onLoad(options){
			this.fleetId = options.id
			this.getList()
		},
		methods:{
			submit(){
				if (!this.reportInfo.content) {
					this.$refs.uToast.show({
						type: 'error',
						message: "请输入要举报的内容！",
					})
					return
				}
				if (this.reportInfo.content.length < 10) {
					this.$refs.uToast.show({
						type: 'error',
						message: "举报内容不能小于10个字！",
					})
					return
				}
				if (this.fileList1.length == 0) {
					this.$refs.uToast.show({
						type: 'error',
						message: "请上传图片！",
					})
					return
				}
				this.reportInfo.id = uni.getStorageSync("firstAuthentication").commonId
				this.reportInfo.name = uni.getStorageSync("firstAuthentication").driverName
				this.reportInfo.flag = 3
				this.alertTitle="确定要举报该车队"
				this.tipsShow = true
			},
			cancelClick(){
				this.tipsShow = false
			},
			 confirmClick(){
				 this.tipsShow = false
				 this.$request.baseRequest('post', '/feedbackReport/api/addInfo', this.reportInfo).then(res => {
				 	if(res.code == 200){
						
				 		this.$refs.uToast.show({
				 			type: 'success',
				 			message: "队员删除成功！",
				 			complete() {
				 				uni.navigateBack({
				 					delta: 1
				 				});
				 			}
				 		})
				 	}else{
						this.$refs.uToast.show({
							type: 'error',
							message: res.message,
						})
					}
				 	})
				 	.catch(res => {
				 		uni.$u.toast(res.message);
				 	});
			 },
			getList() {
				this.$request.baseRequest('get', '/fleetInfo/getFleetInfo', {
						id: this.fleetId
					}).then(res => {
						this.formData = res.data
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			// 删除图片
			deletePic(event) {
				console.log(this[`fileList${event.name}`])
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				uploadImage('image',url, 'appData/',
					result => {
						// 上传成功回调函数
						this.reportInfo.url = result
					}
				)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.center{
		padding: 30rpx;
	}
	.form_css {
		width: 100%;
		display: flex;
		margin: 30rpx 0;
		height: 80rpx;
		border-bottom: 1px solid #eeeeee;
	
		.left-text {
			width: 50%;
			text-align: left;
		}
	
		.right-text {
			width: 50%;
			justify-content: flex-end;
			display: flex;
			text-align: right;
			color: #363636;
			// font-size: 28rpx;
			.img_css{
				margin: 0 10rpx;
			}
		}
	}
	.textarea{
		margin: 30rpx 0;
	}
	.btn_css{
		margin-top: 40rpx;
	}
</style>
