福田皮卡火星7+火星9
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. window.foton = window.foton || {};
  2. (function(){
  3. function pk(){
  4. this.baseUrl = window.location.origin;
  5. this.init();
  6. }
  7. p = pk.prototype;
  8. p.init = function(){
  9. this.bindEvent();
  10. this.listenTopBar();
  11. this.qjzs();
  12. this.jctj();
  13. this.yysj();
  14. // 模块动画
  15. var wow = new WOW({
  16. boxClass: 'wow',
  17. animateClass: 'animated',
  18. offset: 100,
  19. mobile: false,
  20. live: true
  21. });
  22. wow.init();
  23. }
  24. p.bindEvent = function(){
  25. const _this = this;
  26. // 预约试驾
  27. $(".submit").click(e=>{
  28. var flag = true;
  29. var msg = "";
  30. if(!$("#name").val()) {
  31. msg = "姓名不能为空!";
  32. flag = false;
  33. alertMsg(msg);
  34. return false;
  35. }
  36. p.checkPhoneNum($("#realPhone")).then( result => {
  37. if(!result){
  38. }else{
  39. $(".yysj select").each(function() {
  40. var select = $(this).find("option:selected");
  41. if(select.val() == -1) {
  42. flag = false;
  43. msg = "请选择" + select.html();
  44. return false;
  45. }
  46. });
  47. if(!flag) {
  48. alertMsg(msg);
  49. return false;
  50. }
  51. if (flag) {
  52. var params = {
  53. BrandId: $("#brand").val(),
  54. SeriesId: $("#carSeries").val(),
  55. ProvinceId: $("#province").val(),
  56. CityId: $("#city").val(),
  57. DealerId: $("#Dealer").val(),
  58. Name: $("#name").val(),
  59. Phone: $("#realPhone").val(),
  60. Remark: $("#Remark").val()
  61. };
  62. _this.getData('post', _this.baseUrl+"/tunland/clue/PostLeads", params).then(resp => {
  63. if(resp.status == 0){
  64. alertMsg("提交成功");
  65. }
  66. })
  67. p.LzInfo();
  68. } else {
  69. alertMsg(msg);
  70. }
  71. }
  72. })
  73. })
  74. //关闭弹窗按钮
  75. $(".modalfooter button").on("click", function() {
  76. $(".alertbox").hide()
  77. });
  78. }
  79. // 导航栏吸附
  80. p.listenTopBar = function(){
  81. const _this = this;
  82. // 监听页面滚动,联动导航栏
  83. _this.listenScroll = true;
  84. $(document).scroll(e=>{
  85. let bannerH = $("#banner").height() - 71;
  86. let top = $(document).scrollTop();
  87. if(top >= bannerH){
  88. $("#navContainer").addClass("fixed");
  89. }else{
  90. $("#navContainer").removeClass("fixed");
  91. }
  92. })
  93. // 锚点
  94. let ary = ["cpld", "qjzs", "jctj", "cspz"];
  95. $("#navContainer .nav .n").click(e=>{
  96. let index = $(e.currentTarget).index();
  97. let section = $(`.${ary[index]}`);
  98. let top = section.offset().top - 80 - 75;
  99. window.scrollTo({
  100. top: top,
  101. behavior: "smooth"
  102. })
  103. _this.listenScroll = false;
  104. setTimeout(e=>{
  105. _this.listenScroll = true;
  106. },1500)
  107. $("#navContainer .nav .n").removeClass("active");
  108. $(e.currentTarget).addClass("active");
  109. $("#navContainer .nav .line").css("left", 106*index)
  110. })
  111. // 锚点控制导航
  112. let cpld = $(".cpld").offset().top;
  113. let qjzs = $(".qjzs").offset().top;
  114. let jctj = $(".jctj").offset().top;
  115. let cspz = $(".cspz").offset().top;
  116. window.onscroll = function(){
  117. if(_this.listenScroll === false){ return}
  118. let top = window.scrollY + 1000;
  119. let index = 0;
  120. if(top <= qjzs){
  121. index = 0;
  122. }else if(top <= jctj){
  123. index = 1;
  124. }else if(top <= cspz){
  125. index = 2;
  126. }else{
  127. index = 3;
  128. }
  129. $("#navContainer .nav .n").removeClass("active");
  130. $("#navContainer .nav .n").eq(index).addClass("active");
  131. $("#navContainer .nav .line").css("left", 106*index);
  132. }
  133. }
  134. // 全景展示滚动
  135. p.qjzs = function(){
  136. new Swiper(".qjzs .swiper-container", {
  137. prevButton:'.qjzs .wg',
  138. nextButton:'.qjzs .ns',
  139. onSlideChangeStart: function(swiper){
  140. // alert(swiper.activeIndex);
  141. $("#container .qjzs .nav .line").toggleClass("right");
  142. }
  143. });
  144. }
  145. // 精彩图集
  146. p.jctj = function(){
  147. var galleryTop = new Swiper('.swiper1', {
  148. spaceBetween: 10,
  149. onSlideChangeStart: function(swiper){
  150. let index = swiper.activeIndex;
  151. let len = $(".swiper1 img").length;
  152. if(index == 0){
  153. galleryThumbs.slideTo(0);
  154. }else if(index == len-1){
  155. galleryThumbs.slideTo(3);
  156. }
  157. }
  158. });
  159. var galleryThumbs = new Swiper('.swiper2', {
  160. spaceBetween: 24,
  161. slidesPerView: 'auto',
  162. touchRatio: 0.2,
  163. freeMode: true,
  164. watchSlidesProgress: false,
  165. onClick: function(swiper){
  166. let index = swiper.clickedIndex;
  167. galleryTop.slideTo(index);
  168. }
  169. });
  170. }
  171. // 预约试驾
  172. p.yysj = function(){
  173. const _this = this;
  174. setProvince();
  175. setBrand();
  176. function setProvince(){
  177. _this.getData('get', _this.baseUrl+ "/tunland/clue/getProvince").then(resp => {
  178. if(resp.status == 1 ){
  179. return;
  180. }
  181. $("#province").empty();
  182. resp.data.unshift({ID:-1, FNAME:"省份"});
  183. $.each(resp.data, function(i, val) {
  184. var $option = $('<option data-fcode="' + val.FCODE + '" value="' + val.ID + '">' + val.FNAME + '</option>');
  185. $("#province").append($option);
  186. });
  187. })
  188. $("#province").bind("change", function() {
  189. var provinceid = $("#province option:selected").attr("value");
  190. setCity(provinceid);
  191. });
  192. }
  193. function setCity(provinceid){
  194. _this.getData('get', _this.baseUrl+ "/tunland/clue/getCityOfPronvince", {pId: provinceid}).then(resp => {
  195. if(resp.status == 1 ){
  196. return;
  197. }
  198. $("#city").empty();
  199. resp.data.unshift({dmpCityId:-1, cityName:"市"});
  200. $.each(resp.data, function(i, val) {
  201. var $option = $('<option value="' + val.dmpCityId + '">' + val.cityName + '</option>');
  202. $("#city").append($option);
  203. });
  204. })
  205. $("#city").unbind("change");
  206. $("#city").bind("change", function() {
  207. _this.getData('get', _this.baseUrl+"/tunland/clue/getDealer", {cityId:$("#city").val()})
  208. });
  209. }
  210. function setBrand(){
  211. _this.getData('get', _this.baseUrl+ "/tunland/clue/getBrand").then(resp => {
  212. if(resp.status == 1 ){
  213. return;
  214. }
  215. $("#brand").empty();
  216. resp.data.unshift({ID:-1, NAME:"品牌"});
  217. $.each(resp.data, function(i, val) {
  218. if (val.ID == '504f7428-439a-4f87-9540-1ad1f334962e' || val.ID == -1) {
  219. var $option = $('<option value="' + val.ID + '">' + val.NAME + '</option>');
  220. $("#brand").append($option);
  221. }
  222. });
  223. })
  224. $("#brand").bind("change", function() {
  225. setCarSeries($("#brand").val());
  226. });
  227. }
  228. function setCarSeries(brandId){
  229. $("#carSeries").empty();
  230. _this.getData('get', _this.baseUrl+ "/tunland/clue/getSeries", {brandId}).then( resp => {
  231. if(resp.status == 1 ){
  232. return;
  233. }
  234. resp.data.unshift({ID:-1, NAME:"选择车型"});
  235. $.each(resp.data, function(i, val) {
  236. var $option = $('<option value="' + val.ID + '">' + val.NAME + '</option>');
  237. $("#carSeries").append($option);
  238. });
  239. // if(!isNaN(isbind)) {
  240. // $("#carSeries").val(isbind);
  241. // }
  242. })
  243. }
  244. }
  245. p.checkPhoneNum = function(vInput, enable) {
  246. //手机号
  247. var reg = /^1(3|4|5|6|8|7)\d{9}$/;
  248. var flag = false;
  249. var phoneVal = vInput.val();
  250. if(phoneVal == "" || phoneVal == "手机号码") {
  251. alertMsg("手机号不能为空");
  252. } else if(!reg.test(phoneVal)) {
  253. alertMsg("请输入正确的手机号");
  254. } else {
  255. //验证手机号码是否已经注册过
  256. if(enable) {
  257. var urlJson = {
  258. a: "Verifymtel",
  259. tel: phoneVal
  260. }
  261. return new Promise(resolve => {
  262. this.getData('get', _this.baseUrl+ "/tunland/clue/getProvince", urlJson).then(resp => {
  263. if(resp.statcode == 0) {
  264. resolve(true);
  265. }else{
  266. resolve(false);
  267. }
  268. })
  269. })
  270. } else {
  271. return Promise.resolve(true);
  272. }
  273. }
  274. return Promise.resolve(flag);
  275. }
  276. p.LzInfo = function () {
  277. const _this = this;
  278. $.ajax({
  279. type: "POST",
  280. async: false,
  281. url: _this.baseUrl+"/tunland/dmp/dmpLzInfo",
  282. data: {
  283. brandId: $("#brand").val(),
  284. seriesId: $("#carSeries").val(),
  285. provinceId: $("#province").val(),
  286. cityId: $("#city").val(),
  287. name: $("#name").val(),
  288. tel: $("#realPhone").val()
  289. },
  290. dataType: "json"
  291. });
  292. }
  293. p.getData = function(method="GET", url, data={}){
  294. return new Promise(resolve=>{
  295. $.ajax({
  296. url:url,
  297. method: method,
  298. data: method.toUpperCase()=="GET" ? data : JSON.stringify(data),
  299. dataType:'json',
  300. contentType:"application/json;charset=utf-8",
  301. success:e=>{
  302. resolve(e)
  303. }
  304. })
  305. })
  306. }
  307. function alertMsg(content) {
  308. $('.alertbox').show();
  309. $('.alertbox').css("z-index", "999");
  310. $(".modalbody").html(content);
  311. };
  312. window.foton.pk = pk;
  313. })()