<?php
use \common\libs\MyLib;
use \common\models\PriceT;
?>
<link href="/css/tabs.css" rel="stylesheet" type="text/css">
<table width="100%" border="0" align="center" cellpadding="2" 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" class=tab-none>&nbsp;</TD>
                </TR>
                </TBODY>
            </TABLE>
        </td>
    </tr>
    <tr>
        <td height="22" colspan="2" class="td_bg">
            <table width="100%" height="120" border="0" cellpadding="0" cellspacing="0" id="mainTable">
                <tbody style="display:block;">
                <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="strCall('<?= $car_info->phone ?>')">拨号</button>
                                                <button onclick="strHook()">挂机</button>
                                            </td>
                                            <td width="100" height="25" class="bg_tr">车主证件号码</td>
                                            <td height="25" class="td_bg">
                                                <?=$car_info->car_man_number?>
                                            </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>
                                </TD>
                            </TR>
                        </TABLE>
                        <TABLE id=tb cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb" class="hide-table">
                            <TR>
                                <TD vAlign=top>
                                    <form id="orderFrm">
                                        <table width="98%" border="0" align="center" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="40%" valign="top">
                                                    <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
                                                        <tr>
                                                            <td align="center" class="bg_tr">险种</td>
                                                            <td align="center" class="bg_tr">内容</td>
                                                            <td align="center" class="bg_tr" nowrap>不计免赔</td>
                                                        </tr>
                                                        <?php
                                                        $len = count($insurer_type_items);
                                                        for($i = 0; $i < $len; $i++) {
                                                            $item = $insurer_type_items[$i];
                                                            $order_id = $order_info->id;
                                                            if(!$order_id)
                                                                $order_id = 0;
                                                            $tmp_row = PriceT::find()
                                                                ->where('order_id='.$order_id.' and type_id='.$item->id)
                                                                ->one();
                                                            ?>
                                                            <tr>
                                                                <td class="bg_tr" nowrap><?=$item->name?>(<?=$item->code?>)</td>
                                                                <td class="td_bg"><?php
                                                                    if($item->content != '') {
                                                                        $tmp_items = explode(',',$item->content);
                                                                        echo '<select name="types['.$item->id.']">';
                                                                        $tmp_items = explode(',',$item->content);
                                                                        foreach($tmp_items as $tmp_item) {
                                                                            echo '<option';
                                                                            if(!empty($tmp_row) && $tmp_row->val == $tmp_item)
                                                                                echo ' selected ';
                                                                            echo '>'.$tmp_item.'</option>';
                                                                        }
                                                                        echo '</select>';
                                                                    } else {
                                                                        echo '<input name="types['.$item->id.']" style="width:80px;" type="text"';
                                                                        if(!empty($tmp_row))
                                                                            echo ' value="'.$tmp_row->val.'" ';
                                                                        echo '>';
                                                                    }
                                                                    ?>
                                                                </td>
                                                                <td align="center" class="td_bg"><?php
                                                                    if($item->has_nopay) {
                                                                        echo '<input type="checkbox" value="1" name="nopays['.$item->id.']"';
                                                                        if(!empty($tmp_row) && $tmp_row->is_nopay == 1)
                                                                            echo ' checked ';
                                                                        echo '>';
                                                                    }
                                                                    ?>
                                                                </td>
                                                            </tr>
                                                            <?php
                                                        }
                                                        ?>
                                                    </table>
                                                </td>
                                                <td width="10px;">&nbsp;</td>
                                                <td width="55%" valign="top">
                                                    <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
                                                        <tr>
                                                            <td class="bg_tr" nowrap><span style="color:#ff0000">*</span> 商业总净保费</td>
                                                            <td class="td_bg"><input name="total1_clear" id="total1_clear" type="text" value="<?=$order_info->total1_clear?>" style="width:100px;"></td>
                                                            <td class="bg_tr" nowrap>商业含税总保费</td>
                                                            <td class="td_bg"><input name="total1" id="total1" type="text" value="<?=$order_info->total1?>" style="width:100px;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr"><span style="color:#ff0000">*</span> 交强总净保费</td>
                                                            <td class="td_bg"><input name="total2_clear" id="total2_clear" type="text" value="<?=$order_info->total2_clear?>" style="width:100px;"></td>
                                                            <td class="bg_tr">交强含税总保费</td>
                                                            <td class="td_bg"><input name="total2" id="total2" type="text" value="<?=$order_info->total2?>" style="width:100px;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr" nowrap><span style="color:#ff0000">*</span> 折扣后商业净保费</td>
                                                            <td class="td_bg"><input name="total1_real" id="total1_real" type="text" value="<?=$order_info->total1_real?>" style="width:100px;"></td>
                                                            <td class="bg_tr"><span style="color:#ff0000">*</span> 车船税</td>
                                                            <td class="td_bg"><input name="total3" id="total3" type="text" value="<?=$order_info->total3?>" style="width:100px;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr">减免金额</td>
                                                            <td class="td_bg"><input name="total1_dis" id="total1_dis" type="text" value="<?=$order_info->total1_dis?>" style="width:100px;"></td>
                                                            <td class="bg_tr">共计签单</td>
                                                            <td class="td_bg"><input name="total_all" id="total_all" type="text" value="<?=$order_info->total_all?>" style="width:100px;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr">商业折扣率</td>
                                                            <td class="td_bg"><input name="total1_percent" id="total1_percent" type="text" value="<?=$order_info->total1_percent?>" style="width:100px;"></td>
                                                            <td class="bg_tr">应收</td>
                                                            <td class="td_bg"><input name="total_real" id="total_real" type="text" value="<?=$order_info->total_real?>" style="width:100px;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr">商业跟单手续费</td>
                                                            <td class="td_bg"><input name="total1_rate" id="total1_rate" type="text" value="<?=$order_info->total1_rate?>" style="width:100px;"></td>
                                                            <td class="bg_tr">交强跟单手续费</td>
                                                            <td class="td_bg"><input name="total2_rate" id="total2_rate" type="text" value="<?=$order_info->total2_rate?>" style="width:100px;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr">备注</td>
                                                            <td colspan="3" class="td_bg"><input name="price_remark" id="price_remark" type="text" value="<?=$order_info->price_remark?>" style="width:80%;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr">商业险保单号</td>
                                                            <td colspan="3" class="td_bg"><input name="insurer1_no" id="insurer1_no" type="text" value="<?=$order_info->insurer1_no?>" style="width:80%;"></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="bg_tr">交强险保单号</td>
                                                            <td colspan="3" class="td_bg"><input name="insurer2_no" id="insurer2_no" type="text" value="<?=$order_info->insurer2_no?>" style="width:80%;"></td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </form>
                                </TD>
                            </TR>
                            <tr>
                                <td align="center">
                                    <input type=button class="ACT_btn submit-btn" name=Submit2 value=" 提交 "/>
                                    <input type="button" class="ACT_btn back-btn" name="Submit3" value=" 返回 ">
                                </td>
                            </tr>
                        </TABLE>
                    </td>
                </tr>
                </tbody>

            </table>
        </td>
    </tr>
