<?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">
<?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="order_id" value="<?=$order_info->id?>">
            <input type="hidden" name="celuo_id" value="<?=$order_info->celuo_id?>">
            <input type="hidden" name="fanxian_id" value="<?=$order_info->fanxian_id?>">
            <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><?=$order_info->car_no?></td>
                            <th class="bg-warning" nowrap>初登日期</th>
                            <td><?=$car_info->register_date?></td>
                            <th class="bg-warning" nowrap>座位数</th>
                            <td><?=$order_info->seats?></td>
                            <th class="bg-warning" nowrap>电子邮件</th>
                            <td><?=$order_info->email?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">车型</th>
                            <td><?=$order_info->factory_model?></td>
                            <th class="bg-warning" nowrap>发动机号</th>
                            <td><?=$order_info->engine_no?></td>
                            <th class="bg-warning" nowrap>车架号</th>
                            <td><?=$order_info->car_frame_no?></td>
                            <th class="bg-warning" nowrap>新车购置价</th>
                            <td><?=$order_info->purchase_price?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">车主</th>
                            <td><?=$order_info->car_man?></td>
                            <th class="bg-warning">证件类型</th>
                            <td><?=$order_info->car_man_type?></td>
                            <th class="bg-warning">证件号码</th>
                            <td><?=$order_info->car_man_number?></td>
                            <th class="bg-warning">联系电话</th>
                            <td><?=$order_info->car_man_phone?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">被投保人</th>
                            <td><?=$order_info->id_man?></td>
                            <th class="bg-warning">证件类型</th>
                            <td><?=$order_info->id_man_type?></td>
                            <th class="bg-warning">证件号码</th>
                            <td><?=$order_info->id_man_number?></td>
                            <th class="bg-warning">联系电话</th>
                            <td><?=$order_info->id_man_phone?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">投保人</th>
                            <td><?=$order_info->link_man?></td>
                            <th class="bg-warning">证件类型</th>
                            <td><?=$order_info->link_man_type?></td>
                            <th class="bg-warning">证件号码</th>
                            <td><?=$order_info->link_man_number?></td>
                            <th class="bg-warning">联系电话</th>
                            <td><?=$order_info->link_man_phone?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning" nowrap>商业起保日期</th>
                            <td><?=$order_info->insurer1_begin_date?></td>
                            <th class="bg-warning" nowrap>交强起保日期</th>
                            <td><?=$order_info->insurer2_begin_date?></td>
                            <th class="bg-warning">保险公司</th>
                            <td><?=$order_info->company->name?></td>
                            <th class="bg-warning">车辆使用性质</th>
                            <td><?=$order_info->car->carUse->name?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning" nowrap>商业保单号</th>
                            <td><?=$order_info->insurer1_no?></td>
                            <th class="bg-warning" nowrap>商业PDF文件</th>
                            <td>
                                <?php if($order_info->shangye_src != '') { ?>
                                    <a href="<?=$order_info->shangye_src?>"><i class="fa fa-image">保单</i></a>
                                <?php } ?>
                                <?php if($order_info->fapiao_src != '') { ?>
                                    <a href="<?=$order_info->fapiao_src?>"><i class="fa fa-file-pdf-o">发票</i></a>
                                <?php } ?>
                            </td>
                            <th class="bg-warning">交强保单号</th>
                            <td><?=$order_info->insurer2_no?></td>
                            <th class="bg-warning">交强PDF文件</th>
                            <td>
                                <?php if($order_info->jiaoqiang_src != '') { ?>
                                    <a href="<?=$order_info->jiaoqiang_src?>"><i class="fa fa-image">保单</i></a>
                                <?php } ?>
                                <?php if($order_info->jq_fapiao_src != '') { ?>
                                    <a href="<?=$order_info->jq_fapiao_src?>"><i class="fa fa-file-pdf-o">发票</i></a>
                                <?php } ?>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>险种</h5>
                </div>
                <div class="ibox-content">
                    <table class="table table-bordered">
                        <tr>
                            <?php
                            $len = count($insurer_type_items);
                            $index = 0;
                            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();
                                if(!$tmp_row || $tmp_row->val == '' || $tmp_row->val == '否') continue;
                                ?>
                                <th class="bg-warning">
                                    <?=$item->name?>(<?=$item->code?>)
                                </th>
                                <td><?=$tmp_row->val?></td>
                                <td><?=($tmp_row->is_nopay == 1)?'不计免赔':''?></td>
                                <?php
                                if(($index+1)%3==0) {
                                    echo '</tr>';
                                    echo '<tr>';
                                }
                                $index++;
                            }
                            ?>
                        </tr>
                    </table>
                </div>
            </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><?=$order_info->total1_clear?></td>
                            <th class="bg-warning">商业含税总保费</th>
                            <td><?=$order_info->total1?></td>
                            <th class="bg-warning">车船税</th>
                            <td><?=$order_info->total3?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">交强总净保费</th>
                            <td><?=$order_info->total2_clear?></td>
                            <th class="bg-warning">交强含税总保费</th>
                            <td><?=$order_info->total2?></td>
                            <th class="bg-warning">业务自付金额</th>
                            <td><?=$order_info->yuangong_money?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">折扣后商业净保费</th>
                            <td><?=$order_info->total1_real?></td>
                            <th class="bg-warning">减免金额</th>
                            <td><?=$order_info->total1_dis?></td>
                            <th class="bg-warning">商业折扣率</th>
                            <td><?=$order_info->total1_percent?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">共计签单</th>
                            <td><?=$order_info->total_all?></td>
                            <th class="bg-warning">应收</th>
                            <td><?=$order_info->total_real?></td>
                            <th class="bg-warning">支付方式</th>
                            <td><?=$order_info->payType ? $order_info->payType->name : ''?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">备注</th>
                            <td colspan="5"><?=$order_info->price_remark?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>礼券信息</h5>
                    <div class="ibox-tools">
                        <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="$('#giftTable').bootstrapTable('refresh');">
                            <i class="fa fa-refresh"></i> 刷新
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <table id="giftTable">
                        <thead>
                        <tr>
                            <th width="50" data-field="id">ID</th>
                            <th data-field="code">礼券编号</th>
                            <th data-field="name">礼品</th>
                            <th data-field="car_no">车牌号</th>
                            <th data-field="car_frame_no">车架号</th>
                            <th data-field="input_date">发放日期</th>
                            <th data-field="end_date">有效期日期</th>
                            <th data-field="submit_user">提单人</th>
                            <th data-field="use_date">使用日期1</th>
                            <th data-field="status">状态</th>
                            <th data-field="username">操作员</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </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><?=$order_info->money_man?></td>
                            <th class="bg-warning">开户行</th>
                            <td><?=$order_info->money_bank?></td>
                            <th class="bg-warning">银行账号</th>
                            <td><?=$order_info->money_no?></td>
                        </tr>
                        <tr>
                            <th class="bg-warning">送单地址</th>
                            <td colspan="5" class="form-inline">
                                <label><?=$order_info->sendCity?$order_info->sendCity->name:''?></label>
                                <label><?=$order_info->sendDistrict?$order_info->sendDistrict->name:''?></label>
                                <label><?=$order_info->send_address?></label>
                            </td>
                        </tr>
                        <tr>
                            <th class="bg-warning">备注</th>
                            <td colspan="5"><?=$order_info->remark?></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>操作记录</h5>
                    <div class="ibox-tools">
                        <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="$('#logTable').bootstrapTable('refresh');">
                            <i class="fa fa-refresh"></i> 刷新
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <table id="logTable">
                        <thead>
                        <tr>
                            <th data-field="op_man">操作者</th>
                            <th data-field="op_time">操作时间</th>
                            <th data-field="remark">操作内容</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <?php if($uid < 2 && $order_info->status_id > 1) {?>
            <div class="ibox float-e-margins">
                <div class="col-sm-5 col-sm-offset-4">
                    <button type="button" class="btn btn-primary btn-return" type="button">
                        <strong>退单</strong>
                    </button>
                </div>
            </div>
            <?php }?>
        </form>
    </div>


