
<template>
	<scroll-view  :scroll-y="true" class="scrll-height">
	<u-cell-group v-if="itemdata.length != 0">
		<view  v-for="(item,index) in itemdata"  :key="index" @click="toPartcodetal(item.roomId,item.id)"  >
			<u-cell-item  
			:use-label-slot="true" 
			:border-bottom="true" 
			:border-top="false" 
			:key="index" 
			:label-style="{'fontSize':'28rpx', 'color':'rgba(80, 80, 80, 1)' ,'marginBottom':'30rpx'}"
			:icon-style="{'color':'#000'}" 
			:title-style="{'color':'#000','fontSize':'32rpx','fontWeight':' blod'}" 
			:arrow="false" 
			:label="taskName"  
			:title="item.roomName + `  ${position}`"
			>
			<u-icon name="arrow-right" slot="right-icon" color="#B3B3B3" size="38"></u-icon>
			<div solt="label" class="left-boto-txt"  >{{item.username}}：{{item.time}}</div>
			</u-cell-item>
			<view style=" height: 3.5rpx;width: 100%; background: #FFFFFF;"></view>
		</view>
	</u-cell-group>
	<block v-else class="u-m-t-34">
		<u-empty  text="数据为空" mode="list"></u-empty>
	</block>
	</scroll-view>
</template>

<script>
	import {
		listForMobile
	} from '@/api/index.js'
	import dayjs from "dayjs";
	export default {
		props:{
			option:{
				type:Object
			},
			taskName:{
				type:String
			},
			position:{
				type:String
			}
		},
		data(){
			return {
				itemdata:[]
			}
		},
		created() {
			this.getItemdata() 
		},
		methods:{
			getItemdata() {
				let {
					taskId,
					roomId
				} = this.option
				listForMobile({
						taskId,
						roomId
					})
					.then(({
						data
					}) => {
						if(data.list.length == 0) {
							uni.showToast({
								title: '巡检记录列表为空',
								icon: "none",
								duration: 2000
							});
						}
						else if(data.list.length == 1) {
							data.list.forEach(i => {
								i.time = dayjs(i.time).format("YYYY-MM-DD HH:mm:ss")
							})
							this.itemdata = data.list
							//直接跳转巡检详情
							this.toPartcodetal(data.list[0].roomId,data.list[0].id)
						} else {
							data.list.forEach(i => {
								i.time = dayjs(i.time).format("YYYY-MM-DD HH:mm:ss")
							})
							this.itemdata = data.list
						}
					})
			},
			toPartcodetal(roomId,taskId) {
				uni.navigateTo({
					url:`../patroldetail/patroldetail?roomId=${roomId}&taskId=${taskId}`
				})
			}
		}
	}
</script>

<style>
</style>
