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

$my = $this->context->my;
?>
<link href="/css/tabs.css" rel="stylesheet" type="text/css">
<link href="/js/addr/addr.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>
<script type="text/javascript" language="javascript" src="/js/addr/Popt.js"></script>
<script type="text/javascript" language="javascript" src="/js/addr/cityJson.js"></script>
<script type="text/javascript" language="javascript" src="/js/addr/citySet.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>
                                    <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">
                                                <?=$car_info->car_man_number?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <form id="myform">
                                                <input type="hidden" name="car_id" value="<?=$car_info->id?>" />
                                                <td width="100" height="25" class="bg_tr">商业止保日期</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$car_info->insurer1_date?>" name="insurer1_date" onClick="WdatePicker()" /></td>
                                                <td width="100" height="25" class="bg_tr">交强止保日期</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$car_info->insurer2_date?>" name="insurer2_date" onClick="WdatePicker()" /></td>
                                                <td width="100" height="25" class="bg_tr">保险公司</td>
                                                <td height="25" class="td_bg"><input type="text" value="<?=$car_info->company?>" name="company" /></td>
                                            </form>
                                        </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>
                                    <br>
                                    <div id="linkman_list">
                                    </div>

                                    <br>

                                    <div class="xtop">
                                        <div class="xchide">
                                            <div class="qbox">
                                                商业起保日期: <input class="act_date ac1" type="text" name="insurer1_date" value="" onclick="WdatePicker()">
                                            </div>

                                            <div class="qbox">
                                                交强起保日期: <input class="act_date ac2" type="text"  name="insurer2_date" value="" onclick="WdatePicker()">
                                            </div>

                                            <!--                                            <div class="qbox">-->
                                            <!--                                                保险公司:<select name="company" class="cpys" style="width:100px;">-->
                                            <!--                                                    <option value="">---请选择---</option>-->
                                            <!--                                                    --><?php
                                            //                                                    foreach($insurer_company2_items as $item) {
                                            //                                                        echo '<option value="'.$item->name.'"';
                                            //
                                            //                                                        echo '>'.$item->name.'</option>';
                                            //                                                    }
                                            //                                                    ?>
                                            <!--                                                </select>-->
                                            <!--                                            </div>-->
                                            <div class="qbox">
                                                <button class="queding">确定</button>
                                                <button class="qux">取消</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="appointment_list"></div>


                                </TD>
                            </TR>
                        </TABLE>
                        <!--预约信息-->

                        <h3>非车险信息</h3>
                        <div id="non_info"></div>
                        <!--预约信息-->
                        <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>
                        <!--预约信息-->
                        <table>
                            <tbody>
                            <tr>
                                <TD height="30" align="center" class=tab-off id=navcell onclick=open_up(4) name="navcell">▲历史保单</TD>
                            </tr>
                            </tbody>
                        </table>
                        <TABLE id=tb4 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()
                                            ->where('status_id=10 and id<>'.$order_info->id)
                                            ->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>
                            <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>
<style>
    .qbox{
        margin-top:10px;
        margin-left: 10px;
    }
    .xtop{
        position: relative;
    }
    .xchide{
        background: #e4f1fa;
        width: 200px;
        height: 110px;
        margin: auto;
        left: 0;
        top: 0;
        border:1px solid #a5d0e1;
        position: absolute;
        display: none;
        bottom: 0; right: 0;
    }

