<form id="theFrm">
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" class="table">
        <?php if (isset($item_scale)): ?>
            <input type="hidden" name="id" value="<?= $item_scale->id ?>">
        <?php endif; ?>
        <tr>
            <td width="20%" height="25" class="td_bg">父级分类</td>
            <td width="80%" height="25" class="td_bg">
                <select name="pid" id="pid">
                    <option value="0">顶级分类</option>
                    <?php if (count($parents) > 0): ?>
                        <?php foreach ($parents as $parent): ?>
                            <option value="<?= $parent->id ?>" <?= isset($item_scale) ? ($parent->id === $item_scale->pid ? 'selected' : '') : '' ?>>
                                --<?= $parent->name ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
            </td>
        </tr>
        <tr>
            <td width="20%" height="25" class="td_bg">分类名</td>
            <td width="80%" height="25" class="td_bg"><input name="name" type="text" id="name"
                                                             value="<?= isset($item_scale) ? $item_scale->name : '' ?>"
                                                             size="40"/></td>
        </tr>
        <tr>
            <td width="20%" height="25" class="td_bg">售价比例</td>
            <td width="80%" height="25" class="td_bg"><input name="scale" type="text" id="scale"
                                                             value="<?= isset($item_scale) ? $item_scale->scale : '' ?>"
                                                             size="10"/>%</td>
        </tr>
        <tr>
            <td height="22" colspan="2" 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('/fix-car-category/info', params, function (obj) {
                    if (obj.success) {
                        $('#back-btn').click();
                    } else {
                        alert(obj.msg);
                    }
                }, 'json');
            }
        });

        //返回按钮
        $('#back-btn').click(function () {
            window.location.href = '/fix-car-category/index';
        });
    })
</script>
