<?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">
    //详情
    function info(id) {
        var params = $('#searchForm').serialize();
        window.location.href = '/car/xinbao-info?id=' + id+ '&back_params=' + encodeURIComponent(params);
    }
    $(function(){
        $("#search-btn").click(function(){
            $('#page').val(0);
            var params = $('#searchForm').serialize();
            window.location.href = "/car/invalid-xinbao-list?" + params;
        });
        $('#move-btn').click(function(){
            if(confirm('是否确认无效操作?')) {
                var params = $('#listFrm').serialize();
                $.post('/database/invalid3-a',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        window.location.reload();
                    }
                },'json');
            }
        });
//        $('#all-move-btn').click(function(){
//            if(confirm('是否确认恢复操作?')) {
//                var params = $('#searchForm').serialize();
//                $.post('/database/invalid3-all-a',params,function(obj){
//                    alert(obj.msg);
//                    if(obj.success) {
//                        window.location.reload();
//                    }
//                },'json');
//            }
//        });
        $('#all-assign-btn').click(function(){
            if(confirm('是否确认批量分配操作?')) {
                var params = $('#searchForm').serialize();
                $.post('/database/b-all-assign1',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        window.location.reload();
                    }
                },'json');
            }
        });
        $('#assign-btn').click(function(){
            if(confirm('是否确认新保分配操作?')) {
                var params = $('#listFrm').serialize();
                var user_id = $('#user_id').val();
                params = params + '&user_id=' + user_id;
                $.post('/database/b-assign',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        window.location.reload();
                    }
                },'json');
            }
        });
        $('#return-btn').click(function(){
            if(confirm('是否确认收回操作?')) {
                var params = $('#listFrm').serialize();
                $.post('/database/b-return',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);
                });
            }
        });
        $('#wuxiao-assign-btn').click(function(){

            if(confirm('是否确认收回操作?')) {
                var params = $('#searchForm').serialize();
                $.post('/database/b-return-all-wuxiao',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_no" type="text" value="<?=$car_no?>" style="width:100px;">

                联系电话：<input name="phone" type="text" value="<?=$phone?>" style="width:100px;">
                保险日期：
                                从<input class="act_date" name="insurer1_begin" type="text" value="<?=$insurer1_begin?>" onclick="WdatePicker()">至<input class="act_date" name="insurer1_end" type="text" value="<?=$insurer1_end?>" onclick="WdatePicker()">截止



                无效理由：<select name="invalid_id" id="invalid_id">
                    <option value="0">请选择无效理由</option>
                    <?php foreach($failure_items as $item) {?>
                        <option value="<?=$item->id?>"<?php if($item->id==25 || $item->id==37 || $item->id==40){ echo 'disabled';}?> <?php if($item->id==$invalid_id){ echo 'selected';}?>><?=$item->name?></option>
                    <?php  }?>

                </select>
                状态：<select name="status">
                    <option value="0">全部</option>
                    <option value="1" <?=$status==1?'selected':''?>>未分配</option>
                    <option value="2" <?=$status==2?'selected':''?>>已分配</option>
                </select>
                </br>
                保险公司：<input name="company" type="text" value="<?=$company?>" style="width:100px;">

            </td>
        </tr>
        <tr>
            <td class="td_bg">
                <input type="button" class="act_btn" id="search-btn" name="search-btn" value="搜索">
            </td>
        </tr>
        <tr>
            <td class="td_bg">
                分配给业务员 <input id="assign_users" name="assign_users" type="text" value="" style="width:100px;">
                每个业务员分配 <input id="assign_count" name="assign_count" type="text" value="" style="width:50px;"> 条记录
                <input type="button" class="act_btn" id="all-assign-btn" name="all-assign-btn" value="批量分配">
                <input type="button" class="act_btn" id="wuxiao-assign-btn" name="wuxiao-assign-btn" value="批量收回到无效库">
            </td>
        </tr>
        <tr>
            <td class="td_bg">
                <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>
                <input type="button" class="act_btn" id="assign-btn" name="assign-btn" value="勾选分配">
                <input type="button" class="act_btn" id="return-btn" name="return-btn" value="勾选收回">

            </td>
        </tr>
        <tr>
            <td class="td_bg">
                <input type="button" class="act_btn" id="move-btn" name="move-btn" value="勾选无效">
<!--                <input type="button" class="act_btn" id="all-move-btn" name="all-move-btn" value="批量无效">-->
            </td>
        </tr>
    </form>
</table>
<form id="listFrm">
    <input type="hidden" id="hide" name="hide" value="1">
    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
        <tr>
            <td align="center" width="24" align="center" class="bg_tr"><input type="checkbox" id="all"></td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>车牌</td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>车主</td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>联系电话</td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>保险日期</td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>保险公司</td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>新保座席</td>
            <td width="78" align="center" align="center" class="bg_tr" nowrap>无效理由</td>
            <td width="50" align="center" align="center" class="bg_tr" nowrap>当前业务员</td>
            <td width="50" align="center"   class="bg_tr" nowrap>操作</td>
        </tr>
        <?php
        foreach($items as $index => $item) {
            $car_info = $item->car;
            ?>
            <tr onMouseOver=overColor(this) onMouseOut=outColor(this)>
                <td align="center" class="td_bg"nowrap ><input type="checkbox" name="ids[]" value="<?=$car_info->id?>"></td>
                <td align="left" class="td_bg"nowrap ><?=$car_info->car_no?></td>
                <td align="left" class="td_bg"nowrap ><?=$car_info->car_man?></td>
                <td align="left" class="td_bg"nowrap ><?=$car_info->phone?></td>
                <td align="left" class="td_bg"nowrap ><?=$car_info->insurer1_date?></td>
                <td align="left" class="td_bg"nowrap ><?=$car_info->company?></td>
                <td align="left" class="td_bg"nowrap ><?=$car_info->op_user1?></td>
                <td align="left" class="td_bg"nowrap ><?=$item->iv_d?$item->invalid->getPath():''?></td>
                <td align="left" 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->id?>)">详情</a>]
                </td>
            </tr>
            <?php
        }
        ?>
        <tr >
            <td height="25" colspan="12" align="center" class="td_bg"><?=$page_info?></td>
        </tr>
    </table>
</form>