<link href="<?php echo asset_url('css/wendor/summernote.css');?>"/>
<link href="<?php echo asset_url('css/wendor/font-awesome.css');?>"/>
<script src="<?php echo asset_url('js/summernote.min.js');?>"></script>
	<div class="col-md-10" role="main" id="bnb">
		<div class="title-box">
			<p class="t-p">修改卡片</p>
		</div>
		<div class="bs-example">
				<span class="changeInfo-span">*卡片名称：</span>
				<div class="changeInfo-input">
					<input type="text"  id="infoName" class="h5a-input form-control input-sm infoName" maxlength="5" value="<?php echo $name;?>">
					<p class="nullName" id="card_name">请输入卡片名称！</p>
	            	<p><small><i class="fa fa-exclamation-triangle"></i> <strong>提示</strong>: 请输入不超过5个汉字含符号。</small></p>
	        	</div>
				<span class="changeInfo-span">*卡片颜色：</span>
				<div class="changeInfo-input">
					<ul class="changeInfo-ul">
						<li class="changeColor">
							<p class="redCard colorPosition"></p>
							<span class="colorName">红</span>
						</li>
						<li class="changeColor">
							<p class="yellowCard colorPosition"></p>
							<span class="colorName">黄</span>
						</li>
						<li class="changeColor">
							<p class="greenCard colorPosition"></p>
							<span class="colorName">绿</span>						
						</li>
						<li class="changeColor">
							<p class="blueCard colorPosition"></p>
							<span class="colorName">蓝</span>						
						</li>
						<li class="changeColor">
							<p class="whiteCard colorPosition"></p>
							<span class="colorName">白</span>						
						</li>
						<li class="changeColor">
							<p class="blackCard colorPosition"></p>
							<span class="colorName">黑</span>							
						</li>
						<li class="changeColor">
							<p class="greyCard colorPosition"></p>
							<span class="colorName ">灰</span>							
						</li>
						<li class="changeColor">
							<p class="silveryCard colorPosition"></p>
							<span class="colorName">银</span>							
						</li>
						<li class="changeColor">
							<p class="brownCard colorPosition"></p>
							<span class="colorName">褐</span>							
						</li>												
					</ul>
	            	<p><small><i class="fa fa-exclamation-triangle"></i> <strong>提示</strong>: 请选择卡片颜色。</small></p>
	        	</div>	        	

	        	<span class="changeInfo-span">*卡片简介：</span>
	            <div class="changeInfo-input">
	            	<textarea id="summary" class="shoptext" cols="30" rows="3" maxlength="120"><?php echo $card_des;?></textarea>
	            	<p class="nullName nullposition" id="card_summary">请输入卡片简介！</p>
	            	<p><small><i class="fa fa-exclamation-triangle"></i> <strong>提示</strong>: 请输入不超过120个汉字符号。</small></p>
	            </div>
	        	<span class="changeInfo-span">*普通权益介绍：</span>
	            <div class="changeInfo-input">
	            	<textarea id="common" class="shoptext" cols="30" rows="3" maxlength="120"><?php echo $level1_des;?></textarea>
	            	<p class="nullName nullposition" id="card_common">请输入普通权益介绍！</p>
	            	<p><small><i class="fa fa-exclamation-triangle"></i> <strong>提示</strong>: 请输入不超过120个汉字符号。</small></p>
	            </div>
	        	<span class="changeInfo-span">*高级权益介绍：</span>
	            <div class="changeInfo-input">
	            	<textarea id="senior" class="shoptext" cols="30" rows="3" maxlength="120"><?php echo $level2_des;?></textarea>
	            	<p class="nullName nullposition" id="card_senior">请输入高级权益介绍！</p>
	            	<p><small><i class="fa fa-exclamation-triangle"></i> <strong>提示</strong>: 请输入不超过120个汉字符号。</small></p>
	            </div>	            	            
	        	<span class="changeInfo-span">*高级权益价格：</span>
	            <div class="changeInfo-input">
				<div class="bs-example cardInfo-table change-table" >
            		<table class="table" >
		                <thead>
		                    <tr>
		                    	<th><input type="checkbox" id="allChecked" class="price-box"/></th>
		                        <th class="s-thead th-center">时长</th>
		                        <th class="s-thead th-center">价格</th>
		                    </tr>
		                </thead>
		                <tbody>
		                    <tr>
		                     	<td><input type="checkbox" class="isChecked price-box" /></td>
			                    <td class="price-day"><span>7</span>天</td>
			                    <td><input type="text"  class="h5a-input form-control input-sm price-input"readonly="readonly" value="7"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="checkbox" class="isChecked price-box" /></td>
			                    <td class="price-day"><span>30</span>天</td>
			                    <td><input type="text"  class="h5a-input form-control input-sm price-input"readonly="readonly" value="30"></td>
		                    </tr>
		                     <tr>
		                     	<td><input type="checkbox" class="isChecked price-box" /></td>
			                    <td class="price-day"><span>90</span>天</td>
			                    <td><input type="text"  class="h5a-input form-control input-sm price-input"readonly="readonly"value="90"></td>
		                    </tr>
		                   <tr>
		                   		<td><input type="checkbox" class="isChecked price-box" /></td>
			                    <td class="price-day"><span>180</span>天</td>
			                    <td><input type="text"  class="h5a-input form-control input-sm price-input"readonly="readonly"value="180"></td>                 
		                    </tr> 
		                   <tr>
		                   		<td><input type="checkbox" class="isChecked price-box" /></td>
			                    <td class="price-day"><span>365</span>天</td>
			                    <td><input type="text"  class="h5a-input form-control input-sm price-input"readonly="readonly"value="365"></td> 
			                </tr>                                        
	                	</tbody>
           			</table>
        		</div>
        		<p><small><i class="fa fa-exclamation-triangle"></i> <strong>提示</strong>: 请勾选可供购买的高级权益时长，并填写价格。</small></p>	            	
	            </div>		        				
	            <span class="changeInfo-span">*详细规则：</span>
	            <div class="changeInfo-input">
	            	<div id="summernote" ><?php echo $message;?></div>
	            </div>
	            <div class="modal-footer">
	            	<button type="button" class="h5a-btn btn  btn-primary" onclick="revise()">保存</button>
                    <button type="button" onclick="location.href='<?php echo site_url('admin/card/view')?>'" class="h5a-btn btn  btn-default" data-dismiss="modal">返回</button>
                </div>
        </div>
	</div>
