index2.js 13 KB

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