<?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>
                                        <tr>
                                            <td height="22" colspan="6" align="center" class="td_bg">
                                                <input type=button class="ACT_btn baocun" name="next-btn" value=" 保存 "/>
                                            </td>
                                        </tr>
                                    </table>
                                    <br>
                                    <div id="linkman_list">
                                    </div>
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
                                        <form id="linkmanFrm">
                                            <input type="hidden" name="car_id" value="<?=$car_info->id?>">
                                            <tr>
                                                <td align="right" class="bg_tr">姓名：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <input name="name" id="name" type="text" value=""/>
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">联系电话：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <input name="phone" id="phone" type="text" value="" />
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">证件号码：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <input name="id_number" id="id_number" type="text" value=""/>
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">关系：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <select name="type">
                                                            <option>联系人</option>
                                                            <option>被保险人</option>
                                                            <option>车主</option>
                                                        </select>
                                                    </div>
                                                </td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <input type=button class="ACT_btn add-linkman-btn" name="add-linkman-btn" value=" 添加联系人 "/>
                                                    </div>
                                                </td>
                                            </tr>
                                        </form>
                                    </table>
                                    <br>
                                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
                                        <form id="appointmentFrm">
                                            <input type="hidden" name="car_id" value="<?=$car_info->id?>">
                                            <tr>
                                                <td align="right" class="bg_tr">预约日期：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <input class="act_date" name="pdate" id="pdate" type="text" value="" onClick="WdatePicker()"/>
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">预约时间：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <select name="ptime">
                                                            <option>08:00</option>
                                                            <option>08:30</option>
                                                            <option>09:00</option>
                                                            <option>09:30</option>
                                                            <option>10:00</option>
                                                            <option>10:30</option>
                                                            <option>11:00</option>
                                                            <option>11:30</option>
                                                            <option>12:00</option>
                                                            <option>13:00</option>
                                                            <option>13:30</option>
                                                            <option>14:00</option>
                                                            <option>14:30</option>
                                                            <option>15:00</option>
                                                            <option>15:30</option>
                                                            <option>16:00</option>
                                                            <option>16:30</option>
                                                            <option>17:00</option>
                                                        </select>
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">预约类型：</td>
                                                <td class="td_bg">
                                                    <div align="left">
                                                        <select name="ptype">
                                                            <option value="0">--选择类型--</option>
                                                            <?php foreach($list as $k=>$v){ ?>
                                                                <option value='<?= $v->code; ?>'><?= $v->name; ?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">当天预约人数：</td>
                                                <td width="50" class="td_bg">
                                                    <div align="left">
                                                        <span id="day_count">0</span>
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right" class="bg_tr">预约备注：</td>
                                                <td colspan="5" class="td_bg">
                                                    <div align="left">
                                                        <textarea name="remark" style="width:700px; height: 30px;"></textarea>
                                                    </div>
                                                </td>
                                                <td align="right" class="bg_tr">业务分组：</td>
                                                <td class="td_bg">
                                                    <select name="business_group_id">
                                                        <option value="0">请选择</option>
                                                        <?php
                                                        foreach ($business_group as $index => $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            echo $business_group_id == $item->id ? 'selected' : '';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td height="22" colspan="8" align="center" class="td_bg">
                                                    <input id="appointment-save-btn" type=button class="ACT_btn" name="appointment-save-btn" value=" 预约保存 "/>
                                                    <input type=button class="ACT_btn next-btn" name="next-btn" value=" 下一个 "/>
                                                    <input type="button" class="ACT_btn back-btn" name="back-btn" value=" 返回 ">
                                                    <select name="invalid_id" id="invalid_id">
                                                        <option value="0">请选择无效理由</option>
                                                        <?php foreach($failure_items as $item) {?>

                                                            <option value="<?=$item->id?>"<?php if($item->id==25 || $item->id==37 || $item->id==40){ echo 'disabled';}?>><?=$item->name?></option>

                                                            <?php  }?>


                                                    </select>
                                                    <input type=button class="ACT_btn invalid-btn" name="invalid-btn" value=" 无效数据 "/>
                                                </td>
                                            </tr>
                                        </form>
                                    </table>
                                    <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>
                        <!--预约信息-->
                        <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>
                                                <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();
//                                                            $query = PriceT::find()
//                                                                ->where('order_id='.$order_id.' and type_id='.$item->id);
//                                                            echo $query->createCommand()->rawSql."<br>";
                                                            ?>
                                                            <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"><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">商业含税总保费</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"><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 colspan="3" class="td_bg"><input name="price_remark" id="price_remark" type="text" value="<?=$order_info->price_remark?>" style="width:80%;"></td>
                                                        </tr>
                                                    </table>
<!--                                                    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="table">-->
<!--                                                        <tr class="tdbg2">-->
<!--                                                            <td colspan="4" class="bg_tr">短信</td>-->
<!--                                                        </tr>-->
<!--                                                        <tbody>-->
<!--                                                        <tr class="tdbg2">-->
<!--                                                            <td width="85" class="bg_tr">手机号码</td>-->
<!--                                                            <td colspan="3" class="td_bg">-->
<!--                                                                <input type="text" id="sms-tel" name="sms-tel" value="--><?//=$order_info->link_phone==''?$car_info->phone:$order_info->link_phone?><!--">-->
<!--                                                            </td>-->
<!--                                                        </tr>-->
<!--                                                        <tr class="tdbg2">-->
<!--                                                            <td width="85" class="bg_tr">短信内容</td>-->
<!--                                                            <td colspan="3" class="td_bg">-->
<!--                                                                <textarea id="sms-msg" name="sms-msg" style="width: 350px; height: 50px;"></textarea>-->
<!--                                                            </td>-->
<!--                                                        </tr>-->
<!--                                                        <tr class="tdbg2">-->
<!--                                                            <td width="85" class="bg_tr"></td>-->
<!--                                                            <td colspan="3" class="td_bg">-->
<!--                                                                <input class="act_btn sms-make-btn" type="button" value="生成短信内容">-->
<!--                                                                <input class="act_btn sms-send-btn" type="button" value="发送短信">-->
<!--                                                            </td>-->
<!--                                                        </tr>-->
<!--                                                        </tbody>-->
<!--                                                    </table>-->
                                                </td>
                                            </tr>
                                        </table>
                                        <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table" style="table-layout: fixed;">
                                            <input type="hidden" name="order_id" value="<?=$order_info->id?>">
                                            <input type="hidden" name="car_id" id="car_id" value="<?=$order_info->car_id?>">
                                            <tr>
                                                <td width="100" height="25" class="bg_tr">车牌号</td>
                                                <td height="25" class="td_bg">
                                                    <input name="car_no" type="text" value="<?=$car_info->car_no?>" style="width:100px;"/>
                                                </td>
                                                <td width="100" height="25" class="bg_tr">初登日期</td>
                                                <td height="25" class="td_bg">
                                                    <input class="act_date" name="register_date" type="text" value="<?=$car_info->register_date?>" onclick="WdatePicker()"/>
                                                </td>
                                                <td class="bg_tr">电子邮件</td>
                                                <td class="td_bg">
                                                    <input type="text" id="email" name="email" value="<?=$order_info->email?>" style="width:100px;">
                                                </td>
                                                <td class="bg_tr"><span style="color:#ff0000">*</span> 成功理由</td>
                                                <td class="td_bg">
                                                    <select name="success_id" id="success_id">
                                                        <option value="0">---请选择---</option>
                                                        <?php
                                                        foreach($success_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($order_info->success_id == $item->id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td width="100" height="25" class="bg_tr">车主</td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" id="car_man" name="car_man" value="<?=$car_info->car_man?>" style="width:100px;" >
                                                </td>
                                                <td width="100" height="25" class="bg_tr">证件号码</td>
                                                <td height="25" class="td_bg">
                                                    <input type="text" name="car_man_number" id="car_man_number" value="<?=$car_info->car_man_number?>" style="width:100px;">
                                                </td>
                                                <td width="60" height="25" class="bg_tr">座位数</td>
                                                <td height="25" class="td_bg">
                                                    <input name="seats" id="seats" type="text" value="<?=$car_info->seats?>" style="width:50px;"/>
                                                </td>
                                                <td class="bg_tr">送单日期</td>
                                                <td class="td_bg">
                                                    <input class="act_date" type="text" id="send_date" name="send_date" value="<?=$order_info->send_date?>" onClick="WdatePicker()">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="bg_tr">被保险人</td>
                                                <td class="td_bg">
                                                    <input type="text" id="id_man" name="id_man" value="<?=$order_info->id_man?>" style="width:100px;">
                                                </td>
                                                <td class="bg_tr">证件号码</td>
                                                <td class="td_bg">
                                                    <input type="text" id="id_number" name="id_number" value="<?=$order_info->id_number?>" style="width:100px;">
                                                </td>
                                                <td width="60" class="bg_tr">联系人</td>
                                                <td class="td_bg">
                                                    <input type="text" id="link_man" name="link_man" value="<?=$order_info->link_man?>" style="width:100px;">
                                                </td>
                                                <td width="60" class="bg_tr">联系电话</td>
                                                <td class="td_bg">
                                                    <input type="text" id="link_phone" name="link_phone" value="<?=$order_info->link_phone?>" style="width:100px;">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="bg_tr" nowrap><span style="color:#ff0000">*</span> 商业起保日期</td>
                                                <td class="td_bg">
                                                    <input class="act_date" type="text" id="insurer1_begin_date" name="insurer1_begin_date" value="<?=$order_info->insurer1_begin_date?>" onClick="WdatePicker()">
                                                </td>
                                                <td class="bg_tr" nowrap><span style="color:#ff0000">*</span> 交强起保日期</td>
                                                <td class="td_bg">
                                                    <input class="act_date" type="text" id="insurer2_begin_date" name="insurer2_begin_date" value="<?=$order_info->insurer2_begin_date?>" onClick="WdatePicker()">
                                                </td>
                                                <td class="bg_tr">付款方式</td>
                                                <td class="td_bg">
                                                    <select name="shoufei_id" id="shoufei_id">
                                                        <option value="">---收费方式---</option>
                                                        <option value="1">---上门收费---</option>
                                                        <option value="2">---在线支付---</option>
                                                        <option value="3">---客户自上门---</option>
                                                    </select>
                                                    <select name="pay_type_id" id="pay_type_id">
                                                        <option value="">---请选择---</option>
                                                        <?php
                                                        foreach($pay_type_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($item->id == $order_info->pay_type_id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                                <td class="bg_tr">保险公司</td>
                                                <td class="td_bg">
                                                    <select name="company2_id" id="company2_id" style="width:100px;">
                                                        <option value="0">---请选择---</option>
                                                        <?php
                                                        foreach($insurer_company2_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($item->id == $order_info->company2_id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="bg_tr">送单范围</td>
                                                <td colspan="7" class="td_bg">
                                                    <select name="direction1_id">
                                                        <option value="0"></option>
                                                        <?php
                                                        foreach($direction_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($item->id == $order_info->direction1_id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                    <select name="range1_id">
                                                        <option value="0"></option>
                                                        <?php
                                                        foreach($range_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($item->id == $order_info->range1_id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                    <select name="city1_id">
                                                        <option value="0"></option>
                                                        <?php
                                                        foreach($city_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($item->id == $order_info->city1_id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                    <select name="district1_id">
                                                        <option value="0"></option>
                                                        <?php
                                                        foreach($district_items as $item) {
                                                            echo '<option value="'.$item->id.'"';
                                                            if($item->id == $order_info->district1_id)
                                                                echo ' selected ';
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="bg_tr"> 送单地址</td>
                                                <td colspan="3" class="td_bg">
                                                    <input type="text" id="send_address1" name="send_address1" value="<?=$order_info->send_address1?>" style="width: 80%;">
                                                </td>
                                                <td class="bg_tr"> 正本送单地址</td>
                                                <td colspan="3" class="td_bg">

                                                    省份<input type="text" id="city" name="city" value="<?=$order_info->receiver_province?$order_info->receiver_province:''?>"/><br/>
                                                    城市<input type="text" name="pcity" id="pcity" value="<?=$order_info->receiver_city?$order_info->receiver_city:''?>"><br/>
                                                    区县<input type="text" name="pproper" id="pproper" value="<?=$order_info->receiver_county?$order_info->receiver_county:''?>"><br/>
                                                    详细地址<input type="text" name="receiver_address" id="receiver_address" value="<?=$order_info->receiver_address?$order_info->receiver_address:''?>" style="width: 200px;">
                                                </td>
                                            </tr>
                                            <script>
                                                $(function(){
                                                    $('#shoufei_id').change(function(){
                                                        if($(this).val()==2){
                                                            $('.caiwu_tr').show();
                                                        }else{
                                                            $('.caiwu_tr').hide();
                                                        }
                                                    })
                                                })
                                            </script>
                                            <style>
                                                .caiwu_tr{
                                                    display: none;
                                                }
                                            </style>

                                            <tr class="caiwu_tr"<?php if($order_info->shoufei_id==2):?>style="display: table-row;"<?php endif?>>
                                                <td class="bg_tr">领款人</td>
                                                <td class="td_bg"><input name="money_man" id="money_man" type="text" value="<?=$order_info->caiwu?$order_info->caiwu->money_man:''?>" style="width:120px;"></td>
                                                <td class="bg_tr">开户行</td>
                                                <td class="td_bg"><input name="money_bank" id="money_bank" type="text" value="<?=$order_info->caiwu?$order_info->caiwu->money_bank:''?>" style="width:120px;"></td>
                                                <td class="bg_tr">银行账号</td>
                                                <td class="td_bg" colspan="3"><input name="money_no" id="money_no" type="text" value="<?=$order_info->caiwu?$order_info->caiwu->money_no:''?>" style="width: 80%;"></td>
                                            </tr>
                                            <tr>
                                                <td class="bg_tr">备注</td>
                                                <td colspan="7" class="td_bg">
                                                    <input type="text" id="order_remark" name="order_remark" value="<?=$order_info->remark?>" style="width: 80%;">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="bg_tr">业务分组</td>
                                                <td colspan="7" class="td_bg">
                                                    <select name="business_group_id">
                                                        <option value="0">请选择</option>
                                                        <?php
                                                        foreach ($business_group as $index => $item){
                                                            echo '<option value="'.$item->id.'"';
                                                            if($order_info->business_group_id > 0) {
                                                                if($order_info->business_group_id == $item->id)
                                                                    echo ' selected ';
                                                            } else {
                                                                if($order_info->user && $order_info->user->business_group_id > 0) {
                                                                    if($order_info->user->business_group_id == $item->id)
                                                                        echo ' selected ';
                                                                }
                                                            }
                                                            echo '>'.$item->name.'</option>';
                                                        }
                                                        ?>
                                                    </select>
                                                </td>
                                            </tr>
                                        </table>
                                        <p>免费礼品</p>
                                        <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
                                            <tr>
                                                <?php
                                                $index = 0;
                                                foreach($gift_free_group_items as $item) {
                                                    $groups = $item->getGroups();
                                                    $continue_flag = false;
                                                    if(count($groups) > 0) $continue_flag = true;
                                                    foreach($groups as $group) {
                                                        if($group->id == $my->group_id)
                                                            $continue_flag = false;
                                                    }
                                                    if($continue_flag) continue;
                                                    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 width="85" class="bg_tr">'.$item->name.'</td>';
                                                    echo '<td class="td_bg">';
                                                    echo '<select class="gifts" min="'.$item->min_money.'" max="'.$item->max_money.'" name="gifts[]" is_damage="'.$item->is_damage.'" style="width:132px;"';
                                                    if($item->min_money > 0 )
                                                        echo ' disabled ';
                                                    if($sel_gift != null && $sel_gifts[$item->id]->status == 1)
                                                        echo ' readonly ';
                                                    echo '>';
                                                    echo '<option value="0"></option>';
                                                    foreach($item->gifts as $gift) {
                                                        if($gift->total == 0) continue;
                                                        echo '<option value="'.$item->id.'_'.$gift->id.'"';
                                                        if($sel_gift != null && $sel_gift->id == $gift->id) {
                                                            echo ' selected ';
                                                        }
                                                        echo '>'.$gift->name;
                                                        if($gift->total > -1)
                                                            echo '('.$gift->total.')';
                                                        echo '</option>';
                                                    }
                                                    echo '</select>';
                                                    echo '</td>';
                                                }
                                                while($index%4!=0) {
                                                    echo '<td width="85" class="bg_tr"></td>';
                                                    echo '<td class="td_bg"></td>';
                                                    $index++;
                                                }
                                                ?>
                                            </tr>
                                        </table>
                                        <p>收费礼品</p>
                                        <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
                                            <tr>
                                                <?php
                                                $index = 0;
                                                foreach($gift_group_items as $item) {
                                                    $groups = $item->getGroups();
                                                    $continue_flag = false;
                                                    if(count($groups) > 0) $continue_flag = true;
                                                    foreach($groups as $group) {
                                                        if($group->id == $my->group_id)
                                                            $continue_flag = false;
                                                    }
                                                    if($continue_flag) continue;
                                                    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 width="85" class="bg_tr">'.$item->name.'</td>';
                                                    echo '<td class="td_bg">';
                                                    echo '<select class="gifts" min="'.$item->min_money.'" max="'.$item->max_money.'" name="gifts[]" is_damage="'.$item->is_damage.'" style="width:132px;"';
                                                    if($item->min_money > 0 )
                                                        echo ' disabled ';
                                                    if($sel_gift != null && $sel_gifts[$item->id]->status == 1)
                                                        echo ' readonly ';
                                                    echo '>';
                                                    echo '<option value="0"></option>';
                                                    foreach($item->gifts as $gift) {
                                                        if($gift->total == 0) continue;
                                                        echo '<option value="'.$item->id.'_'.$gift->id.'"';
                                                        if($sel_gift != null && $sel_gift->id == $gift->id) {
                                                            echo ' selected ';
                                                        }
                                                        echo '>'.$gift->name;
                                                        if($gift->total > -1)
                                                            echo '('.$gift->total.')';
                                                        echo '</option>';
                                                    }
                                                    echo '</select>';
                                                    echo '</td>';
                                                }
                                                while($index%4!=0) {
                                                    echo '<td width="85" class="bg_tr"></td>';
                                                    echo '<td class="td_bg"></td>';
                                                    $index++;
                                                }
                                                ?>
                                            </tr>
                                        </table>
                                    </form>
                                </TD>
                            </TR>
                            <tr>
                                <td align="center">
                                    <input type=button class="ACT_btn save-btn" name=Submit1 value=" 保存 "/>
                                    <?php
                                    if($order_info->return_status_id > 0) {
                                        ?>
                                        <select name="status_id" id="status_id">
                                            <option value="0"></option>
                                            <option value="2">核保管理</option>
                                            <?php
//                                            if($order_info->return_status_id >= 3)
//                                                echo '<option value="3">送保单打印</option>';
//                                            if($order_info->return_status_id >= 4)
//                                                echo '<option value="4">配送调度</option>';
//                                            if($order_info->return_status_id >= 5)
//                                                echo '<option value="5">正本管理</option>';
//                                            if($order_info->return_status_id >= 6)
//                                                echo '<option value="6">正本打印</option>';
//                                            if($order_info->return_status_id >= 7)
//                                                echo '<option value="7">正本配送</option>';
//                                            if($order_info->return_status_id >= 8)
//                                                echo '<option value="8">正本配送</option>';
//                                            if($order_info->return_status_id >= 9)
//                                                echo '<option value="9">保单办结</option>';
                                            ?>
                                        </select>
                                        <?php
                                    }
                                    ?>
                                    <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>
<!--                        <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');
            }
        });
        gotoPage('/appointment/ajax-index?car_id=<?=$car_info->id?>&page=1&t='+Math.random(),'appointment_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');
            }
        });
        //读取联系人
        gotoPage('/car/ajax-linkman-index?car_id=<?=$car_info->id?>&t='+Math.random(),'linkman_list');
        $('#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();
            var  baoxiangs=$('#company2_id').val();
            var  smstel=$('#sms-tel').val();
//
//            alert(smsmsg);

            if(isNull(smstel)){
                alert('请填写电话号码');
                return ;
            }
            if(baoxiangs==0){
                alert('请选择保险公司');
                return ;
            }

            $.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();
            var  baoxiangs=$('#company2_id').val();
            var  smstel=$('#sms-tel').val();
            var  smsmsg=$('#sms-msg').val();

            if(smsmsg==''){
                alert('短信内容不能为空,请生成短信');
                return ;
            }
            if(isNull(smstel)){
                alert('请填写电话号码');
                return ;
            }
            if(baoxiangs==0){
                alert('请选择保险公司');
                return ;
            }

//            return;
            $.post('/car/sms-send',{tel:tel,msg:msg,company2_id:baoxiangs},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>