main.js.bak 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. var domanUrl = "//" + window.location.host,
  2. // path="//test.iamberry.com",
  3. path="//w.iamberry.com",
  4. base_path= path +"/watero/wechat",
  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_couponList', function() {
  87. mui.openWindow({
  88. url: base_path + '/couponWechat/couponList'
  89. })
  90. });
  91. mui('body').on('tap', '.go-clearing', function() {
  92. var th=this;
  93. $.ajax(base_path + '/cart/addProductToCart', {
  94. data: {"productId":th.getAttribute("proid"),"colorId":th.getAttribute("colorid")},
  95. dataType: 'json',
  96. type: 'GET',
  97. timeout: 15000,
  98. xhrFields: {
  99. withCredentials: true
  100. },
  101. crossDomain: true,
  102. success: function(dt) {
  103. if (dt.isRedirect) {
  104. location.href = dt.redirectURL;
  105. } else {
  106. if(dt.status) {
  107. mui.openWindow({
  108. url: 'clearing.html?cartId=' + dt.data + "&tiemstamp=" + new Date().getTime()
  109. })
  110. } else {
  111. mui.alert(dt.message)
  112. }
  113. }
  114. },
  115. error: function(xhr, type, errorThrown) {
  116. console.log(xhr)
  117. }
  118. })
  119. });
  120. mui('body').on('tap', '.go_gwc_pro', function() {
  121. var th=this;
  122. $.ajax(base_path + '/cart/addProductToCart', {
  123. data: {"productId":th.getAttribute("proid"),"colorId":th.getAttribute("colorid")},
  124. dataType: 'json',
  125. type: 'GET',
  126. timeout: 15000,
  127. xhrFields: {
  128. withCredentials: true
  129. },
  130. crossDomain: true,
  131. success: function(dt) {
  132. if (dt.isRedirect) {
  133. location.href = dt.redirectURL;
  134. } else {
  135. if(dt.status) {
  136. getCartNum()
  137. } else {
  138. mui.alert(dt.message)
  139. }
  140. }
  141. },
  142. error: function(xhr, type, errorThrown) {
  143. errorfn(xhr)
  144. }
  145. })
  146. });
  147. function marquee_Show() {
  148. // mui.ajax(base_path + '/coupon/checkCurrentPreferential?dates='+ new Date().getTime(), {
  149. // dataType: 'json',
  150. // type: 'POST',
  151. // async: false,
  152. // timeout: 15000,
  153. // success: function(dt) {
  154. //// if(dt.status) {
  155. //// marquee = '<span class="mui-h6">专属优惠:</span>'
  156. //// } else {
  157. // marquee = ''
  158. //// }
  159. // },
  160. // error: function(xhr, type, errorThrown) {
  161. // console.log(xhr)
  162. // }
  163. // })
  164. };
  165. mui('body').on('tap', '.go_order_details', function() {
  166. if(this.getAttribute('isSpell')!=null){
  167. location.href='order_details.html?orderId=' + this.getAttribute("value")+'&isSpell='+this.getAttribute('isSpell');
  168. }else{
  169. location.href='order_details.html?orderId=' + this.getAttribute("value")
  170. }
  171. });
  172. mui('body').on('tap', '.go_pay_count', function() {
  173. mui.openWindow({
  174. url: 'order_list.html?salesStatus=1'
  175. })
  176. });
  177. mui('body').on('tap', '.go_pay_ping', function() {
  178. mui.openWindow({
  179. url: 'order_list.html?salesStatus=15'
  180. })
  181. });
  182. mui('body').on('tap', '.go_deliver_count', function() {
  183. mui.openWindow({
  184. url: 'order_list.html?salesStatus=2'
  185. })
  186. });
  187. mui('body').on('tap', '.go_delivered_count', function() {
  188. mui.openWindow({
  189. url: 'order_list.html?salesStatus=5'
  190. })
  191. });
  192. mui('body').on('tap', '.go_all_count', function() {
  193. mui.openWindow({
  194. url: 'order_list.html?salesStatus=-1'
  195. })
  196. });
  197. mui('body').on('tap', '.go_publicity', function() {
  198. mui.openWindow({
  199. url: base_path + '/agentWechat/goPublicity?userType=' + this.getAttribute("userType") + "&isDrp=" + this.getAttribute("isDrp")
  200. })
  201. });
  202. mui('body').on('tap', '.go_order_list', function() {
  203. mui.openWindow({
  204. url: 'order_list.html'
  205. })
  206. });
  207. function errorfn(xhr) {
  208. if(xhr.readyState == 4 && xhr.status == 200) {} else {
  209. var ref = location.href.split("#")[0],
  210. src = '';
  211. if(ref.indexOf('?') != -1) {
  212. src = ref + "&date=" + new Date().getTime()
  213. } else {
  214. src = ref + "?date=" + new Date().getTime()
  215. }
  216. location.href = src;
  217. return
  218. }
  219. }
  220. function CheckImgExists(imgurl) {
  221. var ImgObj = new Image();
  222. ImgObj.src = imgurl;
  223. if(ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
  224. return ImgObj
  225. } else {
  226. return false
  227. }
  228. };
  229. function gotoTop(acceleration, stime) {
  230. acceleration = acceleration || 0.1;
  231. stime = stime || 10;
  232. var x1 = 0,
  233. y1 = 0,
  234. x2 = 0,
  235. y2 = 0,
  236. x3 = 0,
  237. y3 = 0;
  238. if(document.documentElement) {
  239. x1 = document.documentElement.scrollLeft || 0;
  240. y1 = document.documentElement.scrollTop || 0
  241. }
  242. if(document.body) {
  243. x2 = document.body.scrollLeft || 0;
  244. y2 = document.body.scrollTop || 0
  245. }
  246. var x3 = window.scrollX || 0;
  247. var y3 = window.scrollY || 0;
  248. var x = Math.max(x1, Math.max(x2, x3));
  249. var y = Math.max(y1, Math.max(y2, y3));
  250. var speeding = 1 + acceleration;
  251. window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
  252. if(x > 0 || y > 0) {
  253. var run = "gotoTop(" + acceleration + ", " + stime + ")";
  254. window.setTimeout(run, stime)
  255. }
  256. };
  257. function accDiv(arg1, arg2) {
  258. var t1 = 0,
  259. t2 = 0,
  260. r1, r2;
  261. try {
  262. t1 = arg1.toString().split(".")[1].length
  263. } catch(e) {}
  264. try {
  265. t2 = arg2.toString().split(".")[1].length
  266. } catch(e) {}
  267. with(Math) {
  268. r1 = Number(arg1.toString().replace(".", ""));
  269. r2 = Number(arg2.toString().replace(".", ""));
  270. return(r1 / r2) * pow(10, t2 - t1)
  271. }
  272. };
  273. Number.prototype.div = function(arg) {
  274. return accDiv(this, arg)
  275. };
  276. function accAdd(arg1, arg2) {
  277. var r1, r2, m, c;
  278. try {
  279. r1 = arg1.toString().split(".")[1].length
  280. } catch(e) {
  281. r1 = 0
  282. }
  283. try {
  284. r2 = arg2.toString().split(".")[1].length
  285. } catch(e) {
  286. r2 = 0
  287. }
  288. c = Math.abs(r1 - r2);
  289. m = Math.pow(10, Math.max(r1, r2));
  290. if(c > 0) {
  291. var cm = Math.pow(10, c);
  292. if(r1 > r2) {
  293. arg1 = Number(arg1.toString().replace(".", ""));
  294. arg2 = Number(arg2.toString().replace(".", "")) * cm
  295. } else {
  296. arg1 = Number(arg1.toString().replace(".", "")) * cm;
  297. arg2 = Number(arg2.toString().replace(".", ""))
  298. }
  299. } else {
  300. arg1 = Number(arg1.toString().replace(".", ""));
  301. arg2 = Number(arg2.toString().replace(".", ""))
  302. }
  303. return(arg1 + arg2) / m
  304. };
  305. Number.prototype.add = function(arg) {
  306. return accAdd(arg, this)
  307. };
  308. function accSub(arg1, arg2) {
  309. var r1, r2, m, n;
  310. try {
  311. r1 = arg1.toString().split(".")[1].length
  312. } catch(e) {
  313. r1 = 0
  314. }
  315. try {
  316. r2 = arg2.toString().split(".")[1].length
  317. } catch(e) {
  318. r2 = 0
  319. }
  320. m = Math.pow(10, Math.max(r1, r2));
  321. n = (r1 >= r2) ? r1 : r2;
  322. return((arg1 * m - arg2 * m) / m).toFixed(n)
  323. };
  324. Number.prototype.sub = function(arg) {
  325. return accMul(arg, this)
  326. };
  327. function accMul(arg1, arg2) {
  328. var m = 0,
  329. s1 = arg1.toString(),
  330. s2 = arg2.toString();
  331. try {
  332. m += s1.split(".")[1].length
  333. } catch(e) {}
  334. try {
  335. m += s2.split(".")[1].length
  336. } catch(e) {}
  337. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  338. };
  339. Number.prototype.mul = function(arg) {
  340. return accMul(arg, this)
  341. };
  342. function switchcolor(color) {
  343. var pro_color = "";
  344. switch(color) {
  345. case 1:
  346. pro_color = "品蓝";
  347. break;
  348. case 2:
  349. pro_color = "品黑";
  350. break;
  351. case 3:
  352. pro_color = "苹果绿";
  353. break;
  354. case 4:
  355. pro_color = "西瓜红";
  356. break;
  357. case 5:
  358. pro_color = "白色";
  359. break;
  360. case 36:
  361. pro_color = "银色";
  362. break;
  363. case 37:
  364. pro_color = "磨砂";
  365. break;
  366. case 39:
  367. pro_color = "无色透明";
  368. break;
  369. case 40:
  370. pro_color = "茉莉白";
  371. break;
  372. default:
  373. pro_color = "品蓝";
  374. break
  375. }
  376. return pro_color
  377. };
  378. function switchColorImg(colorId){
  379. var img='';
  380. switch (colorId){
  381. case 1:
  382. img='//s.iamberry.com/watero/images/shop/cp-blue.png'
  383. break;
  384. case 2:
  385. img='//s.iamberry.com/watero/images/shop/cp-black.png'
  386. break;
  387. case 3:
  388. img='//s.iamberry.com/watero/images/shop/cp-green.png'
  389. break;
  390. case 4:
  391. img='//s.iamberry.com/watero/images/shop/cp-red.png'
  392. break;
  393. case 39:
  394. img='//s.iamberry.com/watero/wechat/images/971ECE348D1F7D9F8628_20171212154024_8556.jpg'
  395. break;
  396. case 40:
  397. img='//s.iamberry.com/watero/images/product/WaterO_positive.png'
  398. break;
  399. default:
  400. img='//s.iamberry.com/watero/images/shop/cp-blue.png'
  401. break;
  402. }
  403. return img;
  404. };
  405. function getParam(paramName) {
  406. paramValue = "", isFound = !1;
  407. if(this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
  408. arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
  409. while(i < arrSource.length && !isFound) {
  410. arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
  411. }
  412. }
  413. return paramValue == "" && (paramValue = null), paramValue
  414. };
  415. function dc(objectid) {
  416. if(document.getElementById && document.getElementById(objectid)) {
  417. return document.getElementById(objectid)
  418. } else if(document.all && document.all(objectid)) {
  419. return document.all(objectid)
  420. } else if(document.layers && document.layers[objectid]) {
  421. return document.layers[objectid]
  422. } else {
  423. return false
  424. }
  425. };
  426. function formatDate(now) {
  427. now = new Date(now);
  428. var year = now.getFullYear();
  429. var month = now.getMonth() + 1;
  430. var date = now.getDate();
  431. var hour = now.getHours();
  432. var minute = now.getMinutes();
  433. var second = now.getSeconds();
  434. return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second
  435. };
  436. function springFestivalPop() {
  437. if(getCookie("WATERO_WEB_") == null) {
  438. maskspringFestival.show();
  439. $(".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>');
  440. mui('body').on('tap', '#close-springFestival', function(e) {
  441. setCookie();
  442. $(".mui-backdrop").hide();
  443. });
  444. }
  445. };
  446. function getCookie(name) {
  447. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  448. if(arr = document.cookie.match(reg))
  449. return unescape(arr[2]);
  450. else
  451. return null;
  452. };
  453. var maskspringFestival = mui.createMask(function() {
  454. return false;
  455. }); //callback为用户点击蒙版时自动执行的回调;
  456. function setCookie() {
  457. var Days = 30;
  458. var exp = new Date();
  459. exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
  460. document.cookie = "WATERO_WEB_=OK;Path=/;expires=" + exp.toGMTString();
  461. };