<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>
		</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 noRecord from '@/components/xinsoft-no-record/xinsoft-no-record';

export default {    
	components: {
		devBlock,noRecord
	},
	data() {
		return {
			deviceId:'', //设备id
			listCards: []
	    }
	},
	onLoad(options) {
		this.deviceId = options.deviceId;
		//初始化当前列表。
		this.getEqSparePart(this.deviceId);
	},
	methods: {
		getEqSparePart(deviceId){
			this.loadingType = 0;		
			this.$http.request({
			  url: '/apis/sparePart:sparePartList',
			  params:{
				  id:deviceId
			  },
			}).then(res=>{
				console.log(res.data.code)
				if(res.data.code == 0){
					if(res.data.data && res.data.data.datas.length>0){
						this.listCards = this.formaterData(res.data.data.datas);
						console.log(this.listCards)
					}else{
						this.listCards = [];
					}
				}
			}).catch(err=>{
			});
		},
		formaterData(data){
			var resData = [];
			data.forEach((vals,index)=>{
				var combineJSON = {
					id: vals.id,
					title: vals.name,
					titleNumber:'['+vals.code+']',
					contentList: [
						{
							id:1,
							isDouble:true,
							labelName:'规格型号',
							labelContent:vals.type
						},						
						{
							id:2,
							isDouble:true,
							labelName:'库位',
							labelContent:vals.loacationName
						},
						{
							id:3,
							isDouble:true,
							labelName:'备件类型',
							labelContent:vals.spartTypeName
						}
					]
				}
				resData.push(combineJSON);
			});
			return resData;
		}
	}
};
</script>
