lottery.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. var whzl = whzl || {};
  2. whzl.basePath = '<%=basePath%>';
  3. $("#housefold").click(function(){
  4. if($("div[name='house']").is(':hidden')){
  5. $("div[name='house']").slideToggle();
  6. $('#housefold1').toggleClass('fa-angle-double-down fa-angle-double-up');
  7. }else{
  8. $("div[name='house']").slideToggle();
  9. $('#housefold1').toggleClass('fa-angle-double-up fa-angle-double-down');
  10. }
  11. });
  12. $("#peoplefold").click(function(){
  13. if($("div[name='people']").is(':hidden')){
  14. $("div[name='people']").slideToggle();
  15. $('#peoplefold1').toggleClass('fa-angle-double-down fa-angle-double-up');
  16. }else{
  17. $("div[name='people']").slideToggle();
  18. $('#peoplefold1').toggleClass('fa-angle-double-up fa-angle-double-down');
  19. }
  20. });
  21. var yaohaoId = null;
  22. //人员属性
  23. var securityPersonArray = null;
  24. var securityPersonIndex = -1;
  25. var currentIds = null;
  26. var isJumps = false;
  27. var yaohaoNos = null;
  28. $(function() {
  29. yaohaoId = $("#yaohaoId").val();
  30. getSecurityPersonArray();
  31. $('#yaohaoItemDataGrid').datagrid({
  32. rownumbers:false,
  33. border:false,
  34. sortOrder:'desc',
  35. url:'yaohaoAction_listYaohaoItemByYaohaoId?yaohaoItem.yaohao.id='+yaohaoId,
  36. checkOnSelect:true,
  37. selectOnCheck:false,
  38. loadFilter:function(result){
  39. if(result.success){
  40. return result.obj;
  41. }else{
  42. $.messager.alert("提示",result.message);
  43. return ;
  44. }
  45. }
  46. });
  47. });
  48. /**房屋地址*/
  49. var houseAddressFormatter = function(value , row , index){
  50. if(row.house!=null){
  51. return row.house.address;
  52. }else{
  53. return "";
  54. }
  55. };
  56. /**人员姓名*/
  57. var securityPersonNameFormatter = function(value , row , index){
  58. if(row.securityPerson!=null){
  59. return row.securityPerson.name;
  60. }else{
  61. return "";
  62. }
  63. };
  64. /**人员IdCard*/
  65. var securityPersonIdCardFormatter = function(value , row , index){
  66. if(row.securityPerson!=null){
  67. return row.securityPerson.idCard;
  68. }else{
  69. return "";
  70. }
  71. };
  72. /**房屋摇号*/
  73. var houseYaohaoFormatter = function(value , row , index){
  74. if(row.house!=null){
  75. return "";
  76. }else{
  77. return "<a onclick=houseYaohao('" + row.securityPerson.id + "','" + row.securityPerson.securityNum + "','"+ row.securityPerson.name + "') style='cursor:pointer' >房源摇号</a>";
  78. }
  79. };
  80. /**
  81. * 房源摇号
  82. * @param id
  83. * @return
  84. */
  85. var houseYaohao = function(securityPersonId,securityNum,securityPersonName){
  86. var roomType = null;
  87. if(securityNum >=3){
  88. roomType = 2;
  89. }else{
  90. roomType = 1;
  91. }
  92. $.ajax({
  93. type: "post",//使用post方法访问后台
  94. dataType: "json",//返回json格式的数据
  95. url: "yaohaoAction_listCommunityByYaohaoId",//要访问的后台地址
  96. data:{"yaohaoId":yaohaoId ,"roomType" :roomType },
  97. success: function(msg){//msg为返回的数据,在这里做数据绑定
  98. if(msg.success){
  99. communityArray = msg.obj.rows;
  100. $("#communityList").children().remove();
  101. $("#currentPersonName").text(securityPersonName);
  102. if(securityNum >= 3){
  103. $("#currentRoomType").text("二居室");
  104. $("#currentRoomType1").text("二居室");
  105. }else{
  106. $("#currentRoomType").text("一居室");
  107. $("#currentRoomType1").text("一居室");
  108. }
  109. for(i=0;i<communityArray.length;i++){
  110. $("#communityList").append("<div style='cursor:pointer' onclick=houseSelect('" + yaohaoId + "','" + securityPersonId + "','" + roomType + "','" + communityArray[i].communityId + "') class='lottery-community-unit'><div class='lottery-people-name'>" + communityArray[i].communityName + "</div><div class='lottery-people-idcard'>剩余:" + communityArray[i].remainHouse + "</div></div>");
  111. }
  112. $('#communitySelect').modal();
  113. }
  114. }
  115. });
  116. }
  117. var houseSelect = function(yaohaoId,securityPersonId,roomType,communityId){
  118. $("#houseYaohaoDialog").dialog(
  119. {
  120. href:"yaohaoAction_houseYaohao?yaohaoId=" + yaohaoId + "&securityPersonId=" + securityPersonId + "&roomType=" + roomType + "&communityId=" + communityId ,
  121. }
  122. );
  123. /*$("#houseYaohaoDialog").modal({
  124. remote:"yaohaoAction_houseYaohao?yaohaoId=" + yaohaoId + "&securityPersonId=" + securityPersonId + "&roomType=" + roomType + "&communityName=" + communityName
  125. });*/
  126. }
  127. //点击开始摇号
  128. $("#securityPersonBegin").click(
  129. function(){
  130. if(isJumps == false){
  131. isJumps = true;
  132. jumps();
  133. }
  134. }
  135. );
  136. //点击停止摇号
  137. $("#securityPersonOK").click(
  138. function(){
  139. if(isJumps == true){
  140. isJumps = false;
  141. var sum = GetRandomNum(securityPersonArray.length,securityPersonArray.length*2);
  142. $('#currentSecurityPersonName').text("");
  143. $('#currentYaohaoNos').text("");
  144. stops(sum);
  145. }
  146. }
  147. );
  148. //根据摇号id获取人员列表
  149. var getSecurityPersonArray = function(){
  150. $.ajax({
  151. type: "post",//使用post方法访问后台
  152. dataType: "json",//返回json格式的数据
  153. url: "yaohaoAction_listSecurityPersonByYaohao",//要访问的后台地址
  154. data:{"yaohao.id":yaohaoId },
  155. success: function(msg){//msg为返回的数据,在这里做数据绑定
  156. if(msg.success){
  157. securityPersonArray = msg.obj.rows;
  158. if(securityPersonArray[0] != null ){
  159. currentIds = securityPersonArray[0].id;
  160. }
  161. yaohaoNos = msg.obj.total;
  162. }
  163. }
  164. });
  165. }
  166. //获取房源数组中下一个元素的id
  167. var getNextIds = function(){
  168. if(securityPersonArray != null && securityPersonArray.length >0){
  169. if(securityPersonIndex >= securityPersonArray.length-1 ){
  170. securityPersonIndex = 0;
  171. }else{
  172. securityPersonIndex++;
  173. }
  174. return securityPersonArray[securityPersonIndex].id;
  175. }
  176. }
  177. var jumps = function(){
  178. if(!isJumps) {
  179. return;
  180. }else{
  181. $("#securityPerson_" + currentIds ).removeClass('active');
  182. currentIds = getNextIds();
  183. $("#securityPerson_" + currentIds ).addClass('active');
  184. setTimeout("jumps()",30);
  185. }
  186. }
  187. var stops = function(count){
  188. if(count == 0){
  189. setTimeout("reviewSecurityPerson()",400);
  190. return ;
  191. }else{
  192. $("#securityPerson_" + currentIds ).removeClass('active');
  193. currentIds = getNextIds();
  194. $("#securityPerson_" + currentIds ).addClass('active');
  195. count--;
  196. setTimeout("stops("+ count + ")",30 + 400/count);
  197. }
  198. }
  199. var reviewSecurityPerson = function (){
  200. yaohaoNos++;
  201. $.ajax({
  202. type: "post",//使用post方法访问后台
  203. dataType: "json",//返回json格式的数据
  204. url: "yaohaoAction_updateYaohaoItem1",//要访问的后台地址
  205. data:{"yaohao.id":yaohaoId ,
  206. "securityPerson.id":currentIds ,
  207. "yaohaoNo":yaohaoNos
  208. },
  209. success: function(msg){//msg为返回的数据,在这里做数据绑定
  210. if(msg.success){
  211. $('#yaohaoItemDataGrid').datagrid('reload');
  212. //$('#currentSecurityPersonName').text(msg.obj.securityPerson.name);
  213. //$('#currentYaohaoNos').text(msg.obj.yaohaoNo);
  214. }
  215. }
  216. });
  217. $('#currentSecurityPersonName').text($("#securityPersonName_" + currentIds ).text());
  218. $('#currentYaohaoNos').text(yaohaoNos);
  219. $("#securityPerson_" + currentIds ).removeClass('active');
  220. $("#securityPerson_" + currentIds ).addClass('ignore');
  221. $('#securityPersonstop').modal();
  222. securityPersonArray.remove(securityPersonIndex);
  223. }
  224. //获取随机数
  225. function GetRandomNum(Min,Max)
  226. {
  227. var Range = Max - Min;
  228. var Rand = Math.random();
  229. return(Min + Math.round(Rand * Range));
  230. }
  231. /*
  232. * 方法:Array.remove(dx) 通过遍历,重构数组
  233. * 功能:删除数组元素.
  234. * 参数:dx删除元素的下标.
  235. */
  236. Array.prototype.remove=function(dx)
  237. {
  238. if(isNaN(dx)||dx>this.length){return false;}
  239. for(var i=0,n=0;i<this.length;i++)
  240. {
  241. if(this[i]!=this[dx])
  242. {
  243. this[n++]=this[i];
  244. }
  245. }
  246. this.length-=1;
  247. }