<!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/SubLayoutMob">
<!--
 *******************************************************************************
 * @source  : PlanningEventAttendFormMob.html
 * @desc    : 출석체크 이벤트 Page
 *============================================================================
 * STYLE24
 * Copyright(C) 2020 TSIT, All rights reserved.
 *============================================================================
 * VER  DATE         AUTHOR      DESCRIPTION
 * ===  ===========  ==========  =============================================
 * 1.0  2021.04.08   sowon     최초 작성
 *******************************************************************************
 -->
<body>
<script src="//developers.kakao.com/sdk/js/kakao.min.js"></script>
<th:block layout:fragment="content">
	<main role="" id="" class="container dp">
			<section class="content dp_detail_visual">
				<div class="inner">
					<div class="promotion_tit">
						<h3 th:text="${planInfo.planNm}"></h3>
						<div class="period">
							<span th:text="${planInfo.dispStdt}"></span> - <span th:text="${planInfo.dispEddt}"></span>
						</div>
						<button type="button" class="share_btn"><img th:src="${@environment.getProperty('domain.uximage')} + '/images/mo/ico_share_btn.png'" alt="공유" /></button>
					</div>
				</div>
				<div class="inner wide">
					<div class="stamp_event">
						<div class="event_calander">
							<div class="check_title">
								<p>출석할수록 늘어나는 혜택!</p>
								<h3 id="monthHead"><strong>1월</strong> 출석체크</h3>
							</div>
							<div class="check_info">
								<span class="today">오늘</span>
								<span class="complete">출석완료</span>
							</div>
							<div class="tbl_wrap">
								<div class="my_attend_day">
									<p>나의 출석 일수는?</p>
									<span class="day">
										<span></span>일
									</span>
								</div>
								<table>
									<colgroup>
										<col width="14.28%">
										<col width="14.28%">
										<col width="14.28%">
										<col width="14.28%">
										<col width="14.28%">
										<col width="14.28%">
										<col width="14.28%">
									</colgroup>
									<thead>
										<tr>
											<th class="sun">SUN</th>
											<th>MON</th>
											<th>TUE</th>
											<th>WED</th>
											<th>THU</th>
											<th>FRI</th>
											<th class="sat">SAT</th>
										</tr>
									</thead>
									<tbody id="monthTbody">
										
									</tbody>
								</table>
							</div>
							<div class="btn_wrap">
								<button type="button" class="btn_check btn btn_dark" onclick="fnAttendEntry()">출석 체크</button>
							</div>
						</div>
						<div class="event_benefit">
							<h4>출석 일수에 따라 달라지는 혜택</h4>
							<div class="benefit_con">
								<ul>
									<th:block th:each="a, benefitStat : ${benefitList}">
									<li th:if="${a.benefitGb == 'P' and ( a.basDays > 0 and a.pntAmt > 0)}">
										<div class="benfit_point">
											<span th:text="${a.basDays}"></span>일 출석 시 <span class="c_primary"><em th:text="${#numbers.formatInteger(a.pntAmt, 0, 'COMMA')}"></em>P</span>
										</div>
									</li>
									<li th:if="${a.benefitGb == 'C'  and ( a.basDays > 0 and a.dcVal > 0)}">
										<div class="benfit_coupon">
											<th:block th:if="${a.dcWay == '%'}">
												<span th:text="${a.basDays}"></span>일 출석 시 <span class="c_primary"><em th:text="${a.dcVal}"></em>%</span><strong> 할인 쿠폰</strong>
											</th:block>
											<th:block th:if="${a.dcWay == '원'}">
												<span th:text="${a.basDays}"></span>일 출석 시 <span class="c_primary"><em th:text="${#numbers.formatInteger(a.dcVal, 0, 'COMMA')}"></em>원</span><strong> 할인 쿠폰</strong>
											</th:block>
										</div>
									</li>
									<li th:if="${a.benefitGb == 'A'  and ( a.basDays > 0 and a.pntAmt > 0)}">
										<div class="benfit_coupon">
											<th:block th:if="${a.dcWay == '%'}">
												<span th:text="${a.basDays}"></span>일 출석 시 <span class="c_primary"><em th:text="${#numbers.formatInteger(a.pntAmt, 0, 'COMMA')}"></em>P</span> + <span class="c_primary"><em th:text="${a.dcVal}"></em>%</span> <strong>할인 쿠폰</strong>
											</th:block>
											<th:block th:if="${a.dcWay == '원'}">
												<span th:text="${a.basDays}"></span>일 출석 시 <span class="c_primary"><em th:text="${#numbers.formatInteger(a.pntAmt, 0, 'COMMA')}"></em>P</span> + <span class="c_primary"><em th:text="${#numbers.formatInteger(a.dcVal, 0, 'COMMA')}"></em>원</span> <strong>할인 쿠폰</strong>
											</th:block>
										</div>
									</li>
									</th:block>
								</ul>
							</div>
							<!-- //210414_추가 : img => html 구조 변경 -->
						</div>
					</div>
				</div>
				<div class="inner" style="display: none;" id="noticeDiv">
					<div class="announce_txt "> 
						<div class="note_txt">
							<img th:src="${@environment.getProperty('domain.uximage')} + '/images/mo/ico_content_find03.png'" alt="유의사항">
							<p>유의사항</p>
						</div>
						<div class="announce_list">
							<ul>
							<th:block th:each="a, notice : ${noticeInfo}">
								<li th:text="${a.itemVal}"></li>
							</th:block>
							</ul>
						</div>
					</div>
				</div>
				<div class="inner">
					<div class="other_promotion_slide">
						<div class="tit">
							<h4>다른 이벤트 보기</h4>
						</div>
						<div class="swiper-container">
							<div class="swiper-wrapper">
							<th:block th:each="PlanData, PlanStat : ${planList}">
								<div class="swiper-slide">
									 <a href="javascript:void(0);" th:onclick="cfnGoToPlanDetail([[${PlanData.planSq}]])">
										<div class="img">
											<img th:src="${@environment.getProperty('upload.image.view')+PlanData.mainImg+'?RS=960'}">
										</div>
										<div class="txt">
											<p class="subject" th:text="${PlanData.planNm}"></p>
										</div> 
									</a>
								</div>
							</th:block>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!-- (공통) 공유팝업 -->
		<div class="modal fade" id="tglShare" tabindex="-1" role="dialog"
			aria-labelledby="aModalLabel" aria-hidden="true">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="aModalLabel">공유하기</h5>
					</div>
					<div class="modal-body">
						<!-- toggle contents -->
						<div id="layerShare" class="setShare open"
							th:with="stylelUrl=${@environment.getProperty('domain.front')},  planView=${@environment.getProperty('upload.image.view')}">
							<span>
								<button type="button" id="kakao-link-btn" class="kk"
									th:attr="onclick=|cfnSendToKakao('${stylelUrl+'/planning/detail/form?planSq='+planInfo.planSq}', '${planInfo.planNm}', '${planView+ '/'+planInfo.mainMimg}');|">
									<span>카카오톡</span>
								</button>
								<button type="button" class="fb"
									th:attr="onclick=|sendSns('facebook', '${stylelUrl+'/planning/detail/form?planSq='+planInfo.planSq}', '${planInfo.planNm}', '', '');|">
									<span>페이스북</span>
								</button>
								<button type="button" class="tw"
									th:attr="onclick=|sendSns('twitter', '${stylelUrl+'/planning/detail/form?planSq='+planInfo.planSq}',  '${planInfo.planNm+ '#style24몰'}', '', '');|">
									<span>트위터</span>
								</button>
								<button type="button" class="url btn_copy">
									<span>URL</span>
								</button>
							</span>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script>
			// 공유팝업
			$('.share_btn').click(function(e){
				e.preventDefault();
				$('#tglShare').modal("show");
			});
		</script>
		</main>	<script th:inline="javascript">
	/*<![CDATA[*/
	let today = new Date();   
