main.js 16 KB

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