houseYaohao.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. var yaohaoId = null;
  2. var securityPersonId = null;
  3. var roomType = null;
  4. var communityName = null;
  5. //房源属性
  6. var houseArray = null;
  7. var communityNameArray = null;
  8. var houseIndex = -1;
  9. var currentId = null;
  10. var isJump = false;
  11. $(function() {
  12. yaohaoId = $("#yaohaoId").val();
  13. securityPersonId = $("#securityPersonId").val();
  14. roomType = $("#roomType").val();
  15. communityName = $("#communityName").val();
  16. getHouseArray();
  17. });
  18. //点击开始摇号
  19. $("#houseBegin").click(
  20. function(){
  21. if(isJump == false){
  22. isJump = true;
  23. jump();
  24. }
  25. }
  26. );
  27. //点击停止摇号
  28. $("#houseOK").click(
  29. function(){
  30. if(isJump == true){
  31. isJump = false;
  32. var sum = GetRandomNum(houseArray.length,houseArray.length*2);
  33. stop(sum);
  34. }
  35. }
  36. );
  37. //根据摇号id获取房源列表
  38. var getHouseArray = function(){
  39. $.ajax({
  40. type: "post",//使用post方法访问后台
  41. dataType: "json",//返回json格式的数据
  42. url: "yaohaoAction_listHouseByYaohao1",//要访问的后台地址
  43. data:{"yaohaoId":yaohaoId ,"roomType" :roomType , "communityName" : communityName },
  44. success: function(msg){//msg为返回的数据,在这里做数据绑定
  45. if(msg.success){
  46. houseArray = msg.obj.rows;
  47. if(houseArray[0] != null ){
  48. currentId = houseArray[0].id;
  49. }
  50. }
  51. }
  52. });
  53. }
  54. //获取房源数组中下一个元素的id
  55. var getNextId = function(){
  56. if(houseArray!=null && houseArray.length > 0){
  57. if(houseIndex >= houseArray.length-1 ){
  58. houseIndex = 0;
  59. }else{
  60. houseIndex++;
  61. }
  62. return houseArray[houseIndex].id;
  63. }
  64. }
  65. var jump = function(){
  66. if(!isJump) {
  67. return;
  68. }else{
  69. $("#house_" + currentId ).removeClass('active');
  70. currentId = getNextId();
  71. $("#house_" + currentId ).addClass('active');
  72. setTimeout("jump()",50);
  73. }
  74. }
  75. var stop = function(count){
  76. if(count == 0){
  77. setTimeout("reviewHouse()",300);
  78. return ;
  79. }else{
  80. $("#house_" + currentId ).removeClass('active');
  81. currentId = getNextId();
  82. $("#house_" + currentId ).addClass('active');
  83. count--;
  84. setTimeout("stop("+ count + ")",50 + 400/count);
  85. }
  86. }
  87. var reviewHouse = function (){
  88. $.ajax({
  89. type: "post",//使用post方法访问后台
  90. dataType: "json",//返回json格式的数据
  91. url: "yaohaoAction_updateYaohaoItem",//要访问的后台地址
  92. data:{"yaohao.id":yaohaoId ,
  93. "house.id":currentId ,
  94. "securityPerson.id":securityPersonId
  95. },
  96. success: function(msg){//msg为返回的数据,在这里做数据绑定
  97. if(msg.success){
  98. $('#yaohaoItemDataGrid').datagrid('reload');
  99. }
  100. }
  101. });
  102. $('#housestop').modal();
  103. $("#house_" + currentId ).removeClass('active');
  104. $("#house_" + currentId ).addClass('ignore');
  105. houseArray.remove(houseIndex);
  106. }
  107. //获取随机数
  108. function GetRandomNum(Min,Max)
  109. {
  110. var Range = Max - Min;
  111. var Rand = Math.random();
  112. return(Min + Math.round(Rand * Range));
  113. }
  114. /*
  115. * 方法:Array.remove(dx) 通过遍历,重构数组
  116. * 功能:删除数组元素.
  117. * 参数:dx删除元素的下标.
  118. */
  119. Array.prototype.remove=function(dx)
  120. {
  121. if(isNaN(dx)||dx>this.length){return false;}
  122. for(var i=0,n=0;i<this.length;i++)
  123. {
  124. if(this[i]!=this[dx])
  125. {
  126. this[n++]=this[i];
  127. }
  128. }
  129. this.length-=1;
  130. }