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

?>
<?php $this->beginBlock('header_css'); ?>
    <link href="/assets/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/assets/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="/assets/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
<?php $this->endBlock(); ?>

    <div class="wrapper wrapper-content animated fadeInRight">
        <form class="form-horizontal" id="orderFrm">
            <input type="hidden" name="car_id" value="<?=$order_info->car_id?>">
            <input type="hidden" name="id" value="<?=$order_info->id?>">
            <input type="hidden" name="celuo_id" id="celuo_id" value="<?=$order_info->celuo_id?>">
            <input type="hidden" name="fanxian_id" id="fanxian_id" value="<?=$order_info->fanxian_id?>">
            <input type="hidden" name="auto_mold_code" id="auto_mold_code" value="">
            <input type="hidden" name="vehicle_year" id="vehicle_year" value="">
            <input type="hidden" name="min_chesun" id="min_chesun" value="">
            <input type="hidden" name="max_chesun" id="max_chesun" value="">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>保单信息</h5>
                </div>
                <div class="ibox-content">
                    <table class="table table-bordered">
                        <tr>
                            <th class="bg-warning">车牌号</th>
                            <td><input name="car_no" class="form-control" style="width:100%;" type="text" value="<?=$order_info->car_no!='' ? $order_info->car_no:$car_info->car_no?>"></td>
                            <th class="bg-warning" nowrap>初登日期</th>
                            <td><input name="register_date" class="form-control date" style="width:100%;" type="text" value="<?=$car_info->register_date?>"></td>
                            <th class="bg-warning" nowrap>座位数</th>
                            <td><input name="seats" id="seats" class="form-control" style="width:100%;" type="text" value="<?=$order_info->seats ? $order_info->seats:$car_info->seats?>"></td>
                            <th class="bg-warning" nowrap>电子邮件</th>
                            <td><input name="email" class="form-control" style="width:100%;" type="text" value="<?=$order_info->email?>"></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">车架号</th>
                            <td><input name="car_frame_no" class="form-control" style="width:100%;" type="text" value="<?=$order_info->car_frame_no!='' ? $order_info->car_frame_no:$car_info->car_frame_no?>"></td>
                            <th class="bg-warning" nowrap>发动机号</th>
                            <td><input name="engine_no" class="form-control date" style="width:100%;" type="text" value="<?=$order_info->engine_no!='' ? $order_info->engine_no:$car_info->engine_no?>"></td>
                            <th class="bg-warning" nowrap>厂牌型号</th>
                            <td><input name="factory_model" id="factory_model" class="form-control" style="width:100%;" type="text" value="<?=$order_info->factory_model!='' ? $order_info->factory_model:$car_info->factory_model?>"></td>
                            <th class="bg-warning" nowrap>新车购置价</th>
                            <td><input name="purchase_price" id="purchase_price" class="form-control" style="width:100%;" type="text" value="<?=$order_info->purchase_price!='' ? $order_info->purchase_price:$car_info->purchase_price?>"></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">车主</th>
                            <td><input name="car_man" class="form-control" style="width:100%;" type="text" value="<?=$order_info->car_man!='' ? $order_info->car_man:$car_info->car_man?>"></td>
                            <th class="bg-warning">证件类型</th>
                            <td>
                                <select name="car_man_type" class="form-control">
                                    <option value="身份证">身份证</option>
                                    <option value="营业执照">营业执照</option>
                                </select>
                            </td>
                            <th class="bg-warning" nowrap>证件号码</th>
                            <td><input name="car_man_number" class="form-control" style="width:100%;" type="text" value="<?=$order_info->car_man_number!='' ? $order_info->car_man_number:$car_info->car_man_number?>"></td>
                            <th class="bg-warning">联系电话</th>
                            <td><input name="car_man_phone" class="form-control" style="width:100%;" type="text" value="<?=$order_info->car_man_phone!='' ? $order_info->car_man_phone:$car_info->car_man_phone?>"></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">被保险人</th>
                            <td><input name="id_man" class="form-control" style="width:100%;" type="text" value="<?=$order_info->id_man!='' ? $order_info->id_man:$car_info->id_man?>"></td>
                            <th class="bg-warning">证件类型</th>
                            <td>
                                <select name="id_man_type" class="form-control">
                                    <option value="身份证">身份证</option>
                                    <option value="营业执照">营业执照</option>
                                </select>
                            </td>
                            <th class="bg-warning">证件号码</th>
                            <td><input name="id_man_number" class="form-control" style="width:100%;" type="text" value="<?=$order_info->id_man_number!='' ? $order_info->id_man_number:$car_info->id_man_number?>"></td>
                            <th class="bg-warning">联系电话</th>
                            <td><input name="id_man_phone" class="form-control" style="width:100%;" type="text" value="<?=$order_info->id_man_phone!='' ? $order_info->id_man_phone:$car_info->id_man_phone?>"></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">投保人</th>
                            <td><input name="link_man" class="form-control" style="width:100%;" type="text" value="<?=$order_info->link_man!='' ? $order_info->link_man:''?>"></td>
                            <th class="bg-warning">证件类型</th>
                            <td>
                                <select name="link_man_type" class="form-control">
                                    <option value="身份证">身份证</option>
                                    <option value="营业执照">营业执照</option>
                                </select>
                            </td>
                            <th class="bg-warning">证件号码</th>
                            <td><input name="link_man_number" class="form-control" style="width:100%;" type="text" value="<?=$order_info->link_man_number!='' ? $order_info->link_man_number:''?>"></td>
                            <th class="bg-warning">联系电话</th>
                            <td><input name="link_man_phone" class="form-control" style="width:100%;" type="text" value="<?=$order_info->link_man_phone!='' ? $order_info->link_man_phone:''?>"></td>
                        </tr>
                        <tr>
                            <th class="bg-warning" nowrap>商业起保日期</th>
                            <td>
                                <input type="text" id="insurer1_begin_date" name="insurer1_begin_date" class="form-control date" value="<?=$order_info->insurer1_begin_date?>" autocomplete="off">
                            </td>
                            <th class="bg-warning" nowrap>交强起保日期</th>
                            <td>
                                <input type="text" id="insurer2_begin_date" name="insurer2_begin_date" class="form-control date" value="<?=$order_info->insurer2_begin_date?>" autocomplete="off">
                            </td>
                            <th class="bg-warning">保险公司</th>
                            <td>
                                <select name="company_id" id="company_id" class="form-control">
                                    <option value="0">---请选择---</option>
                                    <?php
                                    foreach($insurer_company_items as $item) {
                                        echo '<option value="'.$item->id.'"';
                                        if($item->id == $order_info->company_id)
                                            echo ' selected ';
                                        echo '>'.$item->name.'</option>';
                                    }
                                    ?>
                                </select>
                            </td>
                            <th class="bg-warning">车辆使用性质</th>
                            <td class="form-inline" nowrap>
                                <select name="car_use_id" id="car_use_id" class="form-control">
                                    <option value="0">---请选择---</option>
                                    <?php
                                    foreach($car_use_items as $item) {
                                        echo '<option value="'.$item->id.'"';
                                        if($item->id == $order_info->car->car_use_id)
                                            echo ' selected ';
                                        echo '>'.$item->name.'</option>';
                                    }
                                    ?>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>险种</h5>
                <div class="ibox-tools">
                    <button type="button" class="btn btn-primary btn-xs" data-id="0" onclick="getCarInfo();">
                        <i class="fa fa-gift"></i> 获取去年险种信息
                    </button>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered">
                    <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();
                            ?>
                            <th class="bg-warning">
                                <?=$item->name?>(<?=$item->code?>)
                            </th>
                            <td>
                                <?php
                                if($item->content != '') {
                                    $tmp_items = explode(',',$item->content);
                                    echo '<select name="types['.$item->id.']" id="types_'.$item->id.'" class="form-control insurer-select" data-id="'.$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.']" id="types_'.$item->id.'" class="form-control insurer-input" data-id="'.$item->id.'" style="width:100px;" type="text"';
                                    if(!empty($tmp_row))
                                        echo ' value="'.$tmp_row->val.'" ';
                                    echo '>';
                                }
                                ?>
                            </td>
                            <td>
                                <?php if($item->has_nopay == 1) { ?>
                                <div class="checkbox checkbox-inline">
                                    <input type="checkbox" name="nopays[<?=$item->id?>]" id="nopays_<?=$item->id?>" value="1" <?=(!empty($tmp_row) && $tmp_row->is_nopay == 1)?'checked':''?>>
                                    <label for="nopays_<?=$item->id?>"> 不计免赔 </label>
                                </div>
                                <?php } ?>
                            </td>
                            <?php
                            if(($i+1)%3==0) {
                                echo '</tr>';
                                echo '<tr>';
                            }
                        }
                        ?>
                    </tr>
                </table>
            </div>
        </div>
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>
                    保费信息
                    <span id="total_rate" class="text-danger"></span>
                </h5>
                <div class="ibox-tools">
                    <button type="button" class="btn btn-primary btn-xs" onclick="getYingXiao();">
                        <i class="fa fa-gift"></i> 获取策略
                    </button>
                    <button type="button" class="btn btn-danger btn-xs" onclick="calInsurance();">
                        <i class="fa fa-calculator"></i> 获取算费结果
                    </button>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered">
                    <tr>
                        <th class="bg-warning">商业总净保费</th>
                        <td><input name="total1_clear" id="total1_clear" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total1_clear?>"></td>
                        <th class="bg-warning">商业含税总保费</th>
                        <td><input name="total1" id="total1" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total1?>"></td>
                        <th class="bg-warning">车船税</th>
                        <td><input name="total3" id="total3" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total3?>"></td>
                    </tr>
                    <tr>
                        <th class="bg-warning">交强总净保费</th>
                        <td><input name="total2_clear" id="total2_clear" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total2_clear?>"></td>
                        <th class="bg-warning">交强含税总保费</th>
                        <td><input name="total2" id="total2" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total2?>"></td>
                        <th class="bg-warning">业务自付金额</th>
                        <td><input name="yuangong_money" id="yuangong_money" class="form-control" style="width:120px;" type="text" value="<?=$order_info->yuangong_money?>"></td>
                    </tr>
                    <tr>
                        <th class="bg-warning">折扣后商业净保费</th>
                        <td><input name="total1_real" id="total1_real" class="form-control" readonly style="width:120px;" type="text" value="<?=$order_info->total1_real?>"></td>
                        <th class="bg-warning">减免金额</th>
                        <td><input name="total1_dis" id="total1_dis" class="form-control" readonly style="width:120px;" type="text" value="<?=$order_info->total1_dis?>"></td>
                        <th class="bg-warning">商业折扣率</th>
                        <td><input name="total1_percent" id="total1_percent" class="form-control" readonly style="width:120px;" type="text" value="<?=$order_info->total1_percent?>"></td>
                    </tr>
                    <tr>
                        <th class="bg-warning">共计签单</th>
                        <td><input name="total_all" id="total_all" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total_all?>"></td>
                        <th class="bg-warning">应收</th>
                        <td><input name="total_real" id="total_real" class="form-control" style="width:120px;" type="text" value="<?=$order_info->total_real?>"></td>
                        <th class="bg-warning">支付方式</th>
                        <td>
                            <select name="pay_type_id" id="pay_type_id" class="form-control">
                                <option value="0">---请选择---</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>
                    </tr>
                    <tr>
                        <th class="bg-warning">备注</th>
                        <td colspan="5"><input name="price_remark" id="price_remark" class="form-control" style="width:100%;" type="text" value="<?=$order_info->price_remark?>"></td>
                    </tr>
                    <tr>
                        <th class="bg-warning">短信</th>
                        <td colspan="5">
                            <div class="row">
                                <div class="col-sm-12">
                                    <textarea name="sms-msg" id="sms-msg" class="form-control"></textarea>
                                </div>
                            </div>
                            <div class="row" style="margin-top: 8px;">
                                <div class="col-sm-12 form-inline">
                                    <label>手机号码</label>
                                    <input type="text" name="sms-tel" id="sms-tel" class="form-control">
                                    <button type="button" class="btn btn-primary sms-make-btn">生成短信</button>
                                    <button type="button" class="btn btn-danger sms-send-btn">发送短信</button>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
            <div id="gifts">
            </div>
            <div id="quans">
            </div>
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>其他信息</h5>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered">
                    <tr>
                        <th class="bg-warning">领款人</th>
                        <td><input name="money_man" class="form-control" style="width:100%;" type="text" value="<?=$order_info->money_man?>"></td>
                        <th class="bg-warning">开户行</th>
                        <td><input name="money_bank" class="form-control" style="width:100%;" type="text" value="<?=$order_info->money_bank?>"></td>
                        <th class="bg-warning">银行账号</th>
                        <td><input name="money_no" class="form-control" style="width:100%;" type="text" value="<?=$order_info->money_no?>"></td>
                    </tr>
                    <tr>
                        <th class="bg-warning">送单地址</th>
                        <td colspan="5" class="form-inline">
                            <select name="send_city_id" class="form-control">
                                <option value="0">选择城市</option>
                                <?php
                                foreach($city_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($order_info->send_city_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                            <select name="send_district_id" class="form-control">
                                <option value="0">选择区县</option>
                                <?php
                                foreach($district_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($order_info->send_district_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                            <input type="text" name="send_address" class="form-control" style="width:70%;" value="<?=$order_info->send_address?>">
                        </td>
                    </tr>
                    <tr>
                        <th class="bg-warning">备注</th>
                        <td colspan="7"><input name="order_remark" class="form-control" style="width:100%;" type="text" value="<?=$order_info->remark?>"></td>
                    </tr>
                </table>
                <div>
                    <div class="row">
                        <div class="col-sm-5 col-sm-offset-5">
                            <button type="button" class="btn btn-primary btn-save" type="button">
                                <strong>保 存</strong>
                            </button>
                            <button type="button" class="btn btn-primary btn-submit" type="button">
                                <strong>提 交</strong>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </form>
    </div>


<?php $this->beginBlock('footer_js'); ?>
    <script src="/assets/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script>
        var o = {};
        var fanxian_rate = 0, max_fanxian = 0;
        //获取险种信息
        function getCarInfo() {
            $.get('/car/bihu-carinfo?id=<?=$car_info->id?>',function(obj) {
                console.log(obj);
                if(obj.code == 200) {
                    if(obj.data && obj.data.UserInfo) {
                        if(obj.data.UserInfo.NextBusinessStartDate) {
                            $('#insurer1_begin_date').val(obj.data.UserInfo.NextBusinessStartDate);
                        }
                        if(obj.data.UserInfo.NextForceStartDate) {
                            $('#insurer2_begin_date').val(obj.data.UserInfo.NextForceStartDate);
                        }
                        if(obj.data.UserInfo.CarUsedType) {
                            $('#car_use_id').val(parseInt(obj.data.UserInfo.CarUsedType));
                        }
                    }
                    if(obj.data && obj.data.SaveQuote) {
                        if(obj.data.SaveQuote.BoLi) {
                            if(obj.data.SaveQuote.BoLi == '0') $('#types_6').val('');
                            if(obj.data.SaveQuote.BoLi == '1') $('#types_6').val('国产');
                            if(obj.data.SaveQuote.BoLi == '2') $('#types_6').val('进口');
                        }
                        if(obj.data.SaveQuote.BuJiMianCheSun) {
                            if(obj.data.SaveQuote.BuJiMianCheSun == "0") $('#nopays_1').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianCheSun == "1") $('#nopays_1').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianChengKe) {
                            if(obj.data.SaveQuote.BuJiMianChengKe == "0") $('#nopays_5').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianChengKe == "1") $('#nopays_5').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianDaoQiang) {
                            if(obj.data.SaveQuote.BuJiMianDaoQiang == "0") $('#nopays_3').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianDaoQiang == "1") $('#nopays_3').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianHuaHen) {
                            if(obj.data.SaveQuote.BuJiMianHuaHen == "0") $('#nopays_7').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianHuaHen == "1") $('#nopays_7').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianSanZhe) {
                            if(obj.data.SaveQuote.BuJiMianSanZhe == "0") $('#nopays_2').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianSanZhe == "1") $('#nopays_2').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianSheShui) {
                            if(obj.data.SaveQuote.BuJiMianSheShui == "0") $('#nopays_8').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianSheShui == "1") $('#nopays_8').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianSiJi) {
                            if(obj.data.SaveQuote.BuJiMianSiJi == "0") $('#nopays_4').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianSiJi == "1") $('#nopays_4').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.BuJiMianZiRan) {
                            if(obj.data.SaveQuote.BuJiMianZiRan == "0") $('#nopays_9').prop('checked', '');
                            if(obj.data.SaveQuote.BuJiMianZiRan == "1") $('#nopays_9').prop('checked', 'checked');
                        }
                        if(obj.data.SaveQuote.CheSun) {
                            $('#types_1').val(obj.data.SaveQuote.CheSun);
                        }
                        if(obj.data.SaveQuote.DaoQiang) {
                            if(parseInt(obj.data.SaveQuote.DaoQiang) > 0) $('#types_3').val('是');
                            else $('#types_3').val('否');
                        }
                        if(obj.data.SaveQuote.ChengKe) {
                            if(obj.data.SaveQuote.ChengKe == "10000") $('#types_5').val('1万');
                            if(obj.data.SaveQuote.ChengKe == "20000") $('#types_5').val('2万');
                            if(obj.data.SaveQuote.ChengKe == "30000") $('#types_5').val('3万');
                            if(obj.data.SaveQuote.ChengKe == "40000") $('#types_5').val('4万');
                            if(obj.data.SaveQuote.ChengKe == "50000") $('#types_5').val('5万');
                            if(obj.data.SaveQuote.ChengKe == "100000") $('#types_5').val('10万');
                        }
                        if(obj.data.SaveQuote.SiJi) {
                            if(obj.data.SaveQuote.SiJi == "10000") $('#types_4').val('1万');
                            if(obj.data.SaveQuote.SiJi == "20000") $('#types_4').val('2万');
                            if(obj.data.SaveQuote.SiJi == "30000") $('#types_4').val('3万');
                            if(obj.data.SaveQuote.SiJi == "40000") $('#types_4').val('4万');
                            if(obj.data.SaveQuote.SiJi == "50000") $('#types_4').val('5万');
                            if(obj.data.SaveQuote.SiJi == "100000") $('#types_4').val('10万');
                        }
                        if(obj.data.SaveQuote.HcSanFangTeYue) {
                            if(obj.data.SaveQuote.HcSanFangTeYue == "1") $('#types_12').val('是');
                            else $('#types_12').val('否');
                        }
                        if(obj.data.SaveQuote.HuaHen) {
                            if(obj.data.SaveQuote.HuaHen == "2000") $('#types_7').val('2000元');
                            if(obj.data.SaveQuote.HuaHen == "5000") $('#types_7').val('5000元');
                            if(obj.data.SaveQuote.HuaHen == "10000") $('#types_7').val('10000元');
                            if(obj.data.SaveQuote.HuaHen == "20000") $('#types_7').val('20000元');
                        }
                        if(obj.data.SaveQuote.SanZhe) {
                            if(obj.data.SaveQuote.SanZhe == "50000") $('#types_2').val('5万');
                            if(obj.data.SaveQuote.SanZhe == "100000") $('#types_2').val('10万');
                            if(obj.data.SaveQuote.SanZhe == "150000") $('#types_2').val('15万');
                            if(obj.data.SaveQuote.SanZhe == "200000") $('#types_2').val('20万');
                            if(obj.data.SaveQuote.SanZhe == "300000") $('#types_2').val('30万');
                            if(obj.data.SaveQuote.SanZhe == "500000") $('#types_2').val('50万');
                            if(obj.data.SaveQuote.SanZhe == "1000000") $('#types_2').val('100万');
                            if(obj.data.SaveQuote.SanZhe == "1500000") $('#types_2').val('150万');
                            if(obj.data.SaveQuote.SanZhe == "2000000") $('#types_2').val('200万');
                        }
                        if(obj.data.SaveQuote.SheShui) {
                            if(obj.data.SaveQuote.SheShui == "1") $('#types_8').val('是');
                            else $('#types_8').val('否');
                        }
                        if(obj.data.SaveQuote.ZiRan) {
                            if(parseInt(obj.data.SaveQuote.ZiRan) > 0) $('#types_9').val('是');
                            else $('#types_9').val('否');
                        }
                    }
                    if(obj.data && obj.data.VehicleItems && obj.data.VehicleItems[0]) {
                        if(obj.data.VehicleItems[0].VehicleNo) {
                            $('#auto_mold_code').val(obj.data.VehicleItems[0].VehicleNo);
                        }
                        if(obj.data.VehicleItems[0].VehicleYear) {
                            $('#vehicle_year').val(obj.data.VehicleItems[0].VehicleYear);
                        }
                        if(obj.data.VehicleItems[0].VehicleName) {
                            $('#factory_model').val(obj.data.VehicleItems[0].VehicleName);
                        }
                        if(obj.data.VehicleItems[0].PurchasePrice) {
                            $('#purchase_price').val(obj.data.VehicleItems[0].PurchasePrice);
                        }
                        if(obj.data.VehicleItems[0].DepreciationPrice) {
                            $('#types_1').val(obj.data.VehicleItems[0].DepreciationPrice);
                            $('#min_chesun').val(obj.data.VehicleItems[0].DownPrice);
                            $('#max_chesun').val(obj.data.VehicleItems[0].UpPrice);
                        }
                        if(obj.data.VehicleItems[0].VehicleSeat) {
                            $('#seats').val(obj.data.VehicleItems[0].VehicleSeat);
                        }
                    }
                } else {
                    parent.layer.msg(obj.msg);
                }
            }, 'json');
        }
        //算费
        function calInsurance() {
            var index = parent.layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var params = $('#orderFrm').serialize();
            $.post('/car/post-precise-price', params, function(obj) {
                if(obj.code == 200) {
                    $.post('/car/get-precise-price', params, function(obj) {
                        console.log(obj);
                        parent.layer.close(index);
                        if(obj.code == 200) {
                            if(obj.data && obj.data.QuoteStatus > 0) {
                                parent.layer.msg('获取成功');
                                $('#total1').val(obj.data.BizTotal.toFixed(2));
                                $('#total1_clear').val(($('#total1').val()/1.06).toFixed(2));
                                $('#total2').val(obj.data.ForceTotal.toFixed(2));
                                $('#total2_clear').val(($('#total2').val()/1.06).toFixed(2));
                                $('#total3').val(obj.data.TaxTotal.toFixed(2));
                                $('#total_rate').html('折扣系数:' + (obj.data.TotalRate * 100).toFixed(2) + '%');
                                calc();
                            } else {
                                if(obj.data) {
                                    parent.layer.msg(obj.data.QuoteResult);
                                } else {
                                    parent.layer.msg('数据为空');
                                }
                            }
                        } else {
                            parent.layer.msg(obj.msg);
                        }
                    }, 'json');
                } else {
                    parent.layer.close(index);
                    parent.layer.msg(obj.msg);
                }
            }, 'json');
        }
        //获取策略
        function getYingXiao() {
            var params = $('#orderFrm').serialize();
            $.post('/marketing-strategy/get-yingxiao', params, function(obj) {
                if(obj.success) {
                    $('#celuo_id').val(obj.celuo_id);
                    // if(obj.num > 1) {
                        layer_show('选择策略', '/marketing-strategy/select-fanxian?ids=' + obj.ids);
                    // } else {
                    //     selectFanxian(obj.ids);
                    // }
                } else {
                    parent.layer.msg(obj.msg);
                }
            }, 'json');
        }
        function selectFanxian(fanxian_id) {
            $('#fanxian_id').val(fanxian_id);
            getGifts(fanxian_id);
            $.get('/marketing-strategy/get-fanxian?fanxian_id=' + fanxian_id, function(obj) {
                if(obj.success) {
                    fanxian_rate = obj.fanxian_rate;
                    max_fanxian = obj.max_fanxian;
                    calc();
                }
            }, 'json');
        }
        function getGifts(fanxian_id) {
            $('#gifts').html('');
            $.get('/marketing-strategy/get-gifts?type=1&order_id=<?=$order_info->id?>&fanxian_id=' + fanxian_id, function(obj){
                if(obj.success) {
                    var html = '<div class="ibox float-e-margins">';
                    html += '<div class="ibox-title">';
                    html += '<h5>礼品</h5>';
                    html += '</div>';
                    html += '<div class="ibox-content">';
                    obj.gifts.forEach(function(item, index) {
                        html += '<table class="table table-bordered">';
                        html += '<tr>';
                        html += '<th class="bg-warning">' + item.free_type + '</th>';
                        html += '</tr>';
                        html += '<tr>';
                        html += '<td>';
                        item.gifts.forEach(function(sub_item, sub_index) {
                            html += '<div class="checkbox checkbox-inline">';
                            html += '<input type="checkbox" id="gift_' + item.id + '_' + sub_item.id + '" name="gift_ids[]" value="' + item.id + '-' + sub_item.id + '"';
                            if(sub_item.selected == 1)
                                html += ' checked ';
                            html += '>';
                            html += '<label for="gift_' + item.id + '_' + sub_item.id + '">' + sub_item.name + '</label>';
                            html += '&nbsp;<a href="' + sub_item.original_img + '"  target="_blank" title="预览"> <i class="fa fa-image"></i> </a>';
                            html += '</div>';
                        });
                        html += '</td>';
                        html += '</tr>';
                        html += '</table>';
                    });
                    html += '</div>';
                    html += '</div>';
                    $('#gifts').html(html);
                } else {
                    // parent.layer.msg(obj.msg);
                }
            }, 'json');
            $('#quans').html('');
            $.get('/marketing-strategy/get-gifts?type=2&order_id=<?=$order_info->id?>&fanxian_id=' + fanxian_id, function(obj){
                if(obj.success) {
                    var html = '<div class="ibox float-e-margins">';
                    html += '<div class="ibox-title">';
                    html += '<h5>礼券</h5>';
                    html += '</div>';
                    html += '<div class="ibox-content">';
                    obj.gifts.forEach(function(item, index) {
                        html += '<table class="table table-bordered">';
                        html += '<tr>';
                        html += '<th class="bg-warning">' + item.free_type + '</th>';
                        html += '</tr>';
                        html += '<tr>';
                        html += '<td>';
                        item.gifts.forEach(function(sub_item, sub_index) {
                            html += '<div class="checkbox checkbox-inline">';
                            html += '<input type="checkbox" id="gift_' + item.id + '_' + sub_item.id + '" name="gift_ids[]" value="' + item.id + '-' + sub_item.id + '"';
                            if(sub_item.selected == 1)
                                html += ' checked ';
                            html += '>';
                            html += '<label for="gift_' + item.id + '_' + sub_item.id + '">' + sub_item.name + '</label>';
                            html += '&nbsp;<a href="' + sub_item.original_img + '"  target="_blank" title="预览"> <i class="fa fa-image"></i> </a>';
                            html += '</div>';
                        });
                        html += '</td>';
                        html += '</tr>';
                        html += '</table>';
                    });
                    html += '</div>';
                    html += '</div>';
                    $('#quans').html(html);
                } else {
                    //parent.layer.msg(obj.msg);
                }
            }, 'json');
        }
        //判断是否填写了选项
        function isNull(data){

            if(data == "" || data == undefined || data == null){
                return true;
            }else{
                return false;
            }
        }
        //报价计算
        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());
            var yuangong_money = Number($('#yuangong_money').val());
            total_all = total1 + total2 + total3;
            total1_real = total1_clear * ( 1 - fanxian_rate) - yuangong_money;
            total1_dis = total1_clear * fanxian_rate;
            total_real = total_all - total1_dis - yuangong_money;
            total1_percent = parseFloat(total1_real/total1_clear);
            $('#total1_real').val(total1_real.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 params = $('#orderFrm').serialize();
            params = params + '&status_id=' + status_id;
            $.post('/car/order-save',params,function(obj){
                parent.layer.msg(obj.msg);
                if(obj.success && status_id>1) {
                    layer_close();
                }
            },'json');
        }

        $(function() {
            //绑定日期控件
            $('.date').datepicker({
                todayBtn: "linked",
                keyboardNavigation: false,
                forceParse: false,
                calendarWeeks: true,
                autoclose: true
            });
            //险种选择框事件
            $('.insurer-select').change(function() {
                var id = $(this).data('id');
                var val = $(this).val();
                if(val !== '否') {
                    $('#nopays_' + id).prop('checked', 'checked');
                } else {
                    $('#nopays_' + id).prop('checked', '');
                }
            });
            //险种输入框事件
            $('.insurer-input').change(function() {
                var id = $(this).data('id');
                var val = $(this).val();
                if(val !== '') {
                    $('#nopays_' + id).prop('checked', 'checked');
                } else {
                    $('#nopays_' + id).prop('checked', '');
                }
            });

            getGifts(<?=$order_info->fanxian_id?>);
            $('#total1_clear').blur(function(){
                $('#total1').val(($(this).val() * 1.06).toFixed(2));
                calc();
            });
            $('#total1').blur(function(){
                $('#total1_clear').val(($(this).val()/1.06).toFixed(2));
                calc();
            });
            $('#total2_clear').blur(function(){
                $('#total2').val(($(this).val() * 1.06).toFixed(2));
                calc();
            });
            $('#total2').blur(function(){
                $('#total2_clear').val(($(this).val()/1.06).toFixed(2));
                calc();
            });
            $('#yuangong_money').blur(function(){
                calc();
            });
            $('#total3').blur(function(){
                calc();
            });
            //生成短信内容
            $('.sms-make-btn').click(function(){
                var params = $('#orderFrm').serialize();
                var  baoxiangs=$('#company_id').val();
                var  smstel=$('#sms-tel').val();

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

                $.post('/car/sms-make',params,function(obj){
                    if(obj.success) {
                        $('#sms-msg').val(obj.msg);
                    } else {
                        parent.layer.msg(obj.msg);
                    }
                },'json');
            });
            //发送短信内容
            $('.sms-send-btn').click(function(){
                var tel = $('#sms-tel').val();
                var msg = $('#sms-msg').val();
                var  baoxiangs=$('#company_id').val();
                var  smstel=$('#sms-tel').val();
                var  smsmsg=$('#sms-msg').val();

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

//            return;
                $.post('/car/sms-send',{tel:tel,msg:msg,company_id:baoxiangs},function(obj){
                    parent.layer.msg(obj.msg);
                },'json');
            });
            $('.btn-save').click(function(){
                saveOrder(1);
            });
            $('.btn-submit').click(function(){
                saveOrder(2);
            });
        });
    </script>
<?php $this->endBlock(); ?>