| 
					
				 | 
			
			
				@@ -7,19 +7,37 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 $(document).ready(function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let isAdding = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let model = ''; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 初始化数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     initVersion(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 新增版本 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $("#add-version").click(function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            let [name, standardBill, rationLib, standardBillString, rationLibString] = getAndValidData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let [name, standardBill, rationLib, standardBillString, rationLibString] = getAndValidData(model); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let id = $("#version-id").val(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let postData = {}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            let url = '/version/add'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            switch (model) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                case 'all': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    postData = {model: model, name: name, standard_bill_id: standardBill, ration_lib_id: rationLib, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        standard_bill: standardBillString, ration_lib: rationLibString}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                case 'bill': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    url = '/version/addLib'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    postData = {model: model, standard_bill_id: standardBill, standard_bill: standardBillString, id: id}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                case 'ration': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    url = '/version/addLib'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    postData = {model: model, ration_lib_id: rationLib, ration_lib: rationLibString, id: id}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             $.ajax({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                url: '/version/add', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                url: url, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 type: 'post', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                data: {name: name,standard_bill_id: standardBill, ration_lib_id: rationLib, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    standard_bill: standardBillString, ration_lib: rationLibString}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                data: postData, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 error: function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     isAdding = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -69,6 +87,71 @@ $(document).ready(function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         targetSelector.html(html); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 添加 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $(".add-version").click(function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        model = $(this).data('model'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        switch (model) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 'all': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#name-area").show(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#bill-area").show(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#ration-area").show(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#add-version-title").text('添加新版本'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 'bill': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#name-area").hide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#bill-area").show(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#ration-area").hide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#add-version-title").text('添加标准清单'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            case 'ration': 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#name-area").hide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#bill-area").hide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#ration-area").show(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                $("#add-version-title").text('添加定额库'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $("#addversion").modal('show'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 移除操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    let isDeleting = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $(".remove-version").click(function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let model = $(this).data('model'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let id = $("#version-id").val(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let deleteId = $(this).data('id'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        deleteId = parseInt(deleteId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (model === undefined || model === '' || isNaN(deleteId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (isDeleting) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $.ajax({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            url: '/version/deleteLib', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            type: 'post', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            data: {id: id, model: model, delete_id: deleteId}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            error: function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                isDeleting = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            beforeSend: function() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                isDeleting = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            success: function(response) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                isDeleting = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (response.err === 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    window.location.reload(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    let msg = response.msg === undefined ? '未知错误' : response.msg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    alert(msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -103,22 +186,23 @@ function initVersion() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 校验数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @param {String} model 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @return {Array} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function getAndValidData() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function getAndValidData(model) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let name = $("input[name='version_name']").val(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let standardBill = $("select[name='standard_bill']").val(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let rationLib = $("select[name='ration_lib']").val(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (name === '') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (name === '' && model === 'all') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw '版本名字不能为空'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (standardBill === '' || standardBill === undefined) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if ((model === 'all' || model === 'bill') && (standardBill === '' || standardBill === undefined)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw '请选择标准清单库'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    if (rationLib === '' || rationLib === undefined) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if ((model === 'all' || model === 'ration') && (rationLib === '' || rationLib === undefined)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw '请选择定额库'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |