<style type="text/css">	
.edit-title{margin: 0px !important;}
.nameid{margin-left: 30px;}
.edit-mypwd .form-group{font-size: 15px;margin-top: 10px;}
.edit-mypwd div.form-group .form-control-feedback{top: 0px !important;}
.edit-mypwd div.form-group .help-block{margin-left: 80px;}
.sort input{width: 40px;text-align: center;border: 1px solid #DDDDDD;}

.t-p{
    font-size: 22px;
    color: #7D7D7D;
    margin-left: 30px;
    padding-top: 0px !important;
    padding-bottom: 0px !important;
}

.dhmgl_box {
    width: 100%;
    padding: 0px 30px;
    overflow: hidden;
    min-width: 960px;
}
</style>	

	<div class="col-md-10" role="main">
		<nav class="breadcrumb"></i> 五折卡模块<span class="c-gray en">&gt;</span>商家管理</nav>
	        <div class="title-box">
	            <p class="t-p"  style="font-size: 28px; color: #7d7d7d;vertical-align: middle; padding-top: 15px !important; padding-bottom: 15px !important;">商家管理</p>
	        </div>
		<div class="dhmgl_box"> 
			<div class="form_head">
	            <span class="form_tle">商家列表</span>
	            <div class="form_btn">
	                <button class="form_btn_A" onclick="window.location.href='<?php echo site_url("admin/shop/add");?>'">新增商家</button>
	                <button class="form_btn_A refresh">排序</button>
	            </div>
	         
	        </div> 
			<div class="m_table_box" style="width:auto;margin-left:0px;margin-top: 13px;">
	            <table>
	                <thead>
	                    <tr>
	                    	<th class="s-thead">排序</th>
	                    	<th class="s-thead">商家名称</th>
	                        <th class="s-thead">商户ID</th>
	                        <th class="s-thead">基础权益</th>
	                        <th class="s-thead">消费次数(基础)</th>
	                        <th class="s-thead">高级权益</th>
	                        <th class="s-thead">消费次数(高级)</th>
	                        <th class="s-thead">状态</th>
	                        <th class="s-thead">操作</th>
	                    </tr>
	                </thead>
	                <tbody>
	                	<?php foreach ($listInfo as $v):?>
	                     <tr class="sjgl_lb_tr">
	                     	<td class="sort"><input type="text" maxlength="3" sid="<?php echo $v['sid'];?>" value="<?php echo $v['sort']?>"></td>
		                    <td><?php echo $v['name'];?></td>
		                    <td><?php echo $v['sid'];?></td>
		                    <td><?php echo '已开通';?></td>
		                    <td><?php echo $v['level1_buy_num'];?></td>
		                     <td><?php echo $v['end_time'] ? date('Y-m-d', $v['end_time']) : '未开通'?></td> 
		                    <td><?php echo $v['level2_buy_num'];?></td>
		                    <td><?php echo $v['status'];?></td>
		                    <?php if($v['status'] == '正常'):?>
		                    <td class="td-center">
		                    	<div class="btn-group">
		                    		<button type="button" class="level sjgl_lb_btn sjgl_gjqy" sid="<?php echo $v['sid']?>" data-target="#myModal" data-toggle="modal">
		                    			高级权益
			                    	</button>
			                    	<button type="button" class="password sjgl_lb_btn sjgl_zhgl" sid="<?php echo $v['sid']?>">
		                            	账号管理
		                            </button>
		                             <button id="delshop" sid="<?php echo $v['sid']?>" status='0' type="button" class=" sjgl_lb_btn sjgl_scsj"  data-target="#delModal" data-toggle="modal" >
		                            	删除商家
		                            </button>
			                    	<a href="<?php echo site_url('admin/shop/edit/'.$v['sid'])?>">
		                            <button type="button" class=" sjgl_lb_btn sjgl_xgxx" style="margin-right:0px;">
		                            	修改信息
		                            </button>
		                            </a>		                         	                     
		                    	</div>	
		                    </td>
			                <?php else:?>
			                    <td class="td-center">
			                    	<div class="btn-group" id="btn-one">
			                             <button id="restoreshop" sid="<?php echo $v['sid']?>" status='1' type="button" class="sjgl_lb_btn" id="last-width" data-toggle="modal" data-target="#recoveryModal">
			                            	恢复商家
			                            </button>
			                    	</div>	
			                    </td>
			                <?php endif;?>	                
	                    </tr>
	                	<?php endforeach;?>                  
	                </tbody>
	            </table>
	        </div>
	        <?php echo $pageinfo;?>
        </div>
	</div>
	<!--高级权益弹框-->
	<div class="modal fade equity" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="top:5%; height:550px;width:425px;">
		<div class="modal-dialog" style="height:500px;margin:0; padding:0;width:423px!important;">
			<form id="level_form" action="" class="registerdate" style="height:500px;margin:0; padding:20px;width:500px;">
				<input type="hidden" value="" name="sid" />
				<input type="hidden" name="mode" value="1" />
				<ul class="equity-ul">
					<li><label class="col-sm-4 right equity-label equity-label1" style="font-size:15px;line-height: 28px!important;">* 合同有效期</label></li>
					<li><input readonly name="start_date" type="text" class="datepicker h5a-input form-control equity-input date1" ></li>
					<li><label class="col-sm-4 right equity-label" style="font-size:15px;line-height: 28px!important;">至</label></li>
					<li><input readonly name="end_date" type="text" class="datepicker h5a-input form-control equity-input date2"></li>
				</ul>
				<label class="error form-field-date">请选择日期</label>
				<div class="lr_ts" style="float:none;padding-left: 10px;">
                         <img src="<?php echo asset_url('images/tips.png');?>" alt="" style="width: 14px;">
                         <span style="font-size:12px;">提示：选择该商家高级权益开始与截止时间。</span>
                </div>

				<div class="equity-month">
					<img src="<?php echo asset_url('images/choice.png');?>" alt="" class="biu_rdo_img " isc="0" cnum="1" style="margin-left:10px;">
					<p style="font-size:15px;display: inline-block;margin-left: 5px;">按月重复</p>
					<div class="equity-days days-height" data-toggle="buttons">
						<span class="btn days-span span-line">1</span>
						<span class="btn days-span ">2</span>
						<span class="btn days-span ">3</span>
						<span class="btn days-span ">4</span>
						<span class="btn days-span ">5</span>
						<span class="btn days-span ">6</span>
						<span class="btn days-span ">7</span>
						<span class="btn days-span ">8</span>
						<span class="btn days-span ">9</span>
						<span class="btn days-span">10</span>
						<span class="btn days-span span-line">11</span>
						<span class="btn days-span">12</span>					
						<span class="btn days-span">13</span>
						<span class="btn days-span">14</span>
						<span class="btn days-span">15</span>
						<span class="btn days-span">16</span>
						<span class="btn days-span ">17</span>
						<span class="btn days-span">18</span>
						<span class="btn days-span">19</span>
						<span class="btn days-span">20</span>
						<span class="btn days-span span-line">21</span>
						<span class="btn days-span">22</span>
						<span class="btn days-span">23</span>					
						<span class="btn days-span">24</span>
						<span class="btn days-span ">25</span>
						<span class="btn days-span">26</span>
						<span class="btn days-span">27</span>
						<span class="btn days-span">28</span>
						<span class="btn days-span">29</span>
						<span class="btn days-span">30</span>
						<span class="btn days-span span-line">31</span>					
					</div>
					<div class="lr_ts" style="float:none;padding-left: 10px;">
                         <img src="<?php echo asset_url('images/tips.png');?>" alt="" style="width: 14px;">
                         <span style="font-size:12px;">提示：选择每月该商家可使用高级权益的日期。</span>
                	</div>
					
				</div>
				<div class="equity-week" > 
					<img src="<?php echo asset_url('images/unchoice.png');?>" alt="" class="biu_rdo_img " isc="0" cnum="2" style="margin-left:10px;">
					<p style="font-size:15px;display: inline-block;margin-left: 5px;">按周重复</p>
					<div class="equity-weeks week-height" data-toggle="buttons" style="display:none">
						<span class="btn week-span" date="1">周一</span>
						<span class="btn" date="2">周二</span>
						<span class="btn" date="3">周三</span>
						<span class="btn" date="4">周四</span>
						<span class="btn" date="5">周五</span>
						<span class="btn" date="6">周六</span>
						<span class="btn" date="7">周日</span>	
					</div>
					<div class="lr_ts" style="float:none;padding-left: 10px;">
                         <img src="<?php echo asset_url('images/tips.png');?>" alt="" style="width: 14px;">
                         <span style="font-size:12px;">提示：选择每周该商家可使用高级权益的日期。</span>
                	</div>
					<label class="error form-field-date1">请选择每月或者每周高级权益日期</label>
				</div>
				<div class="equity-explain">
					<p style="font-size:15px;">* 高级权益说明</p>
					<textarea  maxlength="40"  class="equity-textarea" name="level2_des"></textarea>
				</div>
				
				<div class="lr_ts" style="float:none;padding-left: 10px;">
                         <img src="<?php echo asset_url("images/tips.png");?>" alt="" style="width: 14px;">
                         <span style="font-size:12px;">提示：请输入不超过40个汉字。</span>
                </div>	
				
				<label class="error form-field-erae">请填写高级权益说明</label>
				<div class="equity-button">
					<button type="submit" class="h5a-btn btn  btn-primary equitycof" style="width:90px;border-radius:3px;  margin-right: 128px;">确定</button>
			        <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal" style="width:90px;border-radius:3px;">取消</button>
				</div>
			</form>
		</div>	
	</div>
	<!--确认删除弹出框-->
    <input type="hidden" name="shopid" value="" status=''>
	<div class="modal fade equity" id="delModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="width: 360px;height: 190px;border-radius: 0;top:20%;">
		<div class="modal-dialog" style="  width: 100%!important;margin: 0">
			<p class="delete-title">确定要删除该商家？</p>
			<div class="equity-button">
				<button type="button" class="h5a-btn btn  btn-primary equitycof" id='optdel'>确定</button>
			    <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>
	<!--恢复商家弹出框-->
	<div class="modal fade equity" id="recoveryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="width: 360px;height: 190px;border-radius: 0;top:20%;">
		<div class="modal-dialog "style="    width: 345px!important;margin-top: 0;">
			<p class="delete-title">确定恢复该商家？</p>
			<div class="equity-button">
				<button type="button" class="h5a-btn btn  btn-primary equitycof" id='optrec'>确定</button>
			    <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal">取消</button>
			</div>
		</div>
	</div>



	<!--修改密码-->
	<div class="modal fade equity" id="mypwd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="top:20%;height:330px;width:340px;">
		<div class="modal-dialog edit-mypwd" style="width: 100%!important;margin: 0;">
			<form action="">
				<p class="delete-title edit-title">账户管理</p>
				<div class="form-group has-feedback">
					*商户ID：<span class="nameid"></span>
			    </div>
				<div class="form-group has-feedback">
					<span class="dianm">*新密码：</span>
					<div class="examp examp1">
						<input type="password" name="password1" class="h5a-input form-control input-sm" maxlength="18" data-bv-field="password">
						<i class="form-control-feedback" data-bv-icon-for="code" style="display: none; top: 0px;"></i>
		            	<div class="lr_ts" style="float:none;">
	                         <img src="<?php echo asset_url("images/tips.png")?>" alt="" style="width: 14px;margin-top:5px;">
	                         <span style="font-size:12px;">提示：密码为6-18位。</span>
               			</div>
			        </div>
			    </div>
			    <div class="form-group has-feedback">
					<span class="dianm">*确认密码：</span>
					<div class="examp examp1">
						<input type="password" name="confirmPassword1" class="h5a-input form-control input-sm" maxlength="18" data-bv-field="confirmPassword">
						<i class="form-control-feedback" data-bv-icon-for="code" style="display: none; top: 0px;"></i>
		            	<div class="lr_ts" style="float:none;">
	                         <img src="<?php echo asset_url('images/tips.png');?>" alt="" style="width: 14px;margin-top:5px;">
	                         <span style="font-size:12px;">提示：请再次输入密码。</span>
               			</div>
			        </div>
			    </div>
				<div class="equity-button">
					<button type="submit" class="h5a-btn btn  btn-primary equitycof">确定</button>
				    <button type="button" class="h5a-btn btn  btn-default equityclose" data-dismiss="modal">取消</button>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript" src="<?php echo asset_url('js/paging.js');?>"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
    $("#delshop,#restoreshop").on('click',function(event) {
        event.preventDefault();
        /* Act on the event */
        $("input[name=shopid]").val($(this).attr('sid'));
        $("input[name=shopid]").attr('status',$(this).attr('status'));
    });
    $("#optrec,#optdel").on('click', function(event) {
        event.preventDefault();
        var sid = $("input[name=shopid]").val();
        var status = $("input[name=shopid]").attr('status');
        $.post("<?php echo site_url('admin/shop/changeStatus')?>", {sid: sid,status:status},
           function(data){
             if(data.code == 1){
                location.href='';
             }else{
                alert(data.msg);
             }
        },'json');       
    });
});
$(function (){

	$('.sort input').focusout(function(){
		var sid = $(this).attr('sid');
		var rege = /^\+?[0-9]*$/;

		var sort = $(this).val();
		if(! rege.test(sort))
		{
			alert('请输入正确的排序号');
			$(this).focus();
			return true;
		}
		$.post("<?php echo site_url('admin/shop/change_sort')?>/"+sid+"/"+sort, {},function(){
			return true;
		})
	})

	$('.refresh').click(function(){
		window.location.reload();
	})


	$('.level').bind('click',function(){
		var sid = $(this).attr('sid');
		$.post("<?php echo site_url('admin/shop/level_info')?>/"+sid, {},
		   function(data){
		   	//初始化
		   	$("input[name='start_date']").val('<?php echo date('Y-m-d');?>');
			$("input[name='end_date']").val('<?php echo date('Y-m-d');?>');
			$("textarea[name='level2_des']").val('');
			$('.equity-weeks').find('.active').removeClass('active');
			$('.equity-days').find('.active').removeClass('active');

		     if(data.code == 1){
		     	$("input[name='start_date']").val(data.start_date);
				$("input[name='end_date']").val(data.end_date);
				$("textarea[name='level2_des']").val(data.level2_des)
				if(data.extra.mode == 1){
					$('.biu_rdo_img[cnum=1]').click();
					$('.equity-days').find('span').each(function(){
						for(i in data.extra.date){
							if(data.extra.date[i] == $(this).text()){
								$(this).addClass('active');
							}
						}
					})
				}else{
					$('.biu_rdo_img[cnum=2]').click();
					$('.equity-weeks').find('span').each(function(){
						for(i in data.extra.date){
							if(data.extra.date[i] == $(this).attr('date')){
								$(this).addClass('active');
							}
						}
				
					})
					
				}

		     }
		    $("#myModal").modal();
			$("input[name='sid']").val(sid); 
		},'json');
		
	})


	$('.password').bind('click', function(){
		var sid = $(this).attr('sid');
		$('#mypwd').find('.nameid').text(sid);
		$("input[name='password1']").val('');
		$("input[name='confirmPassword1']").val('');
		$('#mypwd').modal();
	})




// 切换隐藏 月/周
  $('.biu_rdo_img').click(function(){

        var isc=$(this).attr('isc');
        var cnum=$(this).attr('cnum');
        $('input[name=mode]').val(cnum);
        if(isc==0){
            $(this).attr('src','<?php echo asset_url("images/choice.png");?>');
            $(this).attr('isc','1');
            if(cnum==1){
            	$('.biu_rdo_img[cnum=2]').attr('src','<?php echo asset_url("images/unchoice.png")?>');
            	$('.biu_rdo_img[cnum=2]').attr('isc','0');
            	$('.equity-days').show();
				$('.equity-weeks').hide();
            }else{
            	$('.biu_rdo_img[cnum=1]').attr('src','<?php echo asset_url("images/unchoice.png");?>');
            	$('.biu_rdo_img[cnum=1]').attr('isc','0');
            	$('.equity-days').hide();
				$('.equity-weeks').show();
            }
            
        }
    })
	


	$('#level_form').submit(function(){

		//重置
		$('.form-field-erae').hide();
		$('.form-field-date1').hide();
		$('.form-field-date').hide();

		var start_date = $("input[name='start_date']").val();
		var end_date = $("input[name='end_date']").val();
		var mode = $("input[name='mode']").val();
		var level2_des = $("textarea[name='level2_des']").val();
		var date = new Array();
		var sid = $("input[name='sid']").val();


		console.log(start_date, end_date, mode, level2_des, sid);

		if(mode == 1){
			$('.equity-days').find('.active').each(function(){
				date.push($(this).text())
				
			})
		}


		if(mode == 2){
			$('.equity-weeks').find('.active').each(function(){
				date.push($(this).attr('date'))
				
			})
		}

		if(level2_des == ''){
			$('.form-field-erae').show();
			return false;
		}

		if(date.length == 0){
			$('.form-field-date1').show();
			return false;
		}
		if(start_date == '' || end_date == ''){
			$('.form-field-date').show();
			return false;
		}

		$.post("<?php echo site_url('admin/shop/level')?>", { start_date: start_date, end_date: end_date, mode:mode, date:date.toString(), sid:sid,level2_des:level2_des },
		   function(data){
		     if(data.code == 1){
		     	alert('成功');
		     	$('button[sid='+sid+']').parent('div').parent('td').parent('tr').children('td').eq(5).text(end_date);
		     	$("#myModal").modal('hide'); 
		     }else{
		     	alert(data.msg);
		     }
		},'json');

		return false;
	})
	 
});
</script>

