<template>
	<el-dialog width="50%" top="10vh" custom-class="modal" title="检测记录" :close-on-click-modal="false"
		@opened="opened()">
		<div style="height: 70vh; overflow-y: auto">
			<div class="titleBar">
				<div class="titleName">测试级</div>
			</div>
			<el-table ref="multipleTable" empty-text="暂无数据" :data="allData" :header-cell-style="{ height: '40px', background: 'rgba(83, 98, 104, 0.2)', color: '#b2bdc0', 'border-bottom': '0px solid red', }" :cell-style="{ height: '40px', 'border-bottom': 'solid 0px #242424', }" stripe style="width: 100%; margin-bottom: 10px">
				<el-table-column prop="starttime" label="故障时间" width="160" align="center"></el-table-column>
				<el-table-column prop="stationen" label="风场" width="80" align="center"></el-table-column>
				<el-table-column prop="stationcn" label="场站名称" width="120" align="center"></el-table-column>
				<el-table-column prop="windturbineid" label="风机编号" width="100" align="center"></el-table-column>
				<el-table-column prop="model" label="风机型号" width="80" align="center"></el-table-column>
				<el-table-column width="200" label="故障标签">
					<template #default="scope">
						<span>
							<el-select v-model="scope.row.faultcode" @change="selectChange(scope.row)" clearable
								placeholder="请选择" popper-class="select" style="width: 130px; margin-left: 30px">
								<el-option v-for="item in faultLists" :key="item.faultcode" :label="item.faulttype"
									:value="item.faultcode">
								</el-option>
							</el-select>
						</span>
					</template>
				</el-table-column>
				<el-table-column width="120" label="操作">
					<template #default="btn">
						<button class="btn" @click="getReports(btn.row.faultid)">查看检测报告</button>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<TestReport v-model="reportDisplay" :faultid='faultid' 
	  ></TestReport>
	</el-dialog>
</template>
<script>
	import TestReport from "./testReport.vue";
	import axios from "axios";
	export default {
		components: {
			TestReport,
		},
		props: {
			myData: {},
		},
		data() {
			return {
				faultLists: [],
				allData: [],
				reportDisplay: false,
				faultid:''
			};
		},
		created() {
			this.getfaultLables();
		},
		methods: {
			opened() {
				this.getData();
			},
			getData() {
				let that = this;
				that.API.requestData({
					method: "GET",
					subUrl: "http://192.168.1.18:9002/case/fault/list",
					data: {
						station: that.myData.station,
						model: that.myData.model,
						st: that.myData.st,
						et: that.myData.et,
						category: 3
					},
					success(res) {
						if (res) {
							that.allData = res.data;
						}
					},
				});
			},
			getfaultLables() {
				let that = this;
				this.API.requestData({
					method: "GET",
					subUrl: "http://192.168.1.18:9002/know/fault/type/all",
					success(res) {
						if (res) {
							that.faultLists = res.data;
						}
					},
				});
			},
			selectChange(data) {
				let params = [];
				(data.faulttype = this.faultLists.filter(
					(item) => item.faultcode === data.faultcode
				)[0]?.faulttype),
				params.push(data);
				axios({
					method: "post",
					url: "http://192.168.10.19:9002/case/fault/insert",
					data: params,
					header: {
						"Content-Type": "application/json",
					},
				}).then((res) => {
					if (res.data.code !== 200) {
						this.BASE.showMsg({
							type: "error",
							msg: "标签修改失败",
						});
					}
				});
			},
			getReports(id) {
				this.faultid = id;
				this.reportDisplay = true;
			},
		},
	};
</script>
<style lang="less" scoped>
	.btn {
		width: 106px !important;
	}
</style>
