人人商城

selectareasNew.html 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 .provinceall { 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. .modal-body {padding: 0px 30px 0px 30px}
  9. .checkbox-inline, .radio-inline {padding-left: 10px;}
  10. .modal-body {height:auto;}
  11. .row.row-title b {padding: 10px;}
  12. .row.row-areas .item {height:430px;overflow:auto; width: 33.33%; float: left;}
  13. .row.row-areas .child {padding-bottom: 10px; position: relative}
  14. .row.row-areas .child:before {content: ''; position: absolute; border-bottom: 1px dashed #eee; left: 10px; top:-1px; right: 10px}
  15. .row.row-areas .child.active {background: #eee}
  16. .row.row-areas .child.active:before {border: 0}
  17. .row.row-areas .child:first-child:before {top: 0}
  18. .p-group, .c-group, .a-group {cursor: default}
  19. input[type=checkbox] {cursor: pointer}
  20. </style>
  21. <div id="modal-areas" class="modal fade" tabindex="-1">
  22. <div class="modal-dialog" style='width: 800px;'>
  23. <div class="modal-content">
  24. <div class="modal-header"><button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择区域</h3></div>
  25. <div class="modal-body">
  26. <div class="row row-title">
  27. <b class="col-sm-4">省份</b>
  28. <b class="col-sm-4">城市</b>
  29. <b class="col-sm-4">地区</b>
  30. </div>
  31. <div class="row row-areas form-horizontal">
  32. <div class="item">
  33. {if empty($areas['stp'])}
  34. {loop $areas['province'] $value}
  35. <div class="child p-group">
  36. <label class="checkbox-inline " style="cursor: default">{php echo $value['@attributes']['name']}</label>
  37. <label class="checkbox-inline pull-right">
  38. <input type="checkbox" id="ch_pcode{php echo $value['@attributes']['code']}" class="provinceall" value="{php echo $value['@attributes']['name']}" data-value="{php echo $value['@attributes']['code']}" title="选择" />
  39. </label>
  40. </div>
  41. {/loop}
  42. {else}
  43. {php echo $areas['stp'];}
  44. {/if}
  45. </div>
  46. <div class="item" id="d_item">
  47. </div>
  48. <div class="item" id="a_item">
  49. </div>
  50. </div>
  51. <div class="row" style="margin-top:10px;display: none;">
  52. 已选择城市:<span id="city_info"></span>
  53. </div>
  54. <div class="row" style="margin-top:10px;display: none;">
  55. 已选择地区:<span id="area_info"></span>
  56. </div>
  57. </div>
  58. <div class="modal-footer">
  59. <span class="pull-left">Tip: 点击省份、城市展开子级</span>
  60. <a href="javascript:;" id='btnSubmitArea' class="btn btn-success" data-dismiss="modal" aria-hidden="true">确定</a>
  61. <a href="javascript:;" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <script language='javascript'>
  67. var last_province_code = 0;
  68. var last_city_code = 0;
  69. var last_area_code = 0;
  70. var xmlCityDoc;
  71. var xml_list = new Array();
  72. var load_list = new Array();
  73. $(function(){
  74. // $(".child:not(.a-group)").unbind('click').click(function () {
  75. //
  76. // });
  77. $(document).on("click", '.child:not(.a-group)',
  78. function (e) {
  79. $(this).addClass('active').siblings().removeClass('active');
  80. }
  81. );
  82. $('.province').mouseover(function(){
  83. $(this).find('ul').show();
  84. }).mouseout(function(){
  85. $(this).find('ul').hide();
  86. });
  87. $('.p-group').click(function(){
  88. var province_code = $(this).find('input').attr('data-value');
  89. load_data(province_code);
  90. load_city(2, province_code, 0, 0);
  91. });
  92. $(document).on("click", '.c-group',
  93. function (e) {
  94. var city_code = $(this).find('input').attr('data-value');
  95. load_city(2, 0, city_code, 0);
  96. }
  97. );
  98. // document.('.c-group').click(function(){
  99. // var city_code = $(this).find('input').attr('data-value');
  100. // load_city(2, 0, city_code, 0);
  101. // });
  102. // $('.a-group').click(function(){
  103. // var area_code = $(this).find('input').attr('data-value');
  104. // load_city(2, 0, 0, area_code);
  105. // });
  106. $('.provinceall').click(function(){
  107. var province_code = $(this).attr('data-value');
  108. load_data(province_code);
  109. var checked = $(this).get(0).checked;
  110. var flag = 0;
  111. if(checked){
  112. flag = 1;
  113. }
  114. load_city(flag, province_code, 0, 0);
  115. });
  116. // $('.cityall').click(function(){
  117. // var city_code = $(this).attr('data-value');
  118. // var checked = $(this).get(0).checked;
  119. // var flag = 0;
  120. //
  121. // if(checked){
  122. // flag = 1;
  123. // }
  124. //
  125. // load_city(flag, 0, city_code, 0);
  126. // });
  127. $(document).on("click", '.cityall',
  128. function (e) {
  129. var city_code = $(this).attr('data-value');
  130. var checked = $(this).get(0).checked;
  131. var flag = 0;
  132. if(checked){
  133. flag = 1;
  134. }
  135. load_city(flag, 0, city_code, 0);
  136. }
  137. );
  138. $('.areaall').click(function(){
  139. var area_code = $(this).attr('data-value');
  140. var checked = $(this).get(0).checked;
  141. var flag = 0;
  142. if(checked){
  143. flag = 1;
  144. }
  145. load_city(flag, 0, 0, area_code);
  146. });
  147. });
  148. function load_street(province_code, city_code){
  149. var result= $.inArray(city_code, xml_list);
  150. if (result == -1) {
  151. xml_list.push(city_code);
  152. } else {
  153. return;
  154. }
  155. var left = city_code.substring(0,2);
  156. var xmlUrl = '../addons/ewei_shopv2/static/js/dist/area/list/'+left+'/'+city_code+'.xml';
  157. xmlCityDoc = loadXmlFile(xmlUrl);
  158. var CityList = xmlCityDoc.childNodes[0].getElementsByTagName("county");
  159. var html = '';
  160. if(CityList && CityList.length>0) {
  161. for (var i = 0; i < CityList.length; i++) {
  162. var county = CityList[i];
  163. var county_code = county.getAttribute("code");
  164. var streetlist = county.getElementsByTagName("street");
  165. for (var m = 0; m < streetlist.length; m++) {
  166. var street = streetlist[m];
  167. var sname = street.getAttribute("name");
  168. var scode = street.getAttribute("code");
  169. html +='<div class="col-sm-12 slist pcode_s'+province_code+' ccode_s'+city_code+' acode_s'+county_code+'" style="padding:0;display: none;">';
  170. html +='<input type="checkbox" class="streetall checkbox_pcode'+province_code+' checkbox_ccode'+city_code+' checkbox_acode'+county_code+'" value="'+sname+'" data-value="'+scode+'" style="margin-top:12px;" />';
  171. html +='<span class="a-group">'+sname+'</span></div>';
  172. }
  173. }
  174. }
  175. $('#street_list').append(html);
  176. }
  177. function load_data(province_code){
  178. if (province_code > 0) {
  179. if($.inArray(province_code, load_list) == -1) {
  180. $.ajax({
  181. type: "GET",
  182. url: "{php echo webUrl('util/area/ajax')}",
  183. data: {"province_code":province_code},
  184. async: false,
  185. dataType: "json",
  186. success: function (data) {
  187. var res = data.result;
  188. $("#d_item").append(res.stc);
  189. $("#a_item").append(res.sta);
  190. //
  191. // $('.c-group').click(function(){
  192. // var city_code = $(this).find('input').attr('data-value');
  193. // load_city(2, 0, city_code, 0);
  194. // });
  195. //
  196. // $('.cityall').click(function(){
  197. // var city_code = $(this).attr('data-value');
  198. // var checked = $(this).get(0).checked;
  199. // var flag = 0;
  200. //
  201. // if(checked){
  202. // flag = 1;
  203. // }
  204. //
  205. // load_city(flag, 0, city_code, 0);
  206. // });
  207. select_load(province_code);
  208. }
  209. });
  210. load_list.push(province_code);
  211. }
  212. }
  213. }
  214. function load_city(flag, province_code, city_code, area_code){
  215. if (province_code >0 ) {
  216. $('.clist').hide();
  217. $('.alist').hide();
  218. $('.pcode_c'+province_code).show();
  219. var city_code_first = $('.checkbox_pcode'+province_code).first().attr('data-value');
  220. last_province_code = province_code;
  221. if (flag == 0 ) {
  222. $('.checkbox_pcode'+province_code).removeAttr("checked");
  223. } else if (flag == 1 ) {
  224. $('.checkbox_pcode'+province_code).prop("checked",true);
  225. }
  226. }
  227. if (city_code >0 ) {
  228. $('.alist').hide();
  229. $('.ccode_a'+city_code).show();
  230. last_city_code = city_code;
  231. if (flag == 0 ) {
  232. $('.checkbox_ccode'+city_code).removeAttr("checked");
  233. } else if (flag == 1 ) {
  234. var pcode = $('#ch_ccode'+city_code).attr('pcode');
  235. $('#ch_pcode'+pcode).prop("checked",true);
  236. $('.checkbox_ccode'+city_code).prop("checked",true);
  237. }
  238. }
  239. if (area_code >0 ) {
  240. $('.slist').hide();
  241. $('.acode_s'+area_code).show();
  242. last_area_code = area_code;
  243. if (flag == 0 ) {
  244. $('.checkbox_acode'+area_code).removeAttr("checked");
  245. } else if (flag == 1 ) {
  246. var pcode = $('#ch_acode'+area_code).attr('pcode');
  247. var ccode = $('#ch_acode'+area_code).attr('ccode');
  248. $('#ch_pcode'+pcode).prop("checked",true);
  249. $('#ch_ccode'+ccode).prop("checked",true);
  250. $('.checkbox_acode'+area_code).prop("checked",true);
  251. }
  252. last_area_code = area_code;
  253. }
  254. if (flag == 0 || flag == 1) {
  255. update_area();
  256. }
  257. }
  258. function loadXmlFile(xmlFile) {
  259. var xmlDom = null;
  260. if (window.ActiveXObject) {
  261. xmlDom = new ActiveXObject("Microsoft.XMLDOM");
  262. xmlDom.async = false;
  263. xmlDom.load(xmlFile) || xmlDom.loadXML(xmlFile);//如果用的是XML字符串//如果用的是xml文件
  264. } else if (document.implementation && document.implementation.createDocument) {
  265. var xmlhttp = new window.XMLHttpRequest();
  266. xmlhttp.open("GET", xmlFile, false);
  267. xmlhttp.send(null);
  268. xmlDom = xmlhttp.responseXML;
  269. } else {
  270. xmlDom = null;
  271. }
  272. return xmlDom;
  273. }
  274. function clearSelects(){
  275. $('.c-group').hide();
  276. $('.a-group').hide();
  277. $('.p-group').removeClass('active');
  278. $('.provinceall').attr('checked',false).removeAttr('disabled');
  279. $('.cityall').attr('checked',false).removeAttr('disabled');
  280. $('.areaall').attr('checked',false).removeAttr('disabled');
  281. }
  282. function editArea(btn){
  283. current = $(btn).attr('random');
  284. clearSelects();
  285. var old_areas = $(btn).next().val().split(';');
  286. if(old_areas) {
  287. for(var i in old_areas){
  288. var area_info = old_areas[i].split(' ');
  289. if(area_info[0]) {
  290. load_data(area_info[0]);
  291. $('#ch_pcode'+area_info[0]).prop("checked",true);
  292. }
  293. if(area_info[1]) {
  294. $('#ch_ccode'+area_info[1]).prop("checked",true);
  295. }
  296. if(area_info[2]) {
  297. $('#ch_acode'+area_info[2]).prop("checked",true);
  298. }
  299. }
  300. }
  301. $("#modal-areas").modal();
  302. var citystrs = '';
  303. $('#btnSubmitArea').unbind('click').click(function(){
  304. update_area();
  305. var city_html = $('#city_info').html();
  306. var area_html = $('#area_info').html();
  307. $('.' + current + ' .cityshtml').html(city_html);
  308. $('.' + current + ' .citys').val(city_html);
  309. $('.' + current + ' .citys_code').val(area_html);
  310. load_list =[];
  311. })
  312. var currents = getCurrentsCode(current);
  313. currents = currents.split(';');
  314. var parentdisabled = false;
  315. for (var i in currents){
  316. var area_info = currents[i].split(' ');
  317. if(area_info[0]) {
  318. $('#ch_pcode'+area_info[0]).prop("disabled",true);
  319. }
  320. if(area_info[1]) {
  321. $('#ch_ccode'+area_info[1]).prop("disabled",true);
  322. }
  323. if(area_info[2]) {
  324. $('#ch_acode'+area_info[2]).prop("disabled",true);
  325. }
  326. }
  327. }
  328. function update_area(){
  329. var city_html = '';
  330. var area_html = '';
  331. var city_name_html = '';
  332. var area_name_html = '';
  333. var city_code_html = '';
  334. var area_code_html = '';
  335. $(".cityall:checked").each(function(){
  336. var value = $(this).attr('value');
  337. var code = $(this).attr('data-value');
  338. var pname = $(this).attr('pname');
  339. city_html += value+';';
  340. var checked_num = $(".ccode_a"+code+"").find(".areaall:checked").length;
  341. var all_num = $(".ccode_a"+code+"").find(".areaall").length;
  342. if(checked_num!=all_num){
  343. $(".ccode_a"+code+"").find(".areaall:checked").each(function () {
  344. var value = $(this).attr('value');
  345. city_html += value+';';
  346. });
  347. }
  348. });
  349. $(".areaall:checked").each(function(){
  350. var value = $(this).attr('value');
  351. var code = $(this).attr('data-value');
  352. var cname = $(this).attr('cname');
  353. var ccode = $(this).attr('ccode');
  354. var pcode = $(this).attr('pcode');
  355. area_html += value+';';
  356. area_name_html += cname+' '+value+';';
  357. area_code_html += pcode+' '+ccode+' '+code+';';
  358. });
  359. $('#city_info').html(city_html);
  360. $('#area_info').html(area_code_html);
  361. }
  362. function selectAreas(){
  363. clearSelects();
  364. var old_areas = $('#selectedareas_code').val().split(';');
  365. if(old_areas) {
  366. for(var i in old_areas){
  367. var area_info = old_areas[i].split(' ');
  368. if(area_info[0]) {
  369. load_data(area_info[0]);
  370. $('#ch_pcode'+area_info[0]).prop("checked",true);
  371. }
  372. // if(area_info[1]) {
  373. // $('#ch_ccode'+area_info[1]).prop("checked",true);
  374. // }
  375. // if(area_info[2]) {
  376. // $('#ch_acode'+area_info[2]).prop("checked",true);
  377. // }
  378. }
  379. }
  380. $("#modal-areas").modal();
  381. var citystrs = '';
  382. $('#btnSubmitArea').unbind('click').click(function(){
  383. update_area();
  384. var city_html = $('#city_info').html();
  385. var area_html = $('#area_info').html();
  386. $('#areas').html(city_html);
  387. $("#selectedareas").val(city_html);
  388. $("#selectedareas_code").val(area_html);
  389. load_list =[];
  390. })
  391. }
  392. function select_load(province_code){
  393. var old_areas = $('#selectedareas_code').val().split(';');
  394. if(old_areas) {
  395. for(var i in old_areas){
  396. var area_info = old_areas[i].split(' ');
  397. if (area_info[0] == province_code) {
  398. if(area_info[1]) {
  399. $('#ch_ccode'+area_info[1]).prop("checked",true);
  400. }
  401. if(area_info[2]) {
  402. $('#ch_acode'+area_info[2]).prop("checked",true);
  403. }
  404. }
  405. }
  406. }
  407. }
  408. </script>