{include file="public/heard"}
    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">域名中心</a>
                <a>
                    <cite>域名列表</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
						<form class="layui-form layui-col-space5">
						 <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn layui-btn-danger" id="ney"> 总域名:1 </button>
									<button class="layui-btn layui-btn-danger" id="ok"> 正常:0 </button>
									<button class="layui-btn layui-btn-danger" type="button" id="delAll"><i class="layui-icon"></i>批量删除</button>
									</div>
                                <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input"  autocomplete="off" placeholder="开始日期" name="start" id="start">
								</div>
								<div class="layui-inline layui-show-xs-block">
									<input class="layui-input"  autocomplete="off" placeholder="截止日期" name="end" id="end">
								</div>
								<div class="layui-inline layui-show-xs-block">
								 <select name="type" id="selt" lay-skin="select">
								     <option value="">请选择</option>
									 <option value="uid">UID</option>
									 <option value="id">解析id</option>
									 <option value="name">网站名称</option>
								 </select>
                                    </div>
									<div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username" placeholder="搜索内容" autocomplete="off" class="layui-input"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" type="button" lay-submit="" lay-filter="sreach" lay-skin="select" lay-filter="type">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
								</form>
                        </div>
						 
                        <div class="layui-card-body ">
                            <table class="layui-table" id="mlist" lay-filter="mlist">
                                <thead>
                                    <tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>

	<script type="text/html" id="status">
    {{#  if(d.timeed >0 && d.hour>0){ }}
      <p class="layui-bg-red">正常</p>
     {{#  } else { }}
	  <p class="layui-bg-blue">过期</p>
	 {{#  } }}
    </script>
	<script type="text/html" id="tian">
    {{#  if(d.timeed >0 && d.hour>0){ }}
      {{d.timeed}}天{{d.hour}}小时
     {{#  } else { }}
	  <p class="layui-bg-blue">过期</p>
	 {{#  } }}
    </script>
	<script type="text/html" id="state">
    <input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="开通|关闭" lay-filter="state" {{ d.state > 0 ? 'checked' : '' }}>
    </script>
	<script type="text/html" id="action">
	<div class="layui-btn-group">
    <button class="layui-btn layui-btn-danger"  lay-event="del">删除</button>
	</div>
   </script>
    <script>
	layui.use(['table','form','laydate'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery,laydate = layui.laydate;
        tableIn = table.render({
            elem: '#mlist',
            url: "{:U('simple/domain/doList')}",
            method: 'post',
			page:true,
			parseData: function(res){
			  $("#ney").text("总域名:"+res.money);
			  $("#ok").text("正常运营:"+res.ok);
			},
            cols: [[
			    {type: 'checkbox',width:50,minWidth:30},
				{field:'id',title:"ID", width:60,align: 'center', sort: true},
			    {field:'uid',title: '用户ID',align: 'center', width:120},
				{field:'name',title: '网站名称',align: 'center'},
                {field:'url', title: '跳转地址' ,align: 'center' } ,
				{field:'stoptime', align: 'center',title:'到期时间',edit:"#text",sort: true},
				{field:'timeed', align: 'center',title:'剩余天数',toolbar: '#tian', width:150,sort: true},
				{ align: 'center',toolbar: '#status',title:'是否过期', width:150,sort: true},
				{field: 'state',align: 'center', title: '状态',sort: true,toolbar: '#state',width:120},
				{field: 'num',align: 'center', title: '访问人次',width:100},
				{field: 'count',align: 'center', title: '备注',width:150,edit:"#text"},
                {title: '操作',align: 'center', toolbar: '#action',width:180}
            ]],
			limit:20,
			limits:[20,50,60]
        });	
		var nowTime=new Date();    
    var startTime=laydate.render({
    	elem:'#start',
    	type:'datetime',
    	btns: ['confirm'],
    	max:'nowTime',//默认最大值为当前日期
    	done:function(value,date){
    	    endTime.config.min={    	    		
    	    	year:date.year,
    	    	month:date.month-1,//关键
                date:date.date,
                hours:date.hours,
                minutes:date.minutes,
                seconds:date.seconds
    	    };
    	    
    	}
    })
    var endTime=laydate.render({
    	elem:'#end',
    	type:'datetime',
    	btns: ['confirm'],
    	max:'nowTime',
    	done:function(value,date){   	   
    	    startTime.config.max={
    	    		year:date.year,
        	    	month:date.month-1,//关键
                    date:date.date,
                    hours:date.hours,
                    minutes:date.minutes,
                    seconds:date.seconds
    	    }
    	    
    	}
    })		
		form.on('submit(sreach)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var name=$("input[name=username]").val(),kk=$("#selt").val(),st=$("#start").val(),se=$("#end").val();
			
			var index = layer.load(3, {
					  shade: [0.1,'#fff'] //0.1透明度的白色背景
					});
                 tableIn.reload({
					page:{curr:1
						 },
                     where:{
						 name:name,
						 kk:kk,
						 st:st,
						 se:se
                     }
                 });
				 layer.close(index);
        });
		table.on('edit(mlist)', function(obj){
         loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = obj.data.id,str = obj.value,field=obj.field;
            $.post('{:U("simple/domain/doEdit")}',{'id':id,'count':str,'field':field},function (res) {
                layer.close(loading);
				if(res.code==1){
				  layer.msg(res.msg,{time:1000,icon:1});
				}else{
					layer.msg(res.msg,{time:1000,icon:2});
					return false;
				}
            })		  
		});
		form.on('switch(state)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var menustatus = obj.elem.checked===true?1:0;
            $.post('{:U("simple/domain/doSet")}',{'id':id,'state':menustatus},function (res) {
                layer.close(loading);
                if (res.code==1) {
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
		table.on('tool(mlist)', function(obj){
            var data = obj.data;
			console.log(obj.event);
            if(obj.event === 'del'){
                layer.confirm('您确定要删除该记录吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:U('simple/domain/doDel')}",{id:data.id,tab:'do'},function(res){
                        layer.close(loading);
                        if(res.code==1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                });
            }
        });
		$("#delAll").click(function(){
            layer.confirm('确认要删除选中信息吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('mlist'); //test即为参数id设定的值
				console.log(checkStatus,table);
                var ids = [];
                $(checkStatus.data).each(function (i, o) {
                    ids.push(o.id);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:U('simple/domain/doDel')}", {ids: ids,tab:'do'}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                });
            });
        });
		
      });
    </script>
</html>