<?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 w200">
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <select class="layui-input" name="status">
                                <option value="">--所有--</option>
                                <?php foreach($statusName as $key => $v){?>
                                    <option value="<?php echo $key;?>"<?php if(is_numeric($param['status']) && $key == $param['status']) echo ' selected';?>><?php echo $v;?></option>
                                <?php }?>
                            </select>
                        </div>
                    </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: 70%;">
            <thead>
            <tr>
                <?php if(LibRule::Check('ZS04',true)){ ?>
                    <th width="100px;">操作</th>
                <?php } ?>
                <th width="200px">招商名称</th>
                <th width="50px">状态</th>
                <th width="50px">申请人</th>
                <th width="100px">申请人电话</th>
                <th width="100px"> 申请人IP</th>
                <th width="150px">意向城市</th>
                <th width="120px">申请时间</th>
                <th width="120px">最后处理时间</th>
                <th>处理备注</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($list as $v){?>
                <tr>
                    <?php if(LibRule::Check('ZS04',true)){ ?>
                       <td>
                           <button onclick="withApply(this,'<?php echo $v['za_id']; ?>','<?php echo $v['za_status']; ?>','<?php echo $v['za_check_remark'];?>')" class="layui-btn layui-btn-primary layui-btn-xs">处理</button>
                           <button onclick="deleteWithApply(this,'<?php echo $v['za_id']?>')" class="layui-btn layui-btn-xs">删除</button>
                        </td>
                    <?php } ?>
                    <td><?php echo $v['zsl_showname']; ?></td>
                    <td><?php echo $v['status_name']; ?></td>
                    <td><?php echo $v['za_realname']; ?></td>
                    <td><?php echo $v['za_tel']; ?></td>
                    <td><?php echo $v['za_ip'];?></td>
                    <td><?php echo $v['za_city']; ?></td>
                    <td><?php echo date('Y-m-d H:i',$v['za_atime']); ?></td>
                    <td><?php echo !empty($v['za_etime']) ? date('Y-m-d H:i',$v['za_etime']) : ''; ?></td>
                    <td><?php echo $v['za_check_remark']; ?></td>
                </tr>
            <?php }?>
            </tbody>
        </table>
        <?php echo $page; ?>
    </div>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script>
    layui.use(['table', 'laydate'], function(){
        var table = layui.table,laydate = layui.laydate;

        laydate.render({
            elem: '#betime'
            ,range: '~'
        });
    });
    function deleteWithApply(that,za_id)
    {
        $(that).parent().parent().css('background','#d1e9ff');
        layer.confirm("确认要删除吗，删除后不能恢复", { title: "删除确认" }, function (index) {
            var data = {};
            data['isAjax'] = 1;
            data['za_id'] = za_id;
            $.post(ADMIN_URI + 'zsjm/deleteWithApply', data, function (res) {
                res = JSON.parse(res);
                if (res.status) {
                    layer.msg('删除成功');
                    $(that).parent().parent().remove();
                    layer.close(index);
                } else {
                    layer.msg(res.data);
                }
            });
        },function () {
            $(that).parent().parent().css('background','');
        });
    }

    function withApply(that,id,status,remark) {
        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: 80px;" 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="有效">\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="有效" checked="">\n' +
                '      <input type="radio" name="tou_status" value="-1" title="无效">\n' +
                '    </div>\n' +
                '  </div></form>';
        }
        layer.open({
            area: ['500px', '250px'],
            btnAlign: 'c',
            type: 1,//类型
            title: '处理',//窗口名字
            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();
                // if (value) {
                    var data = {};
                    data['isAjax'] = 1;
                    data['za_id'] = id;
                    data['za_check_remark'] = value;
                    data['za_status'] = tou_status;
                    $.post(ADMIN_URI + 'zsjm/withApply', data, function (res) {
                        res = JSON.parse(res);
                        if (res.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>