<template>
	<div class="l-layout">
		<CommonPageTitle/>
		<v-row ref="searchFilter">
			<v-col :cols="12">
				<v-card class="searchFilter">
					<v-row align="center" no-gutters>
						<v-col :cols="3">
							<!-- 사업장 -->
							<component :is="'SelectBlocMstr'" ref="SelectBlocMstr" :parentPrgmId="myPrgmId"
								:textCols="12" customClass="select-large" />
						</v-col>
						<v-col :cols="3">
							<component :is="'selectCodeList'" :parentPrgmId="myPrgmId" :label="'측정 Data 유형'"
								dataKey="searchReadDataType" :sendParam="{ commGrpCd: 'EM_READ_DATA_TYPE', useFg: '1' }"
								:addAll="true" :textCols="12" customClass="select-large" />
						</v-col>
						<v-col :cols="3">
							<component :is="'SelectReadObj'" :parentPrgmId="myPrgmId" :label="'측정대상'"
								dataKey="searchReadObj" :sendParam="{ useFg: '1' }" :labelCols="12" :textCols="12"
								:addAll="true" customClass="select-large" />
						</v-col>

					</v-row>
					<v-row align="end" no-gutters>
						<v-col :cols="3">
							<component :is="'selectCodeList'" :parentPrgmId="myPrgmId" :label="'사용여부'" dataKey="useFg"
								:sendParam="{ commGrpCd: 'CO_USEFG', useFg: '1' }" :addAll="true" :textCols="12"
								customClass="select-large" />
						</v-col>
						<v-col :cols="3">
							<InputText :parentPrgmId="myPrgmId" label="TAG ID" valueNm="tagId" :labelCols="12"
								:textCols="12" :searchOption="true" customClass="input-large" />
						</v-col>
						<v-col :cols="3">
							<InputText :parentPrgmId="myPrgmId" label="TAG명" valueNm="tagNm" :labelCols="12"
								:textCols="12" :searchOption="true" customClass="input-large" />
						</v-col>
						<v-col :cols="3" class="d-flex align-end justify-end text-right">
							<BtnSearch @click="search" size="large" />
						</v-col>
					</v-row>
				</v-card>
			</v-col>
		</v-row>
		<v-row ref="contents" style="height: calc(100vh - 400px)">
			<v-col :cols="5" class="">
				<v-card class="pb-5">
					<v-card-title class="d-flex justify-space-between align-end">
						<span class="tit ft-size_20 ft-weight_600">TAG 정보</span>
						<Buttons :parentPrgmId="myPrgmId" :bindingData="gridName" :detailList="detailList"
							:btnActionsFnc="btnActions" />
					</v-card-title>
					<v-card-actions>
						<div ref="gridParent" class="w100" style="height: calc(100vh - 400px)">
							<component :ref="gridName" :is="loadGrid ? 'Grid' : null" :gridName="gridName"
								:parentPrgmId="myPrgmId" @getRowsData="getRowData"
								@sendSelectedRowStatInfo="getSelectedRowStatInfo" :selectedRowDataWatchFlag="true" />
						</div>
					</v-card-actions>
					<div class="d-flex align-center justify-space-between">
						<pagination
							id="pagination"
							:total-count="totalCount"
							:page-num="page"
							:limit="limit"
							@loadData="changeGrid"
						/>
					</div>
				</v-card>
			</v-col>
			<v-col :cols="7" class="">
				<v-card class="pb-5">
					<v-card-title>TAG 상세</v-card-title>
					<div class="px-5" style="height:calc(100% - 70px)">
						<v-tabs v-model="tab">
							<v-tab v-for="item in items" :key="item.id" :disabled="item.disabledFlag">
								{{ item.name }}
							</v-tab>
						</v-tabs>
						<v-tabs-items v-model="tab" style="height: calc(100% - 65px);" class="py-6">
							<v-tab-item v-for="(item, idx) in items" :key="item.id">
								<component v-if="item.id == 'tagBaseInfoTab'" :is="'Form'" :parentPrgmId="myPrgmId"
									:detailList="detailList" @gridEditingFinish="gridEditingFinish" />
								<TagAddInfoTab v-if="item.id == 'tagAddInfoTab'" :parentPrgmId="myPrgmId"
									:innerTabGridInfo="{ tab, idx }" />
							</v-tab-item>
						</v-tabs-items>
					</div>
				</v-card>
			</v-col>
		</v-row>
	</div>
