<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase2.php');?>
<div class="layui-card">
    <div class="layui-card-body">
        <div style="padding:0 10px 10px 0;">
            <form class="layui-form">
                <div class="layui-inline w180">
					<a href="<?php echo mvc::$cfg['ADMIN_URI'];?>shop/apiSet" style="color:#fff;" class="layui-btn layui-btn-normal" target="_blank"><i class="layui-icon">&#xe608;</i>添加</a>
                </div>
                <div class="layui-inline w200">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="au_status">
                            <option value="">不限</option>
                            <option value="1"<?php if(isset($Params['au_status']) && $Params['au_status'] ==  1) echo ' selected'; ?>>启用</option>
                            <option value="-1"<?php if(isset($Params['au_status']) && $Params['au_status'] == -1) echo ' selected'; ?>>停用</option> 
                        </select>
                    </div>
                </div>
                <div class="layui-inline w300">
                    <label class="layui-form-label">关键字</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" type="text" name="keyword" class="layui-input" value="<?php echo $Params['keyword'];?>" placeholder="请输入会员名称\名称\备注">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn act-btn" type="submit">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </form>
        </div>
        <table class="layui-table YpTable">
            <thead class="Filter Sortable">
				<tr>
					<th width="100">操作</th>
                    <th width="80" class="Sort"><span>会员名称</span></th>
					<th width="200" class="Sort"><span>名称</span></th>
					<th width="50" class="Sort"><span>状态</span></th>
                    <th width="60" class="Sort"><span>appkey</span></th>
                    <th width="50" class="Sort"><span>密钥</span></th>
                    <th width="180" class="Sort"><span>有效期</span></th>
                    <th width="80">公共包余量</th>
                    <th width="80">VIN解码余量</th>
                    <th class="Sort"><span>备注</span></th>
                    
				</tr>
				<tr>
					<td></td>
					<td><input type="text" class="FilterTxt layui-input"></td>
					<td><input type="text" class="FilterTxt layui-input"></td>
					<td><input type="text" class="FilterTxt layui-input"></td>
					<td><input type="text" class="FilterTxt layui-input"></td>
                    <td><input type="text" class="FilterTxt layui-input"></td>
                    <td><input type="text" class="FilterTxt layui-input"></td>
                    <td><input type="text" class="FilterTxt layui-input"></td>
                    <td><input type="text" class="layui-input"></td>
                    <td><input type="text" class="FilterTxt layui-input"></td>
				</tr>
            </thead>
            <tbody>
            <?php if(!empty($dataArr)){ ?>
                <?php foreach($dataArr as $k => $v ){ ?>
                    <tr>
                        <td>
                            <a class="layui-btn layui-btn-normal layui-btn-xs" href="<?php echo mvc::$cfg['ADMIN_URI'];?>shop/apiSet?au_uid=<?php echo $v['au_uid'];?>" target="_blank">编辑</a>
                            <button class="layui-btn layui-btn-xs" onclick="apiDel(<?php echo $v['au_uid'] ?>)">删除</button>
                        </td>
                        <td>
                            <?php echo $v['user_name']; ?> <br>
                        </td>
                        <td>
                            <?php echo $v['au_comname'];?>
                        </td>
                        <td>
                            <?php if ($v["au_status"] != 1){?>
                                <span class="gray">暂停</span>
                            <?php }else if($v["au_etime"] < time()){?>
                                <span class="orange">过期</span>
                            <?php }else{?>
                                <span class="green">启用</span>
                            <?php }?>
                        </td>
                        <td>
                            <?php echo $v['au_appkey']; ?>
                        </td>
                        <td>
                            <span>
                                <span class="hide">
                                    <?php echo $v['au_appsecret']; ?>
                                </span>
                                <a href="javascript:void(0);" onclick="showsecret(this)">查看</a>  
                            </span>
                            
                        </td>
                        
                        <td>
                            <div>
                                <?php echo date('Y-m-d', $v["au_btime"]);?>
                                至
                                <?php echo date('Y-m-d', $v["au_etime"]);?>
                                <?php if($v['au_etime'] > time()){?>
                                    <?php echo ' <span class="warn" title="剩余天数">['.ceil(($v['au_etime']-time())/3600/24).']</span>';?>
                                <?php }else if($v['au_etime'] > 0 && $v['au_etime'] < time()){?>
                                    <?php echo ' <span class="red2" title="已过期天数">[过'.ceil((time()-$v['au_etime'])/3600/24).']</span>';?>
                                <?php }?>
                            </div>
                        </td>
                        <td>
                            <?php echo $v['tjArr']['common']['count']? $v['tjArr']['common']['count']:0;?>次       
                        </td>
                        <td>
                            <?php echo $v['tjArr']['vin']['count']? $v['tjArr']['vin']['count']:0;?>次   
                        </td>
                        <td>
                            <?php echo $v['au_remark'];?>
                        </td>

                    </tr>
                <?php }?>
            <?php }else{ ?>
                <tr>
                    <td colspan="8" style="text-align:center;">无相关数据</td>
                </tr>
            <?php }?>
            </tbody>
        </table>
        <?php echo $Page;?>
    </div>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script>
    layui.use(['table', 'form','laydate'], function(){
        var table = layui.table,form = layui.form,laydate = layui.laydate;
        laydate.render({
            elem: '#betime'
            ,range: '~'
            ,max:0
        });
    });

    function apiDel(au_uid) {
        layer.confirm('确定删除吗？', function(index) {
            $.ajax({
                url:ADMIN_URI + 'shop/apiDel?isAjax=1&au_uid=' + au_uid,
                dataType: "json",
                success: function (res) {
                    if (res.status) {
                        layer.msg('操作成功', {icon: 1, time:1000}, function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg('删除失败', {icon: 5, time:1000}, function () {
                              window.location.reload();
                        });
                    }
                }
            });
        });
    }
    function showsecret(obj){
        var operatehandler = $(obj).prev();
       if(operatehandler.is(":visible")){
        operatehandler.hide();
        $(obj).text("查看")
       }else{
        operatehandler.show()
        $(obj).text("隐藏")
       }
    }
</script>
