<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<form id="theFrm">
    <?php if (isset($info)): ?>
        <input type="hidden" name="id" value="<?= $info->id ?>">
    <?php endif; ?>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <td width="100" height="25" class="bg_tr">品牌</td>
            <td height="25" class="td_bg">
                <select name="brand_id" id="brand_id" onchange="brandChange($(this).val())">
                    <?php if (count($brands) > 0): ?>
                        <?php foreach ($brands as $brand): ?>
                            <option value="<?= $brand->id ?>" <?= isset($info) ? ($brand->id == $info->brand_id ? 'selected' : '') : '' ?>><?= $brand->name ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
            </td>
            <td width="100" height="25" class="bg_tr">车型</td>
            <td height="25" class="td_bg">
                <select name="series_id" id="series_id" onchange="seriesChange($(this).val())">
                    <?php if (isset($series)): ?>
                        <?php foreach ($series as $val): ?>
                            <option value="<?= $val->id ?>" <?= $val->id == $info->series_id ? 'selected' : '' ?>><?= $val->name ?></option>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <option value="0">--请选择--</option>
                    <?php endif; ?>
                </select>
            </td>
            <td width="100" height="25" class="bg_tr">排量</td>
            <td height="25" class="td_bg">
                <select name="displacement_id" id="displacement_id">
                    <?php if (isset($displacements)): ?>
                        <?php foreach ($displacements as $dis): ?>
                            <option value="<?= $dis->id ?>" <?= $dis->id == $info->displacement_id ? 'selected' : '' ?>><?= $dis->name ?></option>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <option value="0">--请选择--</option>
                    <?php endif; ?>
                </select>
            </td>
            <td width="100" height="25" class="bg_tr">年份</td>
            <td height="25" class="td_bg">
                <input type="text" name="car_year" value="<?= isset($info) ? $info->car_year : '' ?>" onclick="WdatePicker({startDate:'2000',dateFmt:'yyyy'})">年
            </td>
        </tr>
    </table>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <th colspan="8" class="bg_tr">机油</th>
        </tr>
        <tr>
            <td width="100" height="25" class="bg_tr">机油等级</td>
            <td height="25" class="td_bg"><input name="level" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[0]->level :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">用量</td>
            <td height="25" class="td_bg"><input name="use" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[0]->use :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">机油价格</td>
            <td height="25" class="td_bg"><input name="price1" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[0]->price :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">工时费</td>
            <td width="100" height="25" class="bg_tr"><input name="hour1" type="text" id="name"
                                                             value="<?= isset($info) ? $info->carKeepInGoodItems[0]->hour :'' ?>"
                                                             size="40"/></td>
        </tr>
    </table>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <th colspan="4" class="bg_tr">机油滤芯</th>
        </tr>
        <tr>
            <td width="100" height="25" class="bg_tr">机滤价格</td>
            <td height="25" class="td_bg"><input name="price2" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[1]->price :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">工时费</td>
            <td width="100" height="25" class="bg_tr"><input name="hour2" type="text" id="name"
                                                             value="<?= isset($info) ? $info->carKeepInGoodItems[1]->hour :'' ?>"
                                                             size="40"/></td>
        </tr>
    </table>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <th colspan="6" class="bg_tr">空气滤芯</th>
        </tr>
        <tr>
            <td width="100" height="25" class="bg_tr">空滤价格</td>
            <td height="25" class="td_bg"><input name="price3" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[2]->price :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">工时费</td>
            <td width="100" height="25" class="bg_tr"><input name="hour3" type="text" id="name"
                                                             value="<?= isset($info) ? $info->carKeepInGoodItems[2]->hour :'' ?>"
                                                             size="40"/></td>
            </td>
            <td width="100" height="25" class="bg_tr">价格</td>
            <td width="100" height="25" class="bg_tr"><input name="air_price" type="text" id="air_price"
                                                             value="<?= isset($info) ? $info->carKeepInGoodItems[2]->air_price :'' ?>"
                                                             size="40"/></td>
        </tr>
    </table>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <th colspan="4" class="bg_tr">空调滤芯</th>
        </tr>
        <tr>
            <td width="100" height="25" class="bg_tr">空滤价格</td>
            <td height="25" class="td_bg"><input name="price4" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[3]->price :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">工时费</td>
            <td width="100" height="25" class="bg_tr"><input name="hour4" type="text" id="name"
                                                             value="<?= isset($info) ? $info->carKeepInGoodItems[3]->hour :'' ?>"
                                                             size="40"/
        </tr>
    </table>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <tr>
            <th colspan="4" class="bg_tr">汽油滤芯</th>
        </tr>
        <tr>
            <td width="100" height="25" class="bg_tr">汽滤价格</td>
            <td height="25" class="td_bg"><input name="price5" type="text" id="name"
                                                 value="<?= isset($info) ? $info->carKeepInGoodItems[4]->price :'' ?>"
                                                 size="40"/></td>
            <td width="100" height="25" class="bg_tr">工时费</td>
            <td width="100" height="25" class="bg_tr"><input name="hour5" type="text" id="name"
                                                             value="<?= isset($info) ? $info->carKeepInGoodItems[1]->hour :'' ?>"
                                                             size="40"/></td>
        </tr>
        <tr>
            <td height="22" colspan="4" align="center" class="td_bg">
                <input id="submit-btn" type=button class="ACT_btn" name=Submit1
                       value=" 提交  "/>
                &nbsp;&nbsp;
                <input id="back-btn" type="button" class="ACT_btn" name="Submit2" value=" 返回 ">
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript">
    $(function () {
        //提交按钮
        $("#submit-btn").click(function () {
            if (confirm('是否确认提交?')) {
                var params = $("#theFrm").serialize();
                $.post('/keep-in-good/info', params, function (obj) {
                    if (obj.success) {
                        $('#back-btn').click();
                    } else {
                        alert(obj.msg);
                    }
                }, 'json');
            }
        });

        //返回按钮
        $('#back-btn').click(function () {
            window.location.href = '/keep-in-good/index';
        });
    })

    <?php if(!isset($info)): ?>
    $('#brand_id').change();
    <?php endif; ?>
    //品牌change事件
    function brandChange(brand) {
        if (brand <= 0) return false;
        $.post('/car/series?brand_id=' + brand, '', function (data) {
            if (data.success) {
                $('#series_id').html(data.html);
            }
        })
    }

    //车型或车系change事件
    function seriesChange(series) {
        if (series <= 0) return false;
        $.post('/car/displacement?series_id=' + series, '', function (data) {
            if (data.success) {
                $('#displacement_id').html(data.html);
            }
        })
    }
</script>
