人人商城

selectareas.html 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <style type='text/css'>
  2. .province { float:left; position:relative;width:150px; height:35px; line-height:35px;border:1px solid #fff;}
  3. .province:hover { border:1px solid #f7e4a5;border-bottom:1px solid #fffec6; background:#fffec6;}
  4. .province .cityall { margin-top:10px;}
  5. .province ul { list-style: outside none none;position:absolute;padding:0;background:#fffec6;border:1px solid #f7e4a5;display:none;
  6. width:auto; width:300px; z-index:999999;left:-1px;top:32px;}
  7. .province ul li { float:left;min-width:60px;margin-left:20px; height:30px;line-height:30px; }
  8. </style>
  9. <div id="modal-areas" class="modal fade" tabindex="-1">
  10. <div class="modal-dialog" style='width: 920px;'>
  11. <div class="modal-content">
  12. <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择区域</h3></div>
  13. <div class="modal-body" style='height:280px;;' >
  14. {loop $areas['province'] $value}
  15. {if $value['@attributes']['name']=='请选择省份'}{php continue;}{/if}
  16. <div class='province'>
  17. <label class='checkbox-inline' style='margin-left:20px;'>
  18. <input type='checkbox' class='cityall' style='margin-top:12px;' /> {php echo $value['@attributes']['name']}
  19. <span class="citycount" style='color:#ff6600'></span>
  20. </label>
  21. {if count($value['city'])>0}
  22. <ul>
  23. {loop $value['city'] $c}
  24. <li>
  25. <label class='checkbox-inline' >
  26. <input type='checkbox' class='city' style='margin-top:8px;' city="{php echo $c['@attributes']['name']}" /> {php echo $c['@attributes']['name']}
  27. </label>
  28. </li>
  29. {/loop}
  30. </ul>
  31. {/if}
  32. </div>
  33. {/loop}
  34. </div>
  35. <div class="modal-footer">
  36. <a href="javascript:;" id='btnSubmitArea' class="btn btn-success" data-dismiss="modal" aria-hidden="true">确定</a>
  37. <a href="javascript:;" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <script language='javascript'>
  43. $(function(){
  44. $('.province').mouseover(function(){
  45. $(this).find('ul').show();
  46. }).mouseout(function(){
  47. $(this).find('ul').hide();
  48. });
  49. $('.cityall').click(function(){
  50. var checked = $(this).get(0).checked;
  51. var citys = $(this).parent().parent().find('.city');
  52. citys.each(function(){
  53. $(this).get(0).checked = checked;
  54. });
  55. var count = 0;
  56. if(checked){
  57. count = $(this).parent().parent().find('.city:checked').length;
  58. }
  59. if(count>0){
  60. $(this).next().html("(" + count + ")") ;
  61. }
  62. else{
  63. $(this).next().html("");
  64. }
  65. });
  66. $('.city').click(function(){
  67. var checked = $(this).get(0).checked;
  68. var cityall = $(this).parent().parent().parent().parent().find('.cityall');
  69. if(checked){
  70. cityall.get(0).checked = true;
  71. }
  72. var count = cityall.parent().parent().find('.city:checked').length;
  73. if(count>0){
  74. cityall.next().html("(" + count + ")") ;
  75. }
  76. else{
  77. cityall.next().html("");
  78. }
  79. });
  80. });
  81. function clearSelects(){
  82. $('.city').attr('checked',false).removeAttr('disabled');
  83. $('.cityall').attr('checked',false).removeAttr('disabled');
  84. $('.citycount').html('');
  85. }
  86. function editArea(btn){
  87. current = $(btn).attr('random');
  88. clearSelects();
  89. var old_citys = $(btn).prev().val().split(';');
  90. $('.city').each(function(){
  91. var parentcheck = false;
  92. for(var i in old_citys){
  93. if(old_citys[i]==$(this).attr('city')){
  94. parentcheck = true;
  95. $(this).get(0).checked = true;
  96. break;
  97. }
  98. }
  99. if(parentcheck){
  100. $(this).parent().parent().parent().parent().find('.cityall').get(0).checked= true;
  101. }
  102. });
  103. $("#modal-areas").modal();
  104. var citystrs = '';
  105. $('#btnSubmitArea').unbind('click').click(function(){
  106. $('.city:checked').each(function(){
  107. citystrs+= $(this).attr('city') +";";
  108. });
  109. $('.' + current + ' .cityshtml').html(citystrs);
  110. $('.' + current + ' .citys').val(citystrs);
  111. })
  112. var currents = getCurrents(current);
  113. currents = currents.split(';');
  114. var citys = "";
  115. $('.city').each(function(){
  116. var parentdisabled =false;
  117. for(var i in currents){
  118. if(currents[i]!='' && currents[i]==$(this).attr('city')){
  119. $(this).attr('disabled',true);
  120. $(this).parent().parent().parent().parent().find('.cityall').attr('disabled',true);
  121. }
  122. }
  123. });
  124. }
  125. function selectAreas(){
  126. clearSelects();
  127. var old_citys = $('#areas').html().split(';');
  128. $('.city').each(function(){
  129. var parentcheck = false;
  130. for(var i in old_citys){
  131. if(old_citys[i]==$(this).attr('city')){
  132. parentcheck = true;
  133. $(this).get(0).checked = true;
  134. break;
  135. }
  136. }
  137. if(parentcheck){
  138. $(this).parent().parent().parent().parent().find('.cityall').get(0).checked= true;
  139. }
  140. });
  141. $("#modal-areas").modal();
  142. var citystrs = '';
  143. $('#btnSubmitArea').unbind('click').click(function(){
  144. $('.city:checked').each(function(){
  145. citystrs+= $(this).attr('city') +";";
  146. });
  147. $('#areas').html(citystrs);
  148. $("#selectedareas").val(citystrs);
  149. })
  150. }
  151. </script>