<template>
	<view class="container">
		<!-- 公告区域 -->
		<view class="notice">
			<uni-notice-bar show-icon single speed="50" :scrollable="true" background-color="#fff" color="#000" text="今日14:00系统更新请不要进行报修！" />
		</view>
		<view class="gap"></view>

		<!-- 报修区域 -->
		<view class="box_item">
			<view class="item_title">
				报修区域
				<text>*</text>
			</view>
			<view class="item_info" @click="handleSelectArea">请选择报修区域</view>
			<view class="item_icon" @click="handleSelectArea">
				<img src="../../static/images/repairsImg/right.png" />
			</view>
		</view>

		<!-- 详细地址区域 -->
		<view class="box_item">
			<view class="item_title">
				详细地址
				<text>*</text>
			</view>
			<view class="item_info">
				<view class="item_input">
					<input placeholder-style="color:#CCCCCC" type="text" placeholder="请输入详细地址" />
				</view>
			</view>
		</view>

		<!-- 报修物品区域 -->
		<view class="box_item">
			<view class="item_title">
				报修物品
				<text>*</text>
			</view>
			<view class="item_info" @click="handleSelectGoods">请选择报修物品</view>
			<view class="item_icon" @click="handleSelectGoods">
				<img src="../../static/images/repairsImg/right.png" />
			</view>
		</view>

		<!-- 故障描述 -->
		<view class="box_item2">
			<view class="item2_title">
				故障描述
				<text>*</text>
			</view>
			<view class="item2_info">
				<view class="item2_textarea">
					<textarea placeholder-style="color:#CCCCCC" placeholder="请输入故障描述"></textarea>
				</view>
			</view>
		</view>

		<!-- 报修录音区域 -->
		<view class="box_item">
			<view class="item_title">报修录音</view>
			<view class="item_info">
				<view class="info_icon">
					<img src="../../static/images/repairsImg/voice.png" />
				</view>
				<view class="info_tips">点击录音</view>
			</view>
		</view>

		<!-- 上传照片区域 -->
		<view class="box_item3">
			<view class="item3_title">
				上传照片
				<text>（可上传三张，请上传局部图和区域图）</text>
			</view>

			<uni-file-picker
				ref="filePicker"
				limit="3"
				v-model="imgList"
				fileMediatype="image"
				:image-styles="imageStyles"
				mode="grid"
				@select="select"
				@delete="handleDelete"
			></uni-file-picker>
		</view>

		<!-- 报修姓名区域 -->
		<view class="box_item">
			<view class="item_title">
				报修姓名
				<text>*</text>
			</view>
			<view class="item_info">
				<view class="item_input">
					<input placeholder-style="color:#CCCCCC" type="text" placeholder="请输入报修姓名" />
				</view>
			</view>
		</view>

		<!-- 联系电话区域 -->
		<view class="box_item">
			<view class="item_title">
				联系电话
				<text>*</text>
			</view>
			<view class="item_info">
				<view class="item_input">
					<input placeholder-style="color:#CCCCCC" type="text" placeholder="请输入联系电话" />
				</view>
			</view>
		</view>

		<!-- 底部区域 -->
		<view class="foot">
			<view class="foot_btn">确认提交</view>
			<view class="foot_phone">紧急电话 5661626</view>
			<view class="foot_phone">服务监督电话 5661626</view>
		</view>

		<!-- 消息通知按钮区域 -->
		<view class="fixed" @tap="handleClickFixed">
			<view class="fixed_box">
				<img src="../../static/images/repairsImg/message.png" />
				消息通知
			</view>
		</view>

		<!-- 用于图片压缩的canvas画布 -->
		<canvas
			:style="{
				width: cw + 'px',
				height: cw + 'px',
				position: 'absolute',
				zIndex: -1,
				left: '-10000rpx',
				top: '-10000rpx'
			}"
			canvas-id="zipCanvas"
		></canvas>
		<!--画布结束-->
	</view>
</template>

<script>
// 图片压缩方法
import getLessLimitSizeImage from '../util/imageCompress.js'