</style>
<script type="text/javascript" language="javascript">
    function get_city(t){
        var parent_id = $(t).val();
        if(!parent_id > 0){
            return;
        }
        $('#district').empty().css('display','none');
        $('#twon').empty().css('display','none');
///index.php?m=Home&c=Api&a=getRegion&level=2&parent_id='+ parent_id;
        var url = '/car/get-region?level=2&parent_id='+ parent_id;
        $.ajax({
            type : "GET",
            url  : url,
            error: function(request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                v = '<option value="0">选择城市</option>'+ v;
                $('#city').empty().html(v);
            }
        });
    }

    /**
     * 获取地区
     * @param t  城市select对象
     */
    function get_area(t){
        var parent_id = $(t).val();
        if(!parent_id > 0){
            return;
        }
        $('#district').empty().css('display','inline');
        $('#twon').empty().css('display','none');
        //'/index.php?m=Home&c=Api&a=getRegion&level=3&parent_id='+ parent_id;
        var url = '/car/get-region?level=3&parent_id='+ parent_id;
        $.ajax({
            type : "GET",
            url  : url,
            error: function(request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                v = '<option>选择区域</option>'+ v;
                $('#district').empty().html(v);
            }
        });
    }

    // 获取最后一级乡镇
    function get_twon(obj){
        var parent_id = $(obj).val();
        var url = '/car/get-town?&parent_id='+ parent_id;
        //var url = '/index.php?m=Home&c=Api&a=getTwon&parent_id='+ parent_id;
        $.ajax({
            type : "GET",
            url  : url,
            success: function(res) {
                if(parseInt(res) == 0){
                    $('#twon').empty().css('display','none');
                }else{
                    $('#twon').css('display','inline');
                    $('#twon').empty().html(res);
                }
            }
        });
    }
    //太平洋测试拨号挂断
    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 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) {
        var pay_type_id = $("#pay_type_id").val();
        var shoufei_id = $("#shoufei_id").val();
        var money_man = $("#money_man").val();
        var money_no = $("#money_no").val();
        var money_bank = $("#money_bank").val();
        var total1_clear = $('#total1_clear').val();
        var total2_clear = $('#total2_clear').val();
        var total3 = $('#total3').val();
        var total1_real = $('#total1_real').val();
        var insurer1_begin_date = $('#insurer1_begin_date').val();
        var insurer2_begin_date = $('#insurer2_begin_date').val();
        var send_address1 = $('#send_address1').val();
        var send_address2 = $('#send_address2').val();
        var seats = Number($('#seats').val());

        var city = $("#city").val();
        var pcity = $("#pcity").val();
        var pproper = $("#pproper").val();
        var receiver_address = $("#receiver_address").val();




        var company2_id = $("#company2_id").val();
        var reg=/^[0-9]*$/;


        if(status_id == 2){
            if (reg.test(city) || reg.test(pcity) || reg.test(pproper) || reg.test(receiver_address)) {
                alert("请输入正确格式的地址")
                return false;
            }
            if(isNull(shoufei_id)){
                alert('收费方式必填项!');
                return false;
            }
            if(isNull(city)){
                alert('请选择省份!');
                return false;
            }
            if(isNull(pcity)){
                alert('请选择城市!');
                return false;
            }
            if(isNull(pproper)){
                alert('请选择区县!');
                return false;
            }
            if(isNull(receiver_address)){
                alert('请填写详细地址!');
                return false;
            }

//            if(shoufei_id==2){
//                if(isNull(money_man)){
//                    alert('选择在线支付,领款人必填项!');
//                    return false;
//                }
//                if(isNull(money_no)){
//                    alert('选择在线支付,银行账号必填项!');
//                    return false;
//                }
//                if(isNull(money_bank)){
//                    alert('选择在线支付,开户行必填项!');
//                    return false;
//                }
//
//            }
            if(isNull(pay_type_id)){
                alert('付款方式必填项!');
                return false;
            }
            if(isNull(total1_clear)){
                alert('商业总净保费必填项!');
                return false;
            }
            if(isNull(total2_clear)){
                alert('交强总净保费必填项!');
                return false;
            }
            if(isNull(total1_real)){
                alert('折扣后商业净保费必填项!');
                return false;
            }
            if(isNull(total3)){
                alert('车船税必填项!');
                return false;
            }
            if(isNull(insurer1_begin_date)){
                alert('商业起保日期必填项!');
                return false;
            }
            if(isNull(insurer2_begin_date)){
                alert('交强起保日期必填项!');
                return false;
            }
            if(isNull(send_address1)){
                alert('送单地址必填项!');
                return false;
            }



            if(isNull(seats)){
                alert('座位数必填项!');
                return false;
            }
            if(company2_id == 0){
                alert('保险公司必填项!');
                return false;
            }
        }

        var param = $('#orderFrm').serialize();
        param = param + '&' + $('#companyGiftFrm').serialize();
        param = param + '&status_id=' + status_id;
        $.post('/car/order-save',param,function(obj){
            if(obj.success) {
                if(status_id > 1)
                    $('.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 refreshCompanyGift() {
        var total1_clear = Number($('#total1_clear').val());
        //公司礼品
        gotoPage('/gift/ajax-company-index?car_id=<?=$car_info->id?>&order_id=<?=$order_info->id?>&total1_clear=' + total1_clear,'company_gift_list');
    }
    //删除自费礼品
    function deleteGift(gift_id) {
        if(confirm('是否确认删除数据?')) {
            $.post('/gift/car-delete-save',{gift_id:gift_id},function(obj){
                alert(obj.msg);
                if(obj.success) {
                    gotoPage('/gift/ajax-car-index?car_id=<?=$car_info->id?>&t='+Math.random(),'gift_list');
                }
            },'json');
        }
    }
    var next_index = <?=$next_index?>;

    $(function(){
        $("#city").click(function (e) {
            SelCity(this,e);

        });
        //无效按钮
//        $('.invalid-btn').click(function(){
//            var car_id = $('#car_id').val();
//            var invalid_id = $('#invalid_id').val();
//            if(invalid_id == 0) {
//                alert('必须选择无效理由!');
//                return;
//            }
//            if(confirm('是否无效这条数据?')) {
//                $.post('/car/invalid-f',{car_id:car_id,invalid_id:invalid_id},function(obj){
//                    alert(obj.msg);
//                    if(obj.success) {
//                        $('#appointment-save-btn').attr('disabled',true);
//                        $('.save-btn').attr('disabled',true);
//                        $('.invalid-btn').attr('disabled',true);
//                        next_index = next_index - 1;
//                        if(next_index < 0) next_index = 0;
//                    }
//                },'json');
//            }
//        });
        //车险id,传入进去
        var releId=<?=$order_info->relevancy_non_id?$order_info->relevancy_non_id:0?>;
        var nonId=<?=$order_info->non_id?$order_info->non_id:0?>;
        if(releId && nonId){
            gotoPage('/non-auto-insurance/ajax-bd-info?id='+nonId+'&ordid='+releId +'&fixId='+<?=$order_info->id?>,'non_info');
        }else{
            gotoPage('/non-auto-insurance/ajax-bd-info?fixId=<?=$order_info->id?>','non_info');
        }
        $('.invalid-btn').click(function(){
            var car_id = $('#car_id').val();
            var invalid_id = $('#invalid_id').val();
//            var invalid_id = $('#invalid_id').val();
            if(invalid_id == 0) {
                alert('必须选择无效理由!');
                return;
            }
            if(invalid_id ==26 ||invalid_id ==27 || invalid_id ==34 ||invalid_id ==35 ||invalid_id ==36 ){
                $('.xchide').show()
//                alert('请更新保险日期')
//                $(".baocun").click()
                return
            }
            if(confirm('是否无效这条数据?')) {

                $.post('/car/invalid-man',{car_id:car_id,invalid_id:invalid_id},function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('.xchide').hide()
                        $('#appointment-save-btn').attr('disabled',true);
                        $('.save-btn').attr('disabled',true);
                        $('.invalid-btn').attr('disabled',true);
                        next_index = next_index - 1;
                        if(next_index < 0) next_index = 0;
                    }
                },'json');
            }
        });
        $('.qux').click(function(){
            $('.xchide').hide()
        })
        $('.queding').click(function(){
            var ac1=$('.ac1').val();
            var ac2=$('.ac2').val();
//            var ac3=$('.cpys').val();
            var car_id = $('#car_id').val();
            var invalid_id = $('#invalid_id').val();
            if(ac1==''|| ac2==''){
                alert('请填写保险日期')
                return false;
            }else{
                if(confirm('是否无效这条数据?')) {

                    $.post('/car/invalid-man',{car_id:car_id,invalid_id:invalid_id,ac1:ac1,ac2:ac2},function(obj){
                        alert(obj.msg);
                        if(obj.success) {
                            $('.xchide').hide()
                            $('#appointment-save-btn').attr('disabled',true);
                            $('.save-btn').attr('disabled',true);
                            $('.invalid-btn').attr('disabled',true);
                            next_index = next_index - 1;
                            if(next_index < 0) next_index = 0;
                        }
                    },'json');


                }
            }

        })




        //更新公司礼品
        refreshCompanyGift();
        //操作历史
        gotoPage('/car/ajax-history-index-xubao?car_id=<?=$car_info->id?>&page=1&t='+Math.random(),'car_history_list');
        //添加自费礼品
        $('#gift-add-btn').click(function(){
            var params = $('#giftFrm').serialize();
            $.post('/gift/car-add-save',params,function(obj){
                alert(obj.msg);
                if(obj.success) {
                    $('#giftFrm')[0].reset();
                    gotoPage('/gift/ajax-car-index?car_id=<?=$car_info->id?>&t='+Math.random(),'gift_list');
                }
            },'json');
        });
        gotoPage('/gift/ajax-car-index?car_id=<?=$car_info->id?>','gift_list');
        //预约人数
        $('#pdate').blur(function(){
            var params = $("#appointmentFrm").serialize();
            $.post('/appointment/count',params,function(obj){
                if(obj.success) {
                    $('#day_count').html(obj.count);
                }
            },'json');
        });
        //添加预约
        $('#appointment-save-btn').click(function(){
            if(confirm('是否确认提交?')) {
                var params = $("#appointmentFrm").serialize();
                $.post('/appointment/save',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('#appointmentFrm')[0].reset();
                        gotoPage('/appointment/ajax-index?car_id=<?=$car_info->id?>&page=1&t='+Math.random(),'appointment_list');
                    }
                },'json');
            }
        });


        //添加联系人
        $('.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');
            }
        });

        $('#brand_id').change(function(){
            var brand_id = $(this).val();
            $('#series_id').html('<option value="0">---请选择---</option>');
            $('#displacement_id').html('<option value="0">---请选择---</option>');
            if(brand_id > 0) {
                $.get('/car/series',{brand_id:brand_id},function(obj){
                    if(obj.success) {
                        $('#series_id').html(obj.html);
                    }
                },'json');
            }
        });
        $('#series_id').change(function(){
            var series_id = $(this).val();
            $('#displacement_id').html('<option value="0">---请选择---</option>');
            if(series_id > 0) {
                $.get('/car/displacement',{series_id:series_id},function(obj){
                    if(obj.success) {
                        $('#displacement_id').html(obj.html);
                    }
                },'json');
            }
        });
        $('#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();
        });

        //保存
        $('.save-btn').click(function(){
            SaveOrder(1);
        });
        //提交
        $('.submit-btn').click(function(){
            <?php
            if($order_info->return_status_id > 0) {
                ?>
                var status_id = $('#status_id').val();
                if(status_id == 0) {
                    alert('请先选择提交目标');
                    return;
                }
                if(status_id == 1) status_id = 2;
                if(confirm('是否提交此保单?')) {
                    SaveOrder(status_id);
                }
                <?php
            } else {
                ?>
                if(confirm('是否提交此保单?')) {
                    SaveOrder(2);
                }
                <?php
            }
            ?>
        });

        //返回
        $('.back-btn').click(function(){
            <?php
            $url = '';
            if($type == 1)
                $url = '/renewal/first?'.$back_params;
            if($type == 2)
                $url = '/renewal/today?'.$back_params;
            if($type == 3)
                $url = '/renewal/all?'.$back_params;
            if($type == 4)
                $url = '/renewal/return-list?'.$back_params;
            echo 'window.location.href = "'.$url.'"';
            ?>
        });
        //下一个
        $('.next-btn').click(function(){
            var params = 'index=' + next_index + '&type=<?=$type?>';
            $.get('/renewal/ajax-next',params,function(obj){
                if(obj.success) {
                    if(obj.car_id > 0) {
                        window.location.href = '/car/info-renewal?id=' + obj.car_id + '&type=<?=$type?>&next_index=<?=$next_index?>' + '&back_params=' + encodeURIComponent('<?=$back_params?>');
                    } else {
                        alert('没有记录');
                    }
                }
            },'json');
        });
        //生成短信内容
        $('.sms-make-btn').click(function(){
            var params = $('#orderFrm').serialize();
            $.post('/car/sms-make',params,function(obj){
                if(obj.success) {
                    $('#sms-msg').val(obj.msg);
                } else {
                    alert(obj.msg);
                }
            },'json');
        });
        //发送短信内容
        $('.sms-send-btn').click(function(){
            var tel = $('#sms-tel').val();
            var msg = $('#sms-msg').val();
            $.post('/car/sms-send',{tel:tel,msg:msg},function(obj){
                alert(obj.msg);
            },'json');
        });
        
        //保存
        $(".baocun").click(function(){
            var params = $('#myform').serialize();
            $.post('/car/baocun',params,function(obj){
                alert(obj.msg);
            },'json');
        });

        //判断礼品
        $('#total1_clear').change(function(){
            var txtObj = $('input[name="types[1]"]');
            var txtValue = Number(txtObj.val());
            var money = Number($(this).val());
            $('.gifts').each(function() {
                var obj = $(this);
                var min = obj.attr('min');
                var max = obj.attr('max');
                var damage = obj.attr('is_damage');
                if(damage>0) {
                    if(txtValue>0) {
                        obj.removeAttr('disabled');
                    } else {
                        obj.val(0);
                        obj.attr('disabled',true);
                        return;
                    }
                }
                if(min > 0) {
                    if(min > money) {
                        obj.val(0);
                        obj.attr('disabled',true);
                    } else {
                        obj.removeAttr('disabled');
                    }
                }

                if(max > 0) {
                    if(max < money) {
                        obj.val(0);
                        obj.attr('disabled',true);
                    } else if(min>0 && min<=money){
                        obj.removeAttr('disabled');
                    }
                }
            });
        });
        $('input[name="types[1]"]').change(function(){
            $('#total1_clear').change();
        });
        $('#total1_clear').change();
    });
</script>