<template>
	<view class="center">
		<view class="">被举报车队</view>
		<view class="">举报信息</view>
		<u--textarea v-model="content" placeholder="输入要举报的内容,10-300字" maxlength="300" autoHeight count></u--textarea>
	     <u-upload class="uview-upload" :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic"
	     	name="1" multiple :maxCount="1" style="z-index: 9999;"></u-upload>
	</view>
</template>

<script>
	import uploadImage from '@/components/ossutil/uploadFile.js';
	export default{
		data(){
			return{
				fileList1:[],
				content:"",
				textNumber:300,
				formData:{}
			}
		},
		onShow(){
			
		},
		onLoad(){
			
		},
		methods:{
			// 删除图片
			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 => {
						// 上传成功回调函数
						if(this.formData.coverUrl){
							this.formData.coverUrl = this.formData.coverUrl+','+ result
						}else{
							this.formData.coverUrl = result
						}
						
					}
				)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.center{
		padding: 30rpx;
	}
</style>
