main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. var domanUrl = "//" + window.location.host,
  2. path="//test.iamberry.com",
  3. base_path= path +"/watero/wechat",
  4. html_path = "/static-iamberry/watero",
  5. marquee = '';
  6. mui.each(document.querySelectorAll('#footer-bar .mui-tab-item'), function(index, el) {
  7. el.addEventListener('tap', function() {
  8. switch(index) {
  9. case 0:
  10. mui.openWindow({
  11. url:'index.html'
  12. });
  13. break;
  14. case 1:
  15. mui.openWindow({
  16. url: 'shopping_cart.html'
  17. });
  18. break;
  19. case 2:
  20. mui.openWindow({
  21. url: 'order_list.html'
  22. });
  23. break;
  24. case 3:
  25. mui.openWindow({
  26. url: 'vip_center.html'
  27. });
  28. break;
  29. default:
  30. break
  31. }
  32. }, false)
  33. });
  34. function getCartNum() {
  35. $.ajax(base_path + '/cart/getCartNumByCartOpenId', {
  36. data: {
  37. openid: '230'
  38. },
  39. dataType: 'json',
  40. type: 'post',
  41. timeout: 15000,
  42. xhrFields: {
  43. withCredentials: true
  44. },
  45. crossDomain: true,
  46. success: function(dt) {
  47. if (dt.isRedirect) {
  48. location.href = dt.redirectURL;
  49. } else {
  50. if(dt.status) {
  51. if(dt.data == "0") {
  52. $('.icon-gouwuche span,.cart .my-badge-danger').hide();
  53. } else {
  54. $('.icon-gouwuche span,.cart .my-badge-danger').text(dt.data).show()
  55. }
  56. } else {
  57. console.log(dt)
  58. }
  59. }
  60. },
  61. error: function(xhr, type, errorThrown) {
  62. errorfn(xhr)
  63. }
  64. });
  65. };
  66. mui('body').on('tap', '.go_index', function() {
  67. mui.openWindow({
  68. url: 'index.html'
  69. })
  70. });
  71. mui('body').on('tap', '.go_gwc', function() {
  72. mui.openWindow({
  73. url: 'shopping_cart.html'
  74. })
  75. });
  76. mui('body').on('tap', '.go_web_shop', function() {
  77. mui.openWindow({
  78. url: 'chanpin_list.html'
  79. })
  80. });
  81. mui('body').on('tap', '.go_chanpin_details', function() {
  82. mui.openWindow({
  83. url: 'chanpin_details.html?productId=' + this.getAttribute("proid")+'&colorId='+this.getAttribute("colorid")
  84. })
  85. });
  86. mui('body').on('tap', '.go_chanpin_details2', function() {
  87. mui.openWindow({
  88. url: 'chanpin_details.html?productId=' + this.getAttribute("proid")+'&colorId='+this.getAttribute("colorid")
  89. })
  90. });
  91. mui('body').on('tap', '.go_couponList', function() {
  92. mui.openWindow({
  93. url: base_path + '/couponWechat/couponList'
  94. })
  95. });
  96. mui('body').on('tap', '.go-clearing', function() {
  97. var th=this;
  98. $.ajax(base_path + '/cart/addProductToCart', {
  99. data: {"productId":th.getAttribute("proid"),"colorId":th.getAttribute("colorid")},
  100. dataType: 'json',
  101. type: 'GET',
  102. timeout: 15000,
  103. xhrFields: {
  104. withCredentials: true
  105. },
  106. crossDomain: true,
  107. success: function(dt) {
  108. if (dt.isRedirect) {
  109. location.href = dt.redirectURL;
  110. } else {
  111. if(dt.status) {
  112. mui.openWindow({
  113. url: 'clearing.html?cartId=' + dt.data + "&tiemstamp=" + new Date().getTime()
  114. })
  115. } else {
  116. mui.alert(dt.message)
  117. }
  118. }
  119. },
  120. error: function(xhr, type, errorThrown) {
  121. console.log(xhr)
  122. }
  123. })
  124. });
  125. mui('body').on('tap', '.go_gwc_pro', function() {
  126. var th=this;
  127. $.ajax(base_path + '/cart/addProductToCart', {
  128. data: {"productId":th.getAttribute("proid"),"colorId":th.getAttribute("colorid")},
  129. dataType: 'json',
  130. type: 'GET',
  131. timeout: 15000,
  132. xhrFields: {
  133. withCredentials: true
  134. },
  135. crossDomain: true,
  136. success: function(dt) {
  137. if (dt.isRedirect) {
  138. location.href = dt.redirectURL;
  139. } else {
  140. if(dt.status) {
  141. getCartNum()
  142. } else {
  143. mui.alert(dt.message)
  144. }
  145. }
  146. },
  147. error: function(xhr, type, errorThrown) {
  148. errorfn(xhr)
  149. }
  150. })
  151. });
  152. function marquee_Show() {
  153. // mui.ajax(base_path + '/coupon/checkCurrentPreferential?dates='+ new Date().getTime(), {
  154. // dataType: 'json',
  155. // type: 'POST',
  156. // async: false,
  157. // timeout: 15000,
  158. // success: function(dt) {
  159. //// if(dt.status) {
  160. //// marquee = '<span class="mui-h6">专属优惠:</span>'
  161. //// } else {
  162. // marquee = ''
  163. //// }
  164. // },
  165. // error: function(xhr, type, errorThrown) {
  166. // console.log(xhr)
  167. // }
  168. // })
  169. };
  170. mui('body').on('tap', '.go_order_details', function() {
  171. if(this.getAttribute('isSpell')!=null){
  172. location.href='order_details.html?orderId=' + this.getAttribute("value")+'&isSpell='+this.getAttribute('isSpell');
  173. }else{
  174. location.href='order_details.html?orderId=' + this.getAttribute("value")
  175. }
  176. });
  177. mui('body').on('tap', '.go_pay_count', function() {
  178. mui.openWindow({
  179. url: 'order_list.html?salesStatus=1'
  180. })
  181. });
  182. mui('body').on('tap', '.go_pay_ping', function() {
  183. mui.openWindow({
  184. url: 'order_list.html?salesStatus=15'
  185. })
  186. });
  187. mui('body').on('tap', '.go_deliver_count', function() {
  188. mui.openWindow({
  189. url: 'order_list.html?salesStatus=2'
  190. })
  191. });
  192. mui('body').on('tap', '.go_delivered_count', function() {
  193. mui.openWindow({
  194. url: 'order_list.html?salesStatus=5'
  195. })
  196. });
  197. mui('body').on('tap', '.go_all_count', function() {
  198. mui.openWindow({
  199. url: 'order_list.html?salesStatus=-1'
  200. })
  201. });
  202. mui('body').on('tap', '.go_publicity', function() {
  203. mui.openWindow({
  204. url: base_path + '/agentWechat/goPublicity?userType=' + this.getAttribute("userType") + "&isDrp=" + this.getAttribute("isDrp")
  205. })
  206. });
  207. mui('body').on('tap', '.go_order_list', function() {
  208. mui.openWindow({
  209. url: 'order_list.html'
  210. })
  211. });
  212. function errorfn(xhr) {
  213. if(xhr.readyState == 4 && xhr.status == 200) {} else {
  214. var ref = location.href.split("#")[0],
  215. src = '';
  216. if(ref.indexOf('?') != -1) {
  217. src = ref + "&date=" + new Date().getTime()
  218. } else {
  219. src = ref + "?date=" + new Date().getTime()
  220. }
  221. location.href = src;
  222. return
  223. }
  224. }
  225. function CheckImgExists(imgurl) {
  226. var ImgObj = new Image();
  227. ImgObj.src = imgurl;
  228. if(ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
  229. return ImgObj
  230. } else {
  231. return false
  232. }
  233. };
  234. function gotoTop(acceleration, stime) {
  235. acceleration = acceleration || 0.1;
  236. stime = stime || 10;
  237. var x1 = 0,
  238. y1 = 0,
  239. x2 = 0,
  240. y2 = 0,
  241. x3 = 0,
  242. y3 = 0;
  243. if(document.documentElement) {
  244. x1 = document.documentElement.scrollLeft || 0;
  245. y1 = document.documentElement.scrollTop || 0
  246. }
  247. if(document.body) {
  248. x2 = document.body.scrollLeft || 0;
  249. y2 = document.body.scrollTop || 0
  250. }
  251. var x3 = window.scrollX || 0;
  252. var y3 = window.scrollY || 0;
  253. var x = Math.max(x1, Math.max(x2, x3));
  254. var y = Math.max(y1, Math.max(y2, y3));
  255. var speeding = 1 + acceleration;
  256. window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
  257. if(x > 0 || y > 0) {
  258. var run = "gotoTop(" + acceleration + ", " + stime + ")";
  259. window.setTimeout(run, stime)
  260. }
  261. };
  262. function accDiv(arg1, arg2) {
  263. var t1 = 0,
  264. t2 = 0,
  265. r1, r2;
  266. try {
  267. t1 = arg1.toString().split(".")[1].length
  268. } catch(e) {}
  269. try {
  270. t2 = arg2.toString().split(".")[1].length
  271. } catch(e) {}
  272. with(Math) {
  273. r1 = Number(arg1.toString().replace(".", ""));
  274. r2 = Number(arg2.toString().replace(".", ""));
  275. return(r1 / r2) * pow(10, t2 - t1)
  276. }
  277. };
  278. Number.prototype.div = function(arg) {
  279. return accDiv(this, arg)
  280. };
  281. function accAdd(arg1, arg2) {
  282. var r1, r2, m, c;
  283. try {
  284. r1 = arg1.toString().split(".")[1].length
  285. } catch(e) {
  286. r1 = 0
  287. }
  288. try {
  289. r2 = arg2.toString().split(".")[1].length
  290. } catch(e) {
  291. r2 = 0
  292. }
  293. c = Math.abs(r1 - r2);
  294. m = Math.pow(10, Math.max(r1, r2));
  295. if(c > 0) {
  296. var cm = Math.pow(10, c);
  297. if(r1 > r2) {
  298. arg1 = Number(arg1.toString().replace(".", ""));
  299. arg2 = Number(arg2.toString().replace(".", "")) * cm
  300. } else {
  301. arg1 = Number(arg1.toString().replace(".", "")) * cm;
  302. arg2 = Number(arg2.toString().replace(".", ""))
  303. }
  304. } else {
  305. arg1 = Number(arg1.toString().replace(".", ""));
  306. arg2 = Number(arg2.toString().replace(".", ""))
  307. }
  308. return(arg1 + arg2) / m
  309. };
  310. Number.prototype.add = function(arg) {
  311. return accAdd(arg, this)
  312. };
  313. function accSub(arg1, arg2) {
  314. var r1, r2, m, n;
  315. try {
  316. r1 = arg1.toString().split(".")[1].length
  317. } catch(e) {
  318. r1 = 0
  319. }
  320. try {
  321. r2 = arg2.toString().split(".")[1].length
  322. } catch(e) {
  323. r2 = 0
  324. }
  325. m = Math.pow(10, Math.max(r1, r2));
  326. n = (r1 >= r2) ? r1 : r2;
  327. return((arg1 * m - arg2 * m) / m).toFixed(n)
  328. };
  329. Number.prototype.sub = function(arg) {
  330. return accMul(arg, this)
  331. };
  332. function accMul(arg1, arg2) {
  333. var m = 0,
  334. s1 = arg1.toString(),
  335. s2 = arg2.toString();
  336. try {
  337. m += s1.split(".")[1].length
  338. } catch(e) {}
  339. try {
  340. m += s2.split(".")[1].length
  341. } catch(e) {}
  342. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  343. };
  344. Number.prototype.mul = function(arg) {
  345. return accMul(arg, this)
  346. };
  347. function switchcolor(color) {
  348. var pro_color = "";
  349. switch(color) {
  350. case 1:
  351. pro_color = "品蓝";
  352. break;
  353. case 2:
  354. pro_color = "品黑";
  355. break;
  356. case 3:
  357. pro_color = "苹果绿";
  358. break;
  359. case 4:
  360. pro_color = "西瓜红";
  361. break;
  362. case 5:
  363. pro_color = "白色";
  364. break;
  365. case 36:
  366. pro_color = "银色";
  367. break;
  368. case 37:
  369. pro_color = "磨砂";
  370. break;
  371. case 39:
  372. pro_color = "无色透明";
  373. break;
  374. case 40:
  375. pro_color = "茉莉白";
  376. break;
  377. default:
  378. pro_color = "品蓝";
  379. break
  380. }
  381. return pro_color
  382. };
  383. function switchColorImg(colorId){
  384. var img='';
  385. switch (colorId){
  386. case 1:
  387. img='//s.iamberry.com/watero/images/shop/cp-blue.png'
  388. break;
  389. case 2:
  390. img='//s.iamberry.com/watero/images/shop/cp-black.png'
  391. break;
  392. case 3:
  393. img='//s.iamberry.com/watero/images/shop/cp-green.png'
  394. break;
  395. case 4:
  396. img='//s.iamberry.com/watero/images/shop/cp-red.png'
  397. break;
  398. case 39:
  399. img='//s.iamberry.com/watero/wechat/images/971ECE348D1F7D9F8628_20171212154024_8556.jpg'
  400. break;
  401. case 40:
  402. img='//s.iamberry.com/watero/images/product/WaterO_positive.png'
  403. break;
  404. default:
  405. img='//s.iamberry.com/watero/images/shop/cp-blue.png'
  406. break;
  407. }
  408. return img;
  409. };
  410. function getParam(paramName) {
  411. paramValue = "", isFound = !1;
  412. if(this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
  413. arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
  414. while(i < arrSource.length && !isFound) {
  415. arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
  416. }
  417. }
  418. return paramValue == "" && (paramValue = null), paramValue
  419. };
  420. function dc(objectid) {
  421. if(document.getElementById && document.getElementById(objectid)) {
  422. return document.getElementById(objectid)
  423. } else if(document.all && document.all(objectid)) {
  424. return document.all(objectid)
  425. } else if(document.layers && document.layers[objectid]) {
  426. return document.layers[objectid]
  427. } else {
  428. return false
  429. }
  430. };
  431. function formatDate(now) {
  432. now = new Date(now);
  433. var year = now.getFullYear();
  434. var month = now.getMonth() + 1;
  435. var date = now.getDate();
  436. var hour = now.getHours();
  437. var minute = now.getMinutes();
  438. var second = now.getSeconds();
  439. return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
  440. };
  441. function springFestivalPop() {
  442. if(getCookie("WATERO_WEB_") == null) {
  443. maskspringFestival.show();
  444. $(".mui-backdrop").append('<div style="position:relative;"><img src="//s.iamberry.com/watero/images/shop/springFestival_2017.png" style="width:80%;margin:10% 10% auto 10%;"/><button type="button" id="close-springFestival" class="mui-btn my-btn-red" style="position: absolute;bottom: 5%;left: 50%;-webkit-transform: translateX(-50%)">我知道了</button></div>');
  445. mui('body').on('tap', '#close-springFestival', function(e) {
  446. setCookie();
  447. $(".mui-backdrop").hide();
  448. });
  449. }
  450. };
  451. function getCookie(name) {
  452. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  453. if(arr = document.cookie.match(reg))
  454. return unescape(arr[2]);
  455. else
  456. return null;
  457. };
  458. var maskspringFestival = mui.createMask(function() {
  459. return false;
  460. }); //callback为用户点击蒙版时自动执行的回调;
  461. function setCookie() {
  462. var Days = 30;
  463. var exp = new Date();
  464. exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
  465. document.cookie = "WATERO_WEB_=OK;Path=/;expires=" + exp.toGMTString();
  466. };
  467. /**
  468. * 该方法用于将Undefined转换为空值
  469. * @param val
  470. */
  471. function convertUndefinedToEmpty(val) {
  472. if (undefined == val || null == val||typeof val == undefined || typeof val == 'undefined'|| 'undefined' == val) {
  473. val = "";
  474. }
  475. return val;
  476. }
  477. /**
  478. * 该方法用于将Undefined转换为空值
  479. * @param val
  480. */
  481. function cufte(val) {
  482. return convertUndefinedToEmpty(val);
  483. }
  484. /**
  485. * 空值返回0,其他值返回原值
  486. * @param val
  487. */
  488. function cufteInt(val) {
  489. if(convertUndefinedToEmpty(val) == "")
  490. return 0;
  491. return val;
  492. }
  493. /**
  494. * 空值返回false
  495. * @param val
  496. */
  497. function isEmpty(val) {
  498. if(convertUndefinedToEmpty(val) == "")
  499. return false;
  500. return true;
  501. }