<?php
use \common\libs\MyLib;
use \common\models\PriceT;

$my = $this->context->my;
?>
<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>
<script type="text/javascript" language="javascript" src="/js/common2.js"></script>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
    <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>
                            <tbody>
                            <tr>
                                <TD height="30" align="center" class=tab-on id=navcell onclick=open_up(1) name="navcell">▼非车险信息</TD>
                            </tr>
                            </tbody>
                        </table>
                        <TABLE id=tb1 cellSpacing=1 cellPadding=0 width="100%" border=0 name="tb">

                            <TR>
                                <TD vAlign=top>
                                    <form id="myform">
                                        <input type="hidden" name="id" value="<?=$info->id?>">
                                        <input type="hidden" name="order_id" value="<?=$order_info->id?>">
                                        <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">
                                                    <select name="scheme_id" id="scheme_id">
                                                        <option value="">请选择</option>
                                                        <?php foreach($scheme_items as $item) {?>
                                                            <option value="<?=$item->id?>" <?php if($item->id==$info->scheme_id) echo 'selected';?>><?=$item->name?></option>
                                                        <?php  }?>
                                                    </select>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">总保额</td>
                                                <td height="25" class="td_bg baoer"></td>
                                                <td width="100" height="25" class="bg_tr">保险费用</td>
                                                <td height="25" class="td_bg feiyong"></td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr">起保日期</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$info->insurer_date_start?>" name="insurer_date_start" onClick="WdatePicker()" /></td>
                                                <td width="100" height="25" class="bg_tr">投保份数</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$info->num?>" name="num"/></td>
                                                <td width="100" height="25" class="bg_tr">座位数</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$info->seat?>" name="seat"/></td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr">被保险人姓名</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$info->insurant_name?>" name="insurant_name"/></td>
                                                <td width="100" height="25" class="bg_tr">证件号</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$info->insurant_number?>" name="insurant_number"/></td>
                                                <td width="100" height="25" class="bg_tr">电话</td>
                                                <td height="25" class="td_bg"><?=$info->insurant_phone?></td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr">投保人姓名</td>
                                                <td height="25" class="td_bg"><?=$info->policy_holder_name?></td>
                                                <td width="100" height="25" class="bg_tr">证件号</td>
                                                <td height="25" class="td_bg"><?=$info->policy_holder_number?></td>
                                                <td width="100" height="25" class="bg_tr">电话</td>
                                                <td height="25" class="td_bg"><?=$info->policy_holder_phone?></td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr">受益人姓名</td>
                                                <td height="25" class="td_bg"><?=$info->beneficiary_name?></td>
                                                <td width="100" height="25" class="bg_tr">证件号</td>
                                                <td height="25" class="td_bg"><?=$info->beneficiary_number?></td>
                                                <td width="100" height="25" class="bg_tr">电话</td>
                                                <td height="25" class="td_bg"><?=$info->beneficiary_phone?></td>
                                            </tr>
                                            <tr>
                                                <td height="22" colspan="6" align="center" class="td_bg">
                                                    <input type=button class="ACT_btn baocun" name="next-btn" value=" 保存 "/>
                                                    <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>
                                    </form>




                                </TD>
                            </TR>
                        </TABLE>

                        <!--保单信息-->
                        <table>
                            <tbody>
                            <tr>
                                <TD height="30" align="center" class=tab-off id=navcell onclick=open_up(2) name="navcell">▲核保信息</TD>
                            </tr>
                            </tbody>
                        </table>
                        <TABLE id=tb2 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>


                                            </tr>
                                        </table>


                                    </form>
                                </TD>
                            </TR>
                            <tr>
                                <td align="center">
<!--                                    <input type=button class="ACT_btn save-btn" name=Submit1 value=" 保存 "/>-->
<!---->
<!--                                    <input type=button class="ACT_btn submit-btn" name=Submit2 value=" 提交 "/>-->
<!--                                    <input type=button class="ACT_btn next-btn" name=Submit5 value=" 下一个 "/>-->
<!--                                    <input type="button" class="ACT_btn back-btn" name="Submit3" value=" 返回 ">-->
                                </td>
                            </tr>
                        </TABLE>
                        <!--操作记录-->
                        <table>
                            <tbody>
                            <tr>
                                <TD height="30" align="center" class=tab-off id=navcell onclick=open_up(3) name="navcell">▲操作记录</TD>
                            </tr>
                            </tbody>
                        </table>
                        <TABLE id=tb3 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>
                            <tr>
                                <td align="center">
<!--                                    <input type=button class="ACT_btn next-btn" name=Submit5 value=" 下一个 "/>-->
<!--                                    <input type="button" class="ACT_btn back-btn" name="Submit3" value=" 返回 ">-->
                                </td>
                            </tr>
                        </TABLE>
                        <!--历史保单-->

                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<script type="text/javascript" language="javascript">



    //报价计算
    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 SaveOrder(status_id) {





//        if(status_id == 2){
////            if(isNull(shoufei_id)){
////                alert('收费方式必填项!');
////                return false;
////            }
//
////            }
//
//        }


        var params = $('#myform').serialize();
        params = params + '&status_id=' + status_id;
        $.post('/non-auto-insurance/bd-save',params,function(obj){
            if(obj.success) {
                if(status_id > 14) {
                    $('.back-btn').click();
                }else{
                    alert(obj.msg);
                }

            } else {
                alert(obj.msg);
            }

        },'json');


    }

    //判断是否填写了选项
    function isNull(data){

        if(data == "" || data == undefined || data == null){
            return true;
        }else{
            return false;
        }
    }

    function get_category(id){
        $.post('/scheme/chaxun',{id:id},function(obj){
            if(obj.success) {
                $('.baoer').html(obj.info.baoer);
                $('.feiyong').html(obj.info.baofei);

            }else{
                $('.baoer').html('');
                $('.feiyong').html('');
            }
        },'json')
     }


    $(function(){
        get_category(<?=$info->scheme_id?>);
        $(document).on("change",'#scheme_id',function(){
            get_category($(this).val());
        })




        //操作历史
        gotoPage('/non-auto-insurance/ajax-history-index?non_id=<?=$info->id?>&page=1&t='+Math.random(),'car_history_list');
        //添加自费礼品


        //添加联系人
//        $('.add-linkman-btn').click(function(){
//            if(confirm('是否确认提交?')) {
//                var params = $("#linkmanFrm").serialize();
//                $.post('/car/linkman-save',params,function(obj){
//                    alert(obj.msg);
//                    if(obj.success) {
//                        $('#linkmanFrm')[0].reset();
//                        gotoPage('/car/ajax-linkman-index?car_id=<?//=$car_info->id?>//&t='+Math.random(),'linkman_list');
//                    }
//                },'json');
//            }
//        });





        //提交
        $('.submit-btn').click(function(){
            if(confirm('是否提交此保单?')) {
                SaveOrder(15);
            }
        });

        //返回
        $('.back-btn').click(function(){
            window.location.href = '/non-auto-insurance/bd-index';
        });
        //下一个



        //保存
        $(".baocun").click(function(){
            SaveOrder(14);
        });





    });
</script>