<script type="text/javascript">
	
	$(function(){
	$('#mypwd form').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            password: {
                validators: {
                    notEmpty: {
                        message: '密码不能是空的'
                    },
                    different: {
                        field: 'username',
                        message: '密码不能和用户名相同'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_]+$/,
                        message: '只能由字母、数字和下划线组成'
                    },
                    stringLength: {
                        min: 6,
                        max: 18,
                        message: '密码必须大于6，小于18个字符长'
                    },
                    identical: {
                        field: 'confirmPassword',
                        message: '两次密码不一致'
                    }
                }
            },
            password1: {
                validators: {
                    notEmpty: {
                        message: '密码不能是空的'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_]+$/,
                        message: '只能由字母、数字和下划线组成'
                    },
                    stringLength: {
                        min: 6,
                        max: 18,
                        message: '密码必须大于6，小于18个字符长'
                    },
                    identical: {
                        field: 'confirmPassword1',
                        message: '两次密码不一致'
                    }
                }
            },
            confirmPassword: {
                validators: {
                    notEmpty: {
                        message: '确认密码不能是空的'
                    },
                    identical: {
                        field: 'password',
                        message: '两次密码不一致'
                    }
                }
            },
            confirmPassword1: {
                validators: {
                    notEmpty: {
                        message: '确认密码不能是空的'
                    },
                    identical: {
                        field: 'password1',
                        message: '两次密码不一致'
                    }
                }
            }
  
        }
    }).on('success.form.bv',function(e){
    	e.preventDefault();
    	var sid = $('#mypwd').find('.nameid').text();
		var password = $("input[name='password1']").val();
		var confirmPassword1 = $("input[name='confirmPassword1']").val();
		$.post("<?php echo site_url('admin/shop/password')?>", {sid:sid,password:password },
		   function(data){
		   	 alert('成功');
		     $('#mypwd').modal('hide'); 
		     return false;
		});
    });
    
});
</script>