define(function(require, exports, module) {
	var global = require("../../js/global");
	var jGlobal = require("./oneUpgradeGlobal");
	var deviceManage = require("../../deviceManage/js/deviceManage");
	
	//当前页面变量
//	var upgradeTableLength = null;
	var userClickRowArray = [];
	var countDownload = 0; 		//正在下载的计数，全部下载完成后才可以进入下一个页面
	
	//热补丁新增参数
	var curClickRow = {};
	var curClickIndex = null;
	
	function showUpgradeDeviceTable() {
//		console.error(jGlobal.oneUpgrade.multiDevRcmndVersion);
//		console.error(jGlobal.oneUpgrade.multiDevRcmndHotFix);
		
		var selectDevInfos = [];
		for (var key in jGlobal.oneUpgrade.multiDevRcmndVersion) {
			selectDevInfos.push(global.devicesIns.getDeviceInfoByDeviceName(key));
		}
//		console.error(selectDevInfos);
		
		var upgradeDevInfos = [];
		for (var i = 0; i < selectDevInfos.length; i++) {
			var flag = false; //是否已归类
			var deviceName = selectDevInfos[i].deviceName;
			
			for (var j = 0; j < upgradeDevInfos.length; j++) {	//补丁版本 + 推荐的大版本 完全一样的归为一类
				var tmpRecmndVersion = upgradeDevInfos[j].recmndVersion;
				var tmpRecmndHotFix = upgradeDevInfos[j].recmndHotFix;
				
				var tmpFlag = false;
				if (tmpRecmndHotFix.length == 0 && (tmpRecmndVersion != null && tmpRecmndVersion != '' && tmpRecmndVersion != '-')) { //补丁为空，大版本不为空
					if (tmpRecmndVersion == jGlobal.oneUpgrade.multiDevRcmndVersion[deviceName].softwareVersion) { //判断推荐的大版本 是否一致
						tmpFlag = true;
					}
				} else if (tmpRecmndHotFix.length != 0 && (tmpRecmndVersion == null || tmpRecmndVersion == '' || tmpRecmndVersion != '-')) { //补丁不为空，大版本为空
					if (checkHotFixSame(tmpRecmndHotFix, jGlobal.oneUpgrade.multiDevRcmndHotFix[deviceName])) { //判断补丁版本 是否一致
						tmpFlag = true;
					}
				} else if (tmpRecmndHotFix.length != 0 && (tmpRecmndVersion != null && tmpRecmndVersion != '' && tmpRecmndVersion != '-')) { //补丁和大版本都不为空
					if (checkHotFixSame(tmpRecmndHotFix, jGlobal.oneUpgrade.multiDevRcmndHotFix[deviceName]) &&
							(tmpRecmndVersion == jGlobal.oneUpgrade.multiDevRcmndVersion[deviceName].softwareVersion)) { //判断补丁版本 + 推荐的大版本 是否一致
						tmpFlag = true;
					}
				}
				
				if (tmpFlag) {
					flag = true;
					upgradeDevInfos[j].deviceName = "-";
					upgradeDevInfos[j].deviceNum++;
					upgradeDevInfos[j].deviceNames.push(deviceName);
					break;
				}
			}
//			if (!flag) {
//				for (var j = 0; j < upgradeDevInfos.length; j++) {	//按补丁归纳完后,推荐版本完全一样的归为一类
//					var tmpRecmndVersion = upgradeDevInfos[j].recmndVersion;
//					if (tmpRecmndVersion != null && tmpRecmndVersion != '' && tmpRecmndVersion != '-') { //有云端推荐版本
//						if (tmpRecmndVersion == jGlobal.oneUpgrade.multiDevRcmndVersion[deviceName].softwareVersion) {
//							flag = true;
//							upgradeDevInfos[j].deviceName = "-";
//							upgradeDevInfos[j].deviceNum++;
//							upgradeDevInfos[j].deviceNames.push(deviceName);
//							break;
//						}
//					}
//				}
//			}
			if (!flag) {
				for (var j = 0; j < upgradeDevInfos.length; j++) {	//补丁+大版本 不一致, 按型号和软件版本归为一类
					var upgradeDevInfo = upgradeDevInfos[j];
					if (selectDevInfos[i].deviceModel + selectDevInfos[i].softVer == upgradeDevInfo.deviceModel + upgradeDevInfo.softVer) {
						flag = true;
						upgradeDevInfos[j].deviceName = "-";
						upgradeDevInfos[j].deviceNum++;
						upgradeDevInfos[j].deviceNames.push(deviceName);
						break;
					}
				}
			}
			if (!flag) {	//无法归类,单独列出来
				var tmp_upgradeDevInfos = {};
				tmp_upgradeDevInfos.deviceNames = [];
				tmp_upgradeDevInfos.deviceNames.push(deviceName);
				
				tmp_upgradeDevInfos.deviceName = deviceName;
				tmp_upgradeDevInfos.deviceModel = selectDevInfos[i].deviceModel;
				tmp_upgradeDevInfos.hardVer = selectDevInfos[i].hardVer;
				tmp_upgradeDevInfos.softVer = selectDevInfos[i].softVer;
				tmp_upgradeDevInfos.recmndVersion = jGlobal.oneUpgrade.multiDevRcmndVersion[deviceName].softwareVersion;
				tmp_upgradeDevInfos.recmndHotFix = jGlobal.oneUpgrade.multiDevRcmndHotFix[deviceName];
				
				if ((typeof tmp_upgradeDevInfos.recmndVersion == 'string' && tmp_upgradeDevInfos.recmndVersion != '' && tmp_upgradeDevInfos.recmndVersion != '-') || (tmp_upgradeDevInfos.recmndHotFix.length != 0)) {
					tmp_upgradeDevInfos.upgradeVersion = "有新的大版本或补丁版本，请选择";
				} else {
				    tmp_upgradeDevInfos.upgradeVersion = "未匹配到推荐版本，可本地导入";
				}
				tmp_upgradeDevInfos.deviceNum = 1;
				tmp_upgradeDevInfos.recmndVersionMsg = jGlobal.oneUpgrade.multiDevRcmndVersion[deviceName];
				upgradeDevInfos.push(tmp_upgradeDevInfos);
			}
		}
//		upgradeTableLength = upgradeDevInfos.length;
//		console.error(upgradeDevInfos);
		
		$('#table_upgrade').bootstrapTable('load', upgradeDevInfos);
	}
	
	//判断补丁版本是否一致
	function checkHotFixSame(arrayA, arrayB) {		
		if ((arrayA.length == 0) || (arrayB.length == 0) || (arrayA.length != arrayB.length)) {
			return false;
		}
		
		var i = 0;
		for (i = 0; i < arrayA.length; i++) {
			if (arrayA[i].name != arrayB[i].name) {
				return false;
			}
		}
		
		return true;
	}
	
	function recmndVersionShow(value, row, index) {
		if (row.recmndVersion == undefined) {
			return;
		}

	    if (row.recmndVersion == "下载完成" || row.recmndVersion == "文件已存在") {
	    	return '<span style="color:#0cc757;">' + row.recmndVersion + '</span>';
	    } else if (row.recmndVersion == "下载失败" || row.recmndVersion == "md5校验失败") {
	    	return '<span style="color:#f5224c;">' + row.recmndVersion + '</span>';
	    } else {
	    	return '<span>' + row.recmndVersion + '</span>';
	    }
	}
	
	function operateForUpgradeTable() {
	    return '<div>' +
//	                '<div class="table-btn import" style="float: left; width: 75px;">本地导入</div>' +
//	                '<div class="table-btn download" style="float: left; width: 75px; margin-left: 5px;">云端下载</div>' +
	    			'<div class="table-btn select" style="width: 75px;" data-toggle="modal" data-target="#upgradeModal">选择版本</div>' +
	           '</div>';
	}
	
	function importLocalVersion(row, index) {
	    var import_localVersion = $('#selectLocalVersion');
	    import_localVersion.unbind('change');
	    import_localVersion.change(function(evt) {
	    	var srcFilePath = $(this).val();
	        var srcFilePath_array = srcFilePath.split('\\');        
	        var dstFilePath = global.nwPath.resolve(global.oneUpgradeIns.getRootDir(), srcFilePath_array[srcFilePath_array.length - 1]); //选中文件后，把该文件拷贝到指定目录下
	        var params = {};
	        params.srcFilePath = srcFilePath;
	        params.srcFilePath_array = srcFilePath_array;
	        params.dstFilePath = dstFilePath;
	        params.index = index;
	        params.row = row;
	        
	        $(this).val("");

	        if (row.deviceModel != null && row.deviceModel.indexOf("S2928G-E") != -1) {
	    		if (srcFilePath_array[srcFilePath_array.length - 1].length >= 32) {
	    			alert(undefined, "S2928G-E型号设备的升级bin文件名太长，请修改为小于32个字节！");
	    			return;
	    		}
	    	}
	        
	        $("#copyFileModal").modal('show');
	        global.oneUpgradeIns.selectAndCopyToFtpDir(srcFilePath, dstFilePath, selectAndCopyToFtpDirCallback, params);
	    });
	    import_localVersion.trigger('click');
	}
	
	function selectAndCopyToFtpDirCallback(params) {
		/* 拷贝完成后，用户输入md5进行校验 */
		$("#copyFileModal").modal('hide');
		$("#selectVersionModal").modal('show');
	    
	    var srcFilePath_array = params.srcFilePath_array;
	    
	    $("#inputMd5").val("");
	    $("#chooseVersion").val(srcFilePath_array[srcFilePath_array.length - 1]);
	    
	    $("#compareVersion").click(function() {
	    	try {
	    		var selectFileMd5 = global.jsUtil.countFileMd5(params.dstFilePath).toLocaleLowerCase();
				console.log(selectFileMd5);
				
		        if (selectFileMd5 == $("#inputMd5").val().toLocaleLowerCase()) {
//		        	$("#table_upgrade").bootstrapTable('updateRow', {
//		            	index: params.index,
//		            	row: {
//		            		recmndVersion: srcFilePath_array[srcFilePath_array.length - 1]
//		            	}
//		            });
		        	
		        	var fileName = srcFilePath_array[srcFilePath_array.length - 1];
		        	
		        	var $span = '<span class="prompt success">已导入</span>';
		        	$("#bigVersionBin").text(fileName);
		        	$("#bigVersionBin").next().remove();
		        	$("#bigVersionBin").parent().append($span);

		            for (var key in jGlobal.oneUpgrade.multiDevUpgradeVersion) {
		            	if ($.inArray(key, params.row.deviceNames) != -1) {
		        			var objectTmp = {};
		        			objectTmp.versionCode = fileName;
		        			objectTmp.versionName = fileName;
		        			objectTmp.fileMd5 = selectFileMd5;
		        			jGlobal.oneUpgrade.multiDevUpgradeVersion[key] = objectTmp;
		            	}
		            }
		            
		            //用户已点击了该行
					if ($.inArray(params.index, userClickRowArray) === -1) {
						userClickRowArray.push(params.index);
					}
		        } else {
//		        	$("#table_upgrade").bootstrapTable('updateRow', {
//		            	index: params.index,
//		            	row: {
//		            		recmndVersion: "md5校验失败"
//		            	}
//		            });
		        	
		        	$span = '<span class="prompt fail">md5校验失败</span>';
		        	$("#bigVersionBin").next().remove();
		        	$("#bigVersionBin").parent().append($span);
		        	
		        	for (var key in jGlobal.oneUpgrade.multiDevUpgradeVersion) {
		            	if ($.inArray(key, params.row.deviceNames) != -1) {
		            		jGlobal.oneUpgrade.multiDevUpgradeVersion[key] = "";
		            	}
		            }
		        }
		        
		        $("#compareVersion").unbind('click');
	    	} catch (e) {
	    		console.error("异常原因导致失败! ", e);
	    	}
	    });
	}
	
	function downloadVersionFromCloud(row, index) {
		if (row.recmndVersion == null || row.recmndVersion == '-' || row.recmndVersion == "" || row.recmndVersion == undefined) {
			alert(undefined, "云端暂无推荐规则，请根据版本管理系统进行评估。");		
			return;
		}
		if (row.softVer == row.recmndVersion) {
			alert(undefined, "已经是最新推荐版本！");
			return;
		}
		
		//判断当前版本是否已存在
		var downloadDirPath = global.oneUpgradeIns.getRootDir();
		var downloadFileName = row.recmndVersionMsg.fileName;
		var downloadFilePath = global.nwPath.resolve(downloadDirPath, downloadFileName);
		
		if (global.fs.existsSync(downloadFilePath)) { //文件名相同
//			$("#table_upgrade").bootstrapTable('updateRow', {
//				index: index,
//				row: {
//					recmndVersion: "文件已存在"
//				}
//			});
			
			var cloudMd5 = row.recmndVersionMsg.fileMd5.toLocaleLowerCase();
			var localMd5 = global.jsUtil.countFileMd5(downloadFilePath).toLocaleLowerCase();
			console.log("云端推荐版本的Md5 : " + cloudMd5);
			console.log("本地同名版本的Md5 : " + localMd5);
			
			if (cloudMd5 == localMd5) { //Md5也相同
				var $span = '<span class="prompt success">文件已存在</span>';
	        	$("#bigVersionBin").next().remove();
	        	$("#bigVersionBin").parent().append($span);

	        	for (var key in jGlobal.oneUpgrade.multiDevUpgradeVersion) {
	            	if ($.inArray(key, row.deviceNames) != -1) {
	        			var objectTmp = {};
	        			objectTmp.versionCode = row.recmndVersionMsg.fileName;
	        			objectTmp.versionName = row.recmndVersionMsg.fileName;
	        			objectTmp.fileMd5 = row.recmndVersionMsg.fileMd5;
	        			jGlobal.oneUpgrade.multiDevUpgradeVersion[key] = objectTmp;
	            	}
	            }
	        	
	        	//用户已下载了该行
				if ($.inArray(index, userClickRowArray) === -1) {
					userClickRowArray.push(index);
				}
				
				return;
			}
		}
		
//		$("#table_upgrade").bootstrapTable('updateRow', {
//			index: index, 
//			row: {
//				recmndVersion: "正在下载…"
//			}
//		});
		
		var $span = '<span class="prompt">正在下载…</span>';
    	$("#bigVersionBin").next().remove();
    	$("#bigVersionBin").parent().append($span);
    	$("#upgradeModal .close").hide();
		
		for (var key in jGlobal.oneUpgrade.multiDevUpgradeVersion) {
	    	if ($.inArray(key, row.deviceNames) != -1) {
	    		jGlobal.oneUpgrade.multiDevUpgradeVersion[key] = "";
	        }
	    }
		
		countDownload++;
		
		var addParams = {};
		addParams.deviceNames = row.deviceNames;
		addParams.index = index;
		addParams.recmndVersionMsg = row.recmndVersionMsg;
		global.oneUpgradeIns.downloadFileFromCloud(row.recmndVersionMsg, downloadFileFromCloudCallback, addParams);
	}

	function downloadFileFromCloudCallback(err, finish, dataLen, fileLen, addParams) {
		$("#upgradeModal .close").show();
		
		if (err != null) {
			countDownload--;
			
//			$("#table_upgrade").bootstrapTable('updateRow', {
//				index: addParams.index, 
//				row: {
//					recmndVersion: "下载失败"
//				}
//			});
			
			var $span = '<span class="prompt fail">下载失败</span>';
        	$("#bigVersionBin").next().remove();
        	$("#bigVersionBin").parent().append($span);
			
			return;
		}
		
		if (finish == true) {
			setTimeout(function() {
				countDownload--;
				
				var downloadDirPath = global.oneUpgradeIns.getRootDir();
				var downloadFileName = addParams.recmndVersionMsg.fileName;
				var downloadFilePath = global.nwPath.resolve(downloadDirPath, downloadFileName);		
				var downloadFileMd5 = global.jsUtil.countFileMd5(downloadFilePath);
				
				if (downloadFileMd5 == addParams.recmndVersionMsg.fileMd5) {
//					$("#table_upgrade").bootstrapTable('updateRow', {
//						index: addParams.index,
//						row: {
//							recmndVersion: "下载完成"
//						}
//					});
					
					var $span = '<span class="prompt success">下载完成</span>';
		        	$("#bigVersionBin").next().remove();
		        	$("#bigVersionBin").parent().append($span);
					
					for (var key in jGlobal.oneUpgrade.multiDevUpgradeVersion) {
						if ($.inArray(key, addParams.deviceNames) != -1) {
							var objectTmp = {};
							objectTmp.versionCode = addParams.recmndVersionMsg.softwareVersion;
							objectTmp.versionName = addParams.recmndVersionMsg.fileName;
							objectTmp.fileMd5 = addParams.recmndVersionMsg.fileMd5;
							jGlobal.oneUpgrade.multiDevUpgradeVersion[key] = objectTmp;
						}
					}
					
					//用户已下载了该行
					if ($.inArray(addParams.index, userClickRowArray) === -1) {
						userClickRowArray.push(addParams.index);
					}
				} else {
//					$("#table_upgrade").bootstrapTable('updateRow', {
//						index: addParams.index,
//						row: {
//							recmndVersion: "md5校验失败"
//						}
//					});
					
					var $span = '<span class="prompt fail">md5校验失败</span>';
		        	$("#bigVersionBin").next().remove();
		        	$("#bigVersionBin").parent().append($span);
				}
			}, 5000);
		}
	}
	
	function selectUpgradeVersion(row, index) {
		curClickRow = row;
		curClickIndex = index;
		
		//升级大版本界面初始化
		$("#bigVersionRadio").prop('checked', true);
		$("#hotFixRadio").prop('checked', false);
		$("#bigVersionBin").next().remove();

		if (row.recmndVersion != null && row.recmndVersion != '') {
			$("#bigVersionBin").text(row.recmndVersion);
		} else {
			$("#bigVersionBin").text("云端无推荐版本,请从本地导入");
		}
		
		//升级补丁版本界面初始化
		$('#patchUpgradeTable').bootstrapTable({
	        data: []
	    });
		
		//加载补丁数据
		var patchInfo = jGlobal.oneUpgrade.multiDevRcmndHotFix[row.deviceNames[0]];
		console.error("当前选中的设备的补丁信息: ", patchInfo);
		
		var patchList = [];
		for (var i = 0; i < patchInfo.length; i++) {
			var patch = {};
			patch.name = patchInfo[i].name;
			patch.isUpgradeFrame = patchInfo[i].isUpgradeFrame;
			patch.isHotfix = patchInfo[i].isHotfix;
			patch.compileVer = patchInfo[i].compileVer;
			patch.legend = patchInfo[i].details;
			patchList.push(patch);
		}
		
		$('#patchUpgradeTable').bootstrapTable('load', patchList);
		$(".fixed-table-body").addClass('custom-scroll');
		$('#patchUpgradeTable').bootstrapTable('resetView', {height : 300});
		
		//升级补丁默认勾上切不能让用户编辑
		$('#patchUpgradeTable input[name="btSelectItem"]').each(function() {
			if ($(this).parent().next().next().text() == "升级补丁") {
				$(this).attr("disabled", true);
			}
		});
	}
	
	function isUpgradeFrameFormat(value, row, index) {
		if (value) {
			return '升级补丁';
		} else {
			return '普通补丁';
		}
	}
	function legendFormat(value, row, index) {
		var $div = '<div class="patchLegend" title=' + value.replace(/\s+/g, '') + '>' + value + '</div>';
		return $div;
	}
	function isHotfixFormat(value, row, index) {
		if (value) {
			return '热补丁';
		} else {
			return '冷补丁';
		}
	}
	function patchStatusFormat(value, row, index) {
		
	}
	
	function checkboxFormat(value, row, index) {
		return true;
	}
	
	function init() {
		initWindowEvent();
		initPageStatistic();
		initVariable();
		removeGlobalEvent();
		initTable();
		initEvent();
		initDom();
		resize();
		initGlobalEvent();
		
		function initWindowEvent() {
			window.operateForUpgradeTable = operateForUpgradeTable;
			window.recmndVersionShow = recmndVersionShow;
			window.operateEventsForUpgrade = {
//				'click .import': function (e, value, row, index) {        
//			    	importLocalVersion(row, index);
//			    },
//			    'click .download': function (e, value, row, index) {
//			    	downloadVersionFromCloud(row, index);
//			    },
			    'click .select': function (e, value, row, index) {
			    	selectUpgradeVersion(row, index);
			    }
			};
//			window.compareVersion = compareVersion;
			window.isUpgradeFrameFormat = isUpgradeFrameFormat;
			window.isHotfixFormat = isHotfixFormat;
			window.patchStatusFormat = patchStatusFormat;
			window.checkboxFormat = checkboxFormat;
			window.legendFormat = legendFormat;
		}
		function initPageStatistic() {
			statRecordEle("oneUpgrade#selectVersion");
		}
		function initVariable() {
//			upgradeTableLength = null;
			userClickRowArray = [];
			countDownload = 0;
			
			curClickRow = {};
			curClickIndex = null;
		}
		function removeGlobalEvent() {
			global.devicesIns.removeAllListeners("deviceConnected");
			global.devicesIns.removeAllListeners("deviceError");
			global.devicesIns.removeAllListeners("deviceDisconnected");
			
			global.oneUpgradeIns.reg();
		}
		function initTable() {
			$('#table_upgrade').bootstrapTable({
		        data: []
		    });
			
			$(".fixed-table-body").addClass('custom-scroll');
			$("#table_upgrade").show();
			
			showUpgradeDeviceTable();
		}
		function initEvent() {
			$("#selectVersionBack").click(function() {
//				$(".main_content").load("./oneUpgrade/html/selectDevice.html");
				
				var curElement = ".main_content", nextPageUrl = "./oneUpgrade/html/oneUpgradeMenu.html";
				global.enterPageCallback(curElement, nextPageUrl);
			});
			
			$("#gotoUpgrade").click(function() {
//				$(".main_content").load("./oneUpgrade/html/upgrading.html");

//				if (countDownload != 0) {
//					alert(undefined, "还有升级版本未下载完成，请耐心等待！");
//					return;
//				}
				
				if (userClickRowArray.length >= 1) {
					var curElement = ".main_content", nextPageUrl = "./oneUpgrade/html/upgrading.html";
					global.enterPageCallback(curElement, nextPageUrl);
				} else {
					alert(undefined, "还未确认升级版本，请确认！");
				}
			});
			
			/* 热补丁升级新增事件 */
//			$("#hotFixRadio").click(function() {				
//				$('#hotFixContent input[type="checkbox"]').each(function() {
//					$(this).prop('checked', true);
//				});
//			});
//			
//			$("#bigVersionRadio").click(function() {				
//				$('#hotFixContent input[type="checkbox"]').each(function() {
//					$(this).prop('checked', false);
//				});
//			});
			
			$("#bigVersionImport").click(function() {
				importLocalVersion(curClickRow, curClickIndex);
			});
			
			$("#bigVersionDownload").click(function() {
				if (countDownload != 0) {
					alert(undefined, "正在下载中，请稍候！");
					return;
				}
				downloadVersionFromCloud(curClickRow, curClickIndex);
			});
			
			$("#upgradeModal .close").click(function() {				
				//判断是否还有未下载完的版本
				if (countDownload != 0) {
					alert(undefined, "还有版本未下载完成，请耐心等待！");
					return;
				}
				
				$("#upgradeModal").modal('hide');
			});
			
			$("#upgradeModal .btn-confirm").click(function() {
				//判断是否还有未下载完的版本
				if (countDownload != 0) {
					alert(undefined, "还有版本未下载完成，请耐心等待！");
					return;
				}
				
				//选择的是补丁版本
				var isHotFix = $("#hotFixRadio").is(':checked');
				if (isHotFix) {
					//热补丁存储数据
					var hotFixNameArray = $("#patchUpgradeTable").bootstrapTable('getSelections');
					if (hotFixNameArray.length == 0) {
						alert(undefined, "若需要升级补丁，请至少选择一个补丁版本！");
						return;
					}
					for (var key in jGlobal.oneUpgrade.multiDevHotFix) {
						if ($.inArray(key, curClickRow.deviceNames) != -1) {
							jGlobal.oneUpgrade.multiDevHotFix[key] = [];
							jGlobal.oneUpgrade.multiDevHotFix[key] = hotFixNameArray;
						}
					}
					
					//大版本存储数据
					for (var key in jGlobal.oneUpgrade.multiDevUpgradeVersion) {
				    	if ($.inArray(key, curClickRow.deviceNames) != -1) {
				    		jGlobal.oneUpgrade.multiDevUpgradeVersion[key] = "";
				        }
				    }
					
					//用户已选择了该行的版本
					if (hotFixNameArray.length > 0) {
						if ($.inArray(curClickIndex, userClickRowArray) == -1) {
							userClickRowArray.push(curClickIndex);
						}
					}
				}
				
				//选择的是大版本
				var isBigVersion = $("#bigVersionRadio").is(':checked');
				if (isBigVersion) {
					//大版本数据在本地导入或云端下载时已存入
					var text = $("#bigVersionBin").next().text();
					if (text == '' || text.match("失败") != null) {
						alert(undefined, "若需要升级大版本，请导入或下载大版本！");
						return;
					}
					
					//热补丁存储数据 
					for (var key in jGlobal.oneUpgrade.multiDevHotFix) {
				    	if ($.inArray(key, curClickRow.deviceNames) != -1) {
				    		jGlobal.oneUpgrade.multiDevHotFix[key] = [];
				        }
				    }
				}
				
				console.error("大版本: ", jGlobal.oneUpgrade.multiDevUpgradeVersion);
				console.error("补丁版本: ", jGlobal.oneUpgrade.multiDevHotFix);
				
				$("#upgradeModal").modal('hide');
			});
			
			//关闭选择版本对话框后更新表格
			$('#upgradeModal').on('hide.bs.modal', function() {
				//选择的是补丁版本
				var isHotFix = $("#hotFixRadio").is(':checked');
				if (isHotFix) {
					$("#table_upgrade").bootstrapTable('updateRow', {
						index: curClickIndex,
						row: {
							upgradeVersion: "补丁版本"
						}
					});
				}
				
				//选择的是大版本
				var isBigVersion = $("#bigVersionRadio").is(':checked');
				if (isBigVersion) {
					var text = $("#bigVersionBin").text();
					if (text.match("无推荐版本") == null && text.match("失败") == null) {
						$("#table_upgrade").bootstrapTable('updateRow', {
							index: curClickIndex,
							row: {
								upgradeVersion: text
							}
						});
					}
				}
			});
			
			$("#hotFixDownload").click(function() {
				alert(undefined, "云端功能暂未开放！");
			});
		}
		function initDom() {
			$('#selectVersionModal').modal({
				backdrop: 'static',
				show: false
			});
			
			$('#upgradeModal').modal({
				backdrop: 'static',
				show: false
			});
			
			$('#copyFileModal').modal({
				backdrop: 'static',
				show: false
			});
		}
		function resize() {
			var client_h = document.documentElement.clientHeight;
			var head_h = $(".main_menu").height();
			var body_h = client_h - head_h;
			
			$('#table_upgrade').bootstrapTable('resetView', {height : body_h - 55 - 65});
		}
		function initGlobalEvent() {
			global.exitPageCallback.exitFun = function () {
				removeGlobalEvent();
				return true;
			}
		}
	}
	exports.init = init;
});