<!DOCTYPE html>
<html lang="ko"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorator="web/common/layout/CallcenterLayoutWeb">
<!--
 *******************************************************************************
 * @source  : OneToOneQnaFormWeb.html
 * @desc    : 1:1문의 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.02.19   gagamel     최초 작성
 *******************************************************************************
 -->
<body>

<th:block layout:fragment="content">
	<div id="container" class="container cs"> 
		<div class="breadcrumb"> 
			<ul>
				<li class="bread_home"><a href="javascript:void(0);" onclick="cfnGoToPage(_PAGE_MAIN);">홈</a></li>
				<li class="bread_2depth"><a href="javascript:void(0);" onclick="cfnGoToPage(_PAGE_FAQ);">고객센터</a></li>
				<li class="bread_3depth">1:1문의</li>
			</ul> 
		</div>
		<div class="wrap">
			<div class="content contactUs">
				<div class="cont_body">
					<!-- CONT-BODY -->
					<div class="lnb" id="callcenterLnb">
					</div>
					<div class="cont">
						<div>
							<div class="sec_head">
								<h3>1:1 문의</h3>
							</div>
							<div class="sec_body">
								<div class="history_wrap clear">
									<div class="hist_status">
										<ul>
											<li>
												<span>총 문의</span>
												<a href="javascript:void(0);" onclick="" th:text="${qnaCountInfo.totCnt}" id="qnaTotCnt">12</a>
											</li>
											<li>
												<span>답변 완료</span>
												<a href="javascript:void(0);" onclick="" th:text="${qnaCountInfo.ansCnt}" id="qnaAnsCnt">8</a>
											</li>
											<li>
												<span>처리 중</span>
												<a href="javascript:void(0);" onclick="" th:text="${qnaCountInfo.ingCnt}" class="doing" id="qnaIngCnt">0</a>
											</li>
										</ul>
									</div>
									<div class="txt">
										<p>궁금하신 점은 우측 문의하기를 통해 남겨주세요.<br/>문의를 남겨 주시면 24시간 이내(토/일/공휴일 제외)에<br/> 답변 드릴 수 있도록 최선을 다 하겠습니다.</p>
									</div>
									<div class="fr btn_area">
										<button type="button" class="btn" onclick="cfnGoToPage(_PAGE_ONETOONE_QNA_REG);"><span>1:1 문의하기</span></button>
									</div>
								</div>
								<div class="ui_row" id="divQna"> <!-- 데이터 없을시 클래스 nodata 추가 -->
									<!-- list -->
									<div class="foldGroup case1">
										<ul id="ulQna">
										</ul>
									</div>
									<!-- //list -->
								</div>
								<div class="ui_foot">
									<div class="ui_row">
										<ul class="pageNav" id="pageNav">
										</ul>
									</div>
								</div>
							</div>
						</div>
					</div>
					<!-- // CONT-BODY -->
				</div>
			</div>
		</div>
	</div>
	<!-- // container -->
	
	<!-- 문의 이미지 팝업 -->
	<div class="modal fade cs_pop contact_img_pop" id="contactImgPop" tabindex="-1" role="dialog" aria-labelledby="contactImgLabel" aria-hidden="true">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header sr-only">
					<h5 class="modal-title" id="contactImgLabel">이미지 상세보기</h5>
				</div>
				<div class="modal-body">
					<div class="pop_cont">
 						<div class="swiper-container">
							<div class="swiper-wrapper">
								<!-- 이미지 슬라이드 영역 -->
							</div>
						</div>
						<div class="swiper-button-next"></div>
						<div class="swiper-button-prev"></div>
						<div class="swiper-pagination"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- //문의 이미지 팝업 -->
	
	<form id="qnaForm" name="qnaForm" action="#" th:action="@{'/callcenter/onetoone/qna/list'}">
		<input type="hidden" name="pageNo" value ="1"/>
		<input type="hidden" name="pageSize" value ="10"/>
	</form>

