assetManageEdit.js 8.6 KB
Newer Older
doc_wei's avatar
doc_wei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

var userList = new Array();//选择用户返回的集合或者进行回显的集合
var employeeuserList = new Array();//选择用户返回的集合或者进行回显的集合
var userReturnList = new Array();//选择用户返回的集合或者进行回显的集合
var chooseOrNotMy = "1";//人员列表中是否包含自己--1.包含;其他参数不包含
var chooseOrNotEmail = "2";//人员列表中是否必须绑定邮箱--1.必须;其他参数没必要
var checkType = "2";//人员选择类型,1.多选;其他。单选

// 资产信息
layui.config({
	base: basePath, 
	version: skyeyeVersion
}).extend({
    window: 'js/winui.window'
}).define(['window', 'jquery', 'winui', 'fileUpload', 'tagEditor', 'laydate'], function (exports) {
	winui.renderColor();
	layui.use(['form'], function (form) {
		var index = parent.layer.getFrameIndex(window.name);
	    var $ = layui.$,
	    	laydate = layui.laydate;

	    showGrid({
		 	id: "showForm",
doc_wei's avatar
doc_wei 已提交
24
		 	url: flowableBasePath + "asset004",
doc_wei's avatar
doc_wei 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
		 	params: {rowId:parent.rowId},
		 	pagination: false,
		 	template: getFileContent('tpl/assetManage/assetManageEditTemplate.tpl'),
		 	ajaxSendLoadBefore: function(hdb){
		 		hdb.registerHelper("compare1", function(v1, options){
					if(isNull(v1)){
						return path + "assets/img/uploadPic.png";
					}else{
						return basePath + v1;
					}
				});
		 	},
		 	ajaxSendAfter:function(json){
		 		//生产日期
		 		laydate.render({ 
		 		  elem: '#manufacturerTime'
		 		  ,type: 'date'
		 	 	  ,max: getFormatDate(),// 设置最大可选的日期
		 	 	  trigger: 'click'
		 		});
		 		
		 		//采购日期
		 		laydate.render({ 
		 		  elem: '#purchaseTime'
		 		  ,type: 'date'
		 	 	  ,max: getFormatDate(),// 设置最大可选的日期
		 	 	  trigger: 'click'
		 		});
		 		
		 		//资产类型
		 		showGrid({
				 	id: "typeId",
doc_wei's avatar
doc_wei 已提交
57
				 	url: flowableBasePath + "assettype006",
doc_wei's avatar
doc_wei 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71
				 	params: {},
				 	pagination: false,
				 	template: getFileContent('tpl/template/select-option-must.tpl'),
				 	ajaxSendLoadBefore: function(hdb){
				 	},
				 	ajaxSendAfter:function(j){
				 		$("#typeId").val(json.bean.typeId);
				 		form.render('select');
				 	}
				});
		 		
		 		//资产来源
		 		showGrid({
				 	id: "fromId",
doc_wei's avatar
doc_wei 已提交
72
				 	url: flowableBasePath + "assetfrom006",
doc_wei's avatar
doc_wei 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
				 	params: {},
				 	pagination: false,
				 	template: getFileContent('tpl/template/select-option-must.tpl'),
				 	ajaxSendLoadBefore: function(hdb){
				 	},
				 	ajaxSendAfter:function(j){
				 		$("#fromId").val(json.bean.fromId);
				 		form.render('select');
				 	}
				});
		 		
		 		//初始化上传
		 		$("#assetImg").upload({
		            "action": reqBasePath + "common003",
		            "data-num": "1",
		            "data-type": "PNG,JPG,jpeg,gif",
		            "uploadType": 6,
		            "data-value": json.bean.assetImg,
		            //该函数为点击放大镜的回调函数,如没有该函数,则不显示放大镜
		            "function": function (_this, data) {
		                show("#assetImg", data);
		            }
		        });
		 		var userNames = [];
		 		userList = [].concat(json.bean.assetAdmin);
		 		$.each(json.bean.assetAdmin, function(i, item){
		 			userNames.push(item.name);
		 		});
		 		//管理人员选择
				$('#assetAdmin').tagEditor({
			        initialTags: userNames,
			        placeholder: '请选择资产管理人',
					editorTag: false,
			        beforeTagDelete: function(field, editor, tags, val) {
			        	var inArray = -1;
				    	$.each(userList, function(i, item) {
				    		if(val === item.name) {
				    			inArray = i;
				    			return false;
				    		}
				    	});
				    	if(inArray != -1) { //如果该元素在集合中存在
				    		userList.splice(inArray, 1);
				    	}
			        }
			    });
				
				var employeeuserNames = [];
		 		employeeuserList = [].concat(json.bean.employeeId);
		 		$.each(json.bean.employeeId, function(i, item){
		 			employeeuserNames.push(item.name);
		 		});
				//领用人选择
				$('#employeeId').tagEditor({
			        initialTags: employeeuserNames,
			        placeholder: '请选择领用人',
					editorTag: false,
			        beforeTagDelete: function(field, editor, tags, val) {
			        	var inArray = -1;
				    	$.each(employeeuserList, function(i, item) {
				    		if(val === item.name) {
				    			inArray = i;
				    			return false;
				    		}
				    	});
				    	if(inArray != -1) { //如果该元素在集合中存在
				    		employeeuserList.splice(inArray, 1);
				    	}
			        }
			    });

				// 附件回显
				skyeyeEnclosure.initTypeISData({'enclosureUpload': json.bean.enclosureInfo});

    			matchingLanguage();
		 		form.render();
		 	    form.on('submit(formEditBean)', function (data) {
		 	        if (winui.verifyForm(data.elem)) {
		 	        	var params = {
	 	        			rowId: parent.rowId,
	 	        			assetName: $("#assetName").val(),
	 	        			assetNum: $("#assetNum").val(),
	 	        			specifications: $("#specifications").val(),
	 	        			unitPrice: $("#unitPrice").val(),
	 	        			manufacturer: $("#manufacturer").val(),
	 	        			manufacturerTime: $("#manufacturerTime").val(),
	 	        			supplier: $("#supplier").val(),
	 	        			purchaseTime: $("#purchaseTime").val(),
	 	        			storageArea: $("#storageArea").val(),
	 	        			roomAddDesc: $("#roomAddDesc").val(),
							typeId: $("#typeId").val(),
							fromId: $("#fromId").val(),
							enclosureInfo: skyeyeEnclosure.getEnclosureIdsByBoxId('enclosureUpload')
	 	 	        	};
	 	 	        	params.assetImg = $("#assetImg").find("input[type='hidden'][name='upload']").attr("oldurl");
	 	 	        	if(isNull(params.assetImg)){
	 	 	        		winui.window.msg('请上传资产图片', {icon: 2,time: 2000});
	 	 	        		return false;
	 	 	        	}
	 	 	        	if(userList.length == 0 || isNull($('#assetAdmin').tagEditor('getTags')[0].tags)){
	 	 	        		params.assetAdmin = "";
	 	 	        	}else{
	 	        			params.assetAdmin = userList[0].id;
	 	        		}
	 	 	        	if(employeeuserList.length == 0 || isNull($('#employeeId').tagEditor('getTags')[0].tags)){
	 	 	        		params.employeeId = "";
	 	 	        	}else{
	 	        			params.employeeId = employeeuserList[0].id;
	 	        		}
doc_wei's avatar
doc_wei 已提交
182
	 	 	        	AjaxPostUtil.request({url: flowableBasePath + "asset005", params:params, type: 'json', callback: function(json){
doc_wei's avatar
doc_wei 已提交
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
	 		 	   			if(json.returnCode == 0){
	 			 	   			parent.layer.close(index);
	 			 	        	parent.refreshCode = '0';
	 		 	   			}else{
	 		 	   				winui.window.msg(json.returnMessage, {icon: 2,time: 2000});
	 		 	   			}
	 		 	   		}});
		 	        }
		 	        return false;
		 	    });
		 	}
		});
	    
	    //管理人员选择
		$("body").on("click", "#userNameSelPeople", function(e){
			userReturnList = [].concat(userList);
			_openNewWindows({
				url: "../../tpl/common/sysusersel.html", 
				title: "人员选择",
				pageId: "sysuserselpage",
				area: ['80vw', '80vh'],
				callBack: function(refreshCode){
					if (refreshCode == '0') {
						//移除所有tag
						var tags = $('#assetAdmin').tagEditor('getTags')[0].tags;
						for (i = 0; i < tags.length; i++) { 
							$('#assetAdmin').tagEditor('removeTag', tags[i]);
						}
						userList = [].concat(userReturnList);
					    //添加新的tag
						$.each(userList, function(i, item){
							$('#assetAdmin').tagEditor('addTag', item.name);
						});
	                } else if (refreshCode == '-9999') {
	                	winui.window.msg(systemLanguage["com.skyeye.operationFailed"][languageType], {icon: 2,time: 2000});
	                }
				}});
		});
		
		//领用人选择
		$("body").on("click", "#employeePeople", function(e){
			userReturnList = [].concat(employeeuserList);
			_openNewWindows({
				url: "../../tpl/common/sysusersel.html", 
				title: "人员选择",
				pageId: "sysuserselpage",
				area: ['80vw', '80vh'],
				callBack: function(refreshCode){
					if (refreshCode == '0') {
						//移除所有tag
						var tags = $('#employeeId').tagEditor('getTags')[0].tags;
						for (i = 0; i < tags.length; i++) { 
							$('#employeeId').tagEditor('removeTag', tags[i]);
						}
						employeeuserList = [].concat(userReturnList);
					    //添加新的tag
						$.each(employeeuserList, function(i, item){
							$('#employeeId').tagEditor('addTag', item.name);
						});
	                } else if (refreshCode == '-9999') {
	                	winui.window.msg(systemLanguage["com.skyeye.operationFailed"][languageType], {icon: 2,time: 2000});
	                }
				}});
		});
	    
	    $("body").on("click", ".enclosureItem", function(){
	    	download(fileBasePath + $(this).attr("rowpath"), $(this).html());
	    });
	    
	    $("body").on("click", "#cancle", function(){
	    	parent.layer.close(index);
	    });
	});
});