let year = today.getFullYear();
let date = today.getDate();
let month =today.getMonth()+1;
let calendar = [[${month}]];
let planInfo = [[${planInfo}]];
let noticeInfo = [[${noticeInfo}]];
let plan = [[${planInfo}]];
var custAttendList = [[${custAttendList}]];
var appendHtml = function () {
	
	
	$("#monthTbody").html('');
	$.each(calendar, function(idx, item)  { 

				
		html = '<tr>\n';
		
		if (item.sun!=null && item.sun!='') {
			html += '	<td id="td_'+item.sun+'">\n';
			html += '		<div class="date" id="'+item.sun+'">'+item.sun+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date"></div>\n';
			html += '	</td>\n	';
		}
		
		if (item.mon!=null && item.mon!='') {
			html += '	<td id="td_'+item.mon+'">\n';
			html += '		<div class="date" id="'+item.mon+'">'+item.mon+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date"></div>\n';
			html += '	</td>\n	';
		}
		if (item.tue!=null && item.tue!='') {
			html += '	<td id="td_'+item.tue+'">\n';
			html += '		<div class="date" id="'+item.tue+'">'+item.tue+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date"></div>\n';
			html += '	</td>\n	';
		}
		if (item.wed!=null && item.wed!='') {
			html += '	<td id="td_'+item.wed+'">\n';
			html += '		<div class="date" id="'+item.wed+'">'+item.wed+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date"></div>\n';
			html += '	</td>\n	';
		}
		if (item.thu!=null && item.thu!='') {
			html += '	<td id="td_'+item.thu+'">\n';
			html += '		<div class="date" id="'+item.thu+'">'+item.thu+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date"></div>\n';
			html += '	</td>\n	';
		}
		if (item.fri!=null && item.fri!='') {
			html += '	<td id="td_'+item.fri+'">\n';
			html += '		<div class="date" id="'+item.fri+'">'+item.fri+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date" ></div>\n';
			html += '	</td>\n	';
		}
		if (item.sat!=null && item.sat!='') {
			html += '	<td id="td_'+item.sat+'">\n';
			html += '		<div class="date" id="'+item.sat+'">'+item.sat+'</div>\n';
			html += '	</td>\n	';
		}else{
			html += '	<td>\n';
			html += '		<div class="date"></div>\n';
			html += '	</td>\n	';
		}
		
		html += '</tr>\n';

		$("#monthTbody").append(html);
		let custAttendListLength = 0;
		if(cfCheckLogin()){
			custAttendListLength = custAttendList.length;
		}else{
			custAttendListLength = 0;
		}
		$('.day').html('<span>' + custAttendListLength + '</span>일');
		if (cfCheckLogin()) {
			$.each(custAttendList, function(idx1, item1) {
				if(item1.entryDt == item.sun || item1.entryDt == item.mon || item1.entryDt == item.tue|| item1.entryDt == item.wed
						|| item1.entryDt == item.thu || item1.entryDt == item.fri || item1.entryDt == item.sat){
					$("#td_"+item1.entryDt).attr("class","complete");
				}
			})
		}
	})    
} 


