<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>案例材料单价管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var validateForm;
		$(document).ready(function() {
			validateForm = $("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
            laydate.render({
                elem: '#useDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });

            $("#taxPrice").blur(function(){
                var taxprice = $(this).val() || 0;
                var tax = $("#tax").val() || 0;
                if(tax){
                    var p = taxprice / (1 + tax/100) || 0;
                    $("#price").val(p.toFixed(2))
                }
            })
            $("#tax").blur(function(){
                var taxprice = $("#taxPrice").val() || 0;
                var tax = $(this).val() || 0;
                if(taxprice){
                    var p = taxprice / (1 + tax/100)
                    $("#price").val(p.toFixed(2))
                }
            })
	    });
        function doSubmit(editFlag){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            var name = $("#name").val();
            var flag = $("#flag").val();
            var specification = $("#specification").val();
            var calculateUnit = $("#calculateUnit").val();
            var taxPrice = $("#taxPrice").val();
            var price = $("#price").val();
            var useDate = $("#useDate").val();
            var source = $("#source").val();
            var tax = $("#tax").val();
            var material = $("#material").val();
            var brand = $("#brand").val();
            var pp = $("#pp").val();
            var areaId = $("#areaId").val();
            var areaName = $("#areaName").val();
            var index = $("#index").val();
            var map = {};
                map["name"] = name;
                map["specification"] = specification;
                map["calculateUnit"] = calculateUnit;
                map["taxPrice"] = taxPrice;
                map["price"] = price;
                map["useDate"] = useDate;
                map["source"] = source;
                map["tax"] = tax;
                map["material"] = material;
                map["brand"] = brand;
                map["pp"] = pp;
            map["areaId"] = areaId;
            map["areaName"] = areaName;
                map["index"] = index;
                map["editFlag"] = editFlag;
                map["flag"] = flag;
            return JSON.stringify(map);
        }
	</script>
</head>
<body>
<div class="single-form">
    <div class="container">
            <input id="index" value="${caseMaterials.index}" type="hidden">
            <form:form id="inputForm" modelAttribute="caseMaterials"  action="${ctx}/casematerials/caseMaterials/save" method="post" class="form-horizontal">
                <form:hidden path="id"/>
                <input type="hidden" value="${caseInfo.id}" name="caseInfo.id" >
                <input type="hidden" value="${caseMaterials.id}" id="flag" name="flag">

                <div class="form-group layui-row first lw12">
                    <div class="form-group-label"><h2>材价信息</h2></div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label"><span class="require-item">*</span>材料名称：</label>
                        <div class="layui-input-block">
                            <form:input path="name" id="name" htmlEscape="false"  class="form-control layui-input"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">单位：</label>
                        <div class="layui-input-block">
                            <form:input path="calculateUnit" id="calculateUnit" htmlEscape="false"  class="form-control layui-input"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">税率：</label>
                        <div class="layui-input-block">
                            <div class="input-group">
                                <form:input path="tax" id="tax" htmlEscape="false" class="form-control number layui-input" /> <span class="input-group-addon" style="border:none;">%</span>
                            </div>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">材料含税价：</label>
                        <div class="layui-input-block">
                            <form:input path="taxPrice" id="taxPrice" htmlEscape="false"   class="form-control number layui-input"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">材料除税价：</label>
                        <div class="layui-input-block">
                            <form:input path="price" id="price" htmlEscape="false"  class="form-control layui-input" readonly="true"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">价格取用日期：</label>
                        <div class="layui-input-block">
                            <input id="useDate" name="useDate" type="text"  maxlength="20" class="laydate-icondate form-control layer-date layui-input laydate-icon"
                                   value="<fmt:formatDate value="${caseMaterials.useDate}" pattern="yyyy-MM-dd"/>"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">价格来源：</label>
                        <div class="layui-input-block">
                            <form:select path="source" class="form-control simple-select">
                                <form:option value="" label=""/>
                                <form:options items="${fns:getDictList('caseM_source')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                            </form:select>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">规格型号：</label>
                        <div class="layui-input-block">
                            <form:input path="specification" id="specification" htmlEscape="false"   class="form-control layui-input"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">材质：</label>
                        <div class="layui-input-block">
                            <form:input path="material" id="material" htmlEscape="false"  class="form-control layui-input"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm6">
                        <label class="layui-form-label">品牌：</label>
                        <div class="layui-input-block">
                            <form:input path="brand" id="brand" htmlEscape="false"  class="form-control layui-input"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm12 with-textarea">
                        <label class="layui-form-label">参数性能：</label>
                        <div class="layui-input-block">
                            <form:textarea path="pp" id="pp"  rows="4"  htmlEscape="false"  maxlength="500" class="form-control"/>
                        </div>
                    </div>
                    <div class="layui-item layui-col-sm12">
                        <label class="layui-form-label">厂商/工厂所在地：</label>
                        <div class="layui-input-block with-icon">
                            <sys:treeselect id="area" name="area.id" value="${caseMaterials.area.id}" labelName="area.name" labelValue="${caseMaterials.area.name}"
                                            title="区域" url="/sys/area/treeData" cssClass="form-control required simple-select" notAllowSelectParent="true"/>
                            </td>
                        </div>
                    </div>

                 </div>
            </form:form>
    </div>
</div>
</body>
</html>