<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="renderer" content="webkit"> 
  <title>选择样式</title>
  <link rel="Stylesheet" href="/admin/drag/css/drag.base.css">
  <link rel="Stylesheet" href="/admin/drag/css/kesion.form.css">
  <link rel="Stylesheet" href="/admin/drag/css/label.css">
  <link rel="Stylesheet" href="/admin/drag/fonts/iconfont.css">
  
  <style>
  	.format-carousel .li-content{ padding:0;}
  </style>

</head>
<body style="overflow:hidden;">
		
	  <div id="course-style" style="padding-right:20px; overflow:hidden; overflow-y:auto;"> 			
          <table width="100%" cellpadding="0" cellspacing="0" class="ks-table">
    
            <tr>
                <td class="ks-td-tit">选择样式</td>
                <td>
                	<div style="width:690px;">
	                  <div class="format-carousel" id="carousel">
	                      <ul>                         
	                      </ul>
	                  </div>
                  	</div>
                </td>
            </tr>
            <tr id="trLoop">
                <td class="ks-td-tit">循环数量</td>
                <td>
                    <input name="" type="text" class="ks-text" id="loopNum" style="width:100px; text-align:center;">
                </td>
            </tr>
            

            <tr id="code" class="d-none">
                <td class="ks-td-tit"></td>
                <td class="ks-textarea-cover">
                 	<textarea name="" id="styleCode" rows="5" class="ks-textarea"></textarea>
                </td>
            </tr>

         </table>
     	 
         <div class="clear blank10"></div>
        
     </div>
    
    <div class="ks-btn-center" style="border-top:1px solid #ebebeb; padding:20px 0;">
      <button class="ks-btn ks-btn-normal" onClick="Determine()" id="btn-set">确定</button>
      &nbsp;
      <button class="ks-btn" onClick="parent.closeWindow(window.name)">取消</button>
    
    </div>


    <script src="/admin/drag/js/utils.js"></script>
    <script>utils.loadJs(['jquery','assembly','form','nicescroll'])</script>

	<script>
		
		var $carousel = $('#carousel');
		//版式请求
		var hrefSplit = window.location.href.split('?styleType=')[1];
		var moduleName = hrefSplit.split('.')[0];//模块名称
		var subModuleName = hrefSplit.split('.')[1].split('(')[0];//子模块名称
		var styleName = hrefSplit.split('.')[1].split('(')[1].split(',')[0]; //样式名称|id
		var loopNum = hrefSplit.split('.')[1].split('(')[1].split(',')[1].replace(')','');  //循环数量
		var skinId = parent.skinId;
		if(loopNum==undefined){
			$('#trLoop').remove();
		}else{
			$('#loopNum').val(loopNum);
		};

		var module = moduleName;
		if(moduleName=='articlelist'||moduleName=='photolist'||moduleName=='downlist'){
			module = 'info';
		};

		$.ajax({
			url:"/plus/ajaxlabel.aspx?action=listlabeltype&skinid="+skinId+"&labeltype=loop&module="+module+"&submodule="+subModuleName+"",
			success: function(styleData){
				var styleList = styleData.split('@');
				var styleLength = styleList.length;
				var result = '';
				for(var s=0;s<styleLength;s++){
					var src = styleList[s].split('|')[1];
					var name = styleList[s].split('|')[0];
					result+='<li data-name="'+name+'"><div class="li-content"><div class="check"><i class="drag-font drag-i-yes"></i></div><img src="'+src+'" /></div></li>'
				};
				$carousel.find('ul').html(result);
				$carousel.find('li[data-name="'+styleName+'"]').addClass('active');
				var carouselId = $carousel.find('.active').index();
				
				//设置轮播
				$carousel.carousel({
					object:'li',
					scrollType:'slide',
					width:'100%',
					height:'35%',
					arrow:true,
					autoPlay:false,
					dots:1,
					speed:400,
					interval:3000
				});
				
				$carousel.find('.carousel-prev').append('<i class="drag-font drag-i-left"></i>');
				$carousel.find('.carousel-next').append('<i class="drag-font drag-i-right"></i>');
				if(carouselId!=0){
					if($carousel.find('.active').nextAll('li').size()>0){
						$carousel.find('.active').nextAll('li').insertBefore($carousel.find('li:first'));
					};
					$carousel.find('.active').insertBefore($carousel.find('li:first'));
					$carousel.find('.carousel-dots i').eq(carouselId).addClass('on').siblings().removeClass('on');
				};
				
				
			}
		});
		
		tabHeight();
		$(window).resize(function(){
			tabHeight();
		});

		
		//获取代码
		var code = parent.$moduleObject.find('.label_data').html();
		$('#styleCode').val(code);
				
		// $('.ks-checkbox-style').on('click',function(){
		// 	if($(this).attr('check-flag')==0){
		// 		$('#code').fadeOut(300);
		// 		code = '';
		// 	}else{
		// 		$('#code').fadeIn(300);
		// 		code = $('#styleCode').val();
		// 	};
		// });
		
		
		function tabHeight(){
			$('#course-style').height($(window).height()-$('.ks-btn-center').outerHeight());
			
		};
		
		$('.format-carousel').on('click','li',function(){
			var index = $carousel.find('.active').attr('carousel-id');
			if($(this).attr('carousel-id')!=index){
				$(this).addClass('active').siblings().removeClass('active');
				styleName = $(this).attr('data-name');
				$.ajax({
					url:"/plus/ajaxlabel.aspx?action=listlabeltype&skinid="+skinId+"&labeltype=loop&module="+module+"&labelname="+styleName+"&num=1",
					success: function(data){
						var loopNum = $('#loopNum').val();
						var dataLength = $(data).length;
						var code = '';
						for(var d=0;d<dataLength;d++){
							if($(data)[d].className=="label_data"){
								code = $(data)[d].innerHTML;
							};
						}
						$('#styleCode').val(code);
					}
				});
			};
			
			
		});
		
		
		function Determine(){
			
			var loopNum = $('#loopNum').val();
			var moduleCont = $('#styleCode').val();
			
			$.post("/plus/ajaxlabel.aspx",{action:"listlabeltype",tp:moduleCont,skinid:skinId,labeltype:"loop",module:moduleName,submodule:subModuleName,labelname:styleName,num:loopNum},
			function(data){

			   try{
				   var labelData = data.replace('="$n"','="'+loopNum+'"');
					parent.$moduleObject.html(data);
					
					parent.$moduleObject.attr('drag-render','loop in '+moduleName+'.'+subModuleName+'('+styleName+','+loopNum+')');
					parent.closeWindow(window.name);
					parent.popup.tips({
						title:'修改成功'
					});
					parent.frames['dragmain'].moduleJs();
			   }catch(e){
					console.log(e)
				}
				   
			},"text");
		};
					
    </script>


</body>
</html>