<template>
	<view class="container uni-container">
		<uni-section title="详情" type="line">
			<view class=" flex  flex-direction width100">
				<text class="text-cut padding-sm">巡检位置：{{formData.createTime}}</text>
				<text class="text-cut padding-sm">巡检人：{{formData.createTime}}</text>
				<text class="text-cut padding-sm">巡检时间：{{formData.createTime}}</text>
			</view>
		</uni-section>
		<uni-section title="巡检结果" type="line">
			<u--textarea v-model="textareaValue" placeholder="请输入巡检结果" :maxlength="1000" count height="200">
			</u--textarea>
		</uni-section>
		<uni-section title="现场图片" type="line">
			<u-upload :fileList="fileList3" @afterRead="afterRead" @delete="deletePic" name="3" multiple :maxCount="10"
				:previewFullImage="true"></u-upload>
		</uni-section>
		<uni-row :gutter="20">
			<uni-col :span="12">
				<u-button shape="circle" size="small" color="#2563EB" text="立即整改"></u-button>
			</uni-col>
			<uni-col :span="12">
				<u-button shape="circle" size="small" color="#2563EB" text="生成隐患"></u-button>
			</uni-col>
		</uni-row>
	</view>
</template>
<script>
	import {
		addRole,
		changeRoleStatus,
		delRole,
		exportRole,
		getRole,
		listRole,
		updateRole
	} from "@/api/system/role";
	import {
		uploadAvatar
	} from "@/api/system/user"
	let that = null;
	export default {
		data() {
			return {
				// 数据
				tableData: [],
				// 每页数据量
				pageSize: 20,
				// 当前页
				pageNo: 1,
				// 数据总量
				total: 0,
				// tableData数据加载中
				loading: false,
				// 自定义表单数据
				formData: {},
				// 输入框的内容
				textareaValue: '统计字数',
				fileList3: [{
					url: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
				}],
			}
		},
		computed: {},
		// 在 vue页面，向起始页通过事件传递数据
		onLoad: function(option) {
			console.log("option: ",option);
			that = this;
			const eventChannel = this.getOpenerEventChannel();
			// eventChannel.emit('acceptDataFromOpenedPage', {
			// 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
			eventChannel.on('acceptDataFromOpenerPage', function(val) {
				console.log(' val', val)
				that.formData = val
			})
		},
		onReady() {},
		methods: {
			// 删除图片
			deletePic(event) {
				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) {
				console.log(url);
				let data = {
					name: 'avatarFile',
					filePath: url
				}
				this.loading = true
				return uploadAvatar(data).then(response => {
					uni.showToast({
						title: "修改成功",
						icon: 'success'
					})
				})
			},
		}
	}
</script>
<style lang="scss">
	.buttomBorder {
		height: 0px;
		border: 1px dashed #CBD5E1;
	}
</style>