</template>
<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import mixinGlobal from '@/mixin/global.js';
import { resize } from '@/mixin/resize.js';
import BtnSearch from '~/components/common/button/BtnSearch';
import Buttons from '~/components/common/button/Buttons';
import SelectBlocMstr from '@/components/common/select/SelectBlocMstr';
import selectCodeList from '@/components/common/select/selectCodeList';
import SelectReadObj from '@/components/common/select/SelectReadObj';
import InputText from '@/components/common/input/InputText';
import Form from '~/components/common/form/Form';
import TagAddInfoTab from '@/components/pages/ems/TagInfo/TagAddInfoTab';
import Grid from '~/components/common/Grid';
import Utility from '~/plugins/utility';
import pagination from '~/components/Pagination';

let myTitle;
// const myPrgmId = "PRG0051";
let myPrgmId;
export default {
	mixins: [mixinGlobal, resize],
	async asyncData(context) {
		const myState = context.store.state;
		// context.store.commit("setActiveMenuInfo", myState.menuData[myPrgmId]);
		// myTitle = myState.activeMenuInfo.menuNm;
		myPrgmId = context.route.query.prgmId;
		await context.store.commit('setActiveMenuInfo', myState.menuData[myPrgmId]);
		myTitle = await myState.activeMenuInfo.menuNm;
	},
	meta: {
		title: () => {
			return myTitle;
		},
		prgmId: myPrgmId,
		closable: true,
	},
	components: {
		BtnSearch,
		Buttons,
		SelectBlocMstr,
		selectCodeList,
		SelectReadObj,
		InputText,
		Form,
		TagAddInfoTab,
		Grid,
		pagination,
	},
	data() {
		return {
			myPrgmId: myPrgmId,
			gridName: 'rowGrid',
			loadGrid: false,
			tab: null,
			items: [
				{ name: 'TAG 정보', id: 'tagBaseInfoTab', disabledFlag: false },
				{ name: 'TAG 추가 정보', id: 'tagAddInfoTab', disabledFlag: false },
			],
			detailList: myDetail,
			alrmFg: null,
			itemsPerPage: 10,
			itemsPerPageArray: [10, 20, 50],
			limit: 10,
			page: 1,
			totalCount: 0,
		};
	},
	computed: {
		// ...mapState({
		//   pageData: state => state.pageData[myPrgmId]
		// }),
		chkIsFind() {
			// 조회 플래그
			return this.pageData.isFind;
		},
		chkBlocId() {
			return this.pageData.blocId;
		},
		chkReadDataType() {
			// 시스템구분 선택 감지
			return this.pageData.searchReadDataType;
		},
		chkReadObj() {
			return this.pageData.searchReadObj;
		},
		chkUseFg() {
			// 사용여부 선택 감지
			return this.pageData.useFg;
		},
	},
	watch: {
		chkIsFind(val) {
			if (val) {
				this.page = 1;
				this.search();
			}
		},
		chkBlocId() {
			this.setPageData({ isFind: true });
			// this.search();
		},
		chkReadDataType() {
			this.setPageData({ isFind: true });
			// this.search();
		},
		chkReadObj() {
			this.setPageData({ isFind: true });
			// this.search();
		},
		chkUseFg() {
			this.setPageData({ isFind: true });
			// this.search();
		},
	},
	async beforeCreate() {
		myPrgmId = this.$route.query.prgmId;
		await this.$store.dispatch('chkOpenTabList', {
			key: 'create',
			prgmId: myPrgmId,
			defaultData: defaultData,
		});
	},
	created() {
		//
		// this.getBlocMstrList({
		//   dataKey: "blocIdd",
		//   params: { useFg: '1', test: "dfadf"},
		//   addAll: false
		// });
		// 측정 Data 구분 목록 조회
		this.getCodeList({
			dataKey: 'readDataTypeCd',
			params: { commGrpCd: 'EM_READ_DATA_TYPE', useFg: '1' },
			addAll: false,
		});
		// 측정 대상 목록 조회
		this.getReadObjInfoList({
			dataKey: 'readObj',
			params: { useFg: '1' },
			addAll: false,
		});

		// 단위 코드 목록 조회
		this.getCodeList({
			dataKey: 'unitCd',
			params: { commGrpCd: 'CM_UNIT', useFg: '1' },
			addAll: false,
		});

		/////////// 추가 정보 Tab 에서 사용
		// 데이터 유형 목록 조회
		this.getCodeList({
			dataKey: 'addInfoDataKind',
			params: { commGrpCd: 'CO_DATA_TYPE', useFg: '1' },
			addAll: false,
		});

		// 추가 정보 목록 조회
		this.getAddInfoList({
			dataKey: 'addInfo',
			params: { addGrpId: 'TAG_INFO', useFg: '1' },
			addAll: false,
		});
	},
	mounted() {
		this.init();
	},
	beforeDestroy() {
		this.chkOpenTabList({ key: 'destroy', prgmId: myPrgmId });
	},
	methods: {
		...mapActions({
			getCodeList: 'modules/search/getCodeList',
			getBlocMstrList: 'modules/search/getBlocMstrList',
			getReadObjInfoList: 'modules/search/getReadObjInfoList',
			getAddInfoList: 'modules/search/getAddInfoList',
		}),
		init() {
			this.gridInit();
		},
		gridInit() {
			const gridHeight = this.$refs.gridParent.offsetHeight - 16;

			const myOptions = {
				columnOptions: {
					resizable: true,
				},
				scrollX: true,
				header: {
					height: 38,
				},
			};
			this.setGridOption({
				gridKey: this.gridName,
				value: Object.assign(Utility.defaultGridOption(gridHeight), myOptions),
			});

			const _this = this;
			const myColumns = [
				{ header: '회사 ID', name: 'comId', hidden: true },
				{
					header: 'TAG ID',
					name: 'tagId',
					width: 'auto',
					minWidth: 340,
					align: 'left',
				},
				{
					header: 'TAG 명',
					name: 'tagNm',
					width: 'auto',
					minWidth: 220,
					align: 'left',
				},
				{
					header: '측정 값 유형',
					name: 'readDataTypeCd',
					width: 90,
					align: 'left',
					formatter({ value }) {
						let retVal = '';
						const newValue = _this.pageData.readDataTypeCdList.filter(
							item => item.commCd == value,
						);
						if (newValue.length > 0) {
							retVal = newValue[0].commCdNm;
						}
						return retVal;
					},
				},
				{
					header: '측정대상',
					name: 'readObjId',
					width: 100,
					align: 'left',
					formatter({ value }) {
						let retVal = '';
						const newValue = _this.pageData.readObjList.filter(
							item => item.readObjId == value,
						);
						if (newValue.length > 0) {
							retVal = newValue[0].readObjNm;
						}
						return retVal;
					},
				},
				{ header: '배율', name: 'mgnf', width: 80, align: 'right' },
				{
					header: '단위',
					name: 'unitCd',
					width: 80,
					align: 'left',
					formatter({ value }) {
						let retVal = '';
						const newValue = _this.pageData.unitCdList.filter(
							item => item.commCd == value,
						);
						if (newValue.length > 0) {
							retVal = newValue[0].commCdNm;
						}
						return retVal;
					},
				},
				{
					header: '최소값',
					name: 'rangMin',
					width: 100,
					align: 'right',
					hidden: true,
				},
				{
					header: '최대값',
					name: 'rangMax',
					width: 100,
					align: 'right',
					hidden: true,
				},
				{
					header: '경고 상상',
					name: 'alrmHihi',
					width: 100,
					align: 'right',
					hidden: true,
				},
				{
					header: '경고 상',
					name: 'alrmHi',
					width: 100,
					align: 'right',
					hidden: true,
				},
				{
					header: '경고 하',
					name: 'alrmLo',
					width: 100,
					align: 'right',
					hidden: true,
				},
				{
					header: '경고 하하',
					name: 'alrmLolo',
					width: 100,
					align: 'right',
					hidden: true,
				},
				{
					header: '사업장',
					name: 'blocId',
					width: 100,
					align: 'center',
					hidden: true,
					formatter({ value }) {
						let retVal = '';
						const newValue = _this.pageData.blocMstrList.filter(
							item => item.blocId == value,
						);
						if (newValue.length > 0) {
							retVal = newValue[0].blocNm;
						}
						return retVal;
					},
				},
				{
					header: '집계 여부',
					name: 'totFg',
					width: 80,
					align: 'center',
					hidden: true,
					// { header: "집계 여부", name: "totFg", width: 80, align: "center" ,
					formatter({ value }) {
						const newValue = _this.pageData.useFgList.filter(
							item => item.commCd == value,
						);
						return newValue[0].commCdNm;
					},
				},
				{
					header: '사용 여부',
					name: 'useFg',
					width: 80,
					align: 'center',
					hidden: true,
					// { header: "사용 여부", name: "useFg", width: 80, align: "center" ,
					formatter({ value }) {
						const newValue = _this.pageData.useFgList.filter(
							item => item.commCd == value,
						);
						return newValue[0].commCdNm;
					},
				},
			];

			this.setGridColumn({
				gridKey: this.gridName,
				value: myColumns,
			});

			this.loadGrid = true;

			this.getRowGridData();
		},
		async search() {
			await this.getRowGridData();
			await this.setPageData({
				isFind: false,
			});
		},
		async getRowGridData() {
			this.loadGrid = false;
			let res = [];
			let res2 = [];

			if (this.pageData.blocMstrList.length > 0) {
				res = await this.postApiReturn({
					apiKey: 'selectTagBaseInfoPage',
					resKey: 'tagBaseInfoDataPage',
					sendParam: {
						blocId: this.pageData.blocMstrList[this.pageData.blocId].blocId,
						readDataTypeCd: this.pageData.searchReadDataType,
						readObjId: this.pageData.searchReadObj,
						useFg: this.pageData.useFg,
						tagNmLike: this.pageData.tagNm,
						tagIdLike: this.pageData.tagId,
						limit: this.limit,
						page: this.page,
						offset: (this.page - 1) * this.limit, // MariaDB Query에서 직접 계산이 안됨
					},
				});

				res2 = await this.postApiReturn({
					apiKey: 'selectTagBaseInfoPageTotal',
					resKey: 'tagBaseInfoDataPageTotal',
					sendParam: {
						blocId: this.pageData.blocMstrList[this.pageData.blocId].blocId,
						readDataTypeCd: this.pageData.searchReadDataType,
						readObjId: this.pageData.searchReadObj,
						useFg: this.pageData.useFg,
						tagNmLike: this.pageData.tagNm,
						tagIdLike: this.pageData.tagId,
					},
				});

				this.totalCount = res2[0].totalCount;
			} else {
				this.setPageData({ isFind: false });
			}
			const newRes = res.map(item => {
				const newObj = {
					...item,
					rowStat: null,
					blocId: item.blocId,
					useFg: item.useFg === '1' ? true : false, // 화면 개발 편의를 위해 boolean 타입으로 교체, 저장시 "1", "0" 으로 바꿔 보내야 함
					totFg: item.totFg === '1' ? true : false,
				};
				return newObj;
			});

			this.setGridData({
				gridKey: this.gridName,
				value: newRes,
			});

			this.$nextTick(() => {
				if (newRes.length > 0) {
					try {
						this.$refs[this.gridName].focus({
							//rowKey: 0,
							rowKey:
								this.pageData.rowGridSelectKey == '' ||
								this.pageData.rowGridSelectKey == null
									? 0
									: this.pageData.rowGridSelectKey ==
									  this.$refs[this.gridName].getData().length - 1
									? this.pageData.rowGridSelectKey
									: 0,
							columnName: 'tagId',
							setScroll: true,
						});
					} catch (error) {}
					// this.$refs[this.gridName].focus({
					//   rowKey: 0,
					//   columnName: "tagId",
					//   setScroll: true
					// });
				} else {
					this.detailDataInit();
				}
			});
			this.loadGrid = true;
		},
		async getRowData(data) {
			if (data.rowStat === 'I') {
				this.detailList[0].disabled = false;
				this.detailList[1].disabled = false;
			} else {
				this.detailList[0].disabled = true;
				this.detailList[1].disabled = true;
			}
			this.setPageData({
				rowGridSelectKey: data.rowKey,
				rowGridSelectData: data,
			});
			const res = await this.postApiReturn({
				apiKey: 'selectTagAddInfoList',
				resKey: 'tagAddInfoData',
				sendParam: {
					comId: data.comId,
					tagId: data.tagId,
				},
			});

			const newRes = res.map(item => {
				const newObj = {
					...item,
					comId: item.comId || '',
					tagId: item.tagId || '',
					addInfoId: item.addInfoId || '',
					addInfoDataKind: item.addInfoDataKind || '',
					addInfoNumVal: item.addInfoNumVal || '',
					addInfoTxtVal: item.addInfoTxtVal || '',
					addInfoVal: item.addInfoVal || '',
					useFg: item.useFg || '1',
					totFg: item.totFg || '1',
					rowStat: null,
				};
				return newObj;
			});

			var alrmData = newRes.filter(item => {
				return item.addInfoId == 'ALRM_FG';
			});

			if (alrmData.length > 0) {
				this.alrmFg = alrmData[0].addInfoTxtVal;
			} else {
				this.alrmFg = null;
			}

			this.setGridData({
				gridKey: 'rowDetailGrid',
				value: newRes,
			});
		},
		detailDataInit() {
			this.setPageData({
				rowGridSelectKey: null,
				rowGridSelectData: [],
			});
			this.setGridData({
				gridKey: 'rowDetailGrid',
				value: [],
			});
		},
		getSelectedRowStatInfo(data) {
			if (data) {
				var rowStat = data.rowStat;
				if (rowStat === 'I') {
					this.tab = 0;
					for (var i = 1; i < this.items.length; i++) {
						this.items[i].disabledFlag = true;
					}
				} else if (rowStat === 'U') {
					for (var i = 1; i < this.items.length; i++) {
						this.items[i].disabledFlag = false;
					}
				} else if (rowStat === 'D') {
					for (var i = 1; i < this.items.length; i++) {
						this.items[i].disabledFlag = false;
					}
				} else if (rowStat === null) {
					for (var i = 1; i < this.items.length; i++) {
						this.items[i].disabledFlag = false;
					}
				}
			}
		},
		async btnActions(action) {
			let dataArr = [];
			switch (action) {
				case 'add':
					const defaultRow = {
						tagId: '',
						tagNm: '',
						readDataTypeCd: this.pageData.readDataTypeCd,
						readObjId: this.pageData.readObj,
						mgnf: '',
						unitCd: this.pageData.unitCd,
						rangMin: '',
						rangMax: '',
						alrmHihi: '',
						alrmHi: '',
						alrmLo: '',
						alrmLolo: '',
						blocId: '',
						totFg: '1',
						useFg: '1',
					};
					this.$refs[this.gridName].addRow(defaultRow);
					this.detailList[0].disabled = false;
					break;

				case 'remove':
					this.$refs[this.gridName].removeRow();
					this.detailList[0].disabled = true;
					break;

				case 'save':
					dataArr = this.$refs[this.gridName].save();
					var validCheck = true;
					if (dataArr.length > 0) {
						dataArr.filter(item => {
							if (item.rowStat === 'I') {
								if (
									item.tagId == '' ||
									item.tagNm == '' ||
									item.readDataTypeCd == '' ||
									item.readObjId == '' ||
									item.mgnf == ''
								) {
									alert('필수 입력값을 입력해주세요.');
									validCheck = false;
								}
								if (this.alrmFg == '1') {
									if (
										isEmpty(item, 'alrmHi') &&
										isEmpty(item, 'alrmHihi') &&
										isEmpty(item, 'alrmLo') &&
										isEmpty(item, 'alrmLolo')
									) {
										alert(
											'"TAG 추가 정보 탭"에서 경보여부 체크 시 경고 기준 값 최소 1개 이상 입력이 필요합니다.',
										);
										validCheck = false;
									}
								}
								if (!isValidAlrmVal(item)) {
									validCheck = false;
								}
								// if (parseInt(item.rangMax) < parseInt(item.rangMin)) {
								// 	alert('최소값이 최대값보다 큽니다.');
								// 	validCheck = false;
								// }
							} else if (item.rowStat === 'U') {
								if (
									item.tagId == '' ||
									item.tagNm == '' ||
									item.readDataTypeCd == '' ||
									item.readObjId == '' ||
									item.mgnf == ''
								) {
									alert('필수 입력값을 입력해주세요.');
									validCheck = false;
								}
								if (this.alrmFg == '1') {
									if (
										isEmpty(item, 'alrmHi') &&
										isEmpty(item, 'alrmHihi') &&
										isEmpty(item, 'alrmLo') &&
										isEmpty(item, 'alrmLolo')
									) {
										alert(
											'"TAG 추가 정보 탭"에서 경보여부 체크 시 경고 기준 값 최소 1개 이상 입력이 필요합니다.',
										);
										validCheck = false;
									}
								}
								if (!isValidAlrmVal(item)) {
									validCheck = false;
								}
								// if (parseInt(item.rangMax) < parseInt(item.rangMin)) {
								// 	alert('최소값이 최대값보다 큽니다.');
								// 	validCheck = false;
								// }
							}
						});
						if (validCheck) {
							const sendParam = {
								datas: {
									dsTagBaseInfo: dataArr.map(item => ({
										...item,
										// blocId: item.blocId,
										blocId: this.pageData.blocMstrList[this.pageData.blocId]
											.blocId,
										useFg: item.useFg ? '1' : '0',
										totFg: item.totFg ? '1' : '0',
										alrmHi: !isEmpty(item, 'alrmHi') ? item.alrmHi : null,
										alrmHihi: !isEmpty(item, 'alrmHihi') ? item.alrmHihi : null,
										alrmLo: !isEmpty(item, 'alrmLo') ? item.alrmLo : null,
										alrmLolo: !isEmpty(item, 'alrmLolo') ? item.alrmLolo : null,
									})),
								},
								params: {},
							};
							await this.postUpdateApi({
								apiKey: 'saveTagBaseInfo',
								sendParam: sendParam,
							});

							this.$nextTick(() => {
								// this.setPageData({ isFind: true });
								this.search();
							});
						}
					} else {
						alert('저장할 내용이 없습니다.');
					}
					break;

				default:
					break;
			}
		},
		gridEditingFinish(data) {
			this.$refs[this.gridName].editingFinish(data);
		},
		changeGrid: async function(pageNum, limit) {
			this.page = pageNum;
			this.limit = limit;

			this.search();
		},
	},
};

