main.js 16 KB

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