<?php
use \common\libs\MyLib;
use \common\models\PriceT;
?>
<link href="/css/tabs.css" rel="stylesheet" type="text/css">
<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>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <tr>
        <td colspan="13" height="22" class="td_bg">
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
                <TBODY>
                <TR>
                    <TD height="30" align="center" class=tab-on id=navcell onclick=switchCell(1) name="navcell">预约信息</TD>
                    <TD height="30" align="center" class=tab-off id=navcell onclick=switchCell(2) name="navcell">保单信息</TD>
                    <TD height="30" align="center" class=tab-off id=navcell onclick=switchCell(3) name="navcell">礼品信息</TD>
                    <TD height="30" align="center" class=tab-off id=navcell onclick=switchCell(4) name="navcell">操作记录</TD>
                    <TD height="30" class=tab-none>&nbsp;</TD>
                </TR>
                </TBODY>
            </TABLE>
        </td>
    </tr>
    <tr>
        <td height="22" colspan="2" class="td_bg">
            <table width="100%" align="center" height="120" border="0" cellpadding="0" cellspacing="0" id="mainTable">
                <tr>
                    <td height="120" valign="top" class="td_bg">
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb">
                            <TR>
                                <TD vAlign=top>
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车牌号</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_no?></td>
                                            <td width="100" height="25" class="bg_tr">厂牌型号</td>
                                            <td height="25" class="td_bg"><?=$car_info->factory_model?></td>
                                            <td width="100" height="25" class="bg_tr">品牌</td>
                                            <td height="25" class="td_bg"><?=$car_info->brand?$car_info->brand->name:''?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">发动机号</td>
                                            <td height="25" class="td_bg"><?=$car_info->engine_no?></td>
                                            <td width="100" height="25" class="bg_tr">车架号</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_frame_no?></td>
                                            <td width="100" height="25" class="bg_tr">初登日期</td>
                                            <td height="25" class="td_bg"><?=$car_info->register_date?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车辆类型</td>
                                            <td height="25" class="td_bg"><?=$car_info->carType?$car_info->carType->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">运营性质</td>
                                            <td height="25" class="td_bg"><?=$car_info->carUse?$car_info->carUse->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">座位数</td>
                                            <td height="25" class="td_bg">
                                                <?=$car_info->seats?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车系</td>
                                            <td height="25" class="td_bg"><?=$car_info->series?$car_info->series->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">排量</td>
                                            <td height="25" class="td_bg"><?=$car_info->displacement?$car_info->displacement->name:''?></td>
                                            <td width="100" height="25" class="bg_tr">年份</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_year?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">车主</td>
                                            <td height="25" class="td_bg"><?=$car_info->car_man?></td>
                                            <td width="100" height="25" class="bg_tr">联系电话</td>
                                            <td height="25" class="td_bg"><?=$car_info->phone?>
                                                <button onclick="tpy_call_in('<?= $car_info->phone ?>')">拨号</button>
                                                <button onclick="tpy_call_out()">挂机</button>
                                            </td>
                                            <td width="100" height="25" class="bg_tr"></td>
                                            <td height="25" class="td_bg"></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">商业止保日期</td>
                                            <td height="25" class="td_bg"><?=$car_info->insurer1_date?></td>
                                            <td width="100" height="25" class="bg_tr">交强止保日期</td>
                                            <td height="25" class="td_bg"><?=$car_info->insurer2_date?></td>
                                            <td width="100" height="25" class="bg_tr">保险公司</td>
                                            <td height="25" class="td_bg"><?=$car_info->company?></td>
                                        </tr>
                                        <tr>
                                            <td width="100" height="25" class="bg_tr">备注</td>
                                            <td colspan="5" height="25" class="td_bg"><?=$car_info->remark?></td>
                                        </tr>
                                    </table>
                                    <div id="appointment_list"></div>
                                </TD>
                            </TR>
                        </TABLE>
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD vAlign=top>
                                    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                                            <td width="80" align="center" class="bg_tr" nowrap>被保险人</td>
                                            <td width="120" align="center" class="bg_tr" nowrap>商业起保日期</td>
                                            <td width="120" align="center" class="bg_tr" nowrap>交强起保日期</td>
                                            <td width="120" align="center" class="bg_tr" nowrap>出单日期</td>
                                            <td width="80" align="center" class="bg_tr" nowrap>共计签单</td>
                                            <td width="130" align="center" class="bg_tr" nowrap>业务员</td>
                                            <td width="50" align="center" class="bg_tr" nowrap>状态</td>
                                            <td width="50" align="center" class="bg_tr" nowrap>操作</td>
                                        </tr>
                                        <?php
                                        $order_items = $car_info->getOrders()->orderBy('print_date DESC, id DESC')->all();
                                        foreach($order_items as $index => $item) {
                                            ?>
                                            <tr>
                                                <td align="center" class="td_bg"nowrap ><?=$index+1?></td>
                                                <td class="td_bg" nowrap><?=$item->id_man?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->insurer1_begin_date?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->insurer2_begin_date?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->print_date?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->total_all?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->user?$item->user->getShowName():''?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->status?$item->status->name:''?></td>
                                                <td align="center" class="td_bg" nowrap>[<a href="/insurer/info?id=<?=$item->id?>" target="_blank">详情</a>]</td>
                                            </tr>
                                            <?php
                                        }
                                        ?>
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD vAlign=top>
                                    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table" style="table-layout: fixed;">
                                        <tr>
                                            <td width="50" align="center" class="bg_tr" nowrap>序号</td>
                                            <td width="200" align="center" class="bg_tr" nowrap>礼品名称</td>
                                            <td width="80" align="center" class="bg_tr" nowrap>类型</td>
                                            <td width="50%" align="center" class="bg_tr" nowrap>描述</td>
                                            <td width="80" align="center" class="bg_tr" nowrap>分类</td>
                                            <td width="80" align="center" class="bg_tr" nowrap>添加者</td>
                                            <td width="130" align="center" class="bg_tr" nowrap>操作时间</td>
                                            <td width="50" align="center" class="bg_tr" nowrap>状态</td>
                                        </tr>
                                        <?php
                                        foreach($gift_items as $index => $item) {
                                            //if(!$item->gift) continue;
                                            ?>
                                            <tr>
                                                <td align="center" class="td_bg"nowrap ><?=$index+1?></td>
                                                <td class="td_bg"  style="word-break: break-all"><?=$item->gift->name?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->gift->type?$item->gift->type->name:''?></td>
                                                <td class="td_bg" style="word-break: break-all"><?=$item->gift->remark?></td>
                                                <td align="center" class="td_bg" nowrap><?=$item->strategy_id>0?'公司礼品':'自费礼品'?></td>
                                                <td class="td_bg" nowrap><?=$item->user?$item->user->getShowName():''?></td>
                                                <td align="center" class="td_bg" nowrap><?=date('Y-m-d H:i:s',$item->submit_time)?></td>
                                                <td align="center" class="td_bg" nowrap>
                                                    <?php
                                                    if($item->status == 0) echo '未出库';
                                                    if($item->status == 1) echo '已出库';
                                                    if($item->status == 2) echo '正在退换';
                                                    ?>
                                                </td>
                                            </tr>
                                            <?php
                                        }
                                        ?>
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD vAlign=top>
                                    <div id="car_history_list"></div>
                                </TD>
                            </TR>
                        </TABLE>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td height="22" colspan="2" align="center" class="td_bg">
            <input id="close-btn" type="button" class="ACT_btn" name="Submit3" value=" 关闭 ">
        </td>
    </tr>