function isEmpty(obj, key) {
	if (obj[key] === '' || obj[key] === null || obj[key] === undefined) {
		return true;
	} else {
		return false;
	}
}

function isValidAlrmVal(obj) {
	var keyList = [
		'rangMin',
		'alrmLolo',
		'alrmLo',
		'alrmHi',
		'alrmHihi',
		'rangMax',
	];
	var nameList = [
		'최소',
		'경고 하하',
		'경고 하',
		'경고 상',
		'경고 상상',
		'최대',
	];

	for (var i = 0; i < keyList.length; i++) {
		for (var j = i + 1; j < keyList.length; j++) {
			if (isEmpty(obj, keyList[j])) {
				console.log('obj' + keyList[j] + 'item is empty...');
				continue;
			}
			if (Number(obj[keyList[i]]) >= Number(obj[keyList[j]])) {
				alert(
					nameList[j] +
						'값은 ' +
						nameList[i] +
						'값보다 큰 숫자를 입력해야 합니다.',
				);
				return false;
			}
		}
	}

	return true;
}

const defaultData = {
	/* 검색옵션 */
	tagId: '',
	tagNm: '',
	blocId: '',
	blocMstrList: [],
	searchReadDataType: '',
	searchReadDataTypeList: [],
	searchReadObj: '',
	searchReadObjList: [],
	readDataTypeCd: '',
	readDataTypeCdList: [],
	readObj: '',
	readObjList: [],
	unitCdList: [],
	useFg: '1',
	useFgList: [],
	commGrpCd: '',
	commGrpCdNm: '',

	addInfoDataKind: '',
	addInfoDataKindList: [],
	addInfo: '',
	addInfoList: [],

	// 선택된 그룹코드 상세 데이터
	rowGridSelectKey: 0,
	rowGridSelectData: null,

	isFind: false, // true 경우 조회, 조회버튼도 이 값으로 연동 예정
	/* data 세팅 */
	// 로컬 gridName 값과 동일한 이름으로 세팅
	rowGrid: {
		data: [],
		column: [], // myColumns,
		option: {}, // myOptions
		defaultRow: {
			comId: '',
			tagId: '',
			tagNm: null,
			readDataTypeCd: '',
			readObjId: '',
			mgnf: 100,
			unitCd: '',
			rangMin: null,
			rangMax: null,
			alrmHihi: null,
			alrmHi: null,
			alrmLo: null,
			alrmLolo: null,
			blocId: null,
			totFg: '1',
			useFg: '1',
			// rowStat: null
			rowStat: 'I',
		},
		buttonAuth: {
			add: false,
			remove: false,
			save: true,
			excel: false,
		},
	},
	rowDetailGrid: {
		data: [],
		column: [], // myColumns,
		option: {}, // myOptions
		defaultRow: {
			comId: null,
			tagId: null,
			addInfoId: null,
			addInfoDataKind: null,
			addInfoNumVal: null,
			addInfoTxtVal: null,
			addInfoVal: null,
			useFg: null,
			rowStat: null,
		},
		buttonAuth: {
			remove: false,
			save: true,
			excel: false,
		},
	},
};