<?php $this->beginBlock('footer_js'); ?>
    <script src="/assets/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/assets/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/assets/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>
        var o = {};
        //判断是否填写了选项
        function isNull(data){
            if(data == "" || data == undefined || data == null){
                return true;
            }else{
                return false;
            }
        }
        function searchGifts() {
            $('#giftTable').bootstrapTable('destroy');
            $('#giftTable').bootstrapTable({
                url: "/gift/ticket-use-json",
                pagination: true,
                sidePagination: 'server',
                queryParams: function(params) {
                    o['order_id'] = '<?=$order_info->id?>';
                    o['limit'] = params['limit'];
                    o['offset'] = params['offset'];
                    return o;
                }
            });
            return false;
        }
        //保存订单
        function saveOrder(status_id) {
            var params = $('#orderFrm').serialize();
            params = params + '&status_id=' + status_id;
            $.post('/insurer/office-mng-save',params,function(obj){
                parent.layer.msg(obj.msg);
                if(obj.success && status_id>2) {
                    $('.btn-back').click();
                }
            },'json');
        }
        //操作记录
        function searchOps() {
            $('#logTable').bootstrapTable('destroy');
            $('#logTable').bootstrapTable({
                url: "/car/history-json",
                pagination: true,
                sidePagination: 'server',
                multipleSelectRow: true,
                queryParams: function(params) {
                    o['car_id'] = '<?=$order_info->car_id?>';
                    o['limit'] = params['limit'];
                    o['offset'] = params['offset'];
                    return o;
                }
            });
        }

        $(function() {
            searchOps();
            searchGifts();

            <?php if($uid < 2 && $order_info->status_id > 1) {?>
            layer.config({extend: 'extend/layer.ext.js'});
            $('.btn-return').click(function(){
                layer.prompt({
                    formType: 2,
                    title: '退单理由',
                }, function(value, index){
                    $.post('/insurer/supper-return',{
                        order_id:<?=$order_info->id?>,
                        return_remark:value,
                    },function(obj){
                        layer.alert(obj.msg,function () {
                            window.location.reload();
                        });
                    },'json');
                    layer.close(index);
                });
            });
            <?php }?>

            $('.btn-cancel').click(function(){
                parent.layer.confirm('是否确认放弃处理？', {
                    btn: ['确认','取消'], //按钮
                    shade: false //不显示遮罩
                }, function(){
                    var params = $("#theFrm").serialize();
                    $.post('/insurer/order-cancel-save',{order_id:<?=$order_info->id?>},function(obj){
                        parent.layer.msg(obj.msg);
                        if(obj.success) {
                            $('.btn-back').click();
                        }
                    },'json');
                }, function(){
                    //
                });
            });
            $('.btn-save').click(function(){
                saveOrder(2);
            });
            $('.btn-submit').click(function(){
                saveOrder(5);
            });
            $('.btn-back').click(function() {
                window.location.href = '/insurer/office-mng';
            });
        });
    </script>
<?php $this->endBlock(); ?>