add.html 4.21 KB
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
	.time-input {
		display: block;
		width: 40%;
		float: left;
		padding-left: 10px;
	}
</style>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-user-add">
			<input name="deptId"  type="hidden" id="treeId"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">设备名称:</label>
				<div class="col-sm-8">
					<select id="equipmentId" lay-filter="equipmentId" class="form-control m-b" th:with="equipment=${@equipment.getList()}" onchange="selectEqui(this.value)">
						<option value="">请选择</option>
						<option th:each="item : ${equipment}" th:text="${item['equipmentName']}" th:value="${item['id']}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">设备名称:</label>
				<div class="col-sm-8">
					<select id="methodId" class="form-control m-b"  >
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">数据类型:</label>
				<div class="col-sm-8">
					<select id="dataType" name="dataType" class="form-control m-b" >
						<option value="bool">bool</option>
						<option value="int">int</option>
						<option value="dint">dint</option>
						<option value="dword">dword</option>
						<option value="word">word</option>
						<option value="char">char</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label ">偏移量:</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" id="offset" name="offset"/>
				</div>
			</div>

			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/iCheck/icheck.min.js}"></script>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script>
		var prefix = ctx + "plc/equipmentMethod";



        $("#form-user-add").validate({
        	rules:{
        		username:{
        			required:true,
        		},
        		userPhone:{
        			required:true,
					isPhone:true,
        		},
				startTime:{
        			required:true,
        		},
				endTime:{
					required:true,
				},
        	},
        	messages: {
        		// "email": {
                 //    remote: "Email已经存在"
                // },
        		// "phoneNumber":{
                	// remote: "手机号码已经存在"
        		// }
            },
        	submitHandler:function(form){
        		add();
        	}
        });
		function selectEqui(val){
			$.ajax({
				url: prefix+"/list",
				type: 'post',
				dataType: "json",
				data: {
					equipmentId: val
				},
				success: function (value) {
					// console.log(value.data);
					$("#methodId").contents().remove();
					if (value != null && value.data.length >= 1)
						for (var i = 0; i < value.data.length; i++) {
							$('<option value=' + value.data[i].id + ' code=' + value.data[i].code + '>' + value.data[i].methodName + '</option>').appendTo('#methodId');
						}
				}
			})
		}

        function add() {
        	var id = $("input[name='id']").val();
        	var equipmentId = $("#equipmentId option:selected").val();
        	var methodId = $("#methodId option:selected").val();
			var dataType = $("#dataType option:selected").val();
			var offset = $("#offset").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "plc/equipmentOffset/addSave",
        		data : {
        			"id": id,
        			"equipmentId": equipmentId,
        			"methodId": methodId,
					"dataType": dataType,
					"offset":offset
        		},
        		async : false,
        		error : function(request) {
        			$.modal.msgError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
    </script>
</body>
</html>