<template>
	<view class="page">
		<view class="example-body" v-if="listCards.length>0">
			<view v-for="item in listCards" :key="item.id" class="example-box">
				<dev-block :title="item.title" :titleNumber="item.titleNumber" :note="item.note" 
				:extra="item.extra"  :tagType="item.tagType"
				:contentList="item.contentList"></dev-block>
			</view>
			<!-- <uni-load-more  :loadingType="loadingType" :contentText="contentText" ></uni-load-more> -->
		</view>
		<view class="example-body" v-else>
			<no-record ></no-record>
		</view>
		<view class="goHome" @click='goMain()'>
			<img src="../../static/img/gohome.png">
		</view>
	</view>
</template>

<script>
   
import devBlock from '@/components/xinsoft-dev-block/xinsoft-dev-block.vue'
// import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import noRecord from '@/components/xinsoft-no-record/xinsoft-no-record';

export default {    
	components: {
		devBlock,noRecord
	},
	data() {
		return {
			deviceId:'6' ,//设备id
			listCards:[]
	    }
	},
	onLoad(options) {
		this.deviceId = options.deviceId;
		//初始化当前列表。
		this.getKeep(this.deviceId);
	},
	methods: {
		getKeep(deviceId){
			this.$http.request({
			  url: '/apis/upkeepRecord/getProByDeviceID',
			  params:{
				  deviceId:deviceId
			  },
			}).then(res=>{
				if (!res.data.data|| res.data.data.length ==0) {//没有数据
				    this.listCards= [];
					return;
				}
				if(res.data.code == 0){
					if(res.data.data){
						this.listCards = this.formaterData(res.data.data);
					}
				}
			}).catch(err=>{
			});
		},
		formaterData(data){
			var resData = [];
			data.forEach((values,i)=>{
				var record = values.upkeepRecord;
				values.upkeepRecordDetails.forEach((vals,index)=>{		
					var functions = vals.function;
					var tags = vals.result;
					var tagColor = '';
					if(tags == '通过'){
						tagColor = '106'
					}else if(tags == '通过'){
						tagColor = '108'
					}else{
						tagColor = '107'
					}
					var combineJSON = {
						id: vals.id,
						title: record.planCode+'-'+(record.resultName||''),
						contentList: [
							{
								id:1,
								isDouble:false,
								labelName:'保养项目',
								labelContent:vals.name
							},						
							{
								id:2,
								isDouble:false,
								labelName:'保养工时',
								labelContent:vals.manhour?(vals.manhour+'小时'):''
							},
							{
								id:4,
								isDouble:false,
								labelName:'保养方法',
								labelContent:functions
							},
						],
						note: '',
						//字段值：通过，不通过，待评价
						extra: vals.result,
						tagType:tagColor
					}
					resData.push(combineJSON);
				})
			});
			return resData;
		}
	}
};
</script>
