<template>
	<!-- 设备报修 -->
	<view class="container">
		<u-navbar back-icon-color='#fff' :background="{ background: '#409eff'}" back-text="" title-color='#fff'
			title="我的报修">
		</u-navbar>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="title">
					<view class="title-txt">
						{{item.describes}}
					</view>
					<view class="time">
						{{`${$time.formatDate(item.createTime)}`}}
					</view>
				</view>
				<view class="dec">
					报修单号:<span>{{item.number}}</span>
				</view>
				<view class="dec">
					{{`${params.type=='DEVICE'?'设备' : '模具'}`}}编号:<span>{{item.deviceNumber}}</span>
				</view>
				<view class="dec">
					{{`${params.type=='DEVICE'?'设备' : '模具'}`}}名称:<span>{{item.name}}</span>
				</view>
				<view class="dec">
					所属厂区:<span>{{item.factoryAreaName}}</span>
				</view>
				<view class="images">
					<image :src="cur" mode="" v-for="(cur,key) in item.filePathList" :key='key'
						@click="previewImage(key,item.filePathList)"></image>
				</view>
				<view class="bottom">
					<view class="status">
						<u-tag :text="item.result" bg-color='rgba(255,255,255,0)' color='#2ba471' border-color='#2ba471'
							type="primary" shape='circle' />
					</view>
					<!-- <view class="button">
						<u-button shape="circle" type="primary" size="mini" style="min-width: 120rpx;"
							v-if="item.isCancel == 0" @click="cancle(item)">撤销</u-button>
					</view> -->

				</view>
			</view>
			<view style="height: 94rpx;padding-top: 30rpx;">
				<u-loadmore :status="status" v-if="status != 'loadmore'" />
			</view>
		</view>
		<view style="height: constant(safe-area-inset-bottom); height: env(safe-area-inset-bottom);"></view>
	</view>
</template>

<script setup lang="ts">
	import {
		onShow,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		ref,
		getCurrentInstance
	} from 'vue'
	import * as deviceApi from "@/api/device.js"
	const { proxy } = getCurrentInstance()
	const params = ref({
		pageNo: 1,
		pageSize: 10,
		flag: 1,
	})
	const status = ref('loadmore') //是否显示没有更多了
	const list = ref([])
	async function getList() {
		if (status.value == 'nomore') return;
		status.value = 'loading';
		proxy.$modal.loading('加载中')
		await deviceApi.deviceRepairPage(params.value).then((res) => {
			proxy.$modal.closeLoading()
			if (res.data.list.length > 0) {
				list.value = list.value.concat(res.data.list);
				params.value.pageNo++;
				status.value = 'loadmore'
			} else {
				status.value = 'nomore'
			}
		}).catch(() => { })
	}
	function previewImage(current, array) {
		uni.previewImage({
			urls: array,
			current: current,
			longPressActions: {
				itemList: ['发送给朋友', '保存图片', '收藏'],
				success: function (data) {
					console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
				},
				fail: function (err) {
					// console.log(err.errMsg);
				}
			}
		});
	}
	onShow(() => {
		params.value.pageNo = 1
		list.value = []
		status.value = 'loadmore'
		getList()
	})
	onReachBottom(() => {
		getList()
	})
</script>

<style lang="scss" scoped>
	.list {
		margin-top: 20rpx;

		.item {
			padding: 30rpx 30rpx 0px 30rpx;
			margin-top: 20rpx;
			background: white;

			.title {
				display: flex;
				align-items: center;
				padding-bottom: 20rpx;

				.title-txt {
					color: #409eff;
					font-weight: bold;
					font-size: 36rpx;
					width: 0px;
					flex: 1;
					word-wrap: break-word;
				}

				.time {
					color: #919191;

				}
			}

			.dec {
				padding-bottom: 20rpx;

				span {
					color: #999999;
				}
			}

			.last {
				padding-bottom: 30rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 1px solid #E4E4E4;
				padding: 20rpx 0px;
				height: 90rpx;

			}
		}
	}

	.list {
		background: #f5f5f5;
		margin-top: 20rpx;

		.item {
			padding: 30rpx 30rpx 0px 30rpx;
			margin-top: 20rpx;
			background: white;

			.title {
				display: flex;
				align-items: center;
				padding-bottom: 20rpx;

				.title-txt {
					color: #409eff;
					font-weight: bold;
					font-size: 36rpx;
					width: 0px;
					flex: 1;
				}

				.time {
					color: #919191;

				}
			}

			.dec {
				padding-bottom: 20rpx;

				span {
					color: #999999;
				}
			}

			.last {
				padding-bottom: 30rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 1px solid #E4E4E4;
				padding: 20rpx 0px;
				position: relative;

				.status {
					flex: 1;
				}

				.button {
					position: absolute;
					right: 0rpx;
				}

			}
		}
	}

	.images {
		display: flex;
		width: 100%;

		image {
			width: 30%;
			margin-right: 20rpx;
			height: 200rpx;
			border-radius: 10rpx;
		}
	}
</style>