main.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*document.querySelector('body').addEventListener('touchstart', function(e) {
  2. e.preventDefault();
  3. });*/
  4. var domanUrl = "http://" + window.location.host;
  5. var base_path = "/iamberry/wechat";
  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. //首页
  12. url: base_path + '/index', //'index.html',
  13. id: 'index'
  14. });
  15. break;
  16. case 1:
  17. //打开购物车
  18. mui.openWindow({
  19. url: base_path + '/wxCart/goCart',
  20. id: 'shopping_cart',
  21. });
  22. break;
  23. case 2:
  24. //订单列表
  25. mui.openWindow({
  26. url: '/iamberry/pay/goOrderList',
  27. id: 'order_list'
  28. });
  29. break;
  30. case 3:
  31. //会员中心
  32. mui.openWindow({
  33. url: base_path + '/agentWechat/member', //vip_center.html',
  34. id: 'vip_center',
  35. });
  36. break;
  37. default:
  38. break;
  39. }
  40. }, false);
  41. });
  42. mui.ajax(base_path+'/cart/getCartNumByCartOpenId', {
  43. data:{openid:'230'},
  44. dataType: 'json', //服务器返回json格式数据
  45. type: 'post', //HTTP请求类型
  46. timeout: 15000, //超时时间设置为15秒;
  47. success: function(dt) {
  48. //服务器返回响应
  49. //console.log(dt);
  50. if(dt.status){
  51. dt.data=="0"? $('.icon-gouwuche span').hide():$('.icon-gouwuche span').text(dt.data).show();
  52. }else{
  53. }
  54. },
  55. error: function(xhr, type, errorThrown) {
  56. //异常处理;
  57. errorfn(xhr);
  58. }
  59. });
  60. mui('body').on('tap', '.go_index', function() {
  61. //去首页
  62. mui.openWindow({
  63. url: base_path + '/index',
  64. id: 'index',
  65. });
  66. });
  67. mui('body').on('tap', '.go_gwc', function() {
  68. //去购物车
  69. mui.openWindow({
  70. url: base_path + '/wxCart/goCart', //shopping_cart.html
  71. id: 'shopping_cart'
  72. });
  73. });
  74. mui('body').on('tap', '.go_web_shop', function() {
  75. //去产品列表
  76. mui.openWindow({
  77. url: base_path + '/wxCart/goProductList' //chanpin_list.html
  78. });
  79. });
  80. //产品详情
  81. mui('body').on('tap', '.go_chanpin_details', function() {
  82. mui.openWindow({
  83. url: base_path + '/product/desc?productId=' + this.getAttribute("proid") //chanpin_details.html
  84. });
  85. });
  86. //个人全部优惠券列表
  87. mui('body').on('tap', '.go_couponList', function() {
  88. mui.openWindow({
  89. url: base_path + '/couponWechat/couponList' //couponList。html
  90. });
  91. });
  92. //立即购买 结算
  93. mui('body').on('tap', '.go-clearing', function() {
  94. var param = "productId=" + this.getAttribute("proid");
  95. mui.ajax(base_path + '/cart/addProductToCart?' + param, {
  96. dataType: 'json',
  97. type: 'GET',
  98. timeout: 15000,
  99. success: function(dt) {
  100. if (dt.status) {
  101. window.location.href = '/iamberry/pay/settlement?cartId=' + dt.data + "&tiemstamp=" + new Date().getTime();
  102. } else {
  103. mui.alert(dt.message);
  104. }
  105. },
  106. error: function(xhr, type, errorThrown) {
  107. errorfn(xhr);
  108. }
  109. });
  110. });
  111. //加入购物车
  112. mui('body').on('tap', '.go_gwc_pro', function() {
  113. var param = "productId=" + this.getAttribute("proid");
  114. //去购物车
  115. mui.ajax(base_path + '/cart/addProductToCart?' + param, {
  116. dataType: 'json',
  117. type: 'GET',
  118. timeout: 15000,
  119. success: function(dt) {
  120. if (dt.status) {
  121. // mui.alert("添加成功!");
  122. window.location.href = base_path + '/wxCart/goCart';
  123. } else {
  124. mui.alert(dt.message);
  125. }
  126. },
  127. error: function(xhr, type, errorThrown) {
  128. errorfn(xhr);
  129. }
  130. });
  131. });
  132. mui('body').on('tap', '.go_order_details', function() {
  133. //去订单详情
  134. mui.openWindow({
  135. url: '/iamberry/pay/goOrderInfo?orderId=' + this.getAttribute("value") //order_details.html
  136. });
  137. });
  138. //待支付订单
  139. mui('body').on('tap', '.go_pay_count', function() {
  140. mui.openWindow({
  141. url: '/iamberry/pay/goOrderList?salesStatus=1'
  142. });
  143. });
  144. //已支付订单
  145. mui('body').on('tap', '.go_deliver_count', function() {
  146. mui.openWindow({
  147. url: '/iamberry/pay/goOrderList?salesStatus=2'
  148. });
  149. });
  150. //已发货订单
  151. mui('body').on('tap', '.go_delivered_count', function() {
  152. mui.openWindow({
  153. url: '/iamberry/pay/goOrderList?salesStatus=5'
  154. });
  155. });
  156. //全部订单
  157. mui('body').on('tap', '.go_all_count', function() {
  158. mui.openWindow({
  159. url: '/iamberry/pay/goOrderList?salesStatus=-1'
  160. });
  161. });
  162. mui('body').on('tap', '.go_tixian_guize', function() {
  163. //提现规则
  164. mui.openWindow({
  165. url: base_path + '/integralWechat/withdrawRule' //tixian_guize.html'
  166. });
  167. });
  168. //微代理规则
  169. mui('body').on('tap', '.go_agent_rule', function() {
  170. mui.openWindow({
  171. url: base_path + '/agentWechat/agentRule' //'daili_guize.html'
  172. });
  173. });
  174. //冲奶机宣传片
  175. mui('body').on('tap', '.go_publicity', function() {
  176. mui.openWindow({
  177. url: base_path + '/agentWechat/goPublicity?userType=' + this.getAttribute("userType") + "&isDrp=" + this.getAttribute("isDrp")//'iamberry_video.html'
  178. });
  179. });
  180. mui('body').on('tap', '.go_daili_order_list', function() {
  181. //代理订单列表
  182. mui.openWindow({
  183. url: base_path + '/agentWechat/order' //'daili_order_list.html'
  184. });
  185. });
  186. mui('body').on('tap', '.go_daili_rebackOrder_list', function() {
  187. //代理订单列表
  188. mui.openWindow({
  189. url: base_path + '/agentWechat/reback' //'daili_order_list.html'
  190. });
  191. });
  192. mui('body').on('tap', '.go_order_list', function() {
  193. //订单列表
  194. mui.openWindow({
  195. url: '/iamberry/pay/goOrderList' //order_list.html
  196. });
  197. });
  198. mui('body').on('tap', '.go_xiaxian_list', function() {
  199. //我的下线
  200. mui.openWindow({
  201. url: base_path + '/agentWechat/agentNext' //'xiaxian_list.html'
  202. });
  203. });
  204. mui('body').on('tap', '.go_tixian_apply', function() {
  205. //提现申请<积分>
  206. mui.openWindow({
  207. url: base_path + '/withdraw/index' //'tixian_apply.html',
  208. });
  209. });
  210. mui('body').on('tap', '.go_tixian_cash', function() {
  211. //提现申请<现金>
  212. mui.openWindow({
  213. url: base_path + '/withdraw/cash' //'tixian_apply_cash.html'
  214. });
  215. });
  216. mui('body').on('tap', '.go_daili_2wm', function() {
  217. //查看二维码
  218. mui.openWindow({
  219. url: base_path + '/member/showQrcode'//'daili_2wm.html'
  220. });
  221. });
  222. //现金记录
  223. mui('body').on('tap', '.go_cash_log', function() {
  224. mui.openWindow({
  225. url: base_path + '/cashWechat/log' //cash_log.html
  226. });
  227. });
  228. mui('body').on('tap', '.go_jifen_log', function() {
  229. //积分记录
  230. mui.openWindow({
  231. url: base_path + '/integralWechat/log' //jifen_log.html'
  232. });
  233. });
  234. mui('body').on('tap', '.go_jifen_guize', function() {
  235. //积分规则
  236. mui.openWindow({
  237. url: base_path + '/integralWechat/integralRule' //jifen_guize.html'
  238. });
  239. });
  240. //积分提现记录
  241. mui('body').on('tap', '.go_tixian_log', function() {
  242. mui.openWindow({
  243. url: base_path + '/integralWechat/withdrawLog' //tixian_log.html'
  244. });
  245. });
  246. //可用金额提现记录
  247. mui('body').on('tap', '.go_tixian_cash_log', function() {
  248. mui.openWindow({
  249. url: base_path + '/agentWechat/withdrawCashLog' //tixian_apply_cash.html
  250. });
  251. });
  252. //查看物流信息
  253. mui('body').on('tap', '.show_post_info', function() {
  254. var urlStr = document.domain;
  255. mui.openWindow({
  256. url: 'http://m.kuaidi100.com/index_all.html?type=' + this.getAttribute("postFirm") + '&postid=' + this.getAttribute("postNum") + '&callbackurl=http://' + urlStr + this.getAttribute("gourl") + "&tiemstamp=" + new Date().getTime()
  257. });
  258. });
  259. //=====================================分销===========================================
  260. /*mui('body').on('tap', '.go_fenxiao_guize', function() {
  261. //分销的规则
  262. mui.openWindow({
  263. url: '/iamberry/wechat/drp/rulePage' //'fenxiao_guize.html'
  264. });
  265. });*/
  266. mui('body').on('tap', '.go_fenxiao_tixian_apply', function() {
  267. //分销提现申请
  268. mui.openWindow({
  269. url: base_path + '/drp/withdrawalsPage?openid=' //'fenxiao_tixian_apply.html'
  270. });
  271. });
  272. mui('body').on('tap', '.go_fenxiao_tixian_log', function() {
  273. //分销提现记录
  274. mui.openWindow({
  275. url: base_path + '/drp/withdrawalsList' //'fenxiao_tixian_log.html'
  276. });
  277. });
  278. mui('body').on('tap', '.fenxiao_vip', function() {
  279. //分销二维码
  280. mui.openWindow({
  281. url: base_path + '/drp/rulePage' //'fenxiao_2wm.html'
  282. });
  283. });
  284. mui('body').on('tap', '.to-up-img', function() {
  285. //上传图片入口
  286. mui.openWindow({
  287. url: base_path + '/sharePage/upShare?userType=1'//'up.html',
  288. });
  289. });
  290. //商户个人中心 查看个人信息
  291. mui('body').on('tap', '.fenxiao_info', function() {
  292. //上传图片入口
  293. mui.openWindow({
  294. url: base_path + '/drp/placeInfo_detail'//'personal_information.html',
  295. });
  296. });
  297. //===============================大转盘==============================
  298. //进入大转盘页面
  299. mui('body').on('tap', '.go_luck_draw', function() {
  300. mui.openWindow({
  301. url: base_path + '/activity/go_luck_draw?orderId=' + this.getAttribute("value") //zhuanpan.html
  302. });
  303. });
  304. //进入中奖纪录页面
  305. mui('body').on('tap', '.go_prize_log', function() {
  306. mui.openWindow({
  307. url: base_path + '/activity/go_prize_log?gameId=' + this.getAttribute("value") //wheel_log.html
  308. });
  309. });
  310. function errorfn(xhr){
  311. //异常处理;
  312. if(xhr.readyState == 4 && xhr.status == 200){
  313. }else{
  314. var ref=location.href.split("#")[0],src='';
  315. if (ref.indexOf('?') != -1) {
  316. src = ref + "&date=" + new Date().getTime();
  317. } else {
  318. src = ref + "?date=" + new Date().getTime();
  319. }
  320. var r=confirm("页面出错啦!请刷新重试");
  321. if (r==true){
  322. location.href=src;
  323. }
  324. return;
  325. }
  326. }
  327. //判断图片是否真实存在
  328. function CheckImgExists(imgurl) {
  329. var ImgObj = new Image(); //判断图片是否存在
  330. ImgObj.src = imgurl;
  331. //没有图片,则返回-1
  332. if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
  333. return ImgObj;
  334. } else {
  335. return false;
  336. }
  337. }
  338. /**
  339. ** 除法函数,用来得到精确的除法结果
  340. ** 说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
  341. ** 调用:accDiv(arg1,arg2)
  342. ** 返回值:arg1除以arg2的精确结果
  343. **/
  344. function accDiv(arg1, arg2) {
  345. var t1 = 0, t2 = 0, r1, r2;
  346. try {
  347. t1 = arg1.toString().split(".")[1].length;
  348. }
  349. catch (e) {
  350. }
  351. try {
  352. t2 = arg2.toString().split(".")[1].length;
  353. }
  354. catch (e) {
  355. }
  356. with (Math) {
  357. r1 = Number(arg1.toString().replace(".", ""));
  358. r2 = Number(arg2.toString().replace(".", ""));
  359. return (r1 / r2) * pow(10, t2 - t1);
  360. }
  361. }
  362. //给Number类型增加一个div方法,调用起来更加方便。
  363. Number.prototype.div = function (arg) {
  364. return accDiv(this, arg);
  365. };
  366. /**
  367. ** 加法函数,用来得到精确的加法结果
  368. ** 说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
  369. ** 调用:accAdd(arg1,arg2)
  370. ** 返回值:arg1加上arg2的精确结果
  371. **/
  372. function accAdd(arg1, arg2) {
  373. var r1, r2, m, c;
  374. try {
  375. r1 = arg1.toString().split(".")[1].length;
  376. }
  377. catch (e) {
  378. r1 = 0;
  379. }
  380. try {
  381. r2 = arg2.toString().split(".")[1].length;
  382. }
  383. catch (e) {
  384. r2 = 0;
  385. }
  386. c = Math.abs(r1 - r2);
  387. m = Math.pow(10, Math.max(r1, r2));
  388. if (c > 0) {
  389. var cm = Math.pow(10, c);
  390. if (r1 > r2) {
  391. arg1 = Number(arg1.toString().replace(".", ""));
  392. arg2 = Number(arg2.toString().replace(".", "")) * cm;
  393. } else {
  394. arg1 = Number(arg1.toString().replace(".", "")) * cm;
  395. arg2 = Number(arg2.toString().replace(".", ""));
  396. }
  397. } else {
  398. arg1 = Number(arg1.toString().replace(".", ""));
  399. arg2 = Number(arg2.toString().replace(".", ""));
  400. }
  401. return (arg1 + arg2) / m;
  402. }
  403. //给Number类型增加一个add方法,调用起来更加方便。
  404. Number.prototype.add = function (arg) {
  405. return accAdd(arg, this);
  406. };
  407. /**
  408. ** 减法函数,用来得到精确的减法结果
  409. ** 说明:javascript的减法结果会有误差,在两个浮点数相减的时候会比较明显。这个函数返回较为精确的减法结果。
  410. ** 调用:accSub(arg1,arg2)
  411. ** 返回值:arg1加上arg2的精确结果
  412. **/
  413. function accSub(arg1, arg2) {
  414. var r1, r2, m, n;
  415. try {
  416. r1 = arg1.toString().split(".")[1].length;
  417. }
  418. catch (e) {
  419. r1 = 0;
  420. }
  421. try {
  422. r2 = arg2.toString().split(".")[1].length;
  423. }
  424. catch (e) {
  425. r2 = 0;
  426. }
  427. m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
  428. n = (r1 >= r2) ? r1 : r2;
  429. return ((arg1 * m - arg2 * m) / m).toFixed(n);
  430. }
  431. // 给Number类型增加一个mul方法,调用起来更加方便。
  432. Number.prototype.sub = function (arg) {
  433. return accMul(arg, this);
  434. };
  435. /**
  436. ** 乘法函数,用来得到精确的乘法结果
  437. ** 说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
  438. ** 调用:accMul(arg1,arg2)
  439. ** 返回值:arg1乘以 arg2的精确结果
  440. **/
  441. function accMul(arg1, arg2) {
  442. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  443. try {
  444. m += s1.split(".")[1].length;
  445. }
  446. catch (e) {
  447. }
  448. try {
  449. m += s2.split(".")[1].length;
  450. }
  451. catch (e) {
  452. }
  453. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
  454. }
  455. // 给Number类型增加一个mul方法,调用起来更加方便。
  456. Number.prototype.mul = function (arg) {
  457. return accMul(arg, this);
  458. };
  459. function toApplyAgent(){
  460. var flag = false;
  461. var orderid = '';
  462. mui.ajax(base_path + '/agent/checkApply?dates=' + new Date().getTime(),{
  463. dataType:'json',//服务器返回json格式数据
  464. async: false, //同步
  465. type:'post',//HTTP请求类型
  466. timeout:15000,//超时时间设置为15秒;
  467. success:function(dt){
  468. if(dt.status){
  469. flag = true;
  470. if(dt.data != null && typeof(dt.data)!="undefined" && dt.data != ''){
  471. orderid = dt.data;
  472. }
  473. }else{
  474. if(dt.resultCode != 400){
  475. if(dt.resultCode == 600){
  476. window.location.href= base_path + '/agentWechat/member';
  477. }else{
  478. var nowHref = window.location.href;
  479. var strs = new Array();
  480. strs=nowHref.split("?");
  481. var nowHrefStr = '';
  482. if(strs.length > 0){
  483. nowHrefStr = strs[0];
  484. }else{
  485. nowHrefStr = nowHref;
  486. }
  487. if(nowHrefStr == 'http://test.iamberry.com/iamberry/wechat/agentWechat/agentRule'){
  488. //if(nowHrefStr == 'http://localhost:8080/iamberry/wechat/agentWechat/agentRule'){
  489. mui.alert(dt.message);
  490. }else{
  491. window.location.href= base_path + "/agentWechat/agentRule";
  492. }
  493. }
  494. }else{
  495. mui.alert(dt.message,' ','确定');
  496. }
  497. }
  498. },
  499. error:function(xhr,type,errorThrown){
  500. //异常处理;
  501. errorfn(xhr);
  502. }
  503. });
  504. var btnArray = ['否', '是'];
  505. if(orderid != ''){
  506. mui.confirm('若继续强制申请,则单号为:'+orderid+'的订单将不允许退/换货', ' ', btnArray, function(e) {
  507. if (e.index == 1) {
  508. createApply(orderid);
  509. }
  510. });
  511. }else{
  512. if(flag){
  513. createApply(orderid);
  514. }
  515. }
  516. }
  517. function switchcolor(color){
  518. var pro_color="";
  519. switch (color) {
  520. case 1:pro_color = "蓝色";break;
  521. case 2:pro_color = "粉色";break;
  522. case 3:pro_color = "银色";break;
  523. case 4:pro_color = "香槟金";break;
  524. case 5:pro_color = "苹果绿";break;
  525. case 6:pro_color = "西瓜红";break;
  526. case 7:pro_color = "品蓝";break;
  527. case 8:pro_color = "品黑";break;
  528. default:pro_color = "香槟金";break;
  529. }
  530. return pro_color;
  531. }
  532. //获取地址栏url参数
  533. function getParam(paramName) {
  534. paramValue = "", isFound = !1;
  535. if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
  536. arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
  537. while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
  538. }
  539. return paramValue == "" && (paramValue = null), paramValue
  540. }
  541. //封装document.getElementById
  542. function dc(objectid) {
  543. if(document.getElementById && document.getElementById(objectid)) {
  544. return document.getElementById(objectid);// w3c dom
  545. } else if (document.all && document.all(objectid)) {
  546. return document.all(objectid);// msie 4 dom
  547. } else if (document.layers && document.layers[objectid]) {
  548. return document.layers[objectid];// nn 4 dom.. note: this won't find nested layers
  549. } else {
  550. return false;
  551. }
  552. }
  553. function formatDate(now) {
  554. now = new Date(now);
  555. var year=now.getFullYear();
  556. var month=now.getMonth()+1;
  557. var date=now.getDate();
  558. var hour=now.getHours();
  559. var minute=now.getMinutes();
  560. var second=now.getSeconds();
  561. return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
  562. }
  563. var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1260421959'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s4.cnzz.com/z_stat.php%3Fid%3D1260421959%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));