new.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. var ProductId = "",
  2. ProductIdCountDown = "",
  3. ProductAttrId = [],
  4. ProductAttrInfo = 0;
  5. $(document).ready(function () {
  6. init();
  7. $(window).scroll(WindowScroll);
  8. });
  9. init = function () {
  10. getProductInfo();
  11. }
  12. var getProductInfo = function () {
  13. var pid = getUrlParam("pid") || window.location.pathname.substr(1);
  14. var parameter = urlEncode(["SelectProduct", pid]);
  15. $.ajax({
  16. type: "post",
  17. url: "/taiwan/php/index.php",
  18. data: {mode: parameter},
  19. dataType: "json",
  20. success: function (data) {
  21. $("#PageLoading").css({"display": "none"});
  22. $("#PageWarp").css({"display": "block"});
  23. printProductInfo(data[0][0]);
  24. PrintProductAttribute(data[0][0].ProductAttr);
  25. }
  26. });
  27. }
  28. var printProductInfo = function (data) {
  29. ProductAttrId = data;
  30. ProductId = data.ProductId;
  31. ProductIdCountDown = data.CountDown;
  32. $("#ProductName").html(data.ProductName);
  33. $("#ProductPrice").html(Math.ceil(data.ProductPrice));
  34. $("#ColorPrice").html("฿" + Math.ceil(data.ProductPrice));
  35. $("#ProductPrimeCost").html(Math.ceil(data.ProductPrimeCost));
  36. $("#ProductInfo").html(unescape(data.ProductInfo));
  37. $("#Discount").html(data.Discount);
  38. $("#Sold").html(data.Sold);
  39. $("#Promotion").html(data.Promotion);
  40. $("#ProductInfo img").css({"width":"100%","height":"auto"});
  41. // countTime(ProductIdCountDown);
  42. // countDown(ProductIdCountDown);
  43. setInterval(function () {
  44. freshTime();
  45. }, 1000);
  46. var banner = JSON.parse(data.ProductAttr)["7b824b9c-738b-11e8-a479-0610c52349b6"],
  47. color = JSON.parse(data.ProductAttr)["69d4e108-738a-11e8-a479-0610c52349b6"],
  48. size = JSON.parse(data.ProductAttr)["d6d6361b-acea-11e8-bbc6-0a4b7569e232"],
  49. classs = JSON.parse(data.ProductAttr)["cfb738c4-bff6-11e8-bbc6-0a4b7569e232"],
  50. comment = JSON.parse(data.ProductAttr)["d5cca263-c224-11e8-bbc6-0a4b7569e232"];
  51. $("#Color").html("");
  52. for (var i in color) {
  53. for (var j in color[i]) {
  54. var a = '<a _src=' + color[i][j] + ' onclick = itemClick(this)>' + j + '</a>';
  55. $("#Color").append($(a));
  56. }
  57. }
  58. $("#Color a").eq(0).addClass("checked");
  59. $("#ColorBanner").attr("src", $("#Color a").eq(0).attr("_src"));
  60. // ProductAttrId.push(escape($("#Color a").eq(0).html()), escape($("#Color a").eq(0).attr("_src")));
  61. if (size && !$.isEmptyObject(size)) {
  62. for (var i in size) {
  63. for (var j in size[i]) {
  64. var a = '<a onclick = itemClick(this)>' + size[i][j] + '</a>';
  65. $("#Size").append($(a));
  66. }
  67. }
  68. $("#Size a").eq(0).addClass("checked");
  69. }
  70. else {
  71. $("#Size").parent().hide();
  72. }
  73. var num = 0;
  74. for (var j in banner) {
  75. num++;
  76. }
  77. for (var i in banner) {
  78. for (var j in banner[i]) {
  79. var li = '<li class="item slide"><img src="' + banner[i][j] + '"/></li>';
  80. $(".scroller").append(li);
  81. var i = '<i><span class="pagination">' + (parseInt(j) + 1) + '/' + num + '</span></i>';
  82. $(".nav").append(i);
  83. $(".nav i").eq(0).addClass("current");
  84. }
  85. }
  86. bannerMove();
  87. var mp4 = $("#ProductInfo img.edui-upload-video"), el;
  88. for (var i = 0; i < mp4.length; i++) {
  89. var url = mp4.eq(i).attr("_url");
  90. el = '<video src=' + url + ' controls="controls" preload="auto" width = "100%"></video>';
  91. mp4.eq(i).after(el);
  92. mp4.eq(i).remove();
  93. }
  94. mp4.remove();
  95. //就是这一块
  96. if (comment && !$.isEmptyObject(comment)) {
  97. $("#comment").eq(0).html("");
  98. for (var i in comment) {
  99. //for (var j = 0;j<=i;j++) {
  100. $("#comment").eq(0).append(
  101. $('<li>' +
  102. '<div style="margin-bottom:8px; color: #999;font-size:12px">' +
  103. '<span>' + comment[i].name + '</span>' +
  104. '<span style="float: right;">' +
  105. '<span lass="reviewStar size1 star5">' + comment[i].time + '</span>' +
  106. '</span>' +
  107. '</div>' +
  108. '<div>' +
  109. '<p style="margin-bottom: 8px;font-size: 14px;word-break: break-all;">' + comment[i].text + '</p>' +
  110. '<div class="imgg" style="margin-bottom:10px;overflow: hidden">' + '</div>' +
  111. // '<p style="position: relative;min-height: 10px;">' +
  112. // '<span style="position: absolute;bottom: 0;right: 15px;color:#8f8f94">' + comment[i].time + '</span>' +
  113. // '</p>' +
  114. '</div>' +
  115. '</li>'
  116. ));
  117. if (comment[i].imgurl != "") {
  118. var CreateCommentImg = function (el, img, flag) {
  119. img = flag ? '/taiwan/' + img : img;
  120. var div = '<img style="z-index:0;" src="' + img + '">';
  121. $(".imgg").eq(i).append(div);
  122. }
  123. var img = comment[i]['imgurl'].split(",");
  124. img.forEach(function (val) {
  125. CreateCommentImg(el, val, false);
  126. });
  127. }
  128. //}
  129. }
  130. // $(".u-format .items").eq(0).eq(0).addClass("tab-sel");
  131. }
  132. else {
  133. $(".ProductEvaluate")[0].style.display = "none";
  134. // $(".header-nav")[0].children[2].style.display = "none";
  135. // Roll();
  136. }
  137. }
  138. var bannerMove = function () {
  139. var glide = new Glide('.module-preview ', {
  140. autoplay: 3000
  141. });
  142. glide.on(['mount', 'run.after'], function () {
  143. $(".nav i").removeClass("current");
  144. $(".nav i").eq(glide._i).addClass("current");
  145. })
  146. glide.mount();
  147. }
  148. var ToTop = function () {
  149. $("html,body").scrollTop(0);
  150. }
  151. var ToProductInfo = function () {
  152. $("html,body").scrollTop($(".ProductInfo").offset().top - 50);
  153. // $("html,body").animate({scrollTop: $(".ProductInfo").offset().top - 50});
  154. }
  155. var ToProductEvaluate = function () {
  156. $("html,body").scrollTop($(".ProductEvaluate").offset().top);
  157. // $("html,body").animate({scrollTop: $(".ProductEvaluate").offset().top});
  158. }
  159. function freshTime() {
  160. var arr = ProductIdCountDown.split(/[- : \/]/);
  161. var endtime = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
  162. var nowtime = new Date();
  163. var lefttime = parseInt(endtime.getTime() - nowtime.getTime());//这是毫秒,如果再/1000就是秒
  164. if (lefttime <= 0) {
  165. var toyear = new Date().getFullYear();
  166. var tomonth = new Date().getMonth() + 1;
  167. var today = new Date().getDate() + 2;
  168. arr[0] = toyear;
  169. arr[1] = tomonth;
  170. arr[2] = today;
  171. endtime = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
  172. lefttime = parseInt(endtime.getTime() - nowtime.getTime());//这是毫秒,如果再/1000就是秒
  173. }
  174. var hm = 60 * 60 * 1000;
  175. var h = parseInt((lefttime / hm));
  176. var mm = 60 * 1000;
  177. var m = parseInt((lefttime / mm) % 60);
  178. var s = parseInt((lefttime / 1000) % 60);
  179. m = checktime(m);
  180. s = checktime(s);
  181. $("#J_TimeHour").html(h);
  182. $("#J_TimeMin").html(m);
  183. $("#J_TimeSec").html(s);
  184. if (lefttime < 0) {
  185. $("#J_TimeHour").html(0);
  186. $("#J_TimeMin").html(0);
  187. $("#J_TimeSec").html(0);
  188. }
  189. }
  190. //倒计时效果js代码
  191. function checktime(i) {
  192. if (i < 10) {
  193. i = "0" + i;
  194. }
  195. else {
  196. i = i;
  197. }
  198. return i;
  199. }
  200. var WindowScroll = function () {
  201. var top = $(document).scrollTop();
  202. if (top > $(".group-warp").eq(0).height() * 0.2) {
  203. $("#head").addClass("transparent");
  204. }
  205. if (top >= $(".ProductInfo").offset().top - 100) {
  206. $("#head").addClass("transparent");
  207. $("#head li").removeClass("active");
  208. $("#head li").eq(1).addClass("active");
  209. }
  210. if (top >= $(".ProductEvaluate").offset().top - 500) {
  211. $("#head").addClass("transparent");
  212. $("#head li").removeClass("active");
  213. $("#head li").eq(2).addClass("active");
  214. }
  215. if (top < $(".ProductEvaluate").offset().top - 500) {
  216. $("#head").addClass("transparent");
  217. $("#head li").removeClass("active");
  218. $("#head li").eq(1).addClass("active");
  219. }
  220. if (top <= $(".ProductInfo").offset().top - 100) {
  221. $("#head").addClass("transparent");
  222. $("#head li").removeClass("active");
  223. $("#head li").eq(0).addClass("active");
  224. }
  225. if (top <= $(".group-warp").eq(0).height() * 0.2) {
  226. $("#head").removeClass("transparent");
  227. }
  228. }
  229. var showPage = function () {
  230. // if ($(".widgets-cover").hasClass("show")) {
  231. // $(".widgets-cover").removeClass("show");
  232. // $("body").css({"position": "static", "top": "0px", "scroll-behavior": "unset"});
  233. // }
  234. // else {
  235. // $("body").css({"position": "fixed", "top": "0px", "scroll-behavior": "unset"});
  236. // $(".widgets-cover").addClass("show");
  237. // }
  238. if ($("#page-order").css("display") == "block") {
  239. $("#PageWarp").css({display: "block"});
  240. $("#page-order").animate({left: '100%'}, "", function () {
  241. $("#page-order").css({display: "none"});
  242. });
  243. }
  244. else {
  245. $("#page-order").css({display: "block"});
  246. $("#page-order").animate({left: '0'}, "", function () {
  247. $("#PageWarp").css({display: "none"});
  248. });
  249. }
  250. }
  251. /*********************************************下单页面事件区域*************************************************/
  252. var PrintProductAttribute = function (obj) {
  253. obj = JSON.parse(obj);
  254. var classs = obj['cfb738c4-bff6-11e8-bbc6-0a4b7569e232'],
  255. color = obj['69d4e108-738a-11e8-a479-0610c52349b6'],
  256. size = obj['d6d6361b-acea-11e8-bbc6-0a4b7569e232'];
  257. var
  258. colorel = $(".count_atrr .con"),
  259. sizeel = $(".count_size .con");
  260. // var isclasss = true;
  261. //打印图片颜色分类
  262. colorel.html("");
  263. // for (var i in color) {
  264. // for (var j in color[i]) {
  265. // var div = '<div class="tab" onclick="ColorClick(this,\'' + j + '\')"><img src="' + color[i][j] + '"></div>';
  266. // colorel.append($(div));
  267. // if (i == 0) {
  268. // // ColorClick(colorel.find(".tab").eq(0), j);
  269. // colorel.find(".tab").eq(0).addClass("tab-sel");
  270. // colorel.eq(0).parent().find("span").html(j);
  271. // }
  272. // }
  273. // }
  274. var cname = "";
  275. for (var j in color) {
  276. for (var i in color[j]) {
  277. if (i == "cname") {
  278. cname = color[j][i];
  279. }
  280. else {
  281. img = color[j][i];
  282. if (img.split("/new").length > 1) {
  283. src = img;
  284. }
  285. else {
  286. src = "/new/" + img;
  287. }
  288. name = i;
  289. }
  290. }
  291. var div = '<div class="tab" cname="' + cname + '" onclick="ColorClick(this,\'' + name + '\')"><img src="' + src + '"></div>';
  292. colorel.append($(div));
  293. if (j == 0) {
  294. // ColorClick(colorel.find(".tab").eq(0), j);
  295. colorel.find(".tab").eq(0).addClass("tab-sel");
  296. colorel.eq(0).parent().find("span").html(name);
  297. }
  298. }
  299. //打印尺寸分类
  300. if (size && !$.isEmptyObject(size)) {
  301. sizeel.html("");
  302. for (var i in size) {
  303. for (var j in size[i]) {
  304. var div = '<label class="tab" onclick="SizeClick(this)"><span>' + size[i][j] + '</span></label>';
  305. sizeel.append($(div));
  306. if (i == 0) {
  307. sizeel.find(".tab").eq(0).addClass("tab-sel");
  308. }
  309. }
  310. }
  311. }
  312. else {
  313. sizeel.parent().remove();
  314. }
  315. var classsel = $(".count_classs .con"), classs_obj, classs_a;
  316. //打印套餐
  317. if ($.isEmptyObject(classs)) {
  318. $(".count_classs .con").parent().remove();
  319. ProductAttrId.OrderNum = 1;
  320. }
  321. else {
  322. classsel.html("");
  323. $.each(classs, function (i, val) {
  324. ProductAttrInfo++;
  325. classs_obj = val;
  326. $.each(val, function (j, val1) {
  327. if (j == "type") {
  328. if ($(".dt-paramselect .meal").length != parseInt(val1)) {
  329. while (parseInt(val1) > $(".dt-paramselect .meal").length) {
  330. classs_a = $(".meal").eq(0).clone();
  331. classs_a.hide();
  332. $(".dt-paramselect").append(classs_a);
  333. }
  334. // for (var k = 0; k < parseInt(val1) - $(".dt-paramselect .meal").length; k++) {
  335. // classs_a = $(".meal").eq(0).clone();
  336. // classs_a.hide();
  337. // $(".dt-paramselect").append(classs_a);
  338. // }
  339. }
  340. }
  341. else if (j != "type") {
  342. var div = '<label class="tab" onclick="ClasssClick(this,\'' + j + '\',\'' + val.type + '\')"><span>' + val1 + '</span></label>';
  343. classsel.append($(div));
  344. // div.onclick = function () {
  345. // alert();
  346. // }
  347. // $(div).bind('click', function () {
  348. // alert();
  349. // });
  350. }
  351. });
  352. });
  353. $(".dt-paramselect").append($(".u-fornum"));
  354. $(".count_classs label").eq(0).click();
  355. /*
  356. if (ProductAttrInfo == 1) {
  357. ClasssClick($(".count_classs label").eq(0), ProductAttrId.ProductPrice, classs[0].type);
  358. }
  359. else {
  360. ClasssClick($(".count_classs label").eq(0), ProductAttrId.ProductPrice, ProductAttrInfo);
  361. }
  362. */
  363. // for (var i in classs) {
  364. // for (var j in classs[i]) {
  365. // if (j == "type") {
  366. // // $(".u-fornum").before(colorel.parent().clone().hide());
  367. // // $(".u-fornum").before(sizeel.parent().clone().hide());
  368. // $(".secondsetmeal").append(colorel.parent().clone());
  369. // $(".secondsetmeal").append(sizeel.parent().clone());
  370. // }
  371. // else if (j != "type") {
  372. // var div = '<label class="tab" onclick="ClasssClick(this,\'' + j + '\')"><span>' + classs[i][j] + '</span></label>';
  373. // classsel.append($(div));
  374. // }
  375. // }
  376. // }
  377. // ClasssClick($(".count_classs label").eq(0));
  378. }
  379. console.log(obj);
  380. }
  381. /**/
  382. var ClasssClick = function (el, val, type) {
  383. $(el.parentNode).find(".tab").removeClass("tab-sel");
  384. $(el).addClass("tab-sel");
  385. $(".meal").hide();
  386. $(".meal").eq(0).show();
  387. for (var i = 0; i < parseInt(type); i++) {
  388. $(".meal").eq(i).show();
  389. }
  390. type ? ProductAttrId.OrderNum = type : "";
  391. val ? ProductAttrId.ProductPrice = val : "";
  392. }
  393. /*选择颜色点击事件*/
  394. var ColorClick = function (el, val) {
  395. $(el.parentNode).find(".tab").removeClass("tab-sel");
  396. $(el).addClass("tab-sel");
  397. $(el.parentNode.parentNode).find("span").html(val);
  398. // $(el.parentNode).children().removeClass("checked");
  399. // // $("#Color a").removeClass("checked");
  400. // $(el).addClass("checked");
  401. // if ($(el.parentNode).attr("id") === "Color") {
  402. // $("#ColorBanner").attr("src", $(el).attr("_src"));
  403. // }
  404. // var banner = escape($("#ColorBanner").attr("src")),
  405. // color = escape($("#Color a.checked").html()),
  406. // size = escape($("#Size a.checked").html());
  407. // ProductAttrInfo = [];
  408. // ProductAttrInfo.push(banner, color, size);
  409. }
  410. /*选择尺寸点击事件*/
  411. var SizeClick = function (el) {
  412. $(el.parentNode).find(".tab").removeClass("tab-sel");
  413. $(el).addClass("tab-sel");
  414. }
  415. /*购买数量添加*/
  416. var addnumber = function () {
  417. $('.textWrap .num').html(parseInt($('.textWrap .num').html()) + 1);
  418. }
  419. /*购买数量减少*/
  420. var minnumber = function () {
  421. if (parseInt($('.textWrap .num').html()) > 1) {
  422. $('.textWrap .num').html(parseInt($('.textWrap .num').html()) - 1);
  423. }
  424. }
  425. /*点击购买函数*/
  426. var goShop = function () {
  427. // var num = parseInt($("#number").val()),
  428. // attr = ProductAttrInfo.join(),
  429. // str = "shop.html?pid=" + ProductId + "&attr=" + attr + "&num=" + num;
  430. var num = parseInt($("#number").text()),
  431. obj = [],
  432. attr = {},
  433. numobj = {},
  434. url = "shop.html?pid=" + ProductId + "&attr=",
  435. str = "";
  436. numobj["Number"] = num;
  437. numobj["Money"] = ProductAttrId.ProductPrice;
  438. obj.push(numobj);
  439. for (var i = 0; i < ProductAttrId.OrderNum; i++) {
  440. attr = {};
  441. attr["color"] = $(".meal").eq(i).find(".tt span").eq(0).text();
  442. attr["img"] = $(".meal").eq(i).find("div.tab-sel img").attr("src");
  443. attr['cname'] = $(".meal").eq(i).find("div.tab-sel img").parent().attr("cname");
  444. attr["size"] = $(".meal").eq(i).find("label.tab-sel span").text();
  445. obj.push(attr);
  446. }
  447. OrderPrice = parseInt(obj[0].Number) * parseInt(obj[0].Money);
  448. //facebook购物车推广事件,请勿删除!
  449. fbq('track', 'AddToCart', {
  450. value: OrderPrice,
  451. currency: 'TWD',
  452. content_ids: 'ProductAttrId.ProductRemarks',
  453. content_type: 'product_group',
  454. });
  455. str = escape(JsonToString(obj));
  456. url += str;
  457. console.log(url);
  458. window.location.href = url;
  459. }
  460. getUrlParam = function (name) {
  461. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  462. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  463. if (r != null) return unescape(r[2]);
  464. return null; //返回参数值
  465. }
  466. urlEncode = function (arr) {
  467. var i; //循环初始化
  468. for (i = 0; i < arr.length; i++) {
  469. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  470. }
  471. return arr.join();
  472. }
  473. Roll = function () {
  474. //$(".marquee ul").css('position', 'absolute');
  475. animate();
  476. };
  477. animate = function () {
  478. var boxHeight = $('.marquee').height();
  479. var ulHeight = $(".marquee ul").height();
  480. $(".marquee").css('top', 0);
  481. $(".marquee").animate({scrollTop: $(".marquee")[0].scrollTop == 0 ? (ulHeight - boxHeight) : 0}, 10000, animate);
  482. }
  483. //json转换为string
  484. var JsonToString = function (obj) {
  485. var i,
  486. _type = false,
  487. _str = "",
  488. _type = typeof (obj); //获取类型
  489. //开始序列化
  490. if (obj == null) {
  491. }
  492. else {
  493. obj = obj.valueOf(); //获取值 同时类型也为对应
  494. if ("boolean,number".indexOf(_type) > -1) {//bool和number类型转化
  495. _str = obj.toString();
  496. }
  497. else if (_type == "string") {//json处理字符串时需要加上 "\""符号
  498. _str = "\"" + obj + "\"";
  499. }
  500. else if (typeof obj == "array") { //数组处理
  501. _str = "[";
  502. for (i = 0; i < obj.length; i++) {
  503. _str += JsonToString(obj[i]) + ((i < obj.length - 1) ? "," : "")
  504. }
  505. ;_str += "]";
  506. return _str
  507. }
  508. else {//object处理
  509. _str = "{";
  510. for (i in obj) {
  511. if (obj.hasOwnProperty(i)) {
  512. if (_str.length > 1) {
  513. _str += ","
  514. }
  515. ;_str += "\"" + i + "\":" + JsonToString(obj[i]);
  516. }
  517. }
  518. _str += "}";
  519. }
  520. return _str;
  521. }
  522. }