<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link href="/assets/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<style>
    label.control-label {
        width: 70px;
    }

    .form-inline .form-control {
        width: 180px;
    }
</style>
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>维修信息</h5>
            <div class="ibox-tools">
                <a class="btn btn-primary btn-xs btn-save" data-id="0" href="javascript:void(0);" onclick="saveMyList(0)">
                    <i class="fa fa-save"></i> 保存
                </a>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="history.go(-1)">
                    <i class="fa fa-backward"></i> 返回
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <form role="form" class="form-inline" id="theFrm">
                        <input type="hidden" name="id" id="id" value="<?=$info->id?>" />
                        <input type="hidden" name="car_id" value="<?=$info->car_id?>" />
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">车牌号</label>
                            <input type="text" name="car_no" value="<?=$info->car_no?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">发动机号</label>
                            <input type="text" name="engine_no" value="<?=$info->engine_no?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">车架号</label>
                            <input type="text" name="car_frame_no" value="<?=$info->car_frame_no?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">事故类型</label>
                            <select name="accident_type" id="accident_type" class="form-control">
                                <option><?=$info->accident_type?></option>
                                <option>单方</option>
                                <option>双方</option>
                                <option>多方</option>
                                <option>自费维修</option>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">被保险人</label>
                            <input type="text" name="id_man" value="<?=$info->id_man?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">电话</label>
                            <input type="text" name="id_phone" value="<?=$info->id_phone?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">联系人</label>
                            <input type="text" name="link_man" value="<?=$info->link_man?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">电话</label>
                            <input type="text" name="link_phone" value="<?=$info->link_phone?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">保险公司</label>
                            <input type="text" name="company" value="<?=$info->company?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">接车日期</label>
                            <input type="text" class="input-date form-control" id="receive_date" name="receive_date" autocomplete="off" value="<?=substr($info->receive_date,0,10)?>" />
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">交车方式</label>
                            <select name="receive_type" id="receive_type" class="form-control">
                                <option><?=$info->receive_type?></option>
                                <option>上门接车</option>
                                <option>客户自送</option>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">责任</label>
                            <select name="responsibility" id="responsibility" class="form-control">
                                <option><?=$info->responsibility?></option>
                                <option>全责</option>
                                <option>无责</option>
                                <option>主要责任</option>
                                <option>次要责任</option>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">品牌</label>
                            <select name="brand_id" id="brand_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($brand_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($info->brand_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">车系</label>
                            <select name="series_id" id="series_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($series_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($info->series_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">排量</label>
                            <select name="displacement_id" id="displacement_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($displacement_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($info->displacement_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">年份</label>
                            <input type="text" name="car_year" value="<?=$info->car_year?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">商业保单号</label>
                            <input type="text" name="insurer1_no" value="<?=$info->insurer1_no?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">交强保单号</label>
                            <input type="text" name="insurer2_no" value="<?=$info->insurer2_no?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">险项</label>
                            <input type="text" name="insurer_type" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">新车购置价</label>
                            <input type="text" name="new_price" value="<?=$info->new_price?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">方位</label>
                            <select name="direction_id" id="direction_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($direction_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($info->direction_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">范围</label>
                            <select name="range_id" id="range_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($range_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($info->range_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">地址</label>
                            <input type="text" name="address" value="<?=$info->address?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">范围</label>
                            <select name="range_id" id="range_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($range_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($info->range_id == $item->id)
                                        echo ' selected ';
                                    echo '>'.$item->name.'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">代步车</label>
                            <select name="replace_car_id" id="replace_car_id" class="form-control">
                                <option value="0">无代步车</option>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">接车司机</label>
                            <select name="driver_id" id="driver_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach($driver_items as $item) {
                                    echo '<option value="'.$item->id.'"';
                                    if($item->id == $info->driver_id)
                                        echo ' selected ';
                                    echo '>'.$item->getShowName().'</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">接车里程数</label>
                            <input type="text" name="receive_mileage" value="<?=$info->receive_mileage?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">接车油表数</label>
                            <input type="text" name="receive_oil" value="<?=$info->receive_oil?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">进厂里程数</label>
                            <input type="text" name="factory_mileage" value="<?=$info->factory_mileage?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">进厂油表数</label>
                            <input type="text" name="factory_oil" value="<?=$info->factory_oil?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">预计出厂时间</label>
                            <input type="text" class="input-date form-control" id="finish_date" name="finish_date" autocomplete="off" value="<?=substr($info->finish_date,0,10)?>" />
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">报案号</label>
                            <input type="text" name="report_no" value="<?=$info->report_no?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">报案人</label>
                            <input type="text" name="baoan_man" value="<?=$info->baoan_man?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">报案时间</label>
                            <input type="text" class="input-date form-control" id="baoan_time" name="baoan_time" autocomplete="off" value="<?=substr($info->baoan_time,0,10)?>" />
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">出险时间</label>
                            <input type="text" class="input-date form-control" id="chuxian_time" name="chuxian_time" autocomplete="off" value="<?=substr($info->chuxian_time,0,10)?>" />
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">出险地点</label>
                            <input type="text" name="baoan_address" value="<?=$info->baoan_address?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">事故描述</label>
                            <input type="text" name="shigu_info" value="<?=$info->shigu_info?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">理赔公司</label>
                            <input type="text" name="lipei_company" value="<?=$info->lipei_company?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">主车定损金额</label>
                            <input type="text" name="zhuche_money" value="<?=$info->zhuche_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">三者外修</label>
                            <input type="text" name="sanzhe_money" value="<?=$info->sanzhe_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">物损</label>
                            <input type="text" name="wusun_money" value="<?=$info->wusun_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">拖车</label>
                            <input type="text" name="tuoche" value="<?=$info->tuoche?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">拖车费用</label>
                            <input type="text" name="tuoche_money" value="<?=$info->tuoche_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">定损工时费</label>
                            <input type="text" name="dingsun_hour_money" value="<?=$info->dingsun_hour_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">定损换件费</label>
                            <input type="text" name="dingsun_huanjian_money" value="<?=$info->dingsun_huanjian_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">赔付比例</label>
                            <input type="text" name="peifu_bili" value="<?=$info->peifu_bili?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">赔付金额</label>
                            <input type="text" name="peifu_money" value="<?=$info->peifu_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-3" style="margin-bottom: 8px;">
                            <label class="control-label">客户自付</label>
                            <input type="text" name="kehu_money" value="<?=$info->kehu_money?>" class="form-control">
                        </div>
                        <div class="form-group col-sm-12" style="margin-bottom: 8px;">
                            <label class="control-label">备注</label>
                            <textarea class="form-control" name="remark" id="remark"><?=$info->remark?></textarea>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>礼品列表</h5>
            <div class="ibox-tools">
                <a class="btn btn-primary btn-xs btn-save" data-id="0" href="javascript:void(0);" onclick="myListGiftSave(0)">
                    <i class="fa fa-save"></i> 保存
                </a>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="history.go(-1)">
                    <i class="fa fa-backward"></i> 返回
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <form id="giftFrm" class="col-sm-12">
                    <table id="listTable">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="gift.name">礼品名称</th>
                            <th data-field="gift.type_id" data-formatter="typeFormatter">类型</th>
                            <th data-field="gift.remark">描述</th>
                            <th data-field="strategy_id" data-formatter="strategyFormatter">分类</</th>
                            <th data-field="user" data-formatter="showNameFormatter">添加者</th>
                            <th data-field="submit_time"data-formatter="dateFormatter">操作时间</th>
                            <th data-field="status" data-formatter="statusFormatter">状态</th>
                        </tr>
                        </thead>
                    </table>
                </form>
            </div>
        </div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>保险理赔</h5>
        </div>
        <div id="list3" class="ibox-content"></div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>自费维修</h5>
        </div>
        <div id="list4" class="ibox-content"></div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>汽车保养</h5>
        </div>
        <div id="list5" class="ibox-content"></div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>汽车美容</h5>
        </div>
        <div id="list6" class="ibox-content"></div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>操作记录</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <table id="listTable2">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="op_man">姓名</th>
                            <th data-field="op_time" data-formatter="dateFormatter">操作时间</th>
                            <th data-field="info">意见</th>
                            <th data-field="remark">意见说明</</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-title fixed">
            <h5>审核意见</h5>
            <div class="ibox-tools">
                <?php
                    if($info->status > 0) {
                ?>
                    <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="returnBack(0)">
                        <i class="fa fa-plus"></i> 退回
                    </a>
                <?php
                    }
                ?>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="addInfo(0)">
                    <i class="fa fa-plus"></i> 维修明细
                </a>
                <?php
                    if($info->status > 0 && $info->status < 4) {
                ?>
                    <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="printInfo(0)">
                        <i class="fa fa-plus"></i> 打印接车单
                    </a>
                <?php
                    }
                ?>
                <?php
                    if($info->status != 5) {
                ?>
                    <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="saveSysInfo(0)">
                        <i class="fa fa-save"></i> 提交
                    </a>
                <?php
                    }
                ?>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="goBack()">
                    <i class="fa fa-backward"></i> 返回
                </a>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <form role="form" class="form-horizontal data-from" id="otherFrm">
                    <div class="form-group" style="margin-bottom: 8px;">
                        <div class="col-sm-12">
                            <textarea class="form-control" name="sys_remark" id="sys_remark"></textarea>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</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 type="text/javascript" language="javascript">
    $(function () {
        $('.input-date').datepicker({
            keyboardNavigation: false,
            forceParse: false,
            autoclose: true
        });

        $('#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-fix',{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/displacements-fix',{series_id:series_id},function(obj){
                    if(obj.success) {
                        $('#displacement_id').html(obj.html);
                    }
                },'json');
            }
        });

        reloadItems();
        myListGift();
        myListLog();
    });

    // 刷新明细
    // 动态加载html
    function reloadItems() {
        var id = $('#id').val();
        var lists = {
            'list3': '/fix-car/ajax-item-list?fix_id=' + id + '&big_type_id=1',
            'list4': '/fix-car/ajax-item-list?fix_id=' + id + '&big_type_id=2',
            'list5': '/fix-car/ajax-item-list?fix_id=' + id + '&big_type_id=3',
            'list6': '/fix-car/ajax-item-list?fix_id=' + id + '&big_type_id=4',
        };
        if(id > 0) {
            $.each(lists,function(i,d){
                $.get(d,{},function(res){
                    console.log(res);
                    if(res.code == 200){
                        renderData(res.data, i);
                    }else {
                        alert(res.msg)
                    }
                },'json');
            })
        }
    }

    function renderData(data, id) {
        var html = '';
        var table_data = [];
        $.each(data,function(name,item){
            if (item[1].length) {
                table_data[name] = item[1];
                html += '<div class="ibox float-e-margins">' +
                    '    <div class="ibox-title">' +
                    '        <h5>'+ item[0] +'</h5>' +
                    '    </div>' +
                    '    <div class="ibox-content">' +
                    '        <div class="row">' +
                    '            <div class="col-sm-12">' +
                    '                <table id="'+ id + '_' + name +'_table" data-name="'+ name +'">' +
                    '                    <thead>' +
                    '                    <tr>' +
                    '                        <th data-field="id">ID</th>' +
                    '                        <th data-field="name">名称</th>' +
                    '                        <th data-field="price">价格</th>' +
                    '                        <th data-field="count">数量</th>' +
                    '                        <th data-field="total">合计</th>' +
                    '                        <th data-field="">结算方式</th>' +
                    '                        <th data-field="">实收</th>' +
                    '                        <th data-field="type">分类</th>' +
                    '                        <th data-field="">维修人</th>' +
                    '                        <th data-field="fix_remark">备注</th>' +
                    '                    </tr>' +
                    '                    </thead>' +
                    '                </table>' +
                    '            </div>' +
                    '        </div>' +
                    '    </div>' +
                    '</div>';
            }
        });
        $('#'+ id).html(html).find('table').each(function(i,target){
            $(target).bootstrapTable("destroy");
            $(target).bootstrapTable({
                data: table_data[$(target).data('name')],
                pagination: false,
                queryParams: function (params) {
                    return params;
                }
            });
        }).show();
    }

    // 保存维修信息
    function saveMyList(){
        if(confirm('是否确认提交?')) {
            var params = $("#theFrm").serialize();
            params = params + '&status=<?=$info->status?>';
            $.post('/fix-car/my-list-save',params,function(obj){
                alert(obj.msg);
                if(obj.success) {
                    $('#id').val(obj.fix_id);
                }
            },'json');
        }
    }

    // 礼品信息
    function myListGift() {
        $('#listTable').bootstrapTable('destroy');
        $('#listTable').bootstrapTable({
            data: <?=json_encode($gift_items)?>,
            pagination: true,
            sidePagination: 'server',
            queryParams: function(params) {
                console.log(params);
                return params;
            }
        });
        return false;
    }

    function myListGiftSave(){
        var id = $('#id').val();
        if(id > 0) {
            var params = $("#giftFrm").serialize();
            params = params + '&id=' + id;
            $.post('/fix-car/gift-save',params,function(obj){
                alert(obj.msg);
            },'json');
        } else {
            alert('请先保存维修信息');
        }
    }

    // 操作记录
    function myListLog(){
        $('#listTable2').bootstrapTable('destroy');
        $('#listTable2').bootstrapTable({
            data: <?=json_encode($log_items)?>,
            pagination: true,
            sidePagination: 'server',
            queryParams: function(params) {
                return params;
            }
        });
        return false;
    }

    // 审核意见
    function saveSysInfo(){
        var id = $('#id').val();
        var sys_remark = $('#sys_remark').val();
        if(sys_remark == '') {
            alert('请先输入审核意见');
            return;
        }
        if(id > 0) {
            if(confirm('是否确认提交?')) {
                var params = $("#theFrm").serialize();
                params = params + '&status=<?=$info->status+1?>' + '&sys_remark=' + sys_remark;
                $.post('/fix-car/my-list-save',params,function(obj){
                    alert(obj.msg);
                    if(obj.success) {
                        $('#back-btn').click();
                    }
                },'json');
            }
        } else {
            alert('请先保存维修信息');
        }
    }

    // 退回
    function returnBack(){
        var r = prompt('退回原因', '');
        if(r != null && r != '') {
            $.post('/fix-car/return-op',{
                id:<?=$info->id>0?$info->id:0?>,
                return_remark:r,
                return_status_id:<?=$info->status?>
            },function(obj){
                alert(obj.msg);
                if(obj.success) {
                    $('#back-btn').click();
                }
            },'json');
        } else {
            alert('不填写原因,无法退回');
        }
    }

    // 维修明细
    function addInfo(){
        var id = $('#id').val();
        if(id > 0) {
            layer_show('维修明细', '/fix-car/add-item?fix_id=' + id);
        } else {
            alert('请先保存维修信息');
        }
    }

    // 打印接车单
    function printInfo(){
        window.open('/fix-car/print-receive?id=<?=$info->id?>');
    }

    //返回
    function goBack(){
        <?php
        $url = '';
        switch($type) {
            case 1:
                $url = '/fix-car/step1-list';
                break;
            case 2:
                $url = '/fix-car/step2-list';
                break;
            case 3:
                $url = '/fix-car/step3-list';
                break;
            case 4:
                $url = '/fix-car/step4-list';
                break;
            case 5:
                $url = '/fix-car/step5-list';
                break;
            case 6:
                $url = '/fix-car/step6-list';
                break;
            case 7:
                $url = '/fix-car/step7-list';
                break;
            default:
                $url = '/fix-car/my-list';
                break;
        }
        echo 'window.location.href="'.$url.'"';
        ?>
    }

    function showNameFormatter(value){
        return value.username + '(' + value.name + ')';
    }

    function typeFormatter(value){
        switch (+value) {
            case 1:
                return '实名礼品';
            case 2:
                return '礼券';
        }
    }

    function strategyFormatter(value){
        return value == 0 ? '公司礼品' : '自费礼品';
    }

    function dateFormatter(value){
        var datetime = new Date(value*1000);
        var year = datetime.getFullYear(),
            month = ("0" + (datetime.getMonth() + 1)).slice(-2),
            date = ("0" + datetime.getDate()).slice(-2),
            hour = ("0" + datetime.getHours()).slice(-2),
            minute = ("0" + datetime.getMinutes()).slice(-2),
            second = ("0" + datetime.getSeconds()).slice(-2);
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    }

    function statusFormatter(value){
        var statusTxt = '';
        switch (+value) {
            case 0:
                statusTxt =  "未出库";
                break;
            case 1:
                statusTxt =  "已出库";
                break;
            case 2:
                statusTxt =  "正在退换";
                break;
            case 3:
                statusTxt =  "已使用";
                break;
            default:
                statusTxt = "未知状态";
                break;
        }
        return statusTxt;
    }


</script>
<?php $this->endBlock('footer_js'); ?>
