index.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. {extend name="default/base/base_home" /}
  2. {block name="mall_main"}
  3. <link rel="stylesheet" href="{$Think.HOME_SITE_ROOT}/css/shopnearby.css">
  4. <link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/swiper/swiper.min.css">
  5. <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/swiper/swiper.min.js"></script>
  6. <!--{if $Think.config.ds_config.mapak_type eq '1'}-->
  7. <script type="text/javascript">
  8. window._AMapSecurityConfig = {
  9. securityJsCode:"{$Think.config.ds_config.gaode_jscode}",
  10. }
  11. </script>
  12. <script type="text/javascript" src="//webapi.amap.com/maps?v=2.0&key={$Think.config.ds_config.gaode_ak}"></script>
  13. <!--{else}-->
  14. <script type="text/javascript" src="{$Think.HTTP_TYPE}api.map.baidu.com/api?v=2.0&ak={$Think.config.ds_config.baidu_ak}"></script>
  15. <!--{/if}-->
  16. <!--[if lte IE 9]>
  17. <link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/swiper/idangerous.swiper2.7.6.css">
  18. <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/swiper/idangerous.swiper2.7.6.min.js"></script>
  19. <![endif]-->
  20. <script>
  21. var local;
  22. var map;
  23. var the_sc_id = 0;
  24. var page = 1;
  25. var lock = 1;
  26. $(function () {
  27. $(window).bind("scroll", function () {
  28. var sTop = $(window).scrollTop();
  29. sTop = parseInt(sTop);
  30. if ((sTop + 500) > $('#get_more').offset().top) {
  31. more_store();
  32. //console.log($('#get_more').offset().top);
  33. //console.log(sTop);
  34. }
  35. })
  36. mySwiper=new Swiper('.swiper-container', {
  37. slidesPerView: 9,
  38. paginationClickable: true,
  39. spaceBetween: 0,
  40. // 如果需要前进后退按钮
  41. nextButton: '.swiper-button-next',
  42. prevButton: '.swiper-button-prev',
  43. })
  44. $('.swiper-button-prev').on('click', function(e){
  45. if(mySwiper.hasOwnProperty('swipePrev')){
  46. e.preventDefault()
  47. mySwiper.swipePrev()
  48. }
  49. })
  50. $('.swiper-button-next').on('click', function(e){
  51. if(mySwiper.hasOwnProperty('swipeNext')){
  52. e.preventDefault()
  53. mySwiper.swipeNext()
  54. }
  55. })
  56. if ({$Think.config.ds_config.mapak_type} == '1'){
  57. map = new AMap.Map("nearby_map", {
  58. resizeEnable: true,
  59. zoom:15
  60. });
  61. var lng = getCookie("longitude");
  62. var lat = getCookie("latitude");
  63. //搜索定位
  64. AMap.plugin(['AMap.PlaceSearch','AMap.AutoComplete'], function(){
  65. var auto = new AMap.AutoComplete({input:"keywords"});
  66. var placeSearch = new AMap.PlaceSearch({
  67. map: map
  68. }); //构造地点查询类
  69. auto.on("select", select);//注册监听,当选中某条记录时会触发
  70. function select(e) {
  71. placeSearch.setCity(e.poi.adcode);
  72. placeSearch.search(e.poi.name); //关键字查询查询
  73. }
  74. });
  75. if(!lng && !lat){
  76. map = new AMap.Map("nearby_map", {
  77. resizeEnable: true,
  78. zoom:15
  79. });
  80. //获取用户所在城市信息
  81. AMap.plugin("AMap.CitySearch", function () {
  82. var citySearch = new AMap.CitySearch();
  83. citySearch.getLocalCity(function (status, result) {
  84. if (status === "complete" && result.info === "OK") {
  85. // 查询成功,result即为当前所在城市信息
  86. AMap.plugin("AMap.Geocoder", function () {
  87. var geocoder = new AMap.Geocoder({
  88. // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
  89. city: result.adcode,
  90. });
  91. geocoder.getLocation(result.city, function(status1, result1) {
  92. var location = result1.geocodes[0].location;
  93. var addComp = result1.geocodes[0].addressComponent;
  94. var province = addComp.province;//获取省份
  95. var city = addComp.city;//获取城市
  96. var district = '';//区
  97. var lng = location.lng;
  98. var lat = location.lat;
  99. //初始化定位
  100. var marker = new AMap.Marker({
  101. position: new AMap.LngLat(lng, lat),
  102. icon: '//api.map.baidu.com/images/marker_red_sprite.png',
  103. zoom: 15
  104. });
  105. map.add(marker);
  106. map.panTo([lng, lat]);
  107. setCookie('pos_city', city, 30);
  108. setCookie('pos_district', district, 30);
  109. $("#pos_city").text(city);
  110. $("#pos_district").text(district);
  111. setCookie('longitude', lng, 30);
  112. setCookie('latitude', lat, 30);
  113. get_store(lng, lat);
  114. });
  115. });
  116. }
  117. });
  118. });
  119. }else{
  120. map.panTo([lng, lat]);
  121. //初始化定位
  122. var marker = new AMap.Marker({
  123. position: new AMap.LngLat(lng, lat),
  124. icon: '//api.map.baidu.com/images/marker_red_sprite.png',
  125. zoom: 15
  126. });
  127. map.add(marker);
  128. setCookie('longitude', lng, 30);
  129. setCookie('latitude', lat, 30);
  130. get_store(lng, lat);
  131. var pos_city = getCookie("pos_city");
  132. var pos_district = getCookie("pos_district");
  133. $("#pos_city").text(pos_city);
  134. $("#pos_district").text(pos_district);
  135. }
  136. }else{
  137. map = new BMap.Map('nearby_map');
  138. map.enableScrollWheelZoom();
  139. map.enableContinuousZoom();
  140. //绑定地图单击事件
  141. //map.addEventListener("click", clickMap);
  142. var lng = getCookie("longitude");
  143. var lat = getCookie("latitude");
  144. if (!lng && !lat) {
  145. var geolocation = new BMap.Geolocation();
  146. geolocation.getCurrentPosition(function (r) {
  147. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  148. var lng = r.point.lng;
  149. var lat = r.point.lat;
  150. change_center(lng, lat);
  151. var gc = new BMap.Geocoder(); //初始化,Geocoder类
  152. gc.getLocation(r.point, function (rs) {
  153. var addComp = rs.addressComponents;
  154. var province = addComp.province;//获取省份
  155. var city = addComp.city;//获取城市
  156. var district = addComp.district;//区
  157. var street = addComp.street;//街
  158. setCookie('pos_city', city, 30);
  159. setCookie('pos_district', district, 30);
  160. $("#pos_city").text(city);
  161. $("#pos_district").text(district);
  162. });
  163. } else {
  164. layer.msg('failed' + this.getStatus());
  165. }
  166. }, {enableHighAccuracy: true})
  167. } else {
  168. change_center(lng, lat);
  169. }
  170. var options = {
  171. onSearchComplete: function (results) {
  172. // 判断状态是否正确
  173. if (local.getStatus() == BMAP_STATUS_SUCCESS) {
  174. // var s = [];
  175. // for (var i = 0; i < results.getCurrentNumPois(); i ++){
  176. // s.push('<p class="address_list_wrap" onclick="change_center('+results.getPoi(i).point.lng+','+results.getPoi(i).point.lat+')"><span class="address_mt">'+results.getPoi(i).title + "</span><br><span class='address_mc'> " + results.getPoi(i).address+'</span></p>');
  177. // }
  178. // document.getElementById("r-result").innerHTML = s.join("");
  179. if (results.getCurrentNumPois() > 0) {
  180. change_center(results.getPoi(0).point.lng, results.getPoi(0).point.lat);
  181. }
  182. }
  183. }
  184. };
  185. local = new BMap.LocalSearch(map, options);
  186. var pos_city = getCookie("pos_city");
  187. var pos_district = getCookie("pos_district");
  188. $("#pos_city").text(pos_city);
  189. $("#pos_district").text(pos_district);
  190. }
  191. });
  192. function clickMap(event) {
  193. pinLng = event.point.lng;
  194. pinLat = event.point.lat;
  195. change_center(pinLng, pinLat);
  196. }
  197. function change_center(lng, lat) {
  198. map.clearOverlays(); //清除标注 或者可以把market 放入数组
  199. var point = new BMap.Point(lng, lat);
  200. var marker = new BMap.Marker(point);
  201. map.centerAndZoom(point, 16);
  202. map.addOverlay(marker);
  203. marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
  204. setCookie('longitude', lng, 30);
  205. setCookie('latitude', lat, 30);
  206. get_store(lng, lat);
  207. }
  208. function more_store() {
  209. if (lock) {
  210. return;
  211. }
  212. lock = 1;
  213. var lng = getCookie("longitude");
  214. var lat = getCookie("latitude");
  215. $.getJSON(HOMESITEURL + "/Shopnearby/get_Own_Store_List?longitude=" + lng + "&latitude=" + lat + "&storeclass_id=" + the_sc_id + '&page=' + page, function (data) {
  216. var store_list = data
  217. if (store_list) {
  218. $('.store_list').show();
  219. $('.ds-no-content').hide();
  220. var html = '';
  221. for (var k in store_list) {
  222. var goods_html = '';
  223. for (var j in store_list[k].goods_list) {
  224. var goods = store_list[k].goods_list[j];
  225. goods_html += '<img src="' + goods.goods_image + '">';
  226. }
  227. html += '<a href="' + HOMESITEURL + "/Store/index/store_id/" + store_list[k].store_id + '">' +
  228. '<div class="category_store">' +
  229. '<div class="shop_banner"></div>' +
  230. '<div class="store_info">' +
  231. '<img class="store_info_img" src="' + store_list[k].store_avatar + '">' +
  232. '<div class="store_msg">' +
  233. '<div class="store_name_wrap">' +
  234. '<div class="store_name">' + store_list[k].store_name + '</div>' +
  235. (store_list[k].is_platform_store ? ('<p class="self">{$Think.lang.proprietary}</p>') : '') +
  236. '</div>' +
  237. '<div class="announcement">' +
  238. '<div class="business_time">' +
  239. '<span>' + store_list[k].area_info + '</span>' +
  240. '</div>' +
  241. '<div class="advertisement">' +
  242. '<div class="goods-price">' + store_list[k].store_address + '</div>' +
  243. '<div class="goods-price">' + store_list[k].distance + 'm</div>' +
  244. '</div>' +
  245. '</div>' +
  246. '</div>' +
  247. '</div>' +
  248. '<div class="goods_list">' +
  249. goods_html +
  250. '</div>' +
  251. '</div>' +
  252. '</a>';
  253. if({$Think.config.ds_config.mapak_type} == '1'){
  254. if(store_list[k].store_longitude != '' || store_list[k].store_latitude != ''){
  255. var infoWindow = new AMap.InfoWindow({});
  256. var marker = new AMap.Marker({
  257. position: new AMap.LngLat(store_list[k].store_longitude, store_list[k].store_latitude),
  258. icon: '//api.map.baidu.com/images/marker_red_sprite.png',
  259. zoom: 15
  260. });
  261. marker.content = '<h2 style="color:orangered;font-size:16px">'+store_list[k].store_name+'</h2><p style="font-size:14px">{$Think.lang.address}:' + store_list[k].store_address + '</p><p style="font-size:14px">{$Think.lang.the_phone}:' + store_list[k].store_phone + '</p>';
  262. marker.on('click', markerClick);
  263. map.add(marker);
  264. function markerClick(e) {
  265. infoWindow.setContent(e.target.content);
  266. infoWindow.open(map, e.target.getPosition());
  267. }
  268. }
  269. }else{
  270. var marker = new BMap.Marker(new BMap.Point(store_list[k].store_longitude,store_list[k].store_latitude)); // 创建标注
  271. map.addOverlay(marker);
  272. var content = '<h2 style="color:orangered;font-size:16px">'+store_list[k].store_name+'</h2><p style="font-size:14px">{$Think.lang.address}:' + store_list[k].store_address + '</p><p style="font-size:14px">{$Think.lang.the_phone}:' + store_list[k].store_phone + '</p>';
  273. // 将标注添加到地图中
  274. addClickHandler(content,marker);
  275. }
  276. }
  277. $('.store_list').append(html);
  278. page++;
  279. lock = 0;
  280. }
  281. })
  282. }
  283. function addClickHandler(content,marker){
  284. marker.addEventListener("click",function(e){
  285. openInfo(content,e)}
  286. );
  287. }
  288. function openInfo(content,e){
  289. var opts = {
  290. width : 250, // 信息窗口宽度
  291. height: 80, // 信息窗口高度
  292. };
  293. var p = e.target;
  294. var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
  295. var infoWindow = new BMap.InfoWindow(content,opts); // 创建信息窗口对象
  296. map.openInfoWindow(infoWindow,point); //开启信息窗口
  297. }
  298. function get_store(lng, lat) {
  299. lock = 1;
  300. page = 1;
  301. $('.content-container').text('{$Think.lang.in_the_search}');
  302. $.getJSON(HOMESITEURL + "/Shopnearby/get_Own_Store_List?longitude=" + lng + "&latitude=" + lat + "&storeclass_id=" + the_sc_id, function (data) {
  303. var store_list = data
  304. if (store_list) {
  305. $('.store_list').show();
  306. $('.ds-no-content').hide();
  307. var html = '';
  308. for (var k in store_list) {
  309. var goods_html = '';
  310. for (var j in store_list[k].goods_list) {
  311. var goods = store_list[k].goods_list[j];
  312. goods_html += '<img src="' + goods.goods_image + '">';
  313. }
  314. html += '<a href="' + HOMESITEURL + "/Store/index/store_id/" + store_list[k].store_id + '">' +
  315. '<div class="category_store">' +
  316. '<div class="shop_banner"></div>' +
  317. '<div class="store_info">' +
  318. '<img class="store_info_img" src="' + store_list[k].store_avatar + '">' +
  319. '<div class="store_msg">' +
  320. '<div class="store_name_wrap">' +
  321. '<div class="store_name">' + store_list[k].store_name + '</div>' +
  322. (store_list[k].is_platform_store ? ('<p class="self">{$Think.lang.proprietary}</p>') : '') +
  323. '</div>' +
  324. '<div class="announcement">' +
  325. '<div class="business_time">' +
  326. '<span>' + store_list[k].area_info + '</span>' +
  327. '</div>' +
  328. '<div class="advertisement">' +
  329. '<div class="goods-price">' + store_list[k].store_address + '</div>' +
  330. '<div class="goods-price">' + store_list[k].distance + 'm</div>' +
  331. '</div>' +
  332. '</div>' +
  333. '</div>' +
  334. '</div>' +
  335. '<div class="goods_list">' +
  336. goods_html +
  337. '</div>' +
  338. '</div>' +
  339. '</a>';
  340. if({$Think.config.ds_config.mapak_type} == '1'){
  341. if(store_list[k].store_longitude != '' || store_list[k].store_latitude != ''){
  342. var infoWindow = new AMap.InfoWindow({});
  343. var marker = new AMap.Marker({
  344. position: new AMap.LngLat(store_list[k].store_longitude, store_list[k].store_latitude),
  345. icon: '//api.map.baidu.com/images/marker_red_sprite.png',
  346. zoom: 15
  347. });
  348. marker.content = '<h2 style="color:orangered;font-size:16px">'+store_list[k].store_name+'</h2><p style="font-size:14px">{$Think.lang.address}:' + store_list[k].store_address + '</p><p style="font-size:14px">{$Think.lang.the_phone}:' + store_list[k].store_phone + '</p>';
  349. marker.on('click', markerClick);
  350. map.add(marker);
  351. function markerClick(e) {
  352. infoWindow.setContent(e.target.content);
  353. infoWindow.open(map, e.target.getPosition());
  354. }
  355. }
  356. }else{
  357. var marker = new BMap.Marker(new BMap.Point(store_list[k].store_longitude,store_list[k].store_latitude)); // 创建标注
  358. var content = '<h2 style="color:orangered;font-size:16px">'+store_list[k].store_name+'</h2><p style="font-size:14px">{$Think.lang.address}:' + store_list[k].store_address + '</p><p style="font-size:14px">{$Think.lang.the_phone}:' + store_list[k].store_phone + '</p>';
  359. map.addOverlay(marker); // 将标注添加到地图中
  360. addClickHandler(content,marker);
  361. }
  362. }
  363. $('.store_list').html(html);
  364. page++;
  365. lock = 0;
  366. } else {
  367. $('.store_list').hide();
  368. $('.ds-no-content').show();
  369. $('.content-container').text('{$Think.lang.no_shops}');
  370. }
  371. })
  372. }
  373. function change_map(name) {
  374. if({$Think.config.ds_config.mapak_type} == '1' ){
  375. if (name != '') {
  376. var map = new AMap.Map("nearby_map", {
  377. resizeEnable: true,
  378. zoom:15
  379. });
  380. AMap.plugin('AMap.Geocoder', function () {
  381. var geocoder = new AMap.Geocoder();
  382. geocoder.getLocation(name, function (status, result) {
  383. var lng = result.geocodes[0].location.lng
  384. var lat = result.geocodes[0].location.lat
  385. map.panTo([lng, lat]);
  386. });
  387. });
  388. $('#pos_city').text(name);
  389. setCookie('pos_city', name, 30);
  390. }
  391. }else{
  392. if (name != '') {
  393. map.centerAndZoom(name, 16);
  394. map.setCurrentCity(name);
  395. local.search(name);
  396. $('#pos_city').text(name);
  397. setCookie('pos_city', name, 30);
  398. }
  399. }
  400. }
  401. // function city_click(type, name) {
  402. // $("#pos_" + type).text(name);
  403. // setCookie('pos_' + type, name, 30);
  404. // change_map(name);
  405. // }
  406. function select_sc(storeclass_id) {
  407. the_sc_id = storeclass_id;
  408. $('.category_name .text').removeClass('green');
  409. $('[data-id=' + storeclass_id + ']').parent().addClass('green');
  410. var lng = getCookie("longitude");
  411. var lat = getCookie("latitude");
  412. get_store(lng, lat);
  413. }
  414. </script>
  415. <div class="main_content">
  416. <div class="choose-city-div" style="display: none; ">
  417. <div class="city-content">
  418. <div class="header">
  419. <div class="title">{$Think.lang.your_city}</div>
  420. <span class="close_div" onclick="$('.choose-city-div').hide();$('.choose-city-overlay').hide();">X</span>
  421. </div>
  422. <div class="content">
  423. <div class="content-bottom">
  424. {foreach name='city_list' item='city'}
  425. <div>
  426. <div class="title">{$city.region}</div>
  427. <div class="position-list">
  428. {foreach name='city.child' item='c'}
  429. <li class="position-li " onclick="change_map('{$c.area_name}');$('.position-list li').removeClass('active');$(this).addClass('active')" >{$c.area_name}</li>
  430. {/foreach}
  431. </div>
  432. </div>
  433. {/foreach}
  434. </div>
  435. </div>
  436. </div>
  437. </div>
  438. <div class="choose-city-overlay" style="display: none;"></div>
  439. <div class="ds-header fixed">
  440. <div class="ds-content">
  441. <div class="select-location">
  442. <i class="iconfont" onclick="$('.choose-city-div').show();$('.choose-city-overlay').show();">&#xe720;</i>
  443. <span class="current-position" id="pos_city">{$Think.lang.in_the_location}...</span>
  444. <span class="choose-city" id="pos_district" style="display:none"></span>
  445. </div>
  446. <div class="ds-fl search" data-url="http://install.dev/index.php?m=main&c=index&a=search">
  447. <input type="text" placeholder="{$Think.lang.office_building}" name="keywords" value="" id="keywords" />
  448. <!--{if $Think.config.ds_config.mapak_type eq '2'}--><button class="button search-button" onclick="local.search($('#keywords').val())"><i class="iconfont">&#xe718;</i></button><!--{/if}-->
  449. <ul class="shelper"></ul>
  450. </div>
  451. </div>
  452. </div>
  453. <div class="category w1200">
  454. <div class="nearby_map" id="nearby_map">
  455. </div>
  456. <div class="ds-content">
  457. <div class="category_list">
  458. <div class="ds-category-swiper">
  459. <div id="category-swiper-web" class="swiper-container">
  460. <div class="swiper-wrapper">
  461. <div class="category_name category_all swiper-slide my-active" onclick="select_sc(0)">
  462. <p class="text green"><a href='javascript:volid(0)' data-id="0">{$Think.lang.all_categories}</a></p>
  463. </div>
  464. {foreach name="storeclass_list" item="sc"}
  465. <div class="category_name swiper-slide " onclick="select_sc({$sc.storeclass_id})">
  466. <p class="text "><a href='javascript:volid(0)' data-id="{$sc.storeclass_id}">{$sc.storeclass_name}</a></p>
  467. </div>
  468. {/foreach}
  469. </div>
  470. </div>
  471. <div class="swiper-button-prev swiper-button-white"></div>
  472. <div class="swiper-button-next swiper-button-white"></div>
  473. </div>
  474. </div>
  475. </div>
  476. <div class="store_list" style="display:none">
  477. </div>
  478. </div>
  479. <div id="get_more"></div>
  480. <div class="ds-no-content">
  481. <div class="content">
  482. <div class="content-container">
  483. <p>{$Think.lang.in_the_search}...</p>
  484. </div>
  485. </div>
  486. </div>
  487. </div>
  488. {/block}