<template>
	<view class="container">
		<view class="title">维修日期</view>
		<uni-datetime-picker placeholder="请选择日期" type="date" v-model="single" />
		<view class="title">维修内容</view>
		<view class="textarea">
			<textarea placeholder-style="color:#CCCCCC" placeholder="请输入维修内容"></textarea>
		</view>
		<view class="title">维修结果</view>

		<!-- 录音区域 -->
		<view class="voice">
			<view class="voice_box">
				<img src="../../static/images/repairsImg/voice.png" />
			</view>
			点击录音
		</view>

		<view class="title">关联耗材</view>

		<!-- 每一个耗材盒子区域 -->
		<view class="detail_box">
			<view class="detail_box_item">
				<view class="item_key">耗材名称</view>
				<view class="item_value">螺丝钉</view>
			</view>
			<view class="detail_box_item">
				<view class="item_key">耗材数量</view>
				<view class="item_value">
					<uni-number-box v-model="count" :min="0" @change="bindChange"></uni-number-box>
				</view>
			</view>
			<view class="detail_box_item">
				<view class="item_key">耗材单价</view>
				<view class="item_value">0.5</view>
			</view>
		</view>

		<!-- 添加耗材区域 -->
		<view class="add" @click="handleAdd">
			<text>＋</text>
			添加耗材
		</view>

		<!-- 合计费用区域 -->
		<view class="total">
			<view>合计费用</view>
			<view>10元</view>
		</view>

		<view class="title">维修师傅</view>

		<view class="box">
			<img src="../../static/images/repairsImg/people.png" />
			张三
		</view>

		<view class="title">手机</view>

		<view class="box">
			<img src="../../static/images/repairsImg/phone2.png" />
			13659854589
		</view>

		<view class="title">现场拍照</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 class="btn">确认提交</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>
export default {
	data() {
		return {
			single: '',
			count: 6,
			// 显示的图片数据
			imgList: [],
			// 上传的图片数据
			subImgList: [],
			// 图片上传框的样式
			imageStyles: {
				width: 60,
				height: 60,
				border: {
					color: '#ccc',
					width: 1,
					style: 'dashed',
					radius: '9px'
				}
			},
			//画板边长默认是屏幕宽度，正方形画布
			cw: uni.getSystemInfoSync().windowWidth
		}
	},
	methods: {
		bindChange() {},
		handleAdd() {
			uni.navigateTo({
				url: '/pagesRepairs/addGoods/addGoods'
			})
		},
		// 选择图片回调
		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)
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	box-sizing: border-box;
	padding: 0 30rpx;
	overflow-y: auto;

	.title {
		display: flex;
		align-items: center;
		height: 107rpx;
		font-size: 36rpx;
		font-weight: bold;
	}

	.textarea {
		height: 310rpx;
		border-radius: 10rpx;
		border: 1rpx solid #cccccc;

		textarea {
			box-sizing: border-box;
			padding: 25rpx 35rpx;
			width: 100%;
			font-size: 32rpx;
		}
	}

	.voice {
		display: flex;
		align-items: center;
		height: 94rpx;
		font-size: 32rpx;
		color: #cccccc;
		border-radius: 10rpx;
		border: 1rpx solid #cccccc;

		.voice_box {
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 0 38rpx 0 33rpx;
			width: 101rpx;
			height: 47rpx;
			border-radius: 33rpx;
			box-shadow: 0px 0px 4rpx rgba(0, 0, 0, 0.25);

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

	.detail_box {
		box-sizing: border-box;
		margin-bottom: 46rpx;
		padding: 5rpx 30rpx 0;
		width: 690rpx;
		height: 284rpx;
		border-radius: 9rpx;
		box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.25);

		.detail_box_item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 92rpx;
			font-size: 32rpx;
			border-bottom: 1rpx solid #e5e5e5;

			.item_key {
				width: 150rpx;
				color: #808080;
			}

			.item_value {
				font-weight: bold;
			}
		}
	}

	.add {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 690rpx;
		height: 90rpx;
		color: #6fb6b8;
		font-size: 32rpx;
		border-radius: 9rpx;
		background-color: #ebf2f2;

		text {
			margin-right: 10rpx;
			font-size: 48rpx;
		}
	}

	.total {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: auto;
		width: 622rpx;
		height: 100rpx;
		font-size: 32rpx;
		font-weight: bold;
		border-bottom: 1rpx solid #e5e5e5;
	}

	.box {
		display: flex;
		align-items: center;
		height: 94rpx;
		font-size: 32rpx;
		border-radius: 10rpx;
		border: 1rpx solid #cccccc;

		img {
			margin: 0 14rpx 0 30rpx;
			width: 40rpx;
			height: 40rpx;
		}
	}

	.btn {
		display: flex;
		justify-content: center;
		align-items: center;
		margin: 65rpx 0 60rpx;
		height: 100rpx;
		color: #fff;
		font-size: 32rpx;
		border-radius: 12rpx;
		background-color: #6fb6b8;
	}
}
</style>
