<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].blocMstrList"
				label="사업장을 선택하세요"
				item-text="blocNm"
				item-value="idx"
				solo
				outlined
				:hide-details="true"
				append-icon="mdi-chevron-down"
				class="v-select__custom"
			></v-select>
		</v-col>
	</v-row>
</template>

<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import SelectBlocMstrVue from './SelectBlocMstr.vue';
export default {
	props: {
		parentPrgmId: {
			type: String,
			require: true,
		},
		diffModel: {
			type: String,
			require: false,
		},
		textCols: {
			type: Number,
			require: false,
			default: 8,
		},
		labelCols: {
			type: Number,
			require: false,
			default: 4,
		},
	},
	data() {
		return {
			label: '사업장',
			labelPrepend: true,
			// selectValue: "BL0001"
			// selectValue: selectValue !==undefined ? selectValue : "BL0001"
		};
	},
	computed: {
		...mapState({
			searchParam: state => state.pageData,
			menuData: 'menuData',
		}),
		selectValue: {
			get() {
				if (!this.diffModel) {
					return this.searchParam[this.parentPrgmId].blocId;
				} else {
					return this.searchParam[this.parentPrgmId][this.diffModel];
				}

				// return this.searchParam[this.parentPrgmId].blocId;
			},
			set(value) {
				if (!this.diffModel) {
					this.selectBoxEvt();
					return this.setPageData({ blocId: value });
				} else {
					return this.setPageData({ [this.diffModel]: value });
				}

				// return this.setPageData({ blocId: value });
			},
		},
	},
	created() {
		this.getBlocMstrList();
	},
	methods: {
		...mapMutations({ setPageData: 'setPageData' }),
		...mapActions({
			getBlocMstrList: 'modules/search/getBlocMstrListForPop',
		}),
		selectBoxEvt() {
			localStorage.removeItem(
				this.searchParam[this.parentPrgmId] + 'CheckedRow',
			);
			if (this.searchParam[this.parentPrgmId].isMulti) {
				this.setPageData({ facInfoList: [] });
			} else {
				this.setPageData({ facInfo: {} });
			}
		},
	},
};
</script>

<style></style>
