<?php
use \common\libs\MyLib;
?>
<link href="/css/tabs.css" rel="stylesheet" type="text/css">
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <form id="orderFrm" action="/print/op-send-print" method="post" target="_blank">
        <input type="hidden" name="order_id" value="<?=$order_info->id?>">
        <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
        <tr>
            <td colspan="6" align="center">送单表</td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">车牌号</td>
            <td width="300" height="25" class="td_bg"><input  name="car_no" type="text" value="<?=$order_info->car_no?>" style="width:100px;" /></td>
            <td width="100" height="25" class="td_bg">厂牌型号</td>
            <td height="25" class="td_bg"><input  name="car_model" type="text" value="<?=$order_info->car?$order_info->car->factory_model:''?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">保险公司</td>
            <td height="25" class="td_bg"><input  name="insurer_company" type="text" value="<?=$order_info->company?$order_info->company->name:''?>" style="width:100px;" /></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">联系人</td>
            <td height="25" class="td_bg"><input  name="link_man" type="text" value="<?=$order_info->link_man?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">被保险人</td>
            <td height="25" class="td_bg"><input  name="insurer_man" type="text" value="<?=$order_info->id_man?>" /></td>
            <td width="100" height="25" class="td_bg">缴费方式</td>
            <td height="25" class="td_bg"><input  name="pay_type" type="text" value="<?=$order_info->payType?$order_info->payType->name:''?>" style="width:100px;"/></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">联系电话</td>
            <td height="25" class="td_bg"><input  name="link_tel" type="text" value="<?=$order_info->link_phone?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">保险起期</td>
            <td height="25" class="td_bg"><input  name="insurer_date" type="text" value="<?=$order_info->insurer1_begin_date?>" style="width:100px;" /></td>
            <td width="100" height="25" class="td_bg">出单日期</td>
            <td width="300" height="25" class="td_bg"><input  name="upload_date" type="text" value="<?=$order_info->submit_date?>" style="width:100px;" /></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">交强保费</td>
            <td height="25" class="td_bg"><input  name="total2" type="text" value="<?=$order_info->total2?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">商业保费</td>
            <td height="25" class="td_bg"><input  name="total1" type="text" value="<?=$order_info->total1?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">车船税</td>
            <td height="25" class="td_bg"><input  name="total3" type="text" value="<?=$order_info->total3?>" style="width:100px;"/></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">共计签单</td>
            <td height="25" class="td_bg"><input  name="total_all" type="text" value="<?=$order_info->total_all?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">实收金额</td>
            <td height="25" class="td_bg"><input  name="total_real" type="text" value="<?=$order_info->total_real?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">发票抬头</td>
            <td height="25" class="td_bg"><input  name="piao_header" type="text" value="个人" style="width:100px;"/></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">送单备注</td>
            <td colspan="5" height="25" class="td_bg"><input name="send_remark" type="text" value="<?=$order_info->remark?>" style="width:600px;"/></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">缴费单号</td>
            <td colspan="3" height="25" class="td_bg"><input  name="pay_no" type="text" value="<?=$order_info->pay_no?>"  style="width:100px;" /></td>
            <td width="100" height="25" class="td_bg">送单日期</td>
            <td width="300" height="25" class="td_bg"><input  name="send_date" type="text" value="<?=$order_info->send_date?>" style="width:100px;" /></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">投保单地址</td>
            <td colspan="5" width="80%" height="25" class="td_bg">
                <?php
                $address1 = $order_info->direction1?$order_info->direction1->name:'';
                $address1 .= $order_info->range1?$order_info->range1->name:'';
                $address1 .= $order_info->city1?$order_info->city1->name:'';
                $address1 .= $order_info->district1?$order_info->district1->name:'';
                $address1 .= $order_info->send_address1;
                ?>
                <input name="address1" type="text" value="<?=$address1?>" style="width: 600px;">
            </td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">正本地址</td>
            <td colspan="5" width="80%" height="25" class="td_bg">
                <?php
                $address2 = $order_info->direction2?$order_info->direction2->name:'';
                $address2 .= $order_info->range2?$order_info->range2->name:'';
                $address2 .= $order_info->city2?$order_info->city2->name:'';
                $address2 .= $order_info->district2?$order_info->district2->name:'';
                $address2 .= $order_info->send_address2;
                ?>
                <input name="address2" type="text" value="<?=$address2?>" style="width: 600px;">
            </td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">礼品</td>
            <td colspan="5" height="25" class="td_bg">
                <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
                    <tr>
                        <?php
                        $index = 0;
                        foreach($gift_group_items as $item) {
                            if($index > 0 && $index%4==0) {
                                echo '</tr><tr>';
                            }
                            $index++;
                            $sel_gift = isset($sel_gifts[$item->id])?$sel_gifts[$item->id]->gift:null;
                            echo '<td class="td_bg">';
                            foreach($item->gifts as $gift) {
                                if($sel_gift != null && $sel_gift->id == $gift->id) {
                                    echo '<input type="text" name="gifts[]" value="'.$gift->name.'">';
                                }
                            }
                            echo '</td>';
                        }
                        while($index%4!=0) {
                            $index++;
                            echo '<td class="td_bg"></td>';
                        }
                        ?>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">礼品签字</td>
            <td height="25" class="td_bg"></td>
            <td width="100" height="25" class="td_bg">返现金额</td>
            <td height="25" class="td_bg"><input  name="total1_dis" type="text" value="<?=$order_info->total1_dis?>" /></td>
            <td width="100" height="25" class="td_bg">领款人签字</td>
            <td height="25" class="td_bg"></td>
        </tr>
        <tr>
            <td width="100" height="25" class="td_bg">业务员</td>
            <td height="25" class="td_bg"><input name="sale_man" type="text" value="<?=$order_info->user?$order_info->user->getShowName():''?>" style="width:100px;"/></td>
            <td width="100" height="25" class="td_bg">电话</td>
            <td height="25" class="td_bg"><input name="sale_tel" type="text" value="<?=$order_info->user?$order_info->user->phone:''?>" /></td>
            <td width="100" height="25" class="td_bg">送单员</td>
            <td height="25" class="td_bg"><input name="send_man" type="text" value="" /></td>
        </tr>
    </form>
    <tr>
        <td height="22" colspan="6" align="center" class="td_bg">
            <input id="print-btn" type=button class="ACT_btn" name=Submit2 value=" 打印 "/>
            &nbsp;&nbsp;
            <input id="back-btn" type="button" class="ACT_btn" name="Submit4" value=" 关闭 ">
        </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 SaveOrder(status_id) {
        var param = $('#orderFrm').serialize();
        param = param + '&status_id=' + status_id;
        $.post('/print/send-mng-save',param,function(obj){
            if(obj.success) {
                if(status_id == 4)
                    $('#back-btn').click();
                else
                    alert(obj.msg);
            } else {
                alert(obj.msg);
            }
        },'json');
    }
    $(function () {
        //退回处理
        $('#return-btn').click(function(){
            var r = prompt('退回原因', '');
            if(r != null && r != '') {
                $.post('/insurer/return-op',{
                    order_id:<?=$order_info->id?>,
                    return_remark:r,
                    return_status_id:<?=$order_info->status_id?>
                },function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('#back-btn').click();
                    }
                },'json');
            } else {
                alert('不填写原因,无法退回');
            }
        });
        //放弃处理
        $('#cancel-btn').click(function(){
            if(confirm('是否确认放弃处理?')) {
                $.post('/insurer/order-cancel-save',{order_id:<?=$order_info->id?>},function(obj){
                    if(obj.success) {
                        $('#back-btn').click();
                    } else {
                        alert(obj.msg);
                    }
                },'json');
            }
        });
        //打印按钮
        $("#print-btn").click(function(){
            $('#orderFrm').submit();
//            var params = $("#orderFrm").serialize();
//            window.open('/print/op-send-print?'+params);
        });
        //保存
        $('#save-btn').click(function(){
            SaveOrder(3);
        });
        //提交
        $('#submit-btn').click(function(){
            if(confirm('是否提交此保单？')) {
                SaveOrder(4);
            }
        });

        //返回按钮
        $('#back-btn').click(function(){
            //window.location.href='/print/send-mng?<?=$back_params?>';
            window.close();
        });
    })
</script>
