<template>
	<v-row class="search-box">
		<v-col v-if="label" cols="4">
			<label for="" class="search-box-label ">
				{{ label }}
			</label>
		</v-col>
		<v-col :cols="label ? 7 : ''">
			<v-select
				v-model="selectValue"
				:items="searchParam[parentPrgmId].blocMstrList"
				label="사업장을 선택하세요"
				item-text="blocNm"
				item-value="blocId"
				solo
				append-icon="mdi-chevron-down"
				class="v-select__custom"
			></v-select>
		</v-col>
	</v-row>
</template>

<script>
/*
1. item-value="idx" -> item-value="blocId"
2. { blocMstrList: list, blocId: 0 } -> { blocMstrList: list, blocId: 0 },
*/

import {
	state,
	dispatch,
	commit,
	mapState,
	mapMutations,
	mapActions,
} from 'vuex';
export default {
	props: {
		parentPrgmId: {
			type: String,
			require: true,
		},
		diffModel: {
			type: String,
			require: false,
		},
	},
	data() {
		return {
			label: '사업장',
			labelPrepend: true,
		};
	},
	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];
				}
			},
			set(value) {
				if (!this.diffModel) {
					return this.setPageData({ blocId: value });
				} else {
					return this.setPageData({ [this.diffModel]: value });
				}
			},
		},
	},
	created() {
		this.getBlocMstrList();
	},
	methods: {
		...mapMutations({ setPageData: 'setPageData' }),
		...mapActions({
			getBlocMstrList: 'modules/search/getBlocMstrList2',
		}),
	},
};
</script>

<style></style>
