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

<th:block layout:fragment="content">
	<main role="" id="" class="container cs">
		<!-- 고객센터 Gnb -->
		<nav class="pnb" id="callcenterGnb">
		</nav>
		<!-- //고객센터 Gnb -->
		
		<!-- ★ 컨텐츠 시작 -->
		<section class="content cs_product_1">
			<div class="inner sr-only"><h2 class="title">상품문의</h2></div>
			<div class="inner wide">
				<!-- 게시판info -->
				<ul class="inquiry_box">
					<li>
						<p th:text="${qnaCountInfo.totCnt}" id="qnaTotCnt">999</p>
						<p>총 문의</p>
					</li>
					<li>
						<p th:text="${qnaCountInfo.ansCnt}" id="qnaAnsCnt">456</p>
						<p>답변완료</p>
					</li>
					<li>
						<p th:text="${qnaCountInfo.ingCnt}" id="qnaIngCnt">690</p>
						<p>처리 중</p>
					</li>
				</ul>
				<!-- //게시판info -->
			</div>
			
			<div class="inner wide">
				<!-- 폴딩리스트2 -->
				<div class="ui_row" id="divQna"> <!-- 데이터 없을시 클래스 nodata 추가 -->
					<div class="foldGroup case2">
						<!-- list2 -->
						<ul id="ulQna">
						</ul>
						<!-- //list2 -->
					</div>
				</div>
				<div class="ui_foot">
					<button class="btn btnM btnIcon_more" id="btnQnaMore">더보기</button>
				</div>
			</div>
		</section>
		<!-- ★ 컨텐츠 종료 -->
	</main>
	
	<form id="qnaForm" name="qnaForm" action="#" th:action="@{'/callcenter/goods/qna/list'}">
		<input type="hidden" name="pageNo" value ="1"/>
		<input type="hidden" name="pageSize" value ="10"/>
	</form>

<script th:inline="javascript">
/*<![CDATA[*/
	$(document).ready(function() {
		// 타이틀명
		$('#htopTitle').text('고객센터');
		
		// 고객센터 GNB 설정
		fnSetCallcenterGnb(3);
		
		$('#btnQnaMore').trigger('click');
	});

	// 더보기
	$('#btnQnaMore').on('click', function() {
		gagajf.ajaxFormSubmit($('#qnaForm').prop('action'), '#qnaForm', fnGetListCallback);
	});
	
	// QNA 콜백함수
	var fnGetListCallback = function(result) {
		// 목록
		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 += '				<div class="fold_tit">\n';
				tag += '					<div class="lap1">\n';
				tag += '						<span class="fold_state ' + (item.ansStat == "G060_10" ? "doing" : "done") + '"">' + item.ansStatNm + '</span>\n'; //답변완료 : done / 처리중 : doing
				tag += '						<span class="prod">' + item.goodsNm + ' ' + item.relGoodsCd + '</span>\n';
				tag += '					</div>\n';
				tag += '					<div class="lap2"><span>' + item.questContent.replace(/(\r\n)/g, '<br/>') + '</span></div>\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">\n';
				tag += '		<div class="fold_detail">\n';
				tag += '			<div>\n';
				tag += '				<p>' + item.questContent.replace(/(\r\n)/g, '<br/>') + '</p>\n';
				tag += '			</div>\n';
				tag += '		</div>\n';
				
				if (item.ansStat == 'G060_20') { // 답변완료일 때
					tag += '		<div class="fold_answer">\n';
					tag += '			<div>\n';
					tag += '				<div class="answer_body">' + item.ansContent.replace(/(\r\n)/g, '<br/>') + '</div>\n';
					tag += '				<div class="answer_foot">\n';
					tag += '					<span class="data">' + item.ansDt + '</span>\n';
					tag += '					<button type="button" class="btn_delete" onclick="fnDeleteQna(' + item.counselSq + ');"><span>삭제</span></button>\n';
					tag += '				</div>\n';
					tag += '			</div>\n';
					tag += '		</div>\n';
				}
				
				tag += '	</div>\n';
				tag += '</li>\n';
			
				$('#ulQna').append(tag);
				$('#divQna').removeClass('nodata');
			});
		} else {
// 			let tag = '<li>내역이 없습니다.</li>\n';
// 			$('#ulQna').append(tag);
			$('#divQna').addClass('nodata');
		}
		
		if (result.paging.pageable.totalPage > result.paging.pageable.pageNo) {
			$('#btnQnaMore').parent().show();
			$('#qnaForm input[name=pageNo]').val(result.paging.pageable.pageNo + 1);
		} else {
			$('#btnQnaMore').parent().hide();
		}
	}
	
	// 삭제
	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/goods/qna/delete'
						, jsonData
						, function() {
							$('#qnaForm input[name=pageNo]').val(1);
							$('#ulQna').html('');
							$('#btnQnaMore').trigger('click');
							
							$.get('/callcenter/goods/qna/count/info'
									, function(result) {
										$('#qnaTotCnt').html(result.totCnt);
										$('#qnaAnsCnt').html(result.ansCnt);
										$('#qnaIngCnt').html(result.ingCnt);
									}
								);
						});
			}
		});
	}
/*]]>*/
</script>

</th:block>

</body>
</html>
