wpfw_ewei_shopv2/static/js/dist/area/cascade.js
2023-02-14 19:57:32 +08:00

1 line
5.2 KiB
JavaScript

var xmlDoc,TopnodeList,CityList,citys,countyNodes,nodeindex=0,childnodeindex=0,new_area=0,open_street=0;function cascdeInit(e,t,d,o,n,i,c){id1="sel-provance",id2="sel-city",id3="sel-area",id4="sel-street",new_area=e,open_street=t,c&&(id1+=c,id2+=c,id3+=c,id4+=c),e=1==new_area?"../addons/"+window.ewei_shopv2_module_name+"/static/js/dist/area/AreaNew.xml?v=5":"../addons/"+window.ewei_shopv2_module_name+"/static/js/dist/area/Area.xml?v=4",xmlDoc=loadXmlFile(e);var l=document.getElementById(id1),s=document.getElementById(id2),t=document.getElementById(id3),e=document.getElementById(id4);if(RemoveDropDownList(l),RemoveDropDownList(s),RemoveDropDownList(t),RemoveDropDownList(e),0<(TopnodeList=window.ActiveXObject?xmlDoc.selectSingleNode("address").childNodes:xmlDoc.childNodes[0].getElementsByTagName("province")).length){for(var a=0;a<TopnodeList.length;a++){var r=TopnodeList[a];(m=document.createElement("option")).value=r.getAttribute("name"),m.text=r.getAttribute("name"),r.getAttribute("code")&&m.setAttribute("code",r.getAttribute("code")),d==m.value&&(m.selected=!0,nodeindex=a),l.add(m)}if(0<TopnodeList.length){for(citys=TopnodeList[nodeindex].getElementsByTagName("city"),a=0;a<citys.length;a++){l.options[nodeindex].value;var m,u=TopnodeList[nodeindex].getElementsByTagName("city");(m=document.createElement("option")).value=u[a].getAttribute("name"),m.text=u[a].getAttribute("name"),u[a].getAttribute("code")&&m.setAttribute("code",u[a].getAttribute("code")),o==m.value&&(m.selected=!0,childnodeindex=a),s.add(m)}selectcounty(n,i,c)}}}function selectCity(e){id1="sel-provance",id2="sel-city",id3="sel-area",id4="sel-street",e&&(id1+=e,id2+=e,id3+=e,id4+=e);var t=(c=document.getElementById(id1)).options[c.selectedIndex].value,d=c.options[c.selectedIndex].getAttribute("code");d&&$("#chose_province_code").val(d),countyNodes=TopnodeList[c.selectedIndex];var o,n,i=document.getElementById(id2),c=document.getElementById(id3);if(RemoveDropDownList(i),RemoveDropDownList(c),o=window.ActiveXObject?xmlDoc.selectSingleNode('//address/province [@name="'+t+'"]').childNodes:countyNodes.getElementsByTagName("city"),n=window.ActiveXObject?o[0].childNodes:o[0].getElementsByTagName("county"),0<o.length){for(var l=0;l<o.length;l++){var s=o[l];(a=document.createElement("option")).value=s.getAttribute("name"),a.text=s.getAttribute("name"),s.getAttribute("code")&&a.setAttribute("code",s.getAttribute("code")),i.add(a)}if(0<n.length)for(l=0;l<n.length;l++){document.getElementById(id2);var a,r=document.getElementById(id3);(a=document.createElement("option")).value=n[l].getAttribute("name"),a.text=n[l].getAttribute("name"),n[l].getAttribute("code")&&a.setAttribute("code",n[l].getAttribute("code")),r.add(a)}selectcounty(0,0,e)}}function selectcounty(e,t,d){id1="sel-provance",id2="sel-city",id3="sel-area",id4="sel-street",d&&(id1+=d,id2+=d,id3+=d,id4+=d);var o=document.getElementById(id1),n=document.getElementById(id2),i=(n.options[n.selectedIndex].value,n.options[n.selectedIndex].getAttribute("code"));i&&$("#chose_city_code").val(i);var c=document.getElementById(id3),l=TopnodeList[o.selectedIndex].getElementsByTagName("city")[n.selectedIndex].getElementsByTagName("county");if(1!=new_area||1!=open_street||(o=TopnodeList[o.selectedIndex].getElementsByTagName("city")[n.selectedIndex].getAttribute("code"))&&(n=o.substring(0,2),o="../addons/"+window.ewei_shopv2_module_name+"/static/js/dist/area/list/"+n+"/"+o+".xml",xmlCityDoc=loadXmlFile(o),CityList=window.ActiveXObject?xmlCityDoc.selectSingleNode("address").childNodes.childNodes:xmlCityDoc.childNodes[0].getElementsByTagName("county")),RemoveDropDownList(c),0<l.length){for(var s=0;s<l.length;s++){var a=l[s],r=document.createElement("option");r.value=a.getAttribute("name"),r.text=a.getAttribute("name"),a.getAttribute("code")&&r.setAttribute("code",a.getAttribute("code")),e==r.value&&(r.selected=!0),c.add(r)}1==new_area&&1==open_street&&selectstreet(t,d)}}function selectstreet(e,t){id1="sel-provance",id2="sel-city",id3="sel-area",id4="sel-street",t&&(id1+=t,id2+=t,id3+=t,id4+=t);var d=document.getElementById(id1),o=document.getElementById(id2),n=(o.options[o.selectedIndex].value,document.getElementById(id3)),i=document.getElementById(id4);n.options[n.selectedIndex].value,(t=n.options[n.selectedIndex].getAttribute("code"))&&$("#chose_area_code").val(t);var c=TopnodeList[d.selectedIndex].getElementsByTagName("city")[o.selectedIndex].getElementsByTagName("county")[n.selectedIndex].getAttribute("code");if(RemoveDropDownList(i),CityList&&0<CityList.length)for(var l=0;l<CityList.length;l++){var s=CityList[l];if(s.getAttribute("code")==c)for(var a=s.getElementsByTagName("street"),r=0;r<a.length;r++){var m=a[r],u=document.createElement("option");u.value=m.getAttribute("name"),u.text=m.getAttribute("name"),m.getAttribute("code")&&u.setAttribute("code",m.getAttribute("code")),e==u.value&&(u.selected=!0,nodeindex=r),i.add(u)}}}function RemoveDropDownList(e){if(e){var t=e.options.length;if(0<t)for(var d=t;0<=d;d--)e.remove(d)}}function loadXmlFile(e){var t,d=null;return window.ActiveXObject?((d=new ActiveXObject("Microsoft.XMLDOM")).async=!1,d.load(e)||d.loadXML(e)):d=document.implementation&&document.implementation.createDocument?((t=new window.XMLHttpRequest).open("GET",e,!1),t.send(null),t.responseXML):null,d}