<template>
	<v-row class="search-box" align="center" no-gutters>
		<!-- <v-col v-if="label" cols="2"> -->
		<!-- <v-col v-if="label" :cols="labelCols">
			<label for="" class="search-box-label">
				<v-icon
					x-small
					:color="item.required ? '#fb8200' : 'primary'"
					class="mr-1"
					>mdi-record-circle</v-icon
				>
				{{ item.label }}
			</label>
		</v-col> -->
		<!-- <v-col :cols="label ? textCols : ''">
			<v-text-field
				readonly
				v-model="selectValue"
				append-icon="mdi-magnify"
				class="v-input__custom"
				@click="dialog = !dialog"
				outlined
				:hide-details="true"
				:disabled="item.disabled || false"
				:required="item.required || false"
			></v-text-field>
		</v-col> -->

		<!-- <v-row justify="center"> -->
		<v-dialog ref="popModal" v-model="dialog" width="1200" overlay-color="#000" overlay-opacity="0.8" scrollable>
			<!-- <template v-slot:activator="{ on, attrs }">
        <v-btn color="primary" dark v-bind="attrs" v-on="on">공정/설비</v-btn>
      </template> -->
			<v-card style="height: 100%">
				<v-card-title class="px-5 py-4 d-flex align-center justify-space-between">
					<span class="custom-title-4">가이드 알람이력</span>
					<a-button icon="close" type="text" @click="closePop()"></a-button>
				</v-card-title>
				<!-- <v-card-title
					class="v-card__title d-flex align-center justify-space-between"
				>
					<span class="custom-title-4">{{ '' }}</span>
					<v-btn icon tile :ripple="false" @click="closePop()">
						<v-icon>mdi-close</v-icon>
					</v-btn>
				</v-card-title> -->
				<!-- <v-card-actions> -->
				<div class="pa-5">
					<!-- <v-text-field label="위치정보 선택"></v-text-field> -->
					<!-- <v-row align="center" no-gutters>
						<v-col :cols="4">
							<div class="d-flex align-center justify-space-between pb-5">
								<v-card-title class="pa-0">가이드 알람이력</v-card-title>
							</div>
						</v-col>
						<v-col :cols="8" class="text-right">
							<v-btn icon tile :ripple="false" @click="closePop()">
								<v-icon>mdi-close</v-icon>
							</v-btn>
						</v-col>
					</v-row> -->
					<v-row align="center" no-gutters>
						<v-col :cols="12">
							<label for="" class="search-box-label">
								<v-icon small :class="['mr-1', 'icon-blue']">$icoBulletPoint</v-icon>
								설비
							</label>
						</v-col>
						<v-col :cols="6" class="pr-2 py-0">
							<v-text-field v-if="dialog" v-model="InputValue['eqpmId']" class="v-input__custom"
								:readonly="true" outlined :hide-details="true">
							</v-text-field>
						</v-col>
						<v-col :cols="6" class="pl-2 py-0">
							<v-text-field v-if="dialog" v-model="InputValue['eqpmNm']" class="v-input__custom"
								:readonly="true" outlined :hide-details="true">
							</v-text-field>
						</v-col>
					</v-row>
					<v-row align="center" no-gutters class="mt-4">
						<v-col :cols="12">
							<label for="" class="search-box-label">
								<v-icon small :class="['mr-1', 'icon-blue']">$icoBulletPoint</v-icon>
								가이드지표
							</label>
						</v-col>
						<v-col :cols="6" class="pr-2 py-0">
							<v-text-field v-if="dialog" v-model="InputValue['gdIdxId']" class="v-input__custom"
								:readonly="true" outlined :hide-details="true">
							</v-text-field>
						</v-col>
						<v-col :cols="6" class="pl-2 py-0">
							<v-text-field v-if="dialog" v-model="InputValue['gdIdxNm']" class="v-input__custom"
								:readonly="true" outlined :hide-details="true">
							</v-text-field>
						</v-col>
					</v-row>
				</div>
				<div class="d-flex align-center justify-space-between pa-4">
					<v-card-title class="py-0 px-2 custom-title-4">설비 가이드 정보</v-card-title>
				</div>
				<div class="px-5" style="height:calc(100% - 76px)">
					<div ref="modalGridParent" class="w100 h100">
						<component :ref="gridName" :is="loadGrid ? 'Grid' : null"
							:dataPath="searchParam.modalData.eqpmDetlPop" :gridName="gridName"
							:parentPrgmId="parentPrgmId" />
					</div>
				</div>
				<!-- <div id="gridParent" ref="gridParent" style="height: 500px">
						<component
							:ref="'gridName' + parentPrgmId"
							:is="loadGrid && dialog ? 'Grid' : null"
							:gridName="gridName"
							:dataPath="searchParam.modalData2.modifyEnrgUsePlanData"
							:parentPrgmId="parentPrgmId"
							:bindingData="bindingData"
							@getRowsData="getRowData"
							@dblClick="setUpdate()"
						/>
					</div> -->

				<v-card-actions class="px-6 py-4 d-flex align-center justify-end">
					<a-button color="primary" type="primary" @click="closePop()">확인</a-button>
				</v-card-actions>
			</v-card>
		</v-dialog>
	</v-row>
</template>

<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import Grid from '~/components/common/Grid';
import Utility from '~/plugins/utility';
import selectCodeList from '@/components/common/select/selectCodeList';
import InputText from '~/components/common/input/InputText';
import dateUtility from '~/plugins/dateUtility';

