selectareas.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <style type='text/css'>
  2. .province { float:left; position:relative;width:170px; height:35px; line-height:35px;border:1px solid #fff;padding-top: -10px}
  3. .province:hover { border:1px solid #a6d2fe;border-bottom:1px solid #a6d2fe; background:#edf6ff;}
  4. .province .cityall { margin-top:10px;}
  5. .province ul { list-style: outside none none;position:absolute;padding:0;background:#edf6ff;border:1px solid #a6d2fe;display:none;
  6. width:auto; width:250px; 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. .checkbox-inline{
  9. margin: 0;
  10. }
  11. </style>
  12. <div id="modal-areas" class="modal fade" tabindex="-1">
  13. <div class="modal-dialog" style='width: 900px;'>
  14. <div class="modal-content">
  15. <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择区域</h3></div>
  16. <div class="modal-body" style='' >
  17. <div class="row show_type_1">
  18. <div class="col-sm-6 col-xs-12">
  19. <b class="frist-title help-block">首重(克) :</b>
  20. <input name="frist" value="1" step="1" type="number" class="form-control mb-3 frist">
  21. </div>
  22. <div class="col-sm-6 col-xs-12">
  23. <b class="frist-price-title help-block">首费(元) :</b>
  24. <input name="frist_price" placeholder="默认0" value="0" step="1" type="number" class="form-control mb-3 frist_price">
  25. </div>
  26. </div>
  27. <div class="row show_type_1">
  28. <div class="col-sm-6 col-xs-12">
  29. <b class="second-title help-block">续重(克) :</b>
  30. <input name="second" placeholder="默认0" value="1" step="1" type="number" class="form-control mb-3 second">
  31. </div>
  32. <div class="col-sm-6 col-xs-12">
  33. <b class="second-price-title help-block">续费(元):</b>
  34. <input name="second_price" placeholder="默认0" value="0" step="1" type="number" class="form-control mb-3 second_price">
  35. </div>
  36. </div>
  37. <div class="row show_type_2" style="display:none;">
  38. <div class="col-sm-6 col-xs-12">
  39. <b class="frist-title">首件(个) :</b>
  40. <input name="frist" value="1" step="1" type="number" class="form-control mb-3 frist">
  41. </div>
  42. <div class="col-sm-6 col-xs-12">
  43. <b class="frist-price-title">运费(元) :</b>
  44. <input name="frist_price" placeholder="默认0" value="0" step="1" type="number" class="form-control mb-3 frist_price">
  45. </div>
  46. </div>
  47. <div class="row show_type_2" style="display:none;">
  48. <div class="col-sm-6 col-xs-12">
  49. <b class="second-title">续件(个) :</b>
  50. <input name="second" placeholder="默认0" value="1" step="1" type="number" class="form-control mb-3 second">
  51. </div>
  52. <div class="col-sm-6 col-xs-12">
  53. <b class="second-price-title">续费(元):</b>
  54. <input name="second_price" placeholder="默认0" value="0" step="1" type="number" class="form-control mb-3 second_price">
  55. </div>
  56. </div>
  57. <?php foreach( $areas['province'] as $value ){ ?>
  58. <?php if( $value['@attributes']['name']=='请选择省份'){ ?>{php continue;}<?php } ?>
  59. <div class='province'>
  60. <label class='checkbox-inline' style='margin-left:20px;padding: 0 0 5px 24px;'>
  61. <input type='checkbox' class='cityall' style="margin-top: -10px" / > {php echo $value['@attributes']['name']}
  62. <span class="citycount" style='color:#ff6600'></span>
  63. </label>
  64. <?php if( count($value['city'])>0){ ?>
  65. <ul style="padding-bottom: 15px;">
  66. <?php foreach( $value['city'] as $c ){ ?>
  67. <li>
  68. <label class='checkbox-inline' >
  69. <input type='checkbox' class='city' style='margin-top:-3px;' code="{php echo $c['@attributes']['code']}" city="{php echo $c['@attributes']['name']}" /> {php echo $c['@attributes']['name']}
  70. </label>
  71. </li>
  72. <?php } ?>
  73. </ul>
  74. <?php } ?>
  75. </div>
  76. <?php } ?>
  77. <div style="clear:both;"></div>
  78. </div>
  79. <div class="modal-footer">
  80. <a href="javascript:;" id='btnSubmitArea' class="btn btn-primary" data-dismiss="modal" aria-hidden="true">确定</a>
  81. <a href="javascript:;" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. <script language='javascript'>
  87. $(function(){
  88. $('.province').mouseenter(function(){
  89. $(this).find('ul').show();
  90. }).mouseleave(function(){
  91. $(this).find('ul').hide();
  92. });
  93. $('.cityall').click(function(){
  94. var checked = $(this).get(0).checked;
  95. var citys = $(this).parent().parent().find('.city');
  96. citys.each(function(){
  97. $(this).get(0).checked = checked;
  98. });
  99. var count = 0;
  100. if(checked){
  101. count = $(this).parent().parent().find('.city:checked').length;
  102. }
  103. if(count>0){
  104. $(this).next().html("(" + count + ")") ;
  105. }
  106. else{
  107. $(this).next().html("");
  108. }
  109. });
  110. $('.city').click(function(){
  111. var checked = $(this).get(0).checked;
  112. var cityall = $(this).parent().parent().parent().parent().find('.cityall');
  113. if(checked){
  114. cityall.get(0).checked = true;
  115. }
  116. var count = cityall.parent().parent().find('.city:checked').length;
  117. if(count>0){
  118. cityall.next().html("(" + count + ")") ;
  119. }
  120. else{
  121. cityall.next().html("");
  122. }
  123. });
  124. });
  125. function clearSelects(){
  126. $('.city').attr('checked',false).removeAttr('disabled');
  127. $('.cityall').attr('checked',false).removeAttr('disabled');
  128. $('.citycount').html('');
  129. }
  130. function editArea(btn){
  131. current = $(btn).attr('random');
  132. clearSelects();
  133. var old_citys = $(btn).prev().val().split(';');
  134. $('.city').each(function(){
  135. var parentcheck = false;
  136. for(var i in old_citys){
  137. if(old_citys[i]==$(this).attr('city')){
  138. parentcheck = true;
  139. $(this).get(0).checked = true;
  140. break;
  141. }
  142. }
  143. if(parentcheck){
  144. $(this).parent().parent().parent().parent().find('.cityall').get(0).checked= true;
  145. }
  146. });
  147. $("#modal-areas").modal();
  148. var citystrs = '';
  149. $('#btnSubmitArea').unbind('click').click(function(){
  150. $('.city:checked').each(function(){
  151. citystrs+= $(this).attr('city') +";";
  152. });
  153. $('.' + current + ' .cityshtml').html(citystrs);
  154. $('.' + current + ' .citys').val(citystrs);
  155. console.log(2);
  156. })
  157. var currents = getCurrents(current);
  158. currents = currents.split(';');
  159. var citys = "";
  160. $('.city').each(function(){
  161. var parentdisabled =false;
  162. for(var i in currents){
  163. if(currents[i]!='' && currents[i]==$(this).attr('city')){
  164. $(this).attr('disabled',true);
  165. $(this).parent().parent().parent().parent().find('.cityall').attr('disabled',true);
  166. }
  167. }
  168. });
  169. }
  170. function selectAreas(){
  171. clearSelects();
  172. var old_citys = $('#areas').html().split(';');
  173. $('.city').each(function(){
  174. var parentcheck = false;
  175. for(var i in old_citys){
  176. if(old_citys[i]==$(this).attr('city')){
  177. parentcheck = true;
  178. $(this).get(0).checked = true;
  179. break;
  180. }
  181. }
  182. if(parentcheck){
  183. $(this).parent().parent().parent().parent().find('.cityall').get(0).checked= true;
  184. }
  185. });
  186. $("#modal-areas").modal();
  187. var citystrs = '';
  188. $('#btnSubmitArea').unbind('click').click(function(){
  189. console.log(1);
  190. $('.city:checked').each(function(){
  191. citystrs+= $(this).attr('city') +";";
  192. });
  193. $('#areas').html(citystrs);
  194. $("#selectedareas").val(citystrs);
  195. })
  196. }
  197. </script>