houseYaohao.jsp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <%@taglib prefix="s" uri="/struts-tags" %>
  3. <% String basePath = request.getScheme()+ "://" + request.getServerName() + ":" +request.getServerPort() + request.getContextPath(); %>
  4. <script>
  5. var yaohaoId = null;
  6. var securityPersonId = null;
  7. var roomType = null;
  8. var communityId = null;
  9. //房源属性
  10. var houseArray = null;
  11. var houseIndex = -1;
  12. var currentId = null;
  13. var isJump = false;
  14. var hasYaohao = false;
  15. //根据摇号id获取房源列表
  16. var getHouseArray = function(){
  17. $.ajax({
  18. type: "post",//使用post方法访问后台
  19. dataType: "json",//返回json格式的数据
  20. url: "yaohaoAction_listHouseByYaohao1",//要访问的后台地址
  21. data:{"yaohaoId":yaohaoId ,"roomType" :roomType , "communityId" : communityId },
  22. success: function(msg){//msg为返回的数据,在这里做数据绑定
  23. if(msg.success){
  24. houseArray = msg.obj.rows;
  25. if(houseArray[0] != null ){
  26. currentId = houseArray[0].id;
  27. }
  28. }
  29. }
  30. });
  31. }
  32. $(function() {
  33. yaohaoId = $("#yaohaoId").val();
  34. securityPersonId = $("#securityPersonId").val();
  35. roomType = $("#roomType").val();
  36. communityId = $("#communityId").val();
  37. getHouseArray();
  38. });
  39. //点击开始摇号
  40. $("#houseBegin").click(
  41. function(){
  42. if(!hasYaohao){
  43. if(isJump == false){
  44. isJump = true;
  45. jump();
  46. }
  47. }
  48. }
  49. );
  50. //点击停止摇号
  51. $("#houseOK").click(
  52. function(){
  53. if(!hasYaohao){
  54. if(isJump == true){
  55. isJump = false;
  56. var sum = GetRandomNum(houseArray.length,houseArray.length*2);
  57. stop(sum);
  58. }
  59. }
  60. }
  61. );
  62. //获取房源数组中下一个元素的id
  63. var getNextId = function(){
  64. if(houseArray!=null && houseArray.length > 0){
  65. if(houseIndex >= houseArray.length-1 ){
  66. houseIndex = 0;
  67. }else{
  68. houseIndex++;
  69. }
  70. return houseArray[houseIndex].id;
  71. }
  72. }
  73. var jump = function(){
  74. if(!isJump) {
  75. return;
  76. }else{
  77. $("#house_" + currentId ).removeClass('active');
  78. currentId = getNextId();
  79. $("#house_" + currentId ).addClass('active');
  80. setTimeout("jump()",50);
  81. }
  82. }
  83. var stop = function(count){
  84. $('#communitySelect').modal('hide');
  85. if(count == 0){
  86. setTimeout("reviewHouse()",300);
  87. return ;
  88. }else{
  89. $("#house_" + currentId ).removeClass('active');
  90. currentId = getNextId();
  91. $("#house_" + currentId ).addClass('active');
  92. count--;
  93. setTimeout("stop("+ count + ")",50 + 400/count);
  94. }
  95. }
  96. var reviewHouse = function (){
  97. $.ajax({
  98. type: "post",//使用post方法访问后台
  99. dataType: "json",//返回json格式的数据
  100. url: "yaohaoAction_updateYaohaoItem",//要访问的后台地址
  101. data:{"yaohao.id":yaohaoId ,
  102. "house.id":currentId ,
  103. "securityPerson.id":securityPersonId
  104. },
  105. success: function(msg){//msg为返回的数据,在这里做数据绑定
  106. if(msg.success){
  107. $('#yaohaoItemDataGrid').datagrid('reload');
  108. $.ajax({
  109. type: "post",//使用post方法访问后台
  110. dataType: "json",//返回json格式的数据
  111. url: "houseAction_findById",//要访问的后台地址
  112. data:{
  113. "house.id":currentId
  114. },
  115. success: function(msg){//msg为返回的数据,在这里做数据绑定
  116. if(msg.success){
  117. $('#yaohaoItemDataGrid').datagrid('reload');
  118. $.messager.alert("提示","恭喜您,您选中了房屋" + msg.obj.address);
  119. hasYaohao = true;
  120. }
  121. }
  122. });
  123. hasYaohao = true;
  124. }
  125. }
  126. });
  127. }
  128. //获取随机数
  129. function GetRandomNum(Min,Max){
  130. var Range = Max - Min;
  131. var Rand = Math.random();
  132. return(Min + Math.round(Rand * Range));
  133. }
  134. /*
  135. * 方法:Array.remove(dx) 通过遍历,重构数组
  136. * 功能:删除数组元素.
  137. * 参数:dx删除元素的下标.
  138. */
  139. Array.prototype.remove=function(dx){
  140. if(isNaN(dx)||dx>this.length){return false;}
  141. for(var i=0,n=0;i<this.length;i++)
  142. {
  143. if(this[i]!=this[dx])
  144. {
  145. this[n++]=this[i];
  146. }
  147. }
  148. this.length-=1;
  149. }
  150. </script>
  151. <div class="container-fluid container-main">
  152. <div class="box box-solid box-primary lottery-house">
  153. <div class="box-body lottery-house-body" name="house">
  154. <input type="hidden" value="${yaohao.id}" id="yaohaoId">
  155. <input type="hidden" value="${securityPerson.id}" id="securityPersonId">
  156. <input type="hidden" value="${roomType}" id="roomType">
  157. <input type="hidden" value="${communityId}" id="communityId">
  158. <s:iterator value="houseList" id="info" >
  159. <s:if test="#info.houseState == 3">
  160. <div class="lottery-house-unit" id="house_${info.id}" >
  161. <div class="lottery-house-community">${info.address}</div>
  162. </div>
  163. </s:if>
  164. <s:else>
  165. <div class="lottery-house-unit ignore" id="house_${info.id}" >
  166. <div class="lottery-house-community">${info.address}</div>
  167. </div>
  168. </s:else>
  169. </s:iterator>
  170. </div>
  171. <div class="lottery-house-foot" name="house">
  172. <button id="houseBegin" type="button" class="btn btn-primary"><i class="fa fa-play"></i> 开始</button>
  173. <button id="houseOK" type="button" class="btn btn-primary" ><i class="fa fa-stop"></i> 停止</button>
  174. </div>
  175. </div>
  176. </div>
  177. <div class="modal fade" id="housestop" tabindex="-2" role="dialog" aria-labelledby="myModalLabel">
  178. <div class="modal-dialog modal-modal">
  179. <div class="modal-content">
  180. <div class="modal-header">
  181. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  182. <h4 class="modal-title"><i class="fa fa-building fa-fw modal-header-icon"></i>&nbsp;房源摇号结果</h4>
  183. </div>
  184. <div class="modal-body">
  185. 本次摇中的房源为:<span class="red" id="currentHouseAddress" ></span>,房源顺位号为: <span class="red" id="currentYaohaoNo"> </span>
  186. </div>
  187. <div class="modal-footer">
  188. <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
  189. </div>
  190. </div>
  191. </div>
  192. </div>