<template>
	<v-row class="search-box" align="center" no-gutters>
		<v-col v-if="label" :cols="labelCols">
			<label for="" class="search-box-label">
				<v-icon x-small color="primary" class="mr-1">mdi-record-circle</v-icon>
				{{ label }}
			</label>
		</v-col>
		<v-col :cols="label ? textCols : ''">
			<v-select
				v-model="selectValue"
				:items="searchParam[parentPrgmId].ercList"
				item-text="ercNm"
				item-value="idx"
				solo
				outlined
				:hide-details="true"
				append-icon="mdi-chevron-down"
				class="v-select__custom"
			></v-select>
			<!-- @change="updateBlocCode($event)" -->
		</v-col>
	</v-row>
</template>

<script>
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
	props: {
		parentPrgmId: {
			type: String,
			require: true,
		},
		autoLoad: {
			type: Boolean,
			require: false,
			default: true,
		},
		label: {
			type: String,
			require: false,
			default: '에너지원',
		},
		textCols: {
			type: Number,
			require: false,
			default: 8,
		},
		labelCols: {
			type: Number,
			require: false,
			default: 4,
		},
		initFlag: {
			type: Boolean,
			require: false,
			default: false,
		},
	},
	data() {
		return {
			// label: "검침대상유형",
			// labelPrepend: true
		};
	},
	computed: {
		...mapState({
			searchParam: state => state.pageData,
		}),
		selectValue: {
			get() {
				return this.searchParam[this.parentPrgmId].ercId;
			},
			set(value) {
				return this.setPageData({ ercId: value });
			},
		},
		blocId() {
			return this.searchParam[this.parentPrgmId].blocMstrList === undefined
				? null
				: this.searchParam[this.parentPrgmId].blocId;
		},
	},
	watch: {
		async blocId(val) {
			if (this.initFlag === true) {
				await this.getErcList({
					useFg: 1,
					blocId: this.searchParam[this.parentPrgmId].blocMstrList[
						this.searchParam[this.parentPrgmId].blocId
					].blocId,
				});
				this.loadFlag = false;
			}
		},
	},
	created() {
		if (this.autoLoad) {
			this.getErcList({
				useFg: 1,
			});
		}
	},
	methods: {
		...mapMutations({ setPageData: 'setPageData' }),
		...mapActions({
			getErcList: 'modules/search/getErcList',
		}),
	},
};
</script>

<style></style>