</table>

<script type="text/javascript" language="javascript">
    //太平洋测试拨号挂断
    function tpy_call_in(mobile){
        var tpy_phone = mobile;
        if(tpy_phone == ""){
            alert("请输入号码");
            return false;
        }
        var ext_phone = '<?=$this->context->my->ext_phone?>';
        $.post('/tpy-phone/call-to',{ext_phone:ext_phone,phone_num:tpy_phone},function(obj){
            if(obj.success) {
                //$('#tpy_call_in').attr('disabled',true);
                //$('#tpy_call_out').removeAttr('disabled');
                alert(obj.msg);
            }else{
                alert(obj.msg);
            }
        },'json');
    }
    //太平洋测试挂断电话
    function tpy_call_out(){
        var ext_phone = '<?=$this->context->my->ext_phone?>';
        $.post('/tpy-phone/hang-up',{ext_phone:ext_phone},function(obj){
            if(obj.success) {
                //$('#tpy_call_out').attr('disabled',true);
                //$('#tpy_call_in').removeAttr('disabled');
                alert(obj.msg);
            }else{
                alert(obj.msg);
            }
        },'json');
    }
    $(function(){
        //操作历史
        gotoPage('/car/ajax-history-index?car_id=<?=$car_info->id?>&page=1','car_history_list');
        gotoPage('/appointment/ajax-index?car_id=<?=$car_info->id?>&page=1','appointment_list');
        //关闭
        $('#close-btn').click(function(){
            window.close();
        });
    });
</script>