main.js 17 KB

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