123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 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<this.length;i++)
- {
- if(this[i]!=this[dx])
- {
- this[n++]=this[i];
- }
- }
- this.length-=1;
- }
|