<?php
use \common\libs\MyLib;
?>


<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<script type="text/javascript" language="javascript" src="/js/layer/layer.js"></script>
<script type="text/javascript" language="javascript">
    //详情
    function info(id,index) {
        var params = $('#searchForm').serialize();
        window.location.href = '/car/info-track?id=' + id + '&type=<?=$type?>' + '&next_index=' + index + '&back_params=' + encodeURIComponent(params);
    }
    function infos(id,index) {
        var params = $('#searchForm').serialize();
        window.location.href = '/car/info-track-fix?id=' + id + '&type=<?=$type?>' + '&next_index=' + index + '&back_params=' + encodeURIComponent(params);
    }
    function message() {

//        actionfi-tuibao
        $.post('/track/end-all', function (obj) {
            if (obj.success) {
//                var uoid = obj.data.id;
//                var ids = obj.data.order_id;
//                var car_no = obj.caid;
//                var car_id = obj.caids;
                var num = obj.num;
//                console.log(num)
                var stri = '有' + num + '条数据，保险快到期临近90天，请尽快处理'
                layer.open({
                    content: stri
                    , btn: ['去处理', '关闭']
                    , shade: 0.0
                    , anim: 5
                    , time: 5000
                    , offset: 'r'
                    , yes: function (index, layero) {
                        //按钮【按钮一】的回调

                        window.location.href = '/track/end-all-list?day=2';
//                        window.location.href = '/insurer/my-list-info?id=' + ids;
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
//                $.post('/insurer/office-read',{uoid:uoid},function(obj){
//                    if(obj.success) {
//                        console.log(obj.data)
//                    }
//
//                },'json');

                    }
                    , cancel: function () {
                        //右上角关闭回调

//                $.post('/insurer/office-read',{uoid:uoid},function(obj){
//                    if(obj.success) {
//                        console.log(obj.data)
//                    }
//
//                },'json');
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });


            } else {
                console.log(obj.msg)
            }

        }, 'json');
    }
    $(function(){
        message()
        $("#search-btn").click(function(){
            $('#page').val(1);
            var params = $('#searchForm').serialize();
            window.location.href = "/track/all?" + params;
        });
        $('.invalid-btn').click(function(){
            if(confirm('是否确认无效?')) {
                var params = $('#listForm').serialize();
                var invalid_id = $('#invalid_id').val();
                params = params + '&invalid_id=' + invalid_id;
                $.post('/track/invalid-c',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        window.location.reload();
                    }
                },'json');
            }
        });
        $('#all').click(function(){
            if($(this).prop('checked')==true) {
                $('input:checkbox').each(function() {
                    $(this).prop('checked', true);
                });
            } else {
                $('input:checkbox').each(function () {
                    $(this).prop('checked',false);
                });
            }
        });
        //数据平移
        $('#assign-other-btn').click(function () {
            if(confirm('是否确认平移?')) {
                var params = $('#listFrm').serialize();
                var user_id = $('#user_id').val();
                params = params + '&user_id=' + user_id;
                $.post('/appointment/assign-cpei',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        window.location.reload();
                    }
                },'json');
            }
        });
    });