<script type="text/javascript">

	/**
	 * description 价格显示
	 */
	var price_data;
	priceD = <?php echo json_encode($price);?>;
	
	for(var i=0;i<priceD.length;i++)
	{
		$(".isChecked").each(function() {
			if( $(this).parent().next().children('span').text() == priceD[i].duration)
			{
				$(this).attr("checked",'true');

				$(this).parent().next().next().children().val(priceD[i].price);
				$(this).parent().next().next().children().removeAttr("readonly");
			}
		});
	}

	if($(".isChecked:checked").length == $(".isChecked").length){
		$('#allChecked').attr("checked",'true');
	}else{
		$('#allChecked').removeAttr("checked");
	}
	
	//common.js 中选择颜色 全局变量
	var card_color=""; 

	$(document).ready(function() {
		$('#summernote').summernote({
			height: 300,
			toolbar: [
				['Insert',['link','table']],
				['Layout',['ul','ol','paragraph']],
				['Style',['bold','italic','underline','clear']]
			]
		});

		/**
		 * 颜色显示
		 */
		$('.changeColor').removeClass('colorOn');
		var return_card_color = "<?php echo $color;?>";
		switch(return_card_color)
		{
			case '#FF0000':
				$(".redCard").parent().addClass('colorOn');
				card_color= $(".redCard").next().html();
			  break;
			case '#FFFF00':
				$(".yellowCard").parent().addClass('colorOn');
				card_color= $(".yellowCard").next().html();			  
			  break;
			case '#000000':
				$(".blackCard").parent().addClass('colorOn');
				card_color= $(".blackCard").next().html();			  
			  break;
			case '#00FF7F':
				$(".greenCard").parent().addClass('colorOn');
				card_color= $(".greenCard").next().html();			  
			  break;
			case '#1E90FF':
				$(".blueCard").parent().addClass('colorOn');
				card_color= $(".blueCard").next().html();			  
			  break;
			case '#FFFFFF':
				$(".whiteCard").parent().addClass('colorOn');
				card_color= $(".whiteCard").next().html();					  
			  break;
			case '#DCDCDC':
				$(".greyCard").parent().addClass('colorOn');
				card_color= $(".greyCard").next().html();
			  break;
			case '#E6E6E6':
				$(".silveryCard").parent().addClass('colorOn');
				card_color= $(".silveryCard").next().html();
			  break;	  
			default:
				$(".brownCard").parent().addClass('colorOn');
				card_color= $(".brownCard").next().html();
		}
	})
	/**
	 * [revise 表单的异步提交]
	 * @return {[json]} [code状态码 msg 错误提示]
	 */
	function revise()
	{
		var card_name = $('#infoName').val();//卡片名称
		var summary = $('#summary').val();//卡片简介
		var common = $('#common').val();//普通权益介绍
		var senior = $('#senior').val();//高级权益介绍

		var post_color; //卡片颜色
		switch(card_color)
		{
			case '红':
				post_color = '#FF0000';				  
			break;
			case '黄':
				post_color = '#FFFF00';								  
			break;
			case '绿':
				post_color = '#00FF7F';								  
			break;
			case '蓝':
				post_color = '#1E90FF';								  
			break;
			case '白':
				post_color = '#FFFFFF';								  
			break;
			case '黑':
				post_color = '#000000';								  
			break;
			case '灰':
				post_color = '#DCDCDC';								  
			break;
			case '银':
				post_color = '#E6E6E6';								  
			break;
			case '褐':
				post_color = '#A0522D';								  
			break;	
		}

		//卡片价格获取 数组传输
		var price_array = new Array();

		$('.isChecked:checked').each(function(index) {
			var dace = $(this).parent().next().children('span').text();//实效
			var pace = $(this).parent().next().next().children().val();//价格
			price_array[index] = dace +'#'+ pace;//拼接字符串
		});
		//详细规则
		var message = $('#summernote').code();
		$.ajax({
			url: "<?php echo site_url('admin/card/store');?>",
			type: 'POST',
			dataType: 'json',
			data: {id:<?php echo $id;?>,name: card_name,color:post_color,card_des:summary,level1:common,level2:senior,message:message,price:price_array},
			success: function(data)
			{
				if(data.code == 1)
				{
					alert("修改成功");
					location.href="<?php echo site_url('admin/card/view');?>"
				}
				else
				{
					alert(data.msg);
				}
			}
		});
	}
</script>