<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
    <style>html{background-color: #fff;padding-bottom: 50px;}</style>
</head>

<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130"><i class="red">*</i>物料代码：</label>
                <div class="layui-input-block ">
                    <input type="text" disabled name="code" readonly autocomplete="off" placeholder="请输入"
                           class="layui-input layui-bg-gray" value="${stockInfo.columns.code}">
                </div>
            </div>
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130"><i class="red">*</i>物料类型：</label>
                <div class="layui-input-block ">
                    <input type="text" disabled name="materialTypeId" readonly autocomplete="off" placeholder="请输入"
                           class="layui-input layui-bg-gray" value="${stockInfo.columns.typeName}">
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 mb-10 pr-30">

            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130"><i class="red">*</i>单位：</label>
                <div class="layui-input-block ">
                    <input type="text" disabled name="unit" readonly autocomplete="off" placeholder="请输入"
                           class="layui-input layui-bg-gray" value="${stockInfo.columns.unit_name}"/>
                </div>
            </div>
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label"><i class="red">*</i>仓库：</label>
                <div class="layui-input-block">
                    <input type="text" disabled name="warehouse" readonly autocomplete="off" placeholder="请输入"
                           class="layui-input layui-bg-gray" value="${stockInfo.columns.warehouseName}"/>
                </div>
            </div>
        </div>
  <%--      <div class="layui-col-xs12 mb-10 pr-30">
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130">低库存预警：</label>
                <div class="layui-input-block ">
                    <input type="text" name="lowStockWarning" autocomplete="off" placeholder="请输入"
                           class="layui-input" value="${stockInfo.columns.low_stock_warning}">
                </div>
            </div>
            <div class="layui-inline layui-col-xs6">
                <label class="layui-form-label w-130">库位：</label>
                <div class="layui-input-block ">
                    <input type="text" name="position" autocomplete="off" placeholder="请输入"
                           class="layui-input" value="${stockInfo.columns.position}">
                </div>
            </div>
        </div>--%>

        <div class="layui-col-xs12 layui-form-item pr-30">
            <label class="layui-form-label"><i class="red">*</i>物料描述：</label>
            <div class="layui-input-block">
                <textarea name="remarks" disabled id="remarks" placeholder=""
                          class="layui-textarea layui-bg-gray">${stockInfo.columns.remarks}</textarea>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <input type="hidden" name="id" value="${id}">
        <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="确认">
        <input type="button" value="取消" class="layui-btn layui-btn-primary " onclick="closeDiv();">
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var $;
    var imgs = '';
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['form', 'layedit', 'laydate', 'jquery', 'layer'], function () {
        $ = layui.jquery;
        form = layui.form;
        $form = $('form');


        form.on('submit(confirm)', function (data) {
            var warning = data.field.lowStockWarning;
            if (!isBlank(warning) && !/^\d+(\.\d{1,2})?$/.test(warning)) {
                layer.msg('低库存预警格式不正确');
                return;
            }
            $.ajax({
                url: '${ctx}/material/saveMaterialStockInfo',
                type: 'post',
                data: {
                    id: '${id}',
                    lowStockWarning: $.trim(data.field.lowStockWarning),
                    position: $.trim(data.field.position)
                },
                dataType: 'JSON',
                success: function (res) {
                    if (res.code === "200") {
                        parent.layer.msg("保存成功", {time: 1000});
                        closeDiv();
                        parent.table.reload('test');
                    } else if (res.code === '501') {
                        layer.msg(res.errMsg);
                    } else {
                        layer.msg("保存失败", {time: 1000});
                    }
                },
                error: function (data) {
                }
            });
        });


    })

    function closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }


</script>
</body>
</html>