</script>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <form id="searchForm">
        <input type="hidden" id="page" name="page" value="<?=$page?>">
        <tr>
            <td class="td_bg">
                车主：<input name="car_man" type="text" value="<?=$car_man?>" style="width: 100px;">
                电话：<input name="phone" type="text" value="<?=$phone?>" style="width: 100px;">
                车牌：<input name="car_no" type="text" value="<?=$car_no?>" style="width: 100px;">
                <?php
                if($this->context->my->role_id != 5) {
                    ?>
                    工号：<input name="username" type="text" value="<?=$username?>" style="width: 100px;">
                    <?php
                }
                ?>
                商业止保日期：从<input name="date_begin" type="text" value="<?=$date_begin?>" style="width:100px;" onclick="WdatePicker()">到<input name="date_end" type="text" value="<?=$date_end?>" style="width:100px;" onclick="WdatePicker()">截止
                排序：<select name="sort_key">
                    <option value="appointment_t.pdate" <?=$sort_key=='appointment_t.pdate'?'selected':''?>>按预约时间</option>
                    <option value="car_t.register_date" <?=$sort_key=='car_t.register_date'?'selected':''?>>按初登时间</option>
                    <option value="car_t.insurer1_date" <?=$sort_key=='car_t.insurer1_date'?'selected':''?>>按保险时间</option>
                </select>
                <select name="sort_value">
                    <option value="ASC" <?=$sort_value=='ASC'?'selected':''?>>顺序</option>
                    <option value="DESC" <?=$sort_value=='DESC'?'selected':''?>>倒序</option>
                </select>
                预约类型：<select name="ptype">
                    <option value="0">全部类型</option>
                    <?php foreach($list as $k=>$v){ ?>
                        <option value='<?= $v->code; ?>' <?php if($ptype == $v->code){ echo 'selected'; } ?> ><?= $v->name; ?></option>
                    <?php } ?>
                </select>
                区域类型：<select name="sort_type">
                    <option value="0" <?=$sort_type==0?'selected':''?>>全部数据</option>
                    <option value="1" <?=$sort_type==1?'selected':''?>>本区数据</option>
                    <option value="2" <?=$sort_type==2?'selected':''?>>本区数据1</option>
                    </select>
                <input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
            </td>

        </tr>
        <tr>
            <td class="td_bg">
                <?php
                if($this->context->my->role_id != 5) {
                    ?>

                    <input type="button" class="act_btn" id="assign-other-btn" name="assign-other-btn" value="批量平移到">
                    业务员：<select name="user_id" id="user_id">
                        <option value="0">请选择</option>
                        <?php
                        foreach($user_items as $item) {
                            echo '<option value="'.$item->id.'"';
                            if($item->id == $user_id)
                                echo ' selected ';
                            echo '>'.$item->getShowName().'</option>';
                        }
                        ?>
                    </select>
                    <?php
                }
                ?>
            </td>
        </tr>
    </form>
</table>
<form id="listFrm">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <tr>
        <td width="24" align="center" class="bg_tr"><?php
            if($this->context->my->role_id==5)
                echo '序号';
            else
                echo '<input type="checkbox" id="all">';
            ?></td>
        <td width="50" align="center" class="bg_tr">预约日期</td>
        <td width="50" align="center" class="bg_tr">预约时间</td>
        <td width="70" align="center" class="bg_tr">车牌号</td>
        <td width="120" align="center" class="bg_tr">车主</td>
        <td width="70" align="center" class="bg_tr">初登日期</td>
        <td width="100" align="center" class="bg_tr" nowrap>商业止保日期</td>
        <td width="100" align="center" class="bg_tr" nowrap>交强止保日期</td>
        <td width="200" align="center" class="bg_tr">预约备注</td>
        <td width="30" align="center" class="bg_tr">业务员</td>
        <td width="30" align="center" class="bg_tr">操作</td>
    </tr>
    <?php
    foreach($items as $index => $item) {
        $start_index = ($page-1) * 20 + $index;
        $car_info = $item->car;
        $endstr1=date("Y-m-d",strtotime("+90 day"));
        $endstr2=date("Y-m-d",strtotime("+97 day"));
        ?>
        <tr class="
        <?php if($endstr1<$car_info->insurer1_date && $endstr2>=$car_info->insurer1_date):?> enddate <?php endif;?>">
            <td align="center" class="td_bg"nowrap ><?php
                if($this->context->my->role_id == 5)
                    echo $start_index + 1;
                else
                    echo '<input type="checkbox" name="ids[]" value="'.$car_info->id.'">';
                ?></td>
            <td align="center" class="td_bg" nowrap><?=$item->pdate?></td>
            <td align="center" class="td_bg" nowrap><?=$item->ptime?></td>
            <td class="td_bg" nowrap><?=$car_info->car_no?></td>
            <td class="td_bg" nowrap><?=$car_info->car_man?></td>
            <td class="td_bg" nowrap><?=$car_info->register_date?></td>
            <td class="td_bg" nowrap><?=$car_info->insurer1_date?></td>
            <td class="td_bg" nowrap><?=$car_info->insurer2_date?></td>
            <td class="td_bg" ><?=MyLib::substr_cut($item->remark,40)?></td>
            <td class="td_bg" nowrap><?=$item->user?$item->user->getShowName():''?></td>
            <td align="center" class="td_bg" nowrap>
                [<a href="javascript:void(0);" onclick="info(<?=$item->car_id?>,<?=$start_index?>)">详情</a>]

            </td>
        </tr>
        <?php
    }
    ?>
    <tr>
        <td height="25" colspan="11" align="center" class="td_bg"><?=$page_info?></td>
    </tr>
</table>
    <style>
        .enddate .td_bg{
            background-color: #a4d8e8!important;
        }
    </style>
</form>
