<?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 0px;">
            <form class="layui-form" method="get" action="<?php echo mvc::$cfg['ADMIN_URI'];?>servicePush/pushApplyRecord">
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block w100">
                        <select class="layui-input" name="status">
                            <option value="">--所有--</option>
                            <?php foreach ($statusName as $k => $v): ?>
                                 <option value="<?php echo $k ?>" <?php  if(is_numeric($param['status']) && $param['status'] == $k) echo "selected"; ?>><?php echo $v; ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>
                </div>
                 <div class="layui-inline">
                    <label class="layui-form-label">申请时间</label>
                    <div class="layui-input-block" style="width:280px;">
                        <input type="text" name="betime" autocomplete="off" id="betime" class="layui-input" value="<?php echo $param['betime'];?>" 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" style="width:1000px;">
            <thead>
            <tr>
                <th width="40px;">操作</th>
                <th width=300px;">店铺名称</th>
                <th width="60px;">状态</th>
                <th width="100px;">手机号</th>
                <th width="150px;">用户名</th>
                <th width="120px;">申请时间</th>
                <th>处理意见</th>
            </tr>
            </thead>
            <tbody>
            <?php if (!empty($list)): ?>
                <?php foreach ($list as $key => $value): ?>
                    <tr>
                        <td><button onclick="audit(this,'<?php echo $value["tua_id"] ?>')" class="layui-btn layui-btn-normal layui-btn-xs">审核</button></td>
                        <td>
                            <?php echo $value['shop_name']; ?>
                            <?php if($value['svip_etime'] > time()){?>
                                <?php echo date('y-m-d', $value['svip_etime']).' <span class="warn" title="剩余天数">['.ceil(($value['svip_etime']-time())/3600/24).']</span>';?>
                            <?php }else if($value['svip_etime'] > 0 && $value['svip_etime'] < time()){?>
                                <?php echo date('y-m-d', $value['svip_etime']).' <span class="red2" title="已过期天数">[过'.ceil((time()-$value['svip_etime'])/3600/24).']</span>';?>
                            <?php }?>
                        </td>
                        <td data-status="<?php echo $value['tua_status']; ?>"><?php echo $statusName[$value['tua_status']]; ?></td>
                        <td><?php echo isset($userlist[$value['tua_pu_id']]['u_mobile']) ? $userlist[$value['tua_pu_id']]['u_mobile'] : ''; ?></td>
                        <td><?php echo isset($userlist[$value['tua_pu_id']]['u_name']) ? $userlist[$value['tua_pu_id']]['u_name'] : ''; ?></td>
                        <td><?php echo date('Y-m-d H:i',$value['tua_atime']); ?></td>
                        <td><?php echo $value['tua_remark']; ?></td>
                    </tr>
                <?php endforeach ?>
            <?php endif ?>
            </tbody>
        </table>
        <?php echo $page;?>
    </div>

</div>


<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script type="text/javascript">
    var json = {};
    json['-1'] =  '<span class="gray">无效</span>';
    json['0'] = '<span class="orange">待处理</span>';
    json['1'] = '<span class="green">已处理</span>';
    layui.use(['table', 'laydate'], function(){
        var table = layui.table,laydate = layui.laydate;
        laydate.render({
            elem: '#betime'
            ,range: '~'
            ,type:'datetime'
            ,max : getNowFormatDate()
        });
        $('[data-betime]').click(function(){
            $('[name="betime"]').val($(this).data('betime'));
            $("form").submit();
        });
    });

    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month
                + seperator1 + strDate + " " + date.getHours() + seperator2
                + date.getMinutes() + seperator2 + date.getSeconds();
        return currentdate;
    }

    function audit(that,tou_id)
    {
        var remark = $(that).parent().next().next().next().next().next().next().text();
        var status = $(that).parent().next().next().attr('data-status');

        var html = '<form class="layui-form"><div style="margin-top: 10px;" class="layui-form-item layui-form-text">\n' +
            '    <label class="layui-form-label">处理意见</label>\n' +
            '    <div class="layui-input-block">\n' +
            '      <textarea style="width: 95%;min-height: 150px;" placeholder="请输入内容" class="layui-textarea">'+remark+'</textarea>\n' +
            '    </div>\n' +
            '  </div>';
            if(status < 0){
                html +=  '<div class="layui-form-item">\n' +
                    '    <label class="layui-form-label">状态</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <input type="radio" name="tou_status" value="-1" title="无效" checked="">\n' +
                    '      <input type="radio" name="tou_status" value="0" title="待处理" >\n' +
                    '      <input type="radio" name="tou_status" value="1" title="已处理">\n' +
                    '    </div>\n' +
                    '  </div></form>';
            }else if(status > 0){
                     html +=  '<div class="layui-form-item">\n' +
                    '    <label class="layui-form-label">状态</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <input type="radio" name="tou_status" value="-1" title="无效">\n' +
                    '      <input type="radio" name="tou_status" value="0" title="待处理">\n' +
                    '      <input type="radio" name="tou_status" value="1" title="已处理" checked="">\n' +
                    '    </div>\n' +
                    '  </div></form>';
            }else{
                 html +=  '<div class="layui-form-item">\n' +
                    '    <label class="layui-form-label">状态</label>\n' +
                    '    <div class="layui-input-block">\n' +
                    '      <input type="radio" name="tou_status" value="-1" title="无效">\n' +
                    '      <input type="radio" name="tou_status" value="0" title="待处理" checked="">\n' +
                    '      <input type="radio" name="tou_status" value="1" title="已处理">\n' +
                    '    </div>\n' +
                    '  </div></form>';
            }

        layer.open({
            area: ['500px', '275px'],
            btnAlign: 'c',
            type: 1,//类型
            title: false,//窗口名字
            content: html,
            btn:['确认','取消'],
            success:function(index,layero){
                $(that).parent().parent().css('background','#d1e9ff');
                layui.use(['form'],function () {
                    var form = layui.form;
                    form.render();
                });
            },
            yes: function (index, layero) {
                var value = layero.find(".layui-textarea").val();
                var tou_status = layero.find("input[name=\"tou_status\"]:checked").val();
                var data = {};
                data['isAjax'] = 1;
                data['tua_id'] = tou_id;
                data['tua_remark'] = value;
                data['tua_status'] = tou_status;
                $.post(ADMIN_URI + 'servicePush/audit', data, function (res) {
                    res = JSON.parse(res);
                    if (res.status) {
                        $(that).parent().next().next().html(json[tou_status]);
                        $(that).parent().next().next().next().next().next().next().text(value);
                        $(that).parent().next().next().attr('data-status',tou_status);
                        layer.msg('审核成功');
                        $(that).parent().parent().css('background','');
                        layer.close(index);
                    } else {
                        layer.msg(res.data);
                    }
                });
            },
            cancel:function (index,layero) {
                $(that).parent().parent().css('background','');
            },
            btn2:function (index,layero) {
                $(that).parent().parent().css('background','');
            }
        });
    }
</script>
