<template>
	<el-container>
		<el-main class="orderMain" v-loading="loading" element-loading-text="加载中...">
			<el-scrollbar>
				<detailView :data="info">
					<template #submit>
						<div class="cardItem">
							<div class="title titleFlex">
								<span class="name">维保部件信息</span>
							</div>
							<div class="cardBody">
								<el-row>
									<el-col :span="24" :lg="24" class="colFlex">
										<span class="label labelText">验证ERP库存：</span>
										<span class="text">{{info.is_verify_erp_inventory?'是':'否'}}</span>
									</el-col>
								</el-row>
							</div>
							<div class="cardBody">
								<sc-table ref="table" :data="info.component_info" style="width: 100%;" :hidePagination="true" :hideDo="true" :hideEmpty="true" :size="size">
									<sc-table-column prop="component_serial_no" label="部件SN/Sp" :show-overflow-tooltip="true" width="160"></sc-table-column>
									<sc-table-column prop="component_manufacturer" label="部件厂商" :show-overflow-tooltip="true" width="130"></sc-table-column>
									<sc-table-column prop="component_model" label="部件型号" :show-overflow-tooltip="true" width="160"></sc-table-column>
									<sc-table-column prop="component_pn" label="部件PN/Sp" :show-overflow-tooltip="true" width="150"></sc-table-column>
									<sc-table-column prop="bd_backup_count" label="甚于BD数" :show-overflow-tooltip="true" width="120"></sc-table-column>
								</sc-table>
							</div>
						</div>
					</template>
				</detailView>
			</el-scrollbar>
		</el-main>
	</el-container>
</template>

<script>
import detailView from "@/views/order/orderList/detailView";
export default {
	name: "order-info",
	components:{
		detailView
	},
	data(){
		return{
			size:'small',
			loading:false,
			params:{
				order_id:Number(this.$route.query.id)
			},
			info:{
				is_verify_erp_inventory:false,
				component_info:[]
			},
		}
	},
	mounted() {
		this.getData();
	},
	methods:{
		async getData() {
			this.loading = true;
			const res = await this.$API.orders.order.maintenance.info.post(this.params);
			if(res.code == 200){
				if(res.data.process_engine){
					let obj = this.processList(res.data.process_engine);
					res.data.process_engine = obj.processedList;
					res.data.process_num = obj.num;
				}
				this.info = res.data;
				if(res.data.component_info.length==0){
					this.info.component_info = [
						{
							component_serial_no:res.data.component_serial_no,
							component_manufacturer:res.data.component_manufacturer,
							component_model:res.data.component_model,
							component_pn:res.data.component_pn,
							bd_backup_count:res.data.bd_backup_count
						}
					]
				}
			}
			this.loading = false;
		},
		processList(list) {
			let obj = {
				num:0,
				processedList:this.$TOOL.objCopy(list)
			}
			let foundNodeTrue = false;
			for (let i = 0; i < obj.processedList.length; i++) {
				if (obj.processedList[i].node === true) {
					foundNodeTrue = true;
					obj.processedList[i].status = 'finish';
					obj.num = i;
				} else if (!foundNodeTrue) {
					obj.processedList[i].status = 'success';
				}
				if (foundNodeTrue && obj.processedList[i].node !== true) break;
			}
			return obj;
		}
	}
}
</script>

<style scoped lang="scss">

</style>
