<script type="text/javascript" language="javascript" src="/js/jquery-1.8.3.js"></script>
<script type="text/javascript" language="javascript" src="/js/datepicker/WdatePicker.js"></script>
<script type="text/javascript" language="javascript" src="/js/ajax.js"></script>
<script type="text/javascript" language="javascript" src="/js/func.js"></script>
<form id="theFrm">
    <input type="hidden" name="id" value="<?= isset($info) ? $info->id : '' ?>">
    <input type="hidden" name="category_1" value="1">
    <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
        <tr>
            <td width="100" height="25" class="bg_tr">辅料名称</td>
            <td class="td_bg" width="300">
                <input type="text" name="name" list="name_list" id="name"
                       value="<?= isset($info) ? $info->category->name : '' ?>">
            </td>
            <td width="100" height="25" class="bg_tr">数量</td>
            <td class="td_bg">
                <input type="text" name="number" value="<?= isset($info) ? $info->number : '' ?>">
            </td>
        </tr>
        <tr>
            <td width="100" height="25" class="bg_tr">价格</td>
            <td height="25" class="td_bg">
                <input type="text" name="price" value="<?= isset($info) ? $info->price : '' ?>">
            </td>
            <td width="100" height="25" class="bg_tr">产地</td>
            <td height="25" class="td_bg" colspan="3">
                <input type="text" name="producing_area" value="<?= isset($info) ? $info->producing_area : '' ?>">
            </td>
        </tr>
        <tr>
            <td height="22" colspan="6" align="center" class="td_bg">
                <?php if (!isset($info)): ?>
                    <input id="submit-btn" type=button class="ACT_btn" name=Submit1 value=" 提交 "/>
                <?php else: ?>
                    <input id="save-btn" type=button class="ACT_btn" name=Submit1 value=" 保存 "/>
                <?php endif; ?>
                <input id="back-btn" type="button" class="ACT_btn" name="Submit2" value=" 返回 ">
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript" language="javascript">
    //提交按钮
    $('#submit-btn').on('click', function () {
        if (!confirm('确定提交吗')) return false;
        var params = $('#theFrm').serialize();
        $.post('/store-room/put-in-store-info', params , function (msg) {
            alert(msg.msg);
            if (msg.success) {
//                location.reload();
                window.location.href = "/store-room/put-in-store";
            }
        }, 'json');
    });
    //保存按钮
    $('#save-btn').on('click', function () {
        var params = $('#theFrm').serialize();
        $.post('/store-room/put-in-store-info', params, function (msg) {
            alert(msg.msg);
            if (msg.success) {
                location.reload();
            }
        }, 'json');
    });
    //返回按钮
    $('#back-btn').on('click', function () {
        window.location.href = '/store-room/put-in-store';
    });
    $('#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', {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/displacement', {series_id: series_id}, function (obj) {
                if (obj.success) {
                    $('#displacement_id').html(obj.html);
                }
            }, 'json');
        }
    });
</script>
