<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>项目安装方式</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
    <style>
        html{
            background-color: #fff;
        }
        .layui-form-select dl {
            max-height: 200px;
        }
    </style>
</head>
<body>
<div class="layui-form mb-0 pr-30" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin">
    <input type="hidden" name="id" value="${materialUnit.id}" autocomplete="off" class="layui-input">
    <div id="textDiv" class="layui-card-body">
        <div class="layui-col-xs6 mb-10">
            <label class="layui-form-label"><i class="mark">*</i>库存单位：</label>
            <div class="layui-input-block">
                <input type="text" name="name" value="${materialUnit.name}" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>

<%--        <div class="layui-col-xs6 mb-10">--%>
<%--            <label class="layui-form-label"><i class="mark">*</i>编码：</label>--%>
<%--            <div class="layui-input-block">--%>
<%--                <input type="text" name="unitCode" value="${materialUnit.unitCode}" <c:if test="${not empty materialUnit.id  }"> readonly</c:if> lay-verify="required" autocomplete="off" class="layui-input">--%>
<%--            </div>--%>
<%--        </div>--%>

        <div class="layui-col-xs6 mb-10">
            <label class="layui-form-label"><i class="mark">*</i>物料类型：</label>
            <div class="layui-input-block">
                <select name="materialType" id="materialType" lay-verify="required">
                    <option value="">请选择</option>
                    <c:forEach items="${typeList}" var="type">
                        <option value="${type.columns.id}" ${type.columns.id eq materialUnit.materialType ? 'selected' : ''}>${type.columns.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
    <%--    <div class="layui-col-xs6 mb-10">
            <label class="layui-form-label"><i class="mark">*</i>所属组别：</label>
            <div class="layui-input-block">
                <select name="UnitGroup" id="UnitGroup" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="Quantity"  <c:if test="${ materialUnit.unitGroup eq 'Quantity' }"> selected</c:if>>数量</option>
                    <option value="Weight" <c:if test="${ materialUnit.unitGroup eq 'Weight' }"> selected</c:if>>重量</option>
                    <option value="Length" <c:if test="${ materialUnit.unitGroup eq 'Length' }"> selected</c:if>>长度</option>
                    <option value="Capacity" <c:if test="${ materialUnit.unitGroup eq 'Capacity' }"> selected</c:if>>容量</option>
                    <option value="Machine" <c:if test="${ materialUnit.unitGroup eq 'Machine' }"> selected</c:if>>资产单位_机器设备</option>
                    <option value="Transport" <c:if test="${ materialUnit.unitGroup eq 'Transport' }"> selected</c:if>>资产单位_运输设备</option>
                    <option value="Building" <c:if test="${ materialUnit.unitGroup eq 'Building' }"> selected</c:if>>资产单位_房屋建筑</option>
                </select>
            </div>
        </div>--%>

    </div>
    <div class="layui-form-item text-c operate-footer" >
        <button class="layui-btn " lay-submit lay-filter="component-form-element" <%--onclick="addRole()"--%>>保存</button>
        <button class="layui-btn layui-btn-primary" onclick="cancel()">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/font/iconfont.js"></script>
<script>
    layui.use(['form','jquery','layedit'], function () {
        $ = layui.$,
            form = layui.form,
            layer = layui.layer;

        var fg=false;
        form.on('submit(component-form-element)',function(data){
            if(fg){
                return;
            }
            fg=true;
            var field = data.field; //获取提交的字段
            $.ajax({
                url: '${ctx}/crmSupplyMaterialSetting/saveMaterialUnit',
                type: 'post',
                data: {
                    id: field.id,
                    name: field.name,
                    materialType:field.materialType,
                    unitCode:field.unitCode,
                    UnitGroup:field.UnitGroup
                },
                success: function(data) {
                    if(data.code === "200"){
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg('操作成功！', {icon:1,time:1000},function(){
                            parent.layer.close(index);
                            parent.window.reload(); //刷新父页面
                        })
                    }else if(data.code ==="501"){
                        layer.msg(data.errMsg,{icon:5,anim:6});
                        fg=false;
                    }else{
                        layer.msg("添加失败！",{icon:5,anim:6});
                        fg=false;
                    }
                },
                complete:function(){

                }
            });

        })

    });

    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
    function cancel(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
</body>
</html>
