福田皮卡火星7+火星9
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. console.log(1111, _this.listenScroll);
  118. if(_this.listenScroll === false){ return}
  119. let top = window.scrollY + 1000;
  120. let index = 0;
  121. if(top <= qjzs){
  122. index = 0;
  123. }else if(top <= jctj){
  124. index = 1;
  125. }else if(top <= cspz){
  126. index = 2;
  127. }else{
  128. index = 3;
  129. }
  130. $("#navContainer .nav .n").removeClass("active");
  131. $("#navContainer .nav .n").eq(index).addClass("active");
  132. $("#navContainer .nav .line").css("left", 106*index);
  133. }
  134. }
  135. // 全景展示滚动
  136. p.qjzs = function(){
  137. new Swiper(".qjzs .swiper-container", {
  138. prevButton:'.qjzs .wg',
  139. nextButton:'.qjzs .ns',
  140. onTouchStart: function(swiper){
  141. // alert(swiper.activeIndex);
  142. $("#container .qjzs .nav .line").toggleClass("right");
  143. }
  144. });
  145. }
  146. // 精彩图集
  147. p.jctj = function(){
  148. var galleryTop = new Swiper('.swiper1', {
  149. spaceBetween: 10,
  150. onSlideChangeStart: function(swiper){
  151. let index = swiper.activeIndex;
  152. let len = $(".swiper1 img").length;
  153. if(index == 0){
  154. galleryThumbs.slideTo(0);
  155. }else if(index == len-1){
  156. galleryThumbs.slideTo(3);
  157. }
  158. }
  159. });
  160. var galleryThumbs = new Swiper('.swiper2', {
  161. spaceBetween: 24,
  162. slidesPerView: 'auto',
  163. touchRatio: 0.2,
  164. freeMode: true,
  165. watchSlidesProgress: false,
  166. onClick: function(swiper){
  167. let index = swiper.clickedIndex;
  168. galleryTop.slideTo(index);
  169. }
  170. });
  171. }
  172. // 预约试驾
  173. p.yysj = function(){
  174. const _this = this;
  175. setProvince();
  176. setBrand();
  177. function setProvince(){
  178. _this.getData('get', _this.baseUrl+ "/tunland/clue/getProvince").then(resp => {
  179. if(resp.status == 1 ){
  180. return;
  181. }
  182. $("#province").empty();
  183. resp.data.unshift({ID:-1, FNAME:"省份"});
  184. $.each(resp.data, function(i, val) {
  185. var $option = $('<option data-fcode="' + val.FCODE + '" value="' + val.ID + '">' + val.FNAME + '</option>');
  186. $("#province").append($option);
  187. });
  188. })
  189. $("#province").bind("change", function() {
  190. var provinceid = $("#province option:selected").attr("value");
  191. setCity(provinceid);
  192. });
  193. }
  194. function setCity(provinceid){
  195. _this.getData('get', _this.baseUrl+ "/tunland/clue/getCityOfPronvince", {pId: provinceid}).then(resp => {
  196. if(resp.status == 1 ){
  197. return;
  198. }
  199. $("#city").empty();
  200. resp.data.unshift({dmpCityId:-1, cityName:"市"});
  201. $.each(resp.data, function(i, val) {
  202. var $option = $('<option value="' + val.dmpCityId + '">' + val.cityName + '</option>');
  203. $("#city").append($option);
  204. });
  205. })
  206. $("#city").unbind("change");
  207. $("#city").bind("change", function() {
  208. _this.getData('get', _this.baseUrl+"/tunland/clue/getDealer", {cityId:$("#city").val()})
  209. });
  210. }
  211. function setBrand(){
  212. _this.getData('get', _this.baseUrl+ "/tunland/clue/getBrand").then(resp => {
  213. if(resp.status == 1 ){
  214. return;
  215. }
  216. $("#brand").empty();
  217. resp.data.unshift({ID:-1, NAME:"品牌"});
  218. $.each(resp.data, function(i, val) {
  219. if (val.ID == '504f7428-439a-4f87-9540-1ad1f334962e' || val.ID == -1) {
  220. var $option = $('<option value="' + val.ID + '">' + val.NAME + '</option>');
  221. $("#brand").append($option);
  222. }
  223. });
  224. })
  225. $("#brand").bind("change", function() {
  226. setCarSeries($("#brand").val());
  227. });
  228. }
  229. function setCarSeries(brandId){
  230. $("#carSeries").empty();
  231. _this.getData('get', _this.baseUrl+ "/tunland/clue/getSeries", {brandId}).then( resp => {
  232. if(resp.status == 1 ){
  233. return;
  234. }
  235. resp.data.unshift({ID:-1, NAME:"选择车型"});
  236. $.each(resp.data, function(i, val) {
  237. var $option = $('<option value="' + val.ID + '">' + val.NAME + '</option>');
  238. $("#carSeries").append($option);
  239. });
  240. // if(!isNaN(isbind)) {
  241. // $("#carSeries").val(isbind);
  242. // }
  243. })
  244. }
  245. }
  246. p.checkPhoneNum = function(vInput, enable) {
  247. //手机号
  248. var reg = /^1(3|4|5|6|8|7)\d{9}$/;
  249. var flag = false;
  250. var phoneVal = vInput.val();
  251. if(phoneVal == "" || phoneVal == "手机号码") {
  252. alertMsg("手机号不能为空");
  253. } else if(!reg.test(phoneVal)) {
  254. alertMsg("请输入正确的手机号");
  255. } else {
  256. //验证手机号码是否已经注册过
  257. if(enable) {
  258. var urlJson = {
  259. a: "Verifymtel",
  260. tel: phoneVal
  261. }
  262. return new Promise(resolve => {
  263. this.getData('get', _this.baseUrl+ "/tunland/clue/getProvince", urlJson).then(resp => {
  264. if(resp.statcode == 0) {
  265. resolve(true);
  266. }else{
  267. resolve(false);
  268. }
  269. })
  270. })
  271. } else {
  272. return Promise.resolve(true);
  273. }
  274. }
  275. return Promise.resolve(flag);
  276. }
  277. p.LzInfo = function () {
  278. const _this = this;
  279. $.ajax({
  280. type: "POST",
  281. async: false,
  282. url: _this.baseUrl+"/tunland/dmp/dmpLzInfo",
  283. data: {
  284. brandId: $("#brand").val(),
  285. seriesId: $("#carSeries").val(),
  286. provinceId: $("#province").val(),
  287. cityId: $("#city").val(),
  288. name: $("#name").val(),
  289. tel: $("#realPhone").val()
  290. },
  291. dataType: "json"
  292. });
  293. }
  294. p.getData = function(method="GET", url, data={}){
  295. return new Promise(resolve=>{
  296. $.ajax({
  297. url:url,
  298. method: method,
  299. data: method.toUpperCase()=="GET" ? data : JSON.stringify(data),
  300. dataType:'json',
  301. contentType:"application/json;charset=utf-8",
  302. success:e=>{
  303. resolve(e)
  304. }
  305. })
  306. })
  307. }
  308. function alertMsg(content) {
  309. $('.alertbox').show();
  310. $('.alertbox').css("z-index", "999");
  311. $(".modalbody").html(content);
  312. };
  313. window.foton.pk = pk;
  314. })()