<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<html>
<head>
    <title>物资品名代码管理</title>
    <meta name="decorator" content="ani"/>
    <link rel="stylesheet" href="${ctxStatic}/common/css/form.css">
</head>
<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-primary">
                <div class="panel-body">
                    <form:form id="inputForm" modelAttribute="materialType"
                               action="${ctx}/warehouse/materialtype/materialType/save" method="post"
                               class="form-horizontal">
                        <form:hidden path="id"/>
                        <form:hidden path="parentIds" />
                        <h3 class="text-center">物资品名代码表</h3>
                        <table class="table table-bordered main-table">
                            <tr>
                                <td><font color="red">*</font>名称</td>
                                <td>
                                    <form:input path="name" htmlEscape="false"
                                                class="form-control required"/>
                                </td>
                                <td><font color="red">*</font>排序</td>
                                <td>
                                    <form:input path="sort" htmlEscape="false" class="form-control required"/>
                                </td>
                            </tr>

                            <tr>
                                <td><font color="red">*</font>编码</td>
                                <td>
                                    <form:input path="code" htmlEscape="false"
                                                class="form-control required"/>
                                </td>
                                <td><font color="red">*</font>上级</td>
                                <td>
                                    <sys:treeselect id="parent" name="parent.id" value="${materialType.parent.id}"
                                                    labelName="parent.name" labelValue="${materialType.parent.name}"
                                                    title="父级编号" url="/warehouse/materialtype/materialType/treeData"
                                                    extId="${materialType.id}" cssClass="form-control required"
                                                    allowClear="true" callback="selectParent"/>
                                </td>
                            </tr>
                            <tr class="other-content">
                                <td><font color="red">*</font>单价</td>
                                <td>
                                    <form:input path="amount" type="number" htmlEscape="false" class="form-control required isIntGteZero"/>
                                </td>
                                <td><font color="red">*</font>单位</td>
                                <td>
                                    <form:input path="unit" htmlEscape="false" class="form-control required"/>
                                </td>
                            </tr>
                            <tr>
                                <td>备注</td>
                                <td colspan="3">
                                    <form:textarea path="remarks" htmlEscape="false" rows="4" class="form-control "/>
                                </td>
                            </tr>
                        </table>
                    </form:form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var info = ${fns:toJson(materialType)};

    console.log(info)
    function save() {
        var isValidate = jp.validateForm('#inputForm');//校验表单
        if(!isValidate){
            return false;
        }else{
            jp.loading();
            jp.post($("#inputForm").attr('action'),$('#inputForm').serialize(),function(data){
                if(data.success){
                    jp.getParent().refresh();
                    var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(dialogIndex);
                    jp.success(data.msg)

                }else{
                    jp.error(data.msg);
                }
            })
        }
    }

    otherContentShow(info.last === 1);

    function selectParent (row, id) {
        var item = row[0];
        otherContentShow(item.parents.length >= 2);
        $("#parentIds").val(item.parents.reverse().slice(1).join(',') + ',' + item.id + ',');
    }

    function otherContentShow (v) {
        v ? $(".other-content").show() : $(".other-content").hide();
    }
</script>
</body>
</html>
