<template>
	<v-row class="search-box" align="center" no-gutters>
		<v-col :cols="label ? textCols : ''">
			<v-select
				v-model="selectValue"
				:items="searchParam[parentPrgmId].tagList"
				item-text="tagNm"
				item-value="idx"
				solo
				append-icon="mdi-chevron-down"
				class="v-select__custom"
				outlined
				hide-details
			></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,
		},
		dataKey: {
			type: String,
			require: true,
		},
		autoLoad: {
			type: Boolean,
			require: false,
			default: true,
		},
		label: {
			type: String,
			require: false,
			default: null,
		},
		addAll: {
			type: Boolean,
			require: false,
			default: false,
		},
		textCols: {
			type: Number,
			require: false,
			default: 12,
		},
	},
	data() {
		return {};
	},
	computed: {
		...mapState({
			searchParam: state => state.pageData,
		}),
		chkSendTagParam() {
			return this.searchParam[this.parentPrgmId].sendTagParam;
		},
		selectValue: {
			get() {
				return this.searchParam[this.parentPrgmId].tagId;
			},
			set(value) {
				return this.setPageData({ tagId: value });
			},
		},
	},
	watch: {
		async chkSendTagParam() {
			if (this.autoLoad) {
				await this.initData();
			}
		},
	},
	async created() {
		this.initData();
	},
	methods: {
		...mapMutations({ setPageData: 'setPageData' }),
		...mapActions({
			postApi: 'modules/list/postApi',
			postUpdateApi: 'modules/list/postUpdateApi',
			postApiReturn: 'modules/list/postApiReturn',
			setTree: 'modules/list/setTree',
			chkOpenTabList: 'chkOpenTabList',
		}),
		async initData() {
			var tagList = await this.postApiReturn({
				apiKey: 'selectTagNmList',
				resKey: 'tagNmListData',
				sendParam: this.searchParam[this.parentPrgmId].sendTagParam,
			});

			if (this.addAll) {
				tagList.unshift({
					tagNm: '전체',
					tagId: '',
				});
			}

			var tempIdx = 0;
			tagList.map(item => {
				item.idx = tempIdx++;
			});

			this.setPageData({ tagId: 0, tagList: tagList });
		},
	},
};
</script>

<style></style>