<script src="/ux/plugins/gaga/gaga.paging.js"></script>
<script th:inline="javascript">
/*<![CDATA[*/
	//슬라이드 - 문의 이미지 팝업
	var contactPopSwiper = new Swiper('.cs_pop.contact_img_pop .swiper-container', {
		navigation: {
			nextEl: '.cs_pop.contact_img_pop .swiper-button-next',
			prevEl: '.cs_pop.contact_img_pop .swiper-button-prev',
		},
		pagination: {
			el: '.cs_pop.contact_img_pop .swiper-pagination',
			clickable: true,
		},
		observer:true,
		observeParents: true,
	});
	
	// 팝업 - 문의 이미지 슬라이드
	$(document).on('click','.contactUs .img_group .thumb_pic',function(e){
		$("#contactImgPop .swiper-wrapper").empty();

		var popSlideIndex = $(this).index();
		contactPopSwiper.slideTo(popSlideIndex);
		contactPopSwiper.update();

		var contactImglength = $('.contactUs .img_group .thumb_pic').length;
		var popImgHtml = "";
		for (i = 1; i <= contactImglength; i++) {
			var contactImg = $(this).find('img');
			var contactImgSrc = $('.img_group .thumb_pic:nth-child('+i+') img').attr('src');
			popImgHtml += "<div class='swiper-slide'><div class='pop_img' style='background-image:url("+ contactImgSrc +")'></div></div>";
		}

		$("#contactImgPop .swiper-wrapper").append(popImgHtml);
		$('#contactImgPop').modal("show");
		
		return false;
	});
	
	$(document).ready(function() {
		// 고객센터 LNB 설정
		fnSetCallcenterLnb(2);
		
		fnGetList();
	});
	
	let fnGetList = function() {
		// Initialize a pagination
		gagaPaging.init('qnaForm', fnGetListCallback, 'pageNav', 10);

		// Load data
		gagaPaging.load(1);
	}
	
	var idx = 1;
	var fnGetListCallback = function(result) {
		$('#ulQna').html('');

		// 목록
		if (result.dataList != null && result.dataList.length > 0) {
			$.each(result.dataList, function(idx, item) {
				let tag = '<li>\n';
				tag += '	<div class="fold_head">\n';
				tag += '		<a href="javascript:void(0)">\n';
				tag += '			<div>\n';
				tag += '				<span class="fold_state ' + (item.ansStat == "G060_10" ? "doing" : "done") + '">' + item.ansStatNm + '</span>\n'; //답변완료 : done / 처리중 : doing
				tag += '				<div class="fold_tit">\n';
				tag += '					<span class="prod">[' + item.counselClsfNm + ']</span>\n';
				tag += '					<span>' + item.questTitle + '</span>\n';
				tag += '				</div>\n';
				tag += '				<span class="data">' + item.questDt + '</span>\n';
				tag += '			</div>\n';
				tag += '		</a>\n';
				tag += '	</div>\n';
				tag += '	<div class="fold_cont" style="display: none;">\n';
				tag += '		<div class="fold_detail">\n'; //문의 내용
				tag += '			<div>\n';
				tag += '				<p>' + item.questContent.replace(/(\r\n)/g, '<br/>') + '</p>\n';
				
				if (!gagajf.isNull(item.sysFileNm1) || !gagajf.isNull(item.sysFileNm2)) {
					tag += '				<p class="img_group">\n';
					
					if (!gagajf.isNull(item.sysFileNm1)) {
						tag += '					<span class="thumb_pic">\n';
						tag += '						<img src="' + _uploadImageUrl + '/' + item.sysFileNm1 + '" alt="" onerror="this.src=\'' + _uximgUrl + '/images/pc/thumb/bg_item_none.png\'" onclick="cfOneToPhotoDetail(\''+item.counselSq+'\', \'1\');">\n';
						tag += '					</span>\n';
					}
					
					if (!gagajf.isNull(item.sysFileNm2)) {
						tag += '					<span class="thumb_pic">\n';
						tag += '						<img src="' + _uploadImageUrl + '/' + item.sysFileNm2 + '" alt="" onerror="this.src=\'' + _uximgUrl + '/images/pc/thumb/bg_item_none.png\'" onclick="cfOneToPhotoDetail(\''+item.counselSq+'\', \'2\');">\n';
						tag += '					</span>\n';
					}
					
					tag += '				</p>\n';
				}
				
				tag += '			</div>\n';
				
				if (item.ansStat == 'G060_20') { // 답변완료일 때
					tag += '			<button type="button" class="btn btn_default btn_del" onclick="fnDeleteQna(' + item.counselSq + ');"><span><i class="ico ico_trash"></i>삭제</span></button>\n';
				}
				
				tag += '		</div>\n';
				
				if (item.ansStat == 'G060_20') { // 답변완료 상태일 때
					tag += '		<div class="fold_answer">\n'; //문의 답변
					tag += '			<div class="answer_head">답변이 등록되었습니다.</div>\n';
					tag += '			<div class="answer_body">' + item.ansContent.replace(/(\r\n)/g, '<br/>') + '</div>\n';
					tag += '			<span class="data">' + item.ansDt + '</span>\n';
					tag += '		</div>\n';
				}
				
				tag += '	</div>\n';
				tag += '</li>\n';
				
				$('#ulQna').append(tag);
			});
			
			$('#divQna').removeClass('nodata');
			if(idx>1){
				document.getElementById('container').scrollIntoView();
			}
			idx++;
		} else {
			let tag = '<li>내역이 없습니다.</li>\n';
			$('#ulQna').append(tag);
			$('#divQna').addClass('nodata');
		}

		// Create pagination
		gagaPaging.createPagination(result.paging.pageable);
	}
	
	// 삭제
	let fnDeleteQna = function(counselSq) {
		mcxDialog.confirm("등록된 내용을 삭제하시겠습니까?", {
			cancelBtnText: "취소",
			sureBtnText: "확인",
			sureBtnClick: function() {
				let params = new Object();
				params.counselSq = counselSq;
				
				var jsonData = JSON.stringify(params);
				gagajf.ajaxJsonSubmit('/callcenter/onetoone/qna/delete'
						, jsonData
						, function() {
							fnGetList();
							
							$.get('/callcenter/onetoone/qna/count/info'
								, function(result) {
									$('#qnaTotCnt').html(result.totCnt);
									$('#qnaAnsCnt').html(result.ansCnt);
									$('#qnaIngCnt').html(result.ingCnt);
								}
							);
						});
			}
		});
	}
/*]]>*/
</script>

</th:block>

</body>
</html>