export default {
	data() {
		return {
			// 显示的图片数据
			imgList: [],
			// 上传的图片数据
			subImgList: [],
			// 图片上传框的样式
			imageStyles: {
				width: 60,
				height: 60,
				border: {
					color: '#ccc',
					width: 1,
					style: 'dashed',
					radius: '9px'
				}
			},
			//画板边长默认是屏幕宽度，正方形画布
			cw: uni.getSystemInfoSync().windowWidth
		}
	},
	methods: {
		// 选择图片回调
		select(e) {
			console.log(e)
			e.tempFiles.forEach((item) => {
				//这里的id和页面中写的html代码的canvas的id要一致
				let canvasId = 'zipCanvas'
				//原图的路径
				let imagePath = item.path
				//大小限制1024kb
				let limitSize = 1024
				//初始绘画区域是画布自身的宽度也就是屏幕宽度
				let drawWidth = uni.getSystemInfoSync().windowWidth

				getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
					uni.showLoading({
						title: '上传中'
					})
					uni.uploadFile({
						url: `https://jiangxih3cpartner.com/reporting/file/fileUpDown`,
						filePath: resPath,
						name: 'file',
						success: (uploadFileRes) => {
							subImgList.value.push(JSON.parse(uploadFileRes.data).data.join())
							imgList.value.push({
								url: item.path,
								name: ''
							})
							uni.hideLoading()
						},
						fail: () => {
							uni.showToast({
								title: '上传失败',
								icon: 'error'
							})
						}
					})
				})
			})
		},
		handleDelete(e) {
			// console.log(e);
			const num = imgList.value.findIndex((v) => v.url === e.tempFilePath)
			subImgList.value.splice(num, 1)
			imgList.value.splice(num, 1)
		},

		// 点击报修区域回调
		handleSelectArea() {
			uni.navigateTo({
				url: '/pagesRepairs/selectArea/selectArea'
			})
		},
		// 点击报修物品回调
		handleSelectGoods() {
			uni.navigateTo({
				url: '/pagesRepairs/selectGoods/selectGoods'
			})
		},
		// 点击消息通知按钮回调
		handleClickFixed() {
			uni.navigateTo({
				url: '/pagesRepairs/message/message'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	width: 100vw;
	height: calc(100vh - 102rpx);
	overflow-y: auto;

	.notice {
		height: 90rpx;
	}

	.gap {
		height: 12rpx;
		background-color: #f2f2f2;
	}

	.box_item {
		display: flex;
		align-items: center;
		margin: 0 30rpx;
		height: 105rpx;
		font-size: 28rpx;
		border-bottom: 1rpx solid #e6e6e6;

		.item_title {
			width: 190rpx;
			font-weight: bold;

			text {
				margin-left: 5rpx;
				color: #d43030;
			}
		}

		.item_info {
			flex: 1;
			display: flex;
			padding: 0 10rpx;
			color: #cccccc;

			.item_input {
				width: 100%;
				height: 105rpx;

				input {
					height: 105rpx;
					line-height: 105rpx;
					color: #000;
				}
			}

			.info_icon {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 79rpx;
				height: 37rpx;
				border-radius: 33rpx;
				border: 1rpx solid #e6e6e6;

				img {
					width: 26rpx;
					height: 26rpx;
				}
			}

			.info_tips {
				margin-left: 33rpx;
				font-size: 28rpx;
				color: #cccccc;
			}
		}

		.item_icon {
			width: 38rpx;
			height: 38rpx;

			img {
				width: 100%;
				height: 100%;
			}
		}
	}

	.box_item2 {
		display: flex;
		align-items: center;
		margin: 0 30rpx;
		height: 237rpx;
		font-size: 28rpx;
		border-bottom: 1rpx solid #e6e6e6;

		.item2_title {
			width: 190rpx;
			font-weight: bold;

			text {
				margin-left: 5rpx;
				color: #d43030;
			}
		}

		.item2_info {
			flex: 1;
			padding: 0 10rpx;

			.item2_textarea {
				display: flex;
				align-items: center;
				width: 100%;
				height: 237rpx;

				textarea {
					box-sizing: border-box;
					padding: 20rpx;
					width: 500rpx;
					height: 176rpx;
					border: 1rpx solid #e6e6e6;
					border-radius: 6rpx;
				}
			}
		}
	}

	.box_item3 {
		margin: 0 30rpx;
		height: 246rpx;
		border-bottom: 1rpx solid #e6e6e6;

		.item3_title {
			height: 95rpx;
			line-height: 95rpx;
			font-size: 28rpx;
			font-weight: bold;

			text {
				font-size: 24rpx;
				color: #808080;
				font-weight: 400;
			}
		}
	}

	.foot {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 0 30rpx;
		height: 407rpx;

		.foot_btn {
			margin-top: 167rpx;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			color: #fff;
			font-size: 32rpx;
			border-radius: 12rpx;
			background-color: #6fb6b8;
		}

		.foot_phone {
			margin-top: 30rpx;
			color: #b3b3b3;
			font-size: 24rpx;
		}
	}

	.fixed {
		z-index: 2;
		position: fixed;
		right: 0;
		bottom: 382rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 211rpx;
		height: 90rpx;
		border-radius: 150rpx 0 0 150rpx;
		border: 1rpx solid #d9d9d9;
		background-color: #fff;
		box-shadow: 0 0 7rpx #d9d9d9;

		.fixed_box {
			display: flex;
			align-items: center;
			font-size: 28rpx;

			img {
				margin-right: 10rpx;
				width: 38rpx;
				height: 38rpx;
			}
		}
	}
}
</style>
