<?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="saveCarInfo()">
                    <i class="fa fa-save"></i> 保存
                </a>
                <a class="btn btn-primary btn-xs edit-btn" data-id="0" href="javascript:void(0);" onclick="nextInfo()">
                    <i class="fa fa-backward"></i> 下一个
                </a>
                <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="ibox-content">
            <div class="row">
                <div class="col-md-12">
                    <form role="form" class="form-inline" id="carFrm">
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">车牌号</label>
                            <input type="text" name="car_no" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">厂牌型号</label>
                            <input type="text" name="car_no" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">品牌</label>
                            <select name="brand_id" id="brand_info" 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-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">车系</label>
                            <select name="series_id" id="series_info" 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-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">发动机号</label>
                            <input type="text" name="engine_no" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">车架号</label>
                            <input type="text" name="car_frame_no" value=""
                                   class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">初登日期</label>
                            <input type="text" class="input-date form-control" id="register_date" name="register_date"
                                   autocomplete="off" value=""/>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">排量</label>
                            <select name="displacement_id" id="displacement_info" 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-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">车辆类型</label>
                            <select name="car_type_id" id="car_type_info" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach ($car_type_items as $item) {
                                    echo '<option value="' . $item->id . '"';
                                    if ($car_info->car_type_id == $item->id)
                                        echo ' selected ';
                                    echo '>' . $item->name . '</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">运营性质</label>
                            <select name="car_use_id" id="car_use_info" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach ($car_use_items as $item) {
                                    echo '<option value="' . $item->id . '"';
                                    if ($car_info->car_use_id == $item->id)
                                        echo ' selected ';
                                    echo '>' . $item->name . '</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">座位数</label>
                            <input type="text" name="seats" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">年份</label>
                            <input type="text" name="car_year" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">车主</label>
                            <input type="text" name="car_man" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">联系电话</label>
                            <input type="text" name="phone" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">证件号码</label>
                            <input type="text" name="car_man_number" value=""
                                   class="form-control">
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">商业止保日期</label>
                            <input type="text" class="input-date form-control" id="insurer1_date" name="insurer1_date"
                                   autocomplete="off" value=""/>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">交强止保日期</label>
                            <input type="text" class="input-date form-control" id="insurer2_date" name="insurer2_date"
                                   autocomplete="off" value=""/>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">保险公司</label>
                            <input type="text" name="company" value="" class="form-control">
                        </div>
                        <div class="form-group col-md-12" style="margin-bottom: 8px;">
                            <label class="control-label">备注</label>
                            <textarea class="form-control" name="car_remark"
                                      id="car_remark"></textarea>
                        </div>
                    </form>
                </div>
            </div>
        </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-4">
                    <dl class="dl-horizontal">
                        <dt>车牌号:</dt>
                        <dd></dd>
                        <dt>厂牌型号:</dt>
                        <dd></dd>
                        <dt>品牌:</dt>
                        <dd></dd>
                    </dl>
                </div>
                <div class="col-sm-4">
                    <dl class="dl-horizontal">
                        <dt>发动机号:</dt>
                        <dd></dd>
                        <dt>车架号:</dt>
                        <dd></dd>
                        <dt>初登日期:</dt>
                        <dd></dd>
                    </dl>
                </div>
                <div class="col-sm-4">
                    <dl class="dl-horizontal">
                        <dt>车辆类型:</dt>
                        <dd></dd>
                        <dt>运营性质:</dt>
                        <dd></dd>
                        <dt>座位数:</dt>
                        <dd></dd>
                    </dl>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-4">
                    <dl class="dl-horizontal">
                        <dt>车系:</dt>
                        <dd></dd>
                        <dt>排量:</dt>
                        <dd></dd>
                        <dt>年份:</dt>
                        <dd></dd>
                    </dl>
                </div>
                <div class="col-sm-4">
                    <dl class="dl-horizontal">
                        <dt>车主:</dt>
                        <dd></dd>
                        <dt>车主证件号码:</dt>
                        <dd></dd>
                        <dt>联系电话:</dt>
                        <dd>
                            <button type="button" class="btn btn-primary" onclick="strCall('')">
                                拨号
                            </button>
                            <button type="button" class="btn btn-primary" onclick="strHook()">挂断</button>
                        </dd>
                    </dl>
                </div>
                <div class="col-sm-4">
                    <form id="insurerFm">
                        <dl class="dl-horizontal">
                            <dt>商业止保日期:</dt>
                            <dd><input type="text" class="input-date form-control" name="insurer1_date"
                                       autocomplete="off"
                                       value=""/></dd>
                            <dt>交强止保日期:</dt>
                            <dd><input type="text" class="input-date form-control" name="insurer2_date"
                                       autocomplete="off"
                                       value=""/></dd>
                            <dt>保险公司:</dt>
                            <dd><input type="text" name="company" value="" class="form-control">
                            </dd>
                        </dl>
                        <button type="button" class="btn btn-primary" onclick="saveInsurerInfo()">拨号</button>
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-4">
                    <dl class="dl-horizontal">
                        <dt>新保座席:</dt>
                        <dd></dd>
                        <dt>客服代表:</dt>
                        <dd></dd>
                        <dt>续保座席:</dt>
                        <dd></dd>
                    </dl>
                </div>
                <div class="col-sm-8">
                    <dl class="dl-horizontal">
                        <dt>区域:</dt>
                        <dd></dd>
                        <dt>备注:</dt>
                        <dd><?= $car_info->remark ?></dd>
                    </dl>
                </div>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-md-12">
                    <form role="form" class="form-inline" id="appointmentFrm">
                        <input type="hidden" name="car_id" value="<?= $car_info->id ?>">
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">预约日期</label>
                            <input type="text" class="input-date form-control" id="pdate" name="pdate" autocomplete="off"
                                   value=""/>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">预约时间</label>
                            <select name="ptime" class="form-control">
                                <option>08:00</option>
                                <option>08:30</option>
                                <option>09:00</option>
                                <option>09:30</option>
                                <option>10:00</option>
                                <option>10:30</option>
                                <option>11:00</option>
                                <option>11:30</option>
                                <option>12:00</option>
                                <option>13:00</option>
                                <option>13:30</option>
                                <option>14:00</option>
                                <option>14:30</option>
                                <option>15:00</option>
                                <option>15:30</option>
                                <option>16:00</option>
                                <option>16:30</option>
                                <option>17:00</option>
                            </select>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">预约类型</label>
                            <select name="ptype" class="form-control">
                                <option value="0">---选择类型---</option>
                                <?php foreach ($list as $k => $v) { ?>
                                    <option value='<?= $v->code; ?>'><?= $v->name; ?></option>
                                <?php } ?>
                            </select>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">当天预约人数</label>
                            <input type="text" id="day_count" value="0" disabled class="form-control">
                        </div>
                        <div class="form-group col-md-12" style="margin-bottom: 8px;">
                            <label class="control-label">预约备注</label>
                            <textarea class="form-control" name="remark"></textarea>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">业务分组</label>
                            <select name="business_group_id" class="form-control">
                                <option value="0">---请选择---</option>
                                <?php
                                foreach ($business_group as $k => $v) {
                                    echo '<option value="' . $v->id . '"';
                                    echo $v->id == $business_group_id ? 'selected' : '';
                                    echo '>' . $v->name . '</option>';
                                }
                                ?>
                            </select>
                        </div>
                        <div class="form-group col-md-12" style="margin-bottom: 8px;">
                            <?php
                            $insurer_date = $car_info->insurer1_date;
                            if ($insurer_date == '') {
                                $insurer_date = $car_info->insurer2_date;
                            }
                            $begin_zhi_date = date('Y-m-d', strtotime('-3 month', strtotime($insurer_date . ' 00:00:00')));
                            $cur_date = date('Y-m-d');
                            //echo '该提示放弃时间'.$begin_zhi_date.'当前'.$cur_date;
                            $d1 = strtotime($cur_date);
                            $d2 = strtotime($begin_zhi_date);
                            $Days = round(($d2 - $d1) / 3600 / 24);
                            $day = (int)$Days;
                            if ($day <= 0) {
                                echo '<button type="button" class="btn btn-primary" onclick="cancelAppointment()">放弃</button>';
                            }
                            //$cur_year = date('Y');
                            //$cur_date = date('m-d');
                            //$year_date = date('Y',strtotime($insurer_date.' 00:00:00'));
                            //$begin_date = date('m-d',strtotime('-3 month',strtotime($insurer_date.' 00:00:00')));
                            //$end_date = date('m-d',strtotime($insurer_date.' 00:00:00'));
                            //echo '今年:'.$cur_year.'<br>结束年份:'.$year_date.'<br>今天日期'.$cur_date.'<br>到期前三个月日期'.$begin_date.'<br>最后真正到期日期'.$end_date.'<br>';
                            //if((date('m') < 10) && ($cur_year >= $year_date && $cur_date >= $begin_date && $cur_date <= $end_date)){
                            //    echo '<input type=button class="act_btn2 cancel-btn" name="cancel-btn" value=" 放弃 "/>';
                            //}else if((date('m') >= 10) && ($cur_date >= $begin_date)){
                            //    echo '<input type=button class="act_btn2 cancel-btn" name="cancel-btn" value=" 放弃 "/>';
                            //}
                            ?>
                            <button type="button" class="btn btn-primary" onclick="appointmentSave()">预约保存</button>
                            <button type="button" class="btn btn-primary" onclick="nextInfo()">下一个</button>
                            <button type="button" class="btn btn-primary" onclick="goBack()">返回</button>
                        </div>
                        <div class="form-group col-md-3" style="margin-bottom: 8px;">
                            <label class="control-label">无效数据</label>
                            <select name="business_group_id" class="form-control">
                                <option value="0">---请选择无效理由---</option>
                                <?php
                                foreach ($failure_items as $item) {
                                    echo '<option value="' . $item->id . '">' . $item->name . '</option>';
                                }
                                ?>
                            </select>
                            <button type="button" class="btn btn-primary" onclick="appointmentInvalid()">无效数据</button>
                        </div>
                    </form>
                    <table id="appointmentTable">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="pdate">预约日期</th>
                            <th data-field="ptime">预约时间</th>
                            <th data-field="ptype">预约类型</th>
                            <th data-field="remark">预约备注</th>
                            <th data-field="show_name">业务员</th>
                            <th data-field="business_group_txt">业务分组</th>
                            <th data-formatter="opFormatter">操作时间</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">
                <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="ibox-content">
            <div class="row">
                <div class="col-md-12">
                    <table id="insurerTable">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="id_man">被保险人</th>
                            <th data-field="insurer2_begin_date">商业起保日期</th>
                            <th data-field="insurer2_begin_date">交强起保日期</th>
                            <th data-field="print_date">出单日期</th>
                            <th data-field="total_all">共计签单</th>
                            <th data-field="show_name">业务员</th>
                            <th data-field="status_txt">状态</th>
                            <th data-formatter="opFormatter">操作</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">
                <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="ibox-content">
            <div class="row">
                <div class="col-md-12">
                    <table id="gift1Frm">
                        <thead>
                        <tr>
                            <th data-field="code">礼品编号</th>
                            <th data-field="type_txt">礼品名称</th>
                            <th data-field="use_date">操作时间</th>
                            <th data-field="show_name">操作员</th>
                            <th data-field="status_txt">状态</th>
                        </tr>
                        </thead>
                    </table>
                </div>
                <div class="col-md-12">
                    <table id="gift2Frm">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="name">礼品名称</th>
                            <th data-field="type_txt">类型</th>
                            <th data-field="remark">描述</th>
                            <th data-field="strategy_txt">分类</
                            </th>
                            <th data-field="show_name">添加者</th>
                            <th data-field="submit_time_txt">操作时间</th>
                            <th data-field="status_txt">状态</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">
                <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="ibox-content">
            <div class="row">
                <div class="col-md-12">
                    <table id="histtoryTable">
                        <thead>
                        <tr>
                            <th data-field="id">ID</th>
                            <th data-field="op_man">姓名</th>
                            <th data-field="op_time_txt">操作时间</th>
                            <th data-field="info">意见</th>
                            <th data-field="remark">意见说明</
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </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
        });

        // 获取数据,初始化
        $.get(window.location.href, function (obj) {
            if (obj.code == 200) {
                init(obj.data);
            } else {
                alert('数据加载错误');
            }
            }
        }, 'json');

        $('#pdate').blur(function () {
            var params = $("#appointmentFrm").serialize();
            $.post('/appointment/count', params, function (obj) {
                if (obj.success) {
                    $('#day_count').val(obj.count);
                }
            }, 'json');
        });
        $('#brand_id').change(function () {
            var brand_id = $(this).val();
            $('#series_id').html('<option value="0">---请选择---</option>');
            $('#displacement_id').html('<option value="0">---请选择---</option>');
            if (brand_id > 0) {
                $.get('/car/series-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');
            }
        });

        myListGift();
        myListLog();
    })

    function init(data){
        carInfoInit(data['car_info']);
        selectInfoInit(data);
    }

    // 品牌选项初始化
    function selectInfoInit(data){
        var keys = [
            'brand',
            'series',
            'displacement',
            'car_type',
            'car_use',
        ];
        $.each(keys,function(index,key){
            var html = '<option value="0">---请选择---</option>';
            $.each(data[key + '_info'],function(key,item){
                html += '<option value="'+ item.id +'" selected="'+ (data[key + '_id'] == item['id']) +'">'+ item.name +'</option>'
            });
            $('#'+ key + '_info').html(html);
        });
    }

    // 页面车辆数据初始化
    function carInfoInit(data){
        // 页面车辆数据初始化
        $('#carFrm').children('.form-control').each(function(key,item){
            $(item).val(data['car_info'][$(item).attr('name')]);
        });
    }

    //拨号
    function strCall(phone) {
        parent.drtCall(phone);
    }
    //挂断
    function strHook() {
        parent.drtHook();
    }
    // 保存车辆信息
    function saveCarInfo() {
        var params = $('#carFrm').serialize();
        $.post('/car/save',params,function(obj){
            alert(obj.msg);
            window.location.reload();
        },'json');
    }
    // 下一条信息
    function nextInfo(){
        var params = 'index=' + next_index + '&type=<?=$type?>';
        $.get('/track/ajax-next', params, function (obj) {
            if (obj.success) {
                if (obj.car_id > 0) {
                    window.location.href = '/car/info-track?id=' + obj.car_id + '&type=<?=$type?>&next_index=<?=$next_index?>' + '&back_params=' + encodeURIComponent('<?=$back_params?>');
                } else {
                    alert('没有记录');
                }
            }
        }, 'json');
    }
    // 返回
    function goBack(){
        <?php
        $url = '';
        if ($type == 1)
            $url = '/track/first?' . $back_params;
        if ($type == 2)
            $url = '/track/today?' . $back_params;
        if ($type == 3)
            $url = '/track/all?' . $back_params;
        echo 'window.location.href = "' . $url . '"';
        ?>
    }
    // 保险信息保存
    function saveInsurerInfo(){
        var params = $('#insurerFm').serialize();
        $.post('/car/baocun', params, function (obj) {
            alert(obj.msg);
        }, 'json');
    }
    // 取消预约
    function cancelAppointment(){
        //这里是后来需求改了,暂时注释
        //if(location == 6){
        //    var url = '/track/car-cancel-e';
        //}else if(location == 3 || ptype == 3){
        //    var url = '/track/car-cancel';
        //}

        var location = '<?= $car_info->location; ?>';
        var ptype = $('#appointment_list').children("table").children("tbody").children("tr").eq(1).children(".ptyp").attr('data');

        if (location == 3) {
            //C库数据
            //放d
            var url = '/track/car-cancel';
        } else if (location == 6 && ptype == 5) {
            var url = '/track/car-cancel-e';
        } else {
            //无效
            alert('不是目标客户,请点击无效数据按钮!');
            return false;
        }
        if (confirm('是否确认放弃?')) {
            $.post(url, {id:<?=$car_info->id?>}, function (obj) {
                alert(obj.msg);
                if (obj.success) {
                    $('.back-btn').click();
                }
            }, 'json');
        }
    }
    // 预约保存
    function appointmentSave(){
        if (confirm('是否确认提交?')) {
            var params = $("#appointmentFrm").serialize();
            $.post('/appointment/save', params, function (obj) {
                alert(obj.msg);
                if (obj.success) {
                    $('#appointmentFrm')[0].reset();
                    gotoPage('/appointment/ajax-index?car_id=<?=$car_info->id?>&page=1', 'appointment_list');
                }
            }, 'json');
        }
    }
    // 无效保存
    function appointmentInvalid(){
        var car_id = $('#car_id').val();
        var invalid_id = $('#invalid_id').val();
        if (invalid_id == 0) {
            alert('必须选择无效理由!');
            return;
        }
        if (confirm('是否无效这条数据?')) {
            $.post('/car/invalid', {car_id: car_id, invalid_id: invalid_id}, function (obj) {
                alert(obj.msg);
                if (obj.success) {
                    $('#appointment-save-btn').attr('disabled', true);
                    $('.save-btn').attr('disabled', true);
                    $('.invalid-btn').attr('disabled', true);
                }
            }, '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'); ?>