<template>
	<div>
		<div class="diamain">
			<div class="left">
				<el-tree :data="data" :props="defaultProps" node-key="id" :default-expand-all="true"
					custom-class="modal" @node-click="handleNodeClick"></el-tree>
			</div>
			<div class="right">
				<div class="table-box">
					<ComTable :data="tableData" height="700px"></ComTable>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import ComTable from "@com/coms/table/table.vue";
	export default {
		components: {
			ComTable
		},
		props: {
			gridDatas: {},
			chartDatas: {},
			formdata: Object,
		},
		data() {
			return {
				form: {
					wtId: "",
					wpId: ""
				},
				tableData: {
					column: [{
							name: "消缺描述",
							field: "xqms",
							width:'400px',
							is_light: false,
						},
						{
							name: "消缺人员",
							field: "xqry",
							is_light: false,
						},
						{
							name: "消缺时间",
							field: "xqsj",
							is_light: false,
						},
						{
							name: "更换部件",
							field: "ghbj",
							is_light: false,
						},
						{
							name: "更换原因",
							field: "ghyy",
							is_light: false,
						},
						{
							name: "更换数量",
							field: "ghsl",
							is_light: false,
						},
					],
					data: [],
				},
				data: [],
				defaultProps: {
					children: "children",
					label: "label",
				},
			};
		},
		methods: {
			async searchH() {
				var that = this;
				const {
					data
				} = await that.API.requestData({
					method: "POST",
					subUrl: "/recommen/findLocationTreeByWtId",
					data: {
						wtId: that.form.wtId,
					},
				});
				that.dialogVisible = true;
				that.data = data.data;
				that.location = data.data[0].id;
				that.searchTab();
			},
			async searchTab() {
				var that = this;
				const {
					data
				} = await that.API.requestData({
					method: "POST",
					subUrl: "/recommen/findWobugeqByLocation",
					data: {
						tablepar: {
							pageNum: 1,
							pageSize: 10,
						},
						location: that.location,
					},
				});
				if(data.data && data.data[0] && data.data[0].xqsj){
					data.data[0].xqsj = new Date(data.data[0].xqsj).formatDate("yyyy-MM-dd hh:mm:ss");
				}
				that.tableData.data = data.data;
			},
			handleNodeClick(data) {
				this.location = data.id;
				this.searchTab();
			},
		},
		watch: {
			formdata(res) {
				if (res) {
					this.form = this.formdata;
					this.searchH();
				}
			}
		}
	};
</script>

<style lang="less">

</style>