var fnAttendEntry = function () {
	if (!cfCheckLogin()) {
		// mcxDialog.alert("로그인 후 참여 가능합니다.");
		mcxDialog.alertC("로그인 후 참여 가능합니다.", { //내용
			sureBtnText: "로그인",  //버튼명
			sureBtnClick: function(){
				location.href="/signin";
			}
		});
		return false;
	}
	
	let data = {planSq : planInfo.planSq};
	let jsonData = JSON.stringify(data);
	gagajf.ajaxJsonSubmit('/planning/event/attend/entry', jsonData, fnInfoConfirmCallBack);
	
}

var fnInfoConfirmCallBack = function(result) {
	mcxDialog.alert(result.msg);
	appendHtml();
	$("#td_"+date).attr("class","complete");
	$('.day').html('<span>' + result.custAttendList.length + '</span>일');
	
};

$(document).ready(function() {
	if(plan.planGb == "P"){
		$('#htopTitle').text('기획전');
	}else{
		$('#htopTitle').text('이벤트/혜택');
	}
	
	$("#monthHead").html("<strong>"+month+"월</strong> 출석체크");
	appendHtml();
	
	if (noticeInfo.length>0) {
		$("#noticeDiv").show();
	}else{
		$("#noticeDiv").hide();
	}
	
	if (!cfCheckLogin()) {
		$(".day").html("<span>0</span>일");
		$("#td_"+date).attr("class","today");
	}else{
		$('.day').html('<span>' + custAttendList.length + '</span>일');
		$("#td_"+date).attr("class","today"); 
		$.each(custAttendList, function(idx, item) {
			if(item.entryDt == date){
				$("#td_"+date).attr("class","complete");
			}
		})
	}
	
	
	
	$(".title").html("<strong>"+month+"월</strong> 출석체크");
	
	//공유 버튼 토글 
	$("button[data-name=openShare]").on("click", function(){
		$(this).toggleClass("on").next(".shareWrap").toggleClass("on");
		return false;
	});
	//영역밖 클릭으로 공유토글 닫기
	$("body").on('click', function(e) { 
		if(!$(".shareWrap.on").parent().has(e.target).length) {
			$("button[data-name=openShare]").removeClass("on");
			$(".shareWrap").removeClass("on");
		};
	});
	
	$('.btn_copy').bind('click', function() {
		copyToClipboard();
	});
	
	/* SLIDE - 다른 기획전,이벤트 보기 */
	var other_promotion_slide = new Swiper('.other_promotion_slide .swiper-container', {
		slidesPerView: 'auto',
		spaceBetween: 8,
		centerMode:true,
	});
	
})
	/*]]>*/
	</script>
</th:block>

</body>
</html>