</table>
<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 strCall(phone) {
//        parent.frames[0].test();
        parent.drtCall(phone);
    }
    function strHook() {
        parent.drtHook();
    }
    //报价计算
    function calc() {
        var total1_clear = Number($('#total1_clear').val());
        var total1 = Number($('#total1').val());
        var total2_clear = Number($('#total2_clear').val());
        var total2 = Number($('#total2').val());
        var total3 = Number($('#total3').val());
        var total1_real = Number($('#total1_real').val());
        var total1_dis = Number($('#total1_dis').val());
        var total1_percent = Number($('#total1_percent').val());
        var total_all = Number($('#total_all').val());
        var total_real = Number($('#total_real').val());
        total1 = 1.06 * total1_clear;
        total2 = 1.06 * total2_clear;
        total_all = total1 + total2 + total3;
        total1_dis = total1_clear - total1_real;
        total_real = total_all - total1_dis;
        total1_percent = parseFloat(total1_real/total1_clear);
        $('#total1').val(total1.toFixed(2));
        $('#total2').val(total2.toFixed(2));
        $('#total1_dis').val(total1_dis.toFixed(2));
        $('#total1_percent').val(total1_percent.toFixed(2));
        $('#total_all').val(total_all.toFixed(2));
        $('#total_real').val(total_real.toFixed(2));
    }

    $(function () {
        $('#total1_clear').blur(function(){
            calc();
            refreshCompanyGift();
        });
        $('#total2_clear').blur(function(){
            calc();
        });
        $('#total3').blur(function(){
            calc();
        });
        $('#total1_dis').blur(function(){
            calc();
        });
        $('#total1_real').blur(function(){
            calc();
        });

        //保存按钮
        $(".submit-btn").click(function(){
            var params = $("#orderFrm").serialize();
            params += '&order_id=<?=$order_info->id?>';
            $.post('/finance/receipt-error-edit-save',params,function(obj){
                alert(obj.msg);
            },'json');
        });

        //返回按钮
        $('.back-btn').click(function(){
            window.location.href='/finance/receipt-error-list?<?=$back_params?>';
        });
    })
</script>
