index2.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. $(function () {
  2. // 轮播
  3. var banner = new Swiper('.banner', {
  4. autoplay: true,//可选选项,自动滑动
  5. loop: true,
  6. pagination: {
  7. el: '.swiper-pagination',
  8. clickable: true,
  9. },
  10. })
  11. $('.searchBoxBj button').on('click',function(){
  12. window.open('farm_list?page=1&condition='+$('.searchBoxBj input').val())
  13. })
  14. // 轮播
  15. // var banner = new Swiper('.farmsSwiper', {
  16. // autoplay: true,//可选选项,自动滑动
  17. // loop: true,
  18. // pagination: {
  19. // el: '.swiper-pagination',
  20. // clickable: true,
  21. // },
  22. // })
  23. // 新闻资讯滚动
  24. function Roll(ele, time, fun) {
  25. var obj = document.getElementById(ele);
  26. var ul = obj.children;
  27. var li = ul[0].children;
  28. console.log(li)
  29. if (fun) {
  30. var fun = fun;
  31. } else {
  32. var fun = function () { };
  33. }
  34. var t;
  35. if (time) {
  36. var time = time;
  37. } else {
  38. var time = 2500;
  39. }
  40. t = setInterval(function () {
  41. fun()
  42. $(li).eq(0).slideUp(function () {
  43. $(ul).append($(li).eq(0));
  44. });
  45. $(li).show();
  46. }, time);
  47. $(ul).on('mouseenter', 'li', function () {
  48. clearInterval(t)
  49. })
  50. $(ul).on('mouseleave', 'li', function () {
  51. t = setInterval(function () {
  52. fun()
  53. $(li).eq(0).slideUp(function () {
  54. $(ul).append($(li).eq(0));
  55. });
  56. $(li).show();
  57. }, time);
  58. })
  59. }
  60. // Roll('farmBrief', 5000)
  61. // Roll('newsListDiv', 2000)
  62. // Roll('videoListBox', 5000,function(){
  63. // $('#videoListBox .videoListUl >li').removeClass('active');
  64. // $('#videoListBox .videoListUl >li').eq(1).addClass('active');
  65. // })
  66. // Roll('gardenMsg', 2000, function(){
  67. // $('#gardenMsg .gardenUl >li').removeClass('active');
  68. // $('#gardenMsg .gardenUl >li').eq(1).addClass('active');
  69. // $('.gardenImg >img').attr('src',$('#gardenMsg .gardenUl >.active').find('.hide_farm_img').val())
  70. // })
  71. // var stu = new Roll("newsListDiv", 12);
  72. // 视频咨询
  73. // var myPlayer = videojs('my-video');
  74. // videojs("my-video").ready(function () {
  75. // var myPlayer = this;
  76. // myPlayer.play();
  77. // });
  78. // 视频咨询
  79. // $('#videoListBox').on('click', '.date', function () {
  80. // $('#videoListBox .videoListUl >li').removeClass('active');
  81. // $(this).parent().addClass('active');
  82. // var myPlayer = videojs('my-video');
  83. // var videoUrl = $(this).find('.hide_video_url').val();
  84. // videojs("my-video", {}, function () {
  85. // window.myPlayer = this;
  86. // $("#mymoda .video-con #my-video source").attr("src", videoUrl);
  87. // myPlayer.src(videoUrl);
  88. // myPlayer.load(videoUrl);
  89. // myPlayer.play();
  90. // });
  91. // // $('.videoBox').html('');
  92. // $(".video_link").click(function () {
  93. // var myPlayer = videojs('my-video');
  94. // var videoUrl = $(this).find('.hide_video_url').val();
  95. // videojs("my-video", {}, function () {
  96. // window.myPlayer = this;
  97. // $("#mymoda .video-con #my-video source").attr("src", videoUrl);
  98. // myPlayer.src(videoUrl);
  99. // myPlayer.load(videoUrl);
  100. // myPlayer.play();
  101. // });
  102. // $(".click-modal").click();
  103. // });
  104. // // 模态窗消失时,关闭视频    
  105. // $('#mymoda').on('hidden.bs.modal', function () {
  106. // myPlayer.pause();
  107. // });
  108. // })
  109. // 四季采摘
  110. $('#gardenMsg').on('click', '.gardenName', function () {
  111. $('#gardenMsg .gardenUl >li').removeClass('active');
  112. $(this).parent().addClass('active');
  113. // $(this).find('.hide_farm_img').val();
  114. $('.gardenImg >img').attr('src', $(this).find('.hide_farm_img').val())
  115. })
  116. // 导游导览
  117. // var map = new AMap.Map('map', {
  118. // resizeEnable: true, //是否监控地图容器尺寸变化
  119. // zoom: 11, //初始化地图层级
  120. // center: [113.397428, 39.90923] //初始化地图中心点
  121. // });
  122. //绘制初始路径
  123. // var path = [];
  124. // path.push([113.641379, 34.574431]);
  125. // path.push([108.877908, 34.389461]);
  126. // path.push([108.350564, 22.847832]);
  127. // map.plugin("AMap.DragRoute", function () {
  128. // route = new AMap.DragRoute(map, path, AMap.DrivingPolicy.LEAST_FEE); //构造拖拽导航类
  129. // route.search(); //查询导航路径并开启拖拽导航
  130. // });
  131. // 民宿导览
  132. var swiper = new Swiper('.homestay', {
  133. slidesPerView: 3,
  134. spaceBetween: 30,
  135. navigation: {
  136. nextEl: '.swiper-button-next',
  137. prevEl: '.swiper-button-prev',
  138. },
  139. autoplay: {
  140. delay: 3000
  141. },
  142. });
  143. })
  144. // 定位
  145. function city_change(obj){
  146. var txt = $(obj).html();
  147. $('.currCity span').html(txt);
  148. }
  149. // 示范区滚动
  150. var currTop = 0;
  151. for(var i = 0; i<4;i++){
  152. var cloneEle = $('.farmsUl li').eq(i).clone();
  153. $('.farmsUl').append(cloneEle)
  154. }
  155. var farmsautoplay = setInterval(() => {
  156. farmsScroll('+')
  157. }, 2000);
  158. $('.farms').mouseover(function(){
  159. clearInterval(farmsautoplay)
  160. });
  161. $('.farms').mouseout(function(){
  162. farmsautoplay = setInterval(() => {
  163. farmsScroll('+')
  164. }, 2000);
  165. });
  166. function handMove(){
  167. clearInterval(farmsautoplay)
  168. }
  169. function farmsScroll(flag){
  170. var allHeight = parseInt($('.farmsUl').height());
  171. var oneHeight = parseInt($('.farmsUl li').outerHeight());
  172. if(flag == '+'){
  173. if(currTop > -(allHeight-oneHeight*4)){
  174. currTop = currTop - oneHeight;
  175. $('.farmsUl').css('transition','all 1s ease 0s')
  176. $('.farmsUl').css('top',currTop);
  177. }else{
  178. currTop = 0
  179. $('.farmsUl').css('top',currTop);
  180. $('.farmsUl').css('transition','none')
  181. }
  182. }else if(flag == '-'){
  183. if(currTop >= 0){
  184. currTop = -(allHeight-oneHeight*4);
  185. $('.farmsUl').css('top',currTop);
  186. $('.farmsUl').css('transition','none')
  187. }else{
  188. currTop = currTop + oneHeight;
  189. $('.farmsUl').css('top',currTop);
  190. $('.farmsUl').css('transition','all 1s ease 0s')
  191. }
  192. }
  193. }
  194. var map = new AMap.Map('map', {
  195. resizeEnable: true, //是否监控地图容器尺寸变化
  196. zoom: 11, //初始化地图层级
  197. center: [113.397428, 39.90923] //初始化地图中心点
  198. });
  199. // var geoc = new AMap.Geocoder();
  200. // function searchWay() {
  201. // clearWay()
  202. // var startPath = $("#startPath").val();
  203. // var endPath = $("#endPath").val();
  204. // if (!startPath) {
  205. // $("#startPath").focus();
  206. // return;
  207. // }
  208. // if (!endPath) {
  209. // $("#endPath").focus();
  210. // return;
  211. // }
  212. // $('.guideMap').append('<div class="loadDiv"><img src="../static/imgs/timg.gif" /></div>')
  213. // //构造路线导航类
  214. // var driving = new AMap.Driving({
  215. // map: map,
  216. // panel: "panel"
  217. // });
  218. // // 根据起终点名称规划驾车导航路线
  219. // driving.search([
  220. // { keyword: startPath, city: '' },
  221. // { keyword: endPath, city: '' }
  222. // ], function (status, result) {
  223. // if (status === 'complete') {
  224. // // log.success('绘制驾车路线完成');
  225. // $('.loadDiv').remove();
  226. // } else {
  227. // alert('获取驾车数据失败:' + result)
  228. // $('.loadDiv').remove();
  229. // }
  230. // });
  231. // }
  232. function clearWay() {
  233. // 清除地图上所有添加的覆盖物
  234. map.clearMap();
  235. $('#panel').html('');
  236. }
  237. // 登录
  238. function login() {
  239. var username = $("#username").val();
  240. var password = $("#password").val();
  241. if (!username) {
  242. $("#username").focus();
  243. return;
  244. }
  245. if (!password) {
  246. $("#password").focus();
  247. return;
  248. }
  249. // $('.notLogin').toggle();
  250. // $('.isLogin').toggle();
  251. // window.open("back_manage");
  252. $.ajax({
  253. url: 'user_land',
  254. data: {
  255. username: username,
  256. password: password
  257. },
  258. type: 'post',
  259. dataType:'json',
  260. success: function (data) {
  261. if (data.code) {
  262. var hrefstr = 'person_farm?name=' + data.username;
  263. window.location.reload();
  264. // $('.isLogin').toggle();
  265. // $('#person_farm').attr('href', hrefstr)
  266. // $('.userPhoto').attr('src', data.user_img)
  267. // $('.notLogin').hide();
  268. // $('.isLogin').show();
  269. } else if (data.code == 0) {
  270. $('body').append('<div class="hint">用户不存在</div>')
  271. setTimeout(function () {
  272. $('.hint').remove();
  273. }, 1000)
  274. } else if (data.code == 2) {
  275. $('body').append('<div class="hint">用户名错误</div>')
  276. setTimeout(function () {
  277. $('.hint').remove();
  278. }, 1000)
  279. } else if (data.code == 3) {
  280. $('body').append('<div class="hint">密码错误</div>')
  281. setTimeout(function () {
  282. $('.hint').remove();
  283. }, 1000)
  284. } else {
  285. $('body').append('<div class="hint">登录失败</div>')
  286. setTimeout(function () {
  287. $('.hint').remove();
  288. }, 1000)
  289. }
  290. },
  291. error: function (type) {
  292. }
  293. })
  294. }
  295. // 返回顶部
  296. function goUp() {
  297. $('body,html').animate({ scrollTop: 0 }, 300)
  298. }
  299. function show() {
  300. $(window).scroll(function () {
  301. if ($(window).scrollTop() > 100) {
  302. $("#back2top").fadeIn(100);
  303. } else {
  304. $("#back2top").fadeOut(100);
  305. }
  306. });
  307. }
  308. show();
  309. // 农场导览弹框
  310. $('.haciendaTxt .btn1').on('click',function(){
  311. $('.tourismShow .title span').html('观光路线')
  312. var img = $(this).find('input').val();
  313. $('.tourismShow .content').html('<div style="text-align:center;width:100%;height:100%"><img style="width:100%;height:100%" src="'+img+'">')
  314. $('.tourismShow').show();
  315. $('.tourismShow').css('opacity',1)
  316. })
  317. $('.tourismShowCloseBtn').on('click',function(){
  318. $('.tourismShow .content').html('')
  319. $('.tourismShow').css('opacity',0)
  320. setTimeout(function(){
  321. $('.tourismShow').hide();
  322. },500)
  323. })
  324. var map;
  325. $('.haciendaTxt .btn2').on('click',function(){
  326. $('.tourismShow .title span').html('导游导览');
  327. var lng = $(this).find('input').val().split(',')[0];
  328. var lat = $(this).find('input').val().split(',')[1];
  329. var html = '<div class="">'+
  330. '<div class="guideForm">起始地点:<input type="text" id="startPath"><button onclick="searchWay(\''+lng+'\',\''+lat+'\')">确定</button></div>'+
  331. '<div id="map">地图</div>'+
  332. '</div>'
  333. $('.tourismShow .content').html(html);
  334. map = new AMap.Map('map', {
  335. resizeEnable: true, //是否监控地图容器尺寸变化
  336. zoom: 11, //初始化地图层级
  337. center: [lng, lat] //初始化地图中心点
  338. });
  339. var startIcon = new AMap.Icon({
  340. // 图标尺寸
  341. size: new AMap.Size(25, 34),
  342. // 图标的取图地址
  343. image: '//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png',
  344. // 图标所用图片大小
  345. imageSize: new AMap.Size(135, 40),
  346. // 图标取图偏移量
  347. imageOffset: new AMap.Pixel(-9, -3)
  348. });
  349. var endIcon = new AMap.Icon({
  350. size: new AMap.Size(25, 34),
  351. image: '//a.amap.com/jsapi_demos/static/demo-center/icons/dir-marker.png',
  352. imageSize: new AMap.Size(135, 40),
  353. imageOffset: new AMap.Pixel(-95, -3)
  354. });
  355. var marker = new AMap.Marker({
  356. icon:endIcon,
  357. position: new AMap.LngLat(lng, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  358. });
  359. map.add(marker);
  360. $('.tourismShow').show();
  361. $('.tourismShow').css('opacity',1);
  362. geocoder = new AMap.Geocoder({
  363. city: "010", //城市设为北京,默认:“全国”
  364. radius: 1000 //范围,默认:500
  365. });
  366. })
  367. function searchWay(lng,lat) {
  368. map.clearMap();
  369. var startPath = $("#startPath").val();
  370. var endPath = '北京';
  371. if (!startPath) {
  372. $("#startPath").focus();
  373. return;
  374. }
  375. $('.tourismShow .content').append('<div class="loadDiv"><img src="../static/imgs/timg.gif" /></div>')
  376. //构造路线导航类
  377. var driving = new AMap.Driving({
  378. map: map,
  379. // panel: "panel"
  380. });
  381. geocoder.getAddress([lng,lat], function(status, result) {
  382. if (status === 'complete'&&result.regeocode) {
  383. var address = result.regeocode.formattedAddress;
  384. // 根据起终点名称规划驾车导航路线
  385. driving.search([
  386. { keyword: startPath, city: '' },
  387. { keyword: address, city: '' }
  388. ], function (status, result) {
  389. if (status === 'complete') {
  390. // log.success('绘制驾车路线完成');
  391. $('.loadDiv').remove();
  392. } else {
  393. alert('获取驾车数据失败:' + result)
  394. $('.loadDiv').remove();
  395. }
  396. });
  397. }else{
  398. log.error('根据经纬度查询地址失败')
  399. }
  400. });
  401. }