const myDetail = [
	{
		type: 'InputText',
		label: 'TAG ID',
		valueNm: 'tagId',
		disabled: false,
		iconShow: true,
		cols: 6,
		class: 'py-2 pr-4',
		required: false,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: 'TAG 명',
		valueNm: 'tagNm',
		disabled: false,
		iconShow: true,
		cols: 6,
		class: 'py-2 pl-4',
		required: false,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'SelectBox',
		label: '측정 값 유형',
		valueNm: 'readDataTypeCd',
		disabled: false,
		iconShow: true,
		cols: 6,
		class: 'py-2 pr-4 pt-5',
		list: 'readDataTypeCdList',
		itemText: 'commCdNm',
		itemValue: 'commCd',
		required: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'SelectBox',
		label: '측정대상',
		valueNm: 'readObjId',
		disabled: false,
		cols: 6,
		class: 'py-2 pl-4 pt-5',
		list: 'readObjList',
		itemText: 'readObjNm',
		itemValue: 'readObjId',
		required: true,
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '배율',
		valueNm: 'mgnf',
		disabled: false,
		cols: 6,
		class: 'py-2 pr-4 pt-5',
		required: true,
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'SelectBox',
		label: '단위',
		valueNm: 'unitCd',
		disabled: false,
		cols: 6,
		class: 'py-2 pl-4 pt-5',
		list: 'unitCdList',
		itemText: 'commCdNm',
		itemValue: 'commCd',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '최소값',
		valueNm: 'rangMin',
		disabled: false,
		cols: 6,
		class: 'py-2 pr-4 pt-5',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '최대값',
		valueNm: 'rangMax',
		disabled: false,
		cols: 6,
		class: 'py-2 pl-4 pt-5',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '경고 상상',
		valueNm: 'alrmHihi',
		disabled: false,
		cols: 6,
		class: 'py-2 pr-4 pt-5',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '경고 상',
		valueNm: 'alrmHi',
		disabled: false,
		cols: 6,
		class: 'py-2 pl-4 pt-5',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '경고 하',
		valueNm: 'alrmLo',
		disabled: false,
		cols: 6,
		class: 'py-2 pr-4 pt-5',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'InputText',
		label: '경고 하하',
		valueNm: 'alrmLolo',
		disabled: false,
		cols: 6,
		class: 'py-2 pl-4 pt-5',
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'CheckBox',
		label: '집계 여부',
		valueNm: 'totFg',
		disabled: false,
		cols: 6,
		class: 'py-2 pr-4 pt-5',
		value: { '1': true, '0': false },
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'CheckBox',
		label: '사용 여부',
		valueNm: 'useFg',
		disabled: false,
		cols: 6,
		class: 'py-2 pl-4 pt-5',
		value: { '1': true, '0': false },
		required: false,
		iconShow: true,
		labelCols: 12,
		textCols: 12,
	},
	{
		type: 'SelectBox',
		label: '사업장',
		valueNm: 'blocId',
		disabled: false,
		cols: 6,
		class: 'py-2 d-none',
		list: 'blocMstrList',
		itemText: 'blocNm',
		itemValue: 'blocId',
	},
	{
		type: 'Label',
		label: '',
		cols: 12,
		class: 'py-2',
	},
	{
		type: 'Label',
		// label:
		// 	'* "TAG 추가 정보 탭"에서 경보여부 체크 시 경고 기준 값 최소 1개 이상 입력 필요',
		cols: 12,
		class: 'py-2',
	},
];
</script>