main.js 16 KB

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