<template>
	<view class="repairList reserveSpace">
		<view class="tab">
			<uv-tabs :list="list" lineWidth="60" lineHeight="10" @click="selectTag"></uv-tabs>
		</view>

		<view class="repairList-main">
			<view v-for="item in repairList" :key="item.id" class="repairItem">
				<view class="repairMain">
					<!-- <view class="userName">用户名</view> -->
					<view class="build">
						<view>
							<text style="margin-right: 10rpx;">{{ item.building }}</text>
							<text> {{ item.room }}</text>
						</view>
						<text style="font-size: 26rpx;">{{ item.createTime }}</text>
					</view>
					<view class="desc">
						<uv-read-more :shadowStyle="shadowStyle" show-height="80rpx" fontSize="30rpx" :toggle="true">
							<view>
								{{ item.context }}
							</view>
						</uv-read-more>
					</view>
					<view class="repairImages">
						<view v-for="(image,index) in item.image" :key="index" class="image-item">
							<image @click="viewImageAsList(index,item.image)" :src="image" mode="widthFix"></image>
						</view>
					</view>
					<view class="btns">
						<view @click="toReject(item.id)" class="btn">驳回</view>
						<view @click="toFinish(item.id)" class="btn">结单</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '待完成',
				}, {
					name: '已完成',
				}],
				current: 0,
				currentIndex: 0,
				repairList: [], //报修列表
			}
		},
		onShow() {
			this.getRepairList()
		},
		methods: {
			//跳转驳回
			toReject(id) {
				uni.navigateTo({
					url: `/pages/reject/reject?orderId=${id}`
				})
			},

			//跳转结单页面
			toFinish(id) {
				uni.navigateTo({
					url: `/pages/finish/finish?orderId=${id}`
				})
			},

			//查看图片
			viewImageAsList(index, imgArr) {
				this.currentIndex = index
				this.$utils.previewImage({
					current: this.currentIndex,
					urls: imgArr
				})
			},

			//选择了顶部的标签
			selectTag(tag) {
				console.log(tag);
			},

			//获取报修列表
			getRepairList() {
				this.$api('getSchoolOrderPage', this.form, res => {
					if (res.code == 200) {
						res.result.records.forEach(item => {
							item.image ? item.image = item.image.split(',') : item.image = []
						})
						this.repairList = res.result.records
					}
				})
			}
		},
		computed: {
			shadowStyle() {
				return {
					// #ifndef APP-NVUE
					backgroundImage: "linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #fff 80%)",
					// #endif
					// #ifdef APP-NVUE
					// nvue上不支持设置复杂的backgroundImage属性
					backgroundImage: "linear-gradient(to top, #fff, rgba(255, 255, 255, 0.5))",
					// #endif
					paddingTop: "50px",
					marginTop: "-50px",
				}
			}
		}
	}
</script>

<style scoped>
	.repairList {
		background: #f8f8f8;
	}

	.tab {
		display: flex;
		align-items: center;
		height: 80rpx;
		background: white;
		margin-bottom: 20rpx;
	}

	.repairList-main {
		min-height: 100vh;
	}

	.repairItem {
		display: flex;
		background: white;
		width: 96%;
		margin: 0rpx auto;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
	}

	.repairMain {
		width: 100%;
		box-sizing: border-box;
		padding-left: 20rpx;
	}

	/* 
	.userName {
		font-size: 32rpx;
		margin: 10rpx 0rpx;
	} */

	.build {
		display: flex;
		justify-content: space-between;
		font-size: 28rpx;
		margin: 20rpx 0rpx;
	}

	.desc {
		overflow-y: scroll;
		margin-bottom: 20rpx;
	}

	.repairImages {
		display: flex;
		flex-wrap: wrap;
		margin: 10rpx 0rpx;
	}

	.image-item {
		width: 24%;
		margin-left: 1%;
		height: 180rpx;
		overflow: hidden;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 20rpx;
		background: #f5f5f5;
		border-radius: 20rpx;
	}

	.image-item image {
		width: 100%;
	}

	.btns {
		margin: 20rpx 0rpx;
		display: flex;
		justify-content: flex-end;
	}

	.btn {
		width: 200rpx;
		height: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50rpx;
		margin-left: 15rpx;
		font-size: 30rpx;
		color: white;
		background: #f9ae3d;
	}

	.btn:nth-child(2) {
		background: #3c9cff;
	}
</style>