var yaohaoId = null; var securityPersonId = null; var roomType = null; var communityName = null; //房源属性 var houseArray = null; var communityNameArray = null; var houseIndex = -1; var currentId = null; var isJump = false; $(function() { yaohaoId = $("#yaohaoId").val(); securityPersonId = $("#securityPersonId").val(); roomType = $("#roomType").val(); communityName = $("#communityName").val(); getHouseArray(); }); //点击开始摇号 $("#houseBegin").click( function(){ if(isJump == false){ isJump = true; jump(); } } ); //点击停止摇号 $("#houseOK").click( function(){ if(isJump == true){ isJump = false; var sum = GetRandomNum(houseArray.length,houseArray.length*2); stop(sum); } } ); //根据摇号id获取房源列表 var getHouseArray = function(){ $.ajax({ type: "post",//使用post方法访问后台 dataType: "json",//返回json格式的数据 url: "yaohaoAction_listHouseByYaohao1",//要访问的后台地址 data:{"yaohaoId":yaohaoId ,"roomType" :roomType , "communityName" : communityName }, success: function(msg){//msg为返回的数据,在这里做数据绑定 if(msg.success){ houseArray = msg.obj.rows; if(houseArray[0] != null ){ currentId = houseArray[0].id; } } } }); } //获取房源数组中下一个元素的id var getNextId = function(){ if(houseArray!=null && houseArray.length > 0){ if(houseIndex >= houseArray.length-1 ){ houseIndex = 0; }else{ houseIndex++; } return houseArray[houseIndex].id; } } var jump = function(){ if(!isJump) { return; }else{ $("#house_" + currentId ).removeClass('active'); currentId = getNextId(); $("#house_" + currentId ).addClass('active'); setTimeout("jump()",50); } } var stop = function(count){ if(count == 0){ setTimeout("reviewHouse()",300); return ; }else{ $("#house_" + currentId ).removeClass('active'); currentId = getNextId(); $("#house_" + currentId ).addClass('active'); count--; setTimeout("stop("+ count + ")",50 + 400/count); } } var reviewHouse = function (){ $.ajax({ type: "post",//使用post方法访问后台 dataType: "json",//返回json格式的数据 url: "yaohaoAction_updateYaohaoItem",//要访问的后台地址 data:{"yaohao.id":yaohaoId , "house.id":currentId , "securityPerson.id":securityPersonId }, success: function(msg){//msg为返回的数据,在这里做数据绑定 if(msg.success){ $('#yaohaoItemDataGrid').datagrid('reload'); } } }); $('#housestop').modal(); $("#house_" + currentId ).removeClass('active'); $("#house_" + currentId ).addClass('ignore'); houseArray.remove(houseIndex); } //获取随机数 function GetRandomNum(Min,Max) { var Range = Max - Min; var Rand = Math.random(); return(Min + Math.round(Rand * Range)); } /* * 方法:Array.remove(dx) 通过遍历,重构数组 * 功能:删除数组元素. * 参数:dx删除元素的下标. */ Array.prototype.remove=function(dx) { if(isNaN(dx)||dx>this.length){return false;} for(var i=0,n=0;i