export default {
	props: {
		parentPrgmId: {
			type: String,
			require: true,
			default: '비교대상 최대(20개)',
		},
		label: {
			type: String,
			require: false,
			default: '전력 계약 정보',
		},
		valueNm: {
			type: String,
			require: false,
			default: '',
		},
		title: {
			type: String,
			require: false,
			default: '전력 계약 목록',
		},
		labelCols: {
			type: Number,
			require: false,
			default: 4,
		},
		textCols: {
			type: Number,
			require: false,
			default: 7,
		},
		item: {
			type: Object,
			require: true,
		},
		bindingData: {
			type: String,
			require: false,
		}
	},
	components: {
		Grid,
		selectCodeList,
		dateUtility,
		InputText
		// Tree
	},
	data() {
		return {
			labelPrepend: true,
			modalDataKey: 'modalData',
			myModalKey: 'eqpmDetlPop',
			gridName: 'eqpmDetlGrid',
			loadGrid: false,
			setGrid: false,
			popCheck: false,
			dialog: false,
			activeRowData: {},
			checkedRowDataList: [],
		};
	},
	computed: {
		...mapState({
			// searchParam: state => state.pageData,
			searchParam(state) {
				return state.pageData[this.parentPrgmId];
			},
			myBindingData(state) {
				//return state.pageData[this.parentPrgmId]["rowGridSelectData"];
				if (!this.bindingData) {
					return state.pageData[this.parentPrgmId]['rowGridSelectData'];
				} else {
					return state.pageData[this.parentPrgmId][this.bindingData][
						'rowGridSelectData'
					];
				}
			},
		}),
		InputValue: {
			get() {
				return this.myBindingData;
			}
		},
		chkDialog() {
			return this.dialog
		},
	},
	watch: {
		async chkDialog(val) {
			if (!val) {
				this.closePop();
			} else {
				// await this.getRowGridData();

			}
		},
		async popCheck(val) {
			if (val) {
				await this.getRowGridData();
				this.dialog = true;
			} else {
				this.dialog = false;
			}
		}
	},

	beforeCreate() {
		this.$store.commit('setPageData', {
			modalData: { eqpmDetlPop },
		});
	},
	created() {
		this.init();
	},
	methods: {
		...mapMutations({
			setPageData: 'setPageData',
			setModalGridData: 'setModalGridData',
			setModalGridColumn: 'setModalGridColumn',
			setModalGridOption: 'setModalGridOption',
		}),
		...mapActions({
			postApiReturn: 'modules/list/postApiReturn',
		}),
		init() {

			this.gridInit();
		},
		closePop() {
			this.popCheck = false;
		},
		search() {
			// this.getData();
		},
		gridInit() {
			// const gridHeight = this.$refs.gridParent.offsetHeight - 30;

			const myOptions = {
				rowHeaders: [
					{
						type: 'rowNum',
						align: 'right',
					},
				],
				columnOptions: {
					resizable: true,
					minWidth: 100
				},
				// setScroll: true,
				header: {
					height: 37,
				},
				rowHeight: 'auto',
			};


			this.setModalGridOption({
				modalKey: this.myModalKey,
				gridKey: this.gridName,
				modalDataKey: this.modalDataKey,
				value: Object.assign(
					// Utility.defaultGridOption(this.$refs.modalGridParent.offsetHeight - 60, myOptions),
					Utility.defaultGridOption(400, myOptions),
					myOptions,
				),
			});

			const myColumns = [
				{
					header: '발생일',
					name: 'totDttmDay',
					align: 'center'
				},
				{
					header: '발생시간대',
					name: 'totDttmTime',
					align: 'center'
				},
				{
					header: '가이드지표명',
					minWidth: 200,
					name: 'gdIdxNm',
				},
				{
					header: '주의',
					width: 100,
					name: 'careStndVal',
					align: 'right'
				},
				{
					header: '경고',
					width: 100,
					name: 'warnStndVal',
					align: 'right'
				},
				{
					header: '가이드값',
					width: 100,
					name: 'totVal',
					align: 'right'
				},
				{
					header: '알람내용',
					minWidth: 300,
					width: 'auto',
					name: 'alrmMsg',
				},
				{
					header: '알람종류',
					name: 'alrmKind',
					hidden: true
				},

			]

			this.setModalGridColumn({
				modalKey: this.myModalKey,
				gridKey: this.gridName,
				modalDataKey: this.modalDataKey,
				value: myColumns,
			});


			this.getRowGridData();
		},
		async getRowGridData() {
			this.loadGrid = false;
			var res = await this.postApiReturn({
				apiKey: 'selectEqpmDetailPop',
				resKey: 'eqpmDetlPopData',
				sendParam: {
					gdIdxId: this.myBindingData.gdIdxId,
					eqpmId: this.myBindingData.eqpmId,
					fromDt: this.myBindingData.fromDt,
					toDt: this.myBindingData.toDt
				},
			});
			const dayjs = require('dayjs');
			var newRes = res.map(item =>
				item = {
					...item,
					totDttmDay: Utility.setFormatDate(item.totDttm, 'YYYY-MM-DD'),
					totDttmTime: Utility.setFormatDate(item.totDttm, 'HH') + "~" + dayjs(item.totDttm).add(1, 'h').format('HH'),
				}
			);


			this.setModalGridData({
				modalKey: this.myModalKey,
				gridKey: this.gridName,
				modalDataKey: this.modalDataKey,
				value: newRes,
			});


			this.loadGrid = true;

			this.setGrid = true;
		}
	},
};
var eqpmDetlPop = {
	eqpmDetlGrid: {
		data: [],
		column: [],
		option: {}
	}
}

// 전력량 요금(원/kWh)
</script>
<style lang="scss" scoped>
.tui-grid-scrollbar-left-bottom {
	display: none !important;
}
</style>