clearing.html 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  8. <title>结算</title>
  9. <link rel="stylesheet" type="text/css" href="css/mui.min.css" />
  10. <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  11. <link rel="stylesheet" type="text/css" href="css/main.css" />
  12. <style>
  13. input[type="checkbox"] {
  14. /*pointer-events: none;*/
  15. }
  16. .mui-switch {
  17. background: #bbb;
  18. height: 20px;
  19. border: 1px solid #bbb;
  20. padding: 0 5px;
  21. }
  22. .mui-switch:before {
  23. content: '';
  24. }
  25. .mui-switch.mui-active:before {
  26. content: '';
  27. }
  28. .mui-switch .mui-switch-handle {
  29. top: -6px;
  30. width: 30px;
  31. height: 30px;
  32. margin-left: 2px;
  33. }
  34. .clearing-box .mui-table-view-cell.mui-active,
  35. .mui-navigate-right.mui-active {
  36. background: #fff !important;
  37. }
  38. .mui-switch.mui-active {
  39. background: #79b3f3;
  40. border-color: #79b3f3;
  41. }
  42. .clearing-box .mui-table-view-cell {
  43. border-bottom: 8px solid #f2f2f2;
  44. }
  45. .clearing-box .mui-table-view-cell:after,
  46. .my-view-no-top:after {
  47. left: 0;
  48. display: none;
  49. }
  50. .shopping-cart-list {
  51. border-bottom: 8px solid #f2f2f2;
  52. }
  53. .clearing-box {
  54. margin: 0;
  55. padding-bottom: 0;
  56. }
  57. .icon-dingwei {
  58. font-size: 22px;
  59. color: #e06974;
  60. }
  61. .my-view-no-top .mui-navigate-right:after{
  62. right: 7px;
  63. }
  64. </style>
  65. <script type="text/javascript">
  66. // 屏蔽分享
  67. window.hiddenAllWechatMenu = true;
  68. </script>
  69. </head>
  70. <body style="background: #f2f2f2;">
  71. <div class="loading-bg">
  72. <div class="mui-loading">
  73. <div class="mui-spinner">
  74. </div>
  75. &nbsp;&nbsp;加载中...
  76. </div>
  77. </div>
  78. <div class="mui-content">
  79. <div style="padding:0 14px 0 14px;background-color: #fff;text-align: center;border-bottom:8px solid #f2f2f2;">
  80. <ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed">
  81. <li class="mui-table-view-cell" style="background-color: #fff;border-radius: 5px;padding: 11px 8px;">
  82. <div class="mui-table" id="user-address-div" style="height: 80px;">
  83. <div class="mui-table-cell mui-col-xs-12 table-middle" style="display: table-cell;">
  84. <div class="btn-add-address"><span class="iconfont icon-jia"></span>添加收货地址</div>
  85. </div>
  86. <!--<div class="mui-table-cell mui-col-xs-1 mui-text-left table-middle">
  87. <p><span class="iconfont icon-dingwei"></span></p>
  88. </div>
  89. <div class="mui-table-cell mui-col-xs-10 mui-text-left table-middle">
  90. <div>收货人:林笑笑 <span class="mui-pull-right">16899996678</span></div>
  91. <p>收货地址:广东省深圳市福田区莲花街道深圳特区 报业大厦12b</p>
  92. </div>
  93. <div class="mui-table-cell mui-col-xs-1 mui-text-right table-middle">
  94. <p><span class="mui-icon mui-icon-arrowright"></span></p>
  95. </div>-->
  96. </div>
  97. </li>
  98. </ul>
  99. </div>
  100. <ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed shopping-cart-list">
  101. </ul>
  102. <div class="clearing-box">
  103. <ul class="mui-table-view my-view-no-top">
  104. <li class="mui-table-view-cell" id="ul-youhuiquan" style="display: none;">
  105. <a class="mui-navigate-right btn-youhuiquan">
  106. 优惠券<span class="mui-pull-right cl-red" style="margin-right: 10px;display: none;">-¥0.0</span>
  107. </a>
  108. </li>
  109. <li class="mui-table-view-cell show_integral">
  110. 可用积分 <span style="margin-left: 10px;" class="integral_num">0</span>,抵扣¥<span class="integral_money">0</span>
  111. <!-- 开关打开状态,多了一个.mui-active类 -->
  112. <div class="mui-switch mui-switch-mini mui-active" id="mySwitch">
  113. <div class="mui-switch-handle"></div>
  114. </div>
  115. </li>
  116. <li class="mui-table-view-cell show_vip_zengsong" style="display: none;">
  117. 会员首次购买单支滤芯产品赠送同款滤芯
  118. </li>
  119. <li class="mui-table-view-cell show_vip_youhui" style="display: none;">
  120. 会员购买滤芯产品享88折优惠,购买其他产品享95折优惠
  121. </li>
  122. <li class="mui-table-view-cell" style="margin-bottom: 60px;">
  123. <div class="mui-input-row">
  124. <label style="width:20%;padding:13px 0;">订单备注</label>
  125. <input style="width: 79%;font-size: 12px;" maxlength="140" id="textarea" type="text" placeholder="您对订单有特殊要求,可以在此备注" />
  126. </div>
  127. <!--<textarea id="textarea" maxlength="140" rows="1" placeholder="您对订单有特殊要求,可以在此备注" style="background-color: #f9f9f9;border: 0;margin:14px 0 0 0;padding: 15px;font-size: 14px;"></textarea>-->
  128. <p id="tips" style="text-align: right"></p>
  129. </li>
  130. </ul>
  131. <!-- <div style="padding:14px 14px 50px 14px;font-size: 12px;color: #999;background: #f2f2f2;">由于购买人数较多,下单后,订单将会按下单顺序依次发货,敬请谅解</div> -->
  132. </div>
  133. <div class="buy-footer1">
  134. <table class="tb-clearing">
  135. <tr>
  136. <td class="quanxuan">
  137. 共<span class="cl-red"><span id="pro-count">0</span>件</span>商品
  138. </td>
  139. <td class="mui-text-center">合计:<span class="count_price_box">¥<span class="count_price">0.00</span></span>元</td>
  140. <td>
  141. <a id="go-pay" class="mui-btn mui-pull-right add_gwc">立即支付</a>
  142. </td>
  143. </tr>
  144. </table>
  145. </div>
  146. </div>
  147. <script src="js/mui.min.js"></script>
  148. <script src="js/jquery-2.1.1.min.js"></script>
  149. <script src="js/main.js"></script>
  150. <script src="js/wechat-utils-1.0.js"></script>
  151. <script>
  152. var userIntegral = 0; // 用户可用积分
  153. var meonyProportion = 0; // 兑换比例:1个积分=?分钱
  154. var payTotal = 0.0; // 支付总金额
  155. var userInputIntegral = 0; // 抵扣积分
  156. var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
  157. var cartIdStr = ""; // 购物车ID
  158. var usePayMoney = 0;
  159. var ipt_balance = 0;
  160. var yhq_val = 0;
  161. var used_balance = 0;
  162. var yhq_type = 1;
  163. var yhq_id = '';
  164. var userIntegralUsed = 1; // 是否使用积分 1:使用 2:不使用
  165. var userIsVip = 1; // 是否为vip :1:非vip 2:vip
  166. var useCouponPrizeColorId = 0; //
  167. mui.ready(function() {
  168. var parameter = {}; //ajax参数json集合
  169. var cartidList = '';
  170. if(!window.sessionStorage) {
  171. mui.alert("您的浏览器不支持sessionStorage");
  172. } else {
  173. //读取上一个页面带过来的sessionStorage
  174. pay_data = JSON.parse(sessionStorage.getItem('pay_data'));
  175. if(pay_data != null) {
  176. cartidList = pay_data.text[0]; //购物项id集合
  177. parameter["cartIds"] = cartidList;
  178. $.ajax(base_path + '/wechat/order/payBefore', {
  179. data: parameter,
  180. dataType: 'json',
  181. type: 'POST',
  182. xhrFields: {
  183. withCredentials: true
  184. },
  185. crossDomain: true,
  186. timeout: 15000,
  187. success: function(dt) {
  188. if(dt.isRedirect) {
  189. location.href = dt.redirectURL;
  190. } else {
  191. console.log(dt);
  192. if(dt.status == true) {
  193. // 购物项遍历
  194. console.log(dt)
  195. var liNote = "";
  196. var yhq_str = "";
  197. payTotal = dt.data.payTotal; // 支付金额,单位分
  198. var hasPrize = false; //判断订单项中是否含有滤芯
  199. var hasKqjhq = false; //判断订单项中是否含有空气净化器
  200. mui.each(dt.data.cartItems, function(index) {
  201. var num = this.cartNum;
  202. var total = (num * this.productDiscount / 100).toFixed(2); //购物车小计,单位分,保留两位小数
  203. var productId = this.cartProductId;
  204. var zeng = '';
  205. if(typeof(this.salesUserGiftList) != "undefined") {
  206. $.each(this.salesUserGiftList, function() {
  207. zeng += this.giftName + '*' + (num * this.userGiftCount) + '件 '
  208. });
  209. }
  210. if(zeng != '') {
  211. zeng = '<p style="font-size:12px;">(赠品:' + zeng + ')</p>';
  212. }
  213. if(this.colorType == 3){
  214. hasPrize = true;
  215. }
  216. if(this.cartColorId == 58){
  217. hasKqjhq = true;
  218. }
  219. liNote += '<li class="mui-table-view-cell" colorId="'+ this.cartColorId +'" colorType="'+ this.colorType +'" productDiscount="'+ this.productDiscount +'" num="'+ this.cartNum +'"><div class="mui-table"><div class="mui-table-cell mui-col-xs-4"><img class="mui-media-object wh-100" src="' + this.productIntroduceImg + '"></div><div class="mui-table-cell table-middle mui-col-xs-8" style="line-height:2.5"><div class="li_product">' + this.productName + '</div><h6><span class="center" style="line-height: 15px;">颜色:' + this.productColor + '</span></br><span class="center color_num" style="line-height: 15px;">数量:' + num + '</span></h6><div>单价 ¥<span class="li_discount">' + (this.productDiscount / 100).toFixed(2) + '</span></div></div></div><div>' + zeng + '</div></li>';
  220. });
  221. var selectcounpon = false;
  222. if(dt.data.couponItems.length > 0) {
  223. $("#ul-youhuiquan").show();
  224. //console.log("有优惠券" + dt.data.couponItems.length + "张")
  225. var str = '';
  226. mui.each(dt.data.couponItems, function(index) {
  227. var opacity = 1,
  228. checked = 'checked',
  229. disabled = '';
  230. if(selectcounpon){
  231. checked = ''
  232. }
  233. if(payTotal < this.couponConsumeEnough && this.couponId != 40001) {
  234. checked = '';
  235. disabled = 'disabled="disabled"';
  236. }
  237. var couponReduce = this.couponName;
  238. var valCouponReduce = (this.couponReduce / 100).toFixed(2)
  239. switch (this.couponId){
  240. case 40001:
  241. if(!hasPrize){
  242. disabled = 'disabled="disabled"'
  243. checked = '';
  244. }
  245. break;
  246. case 50001:
  247. case 50000:
  248. if(!hasKqjhq){
  249. disabled = 'disabled="disabled"'
  250. checked = '';
  251. }
  252. break
  253. default:
  254. break
  255. }
  256. if(checked!=''){
  257. selectcounpon = true;
  258. }
  259. if(isEmpty(disabled)){
  260. opacity = 0.5
  261. }
  262. str += '<li class="my-table-view-cell" style="opacity:' + opacity + '" ><div class="mui-table"><div class="mui-table-cell table-middle mui-col-xs-11">' + couponReduce + '<h6>有效期至:' + this.couponUseEndDate + '</h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="checkbox" val="' + valCouponReduce + '" type="checkbox" ' + checked + ' ' + disabled + ' class="mui-pull-left" id="' + this.couponItemId + '" couponId="'+ this.couponId +'" coupontype="'+ this.couponType+'" couponname="'+ this.couponName+'" /></div></div></li>';
  263. });
  264. str += '<li class="my-table-view-cell" ><div class="mui-table"><div class="mui-table-cell table-middle mui-col-xs-11">暂不使用</h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="checkbox" val="" type="checkbox" class="mui-pull-left" id=""/></div></div></li>';
  265. $("body").append('<div class="my-picker"><ul class="mui-table-view mui-table-view-striped mui-table-view-condensed my-grid-view-no" style="padding: 20px 0 30px 0;overflow: scroll;max-height: 400px;">' + str + '</ul><button class="mui-btn my-btn-block my-btn-buy-know">确认</button></div>');
  266. }
  267. var $productListUl = $(".shopping-cart-list");
  268. $productListUl.empty();
  269. $productListUl.append(liNote);
  270. // 保存数据
  271. cartIdStr = dt.data.cartId; // 购物车ID
  272. userIsVip = dt.data.userIsVip;
  273. userIntegral = dt.data.userIntegral; // 用户可用积分
  274. //计算积分能换算的钱
  275. var myUserIntegral = 0;
  276. if(dt.data.userIsVip == 2 && dt.data.userIntegral >= 10){
  277. $('.show_integral').show();
  278. //积分赋值
  279. $('.integral_num').text(dt.data.userIntegral);
  280. var myUserIntegral = dt.data.userIntegral;
  281. myUserIntegral = parseInt(accDiv(myUserIntegral, 10));
  282. userIntegralUsedNumber = myUserIntegral
  283. $('.integral_money').text(myUserIntegral)
  284. }else{
  285. $('.show_integral').hide();
  286. userIntegralUsed = 2;
  287. }
  288. if(dt.data.hasPreFerential){
  289. $('.show_vip_zengsong').show();
  290. }
  291. //默认自己拉出地址
  292. if(dt.data.addressInfo != undefined && dt.data.addressInfo != null) {
  293. $(".btn-add-address").parent().hide();
  294. $("#user-address-div").append('<div class="mui-table-cell mui-col-xs-1 mui-text-left table-middle addr"><p><span class="iconfont icon-dingwei"></span></p></div><div class="mui-table-cell mui-col-xs-10 mui-text-left table-middle addr"><div>收货人:' + dt.data.addressInfo.salesAddressName + ' <span class="" style="padding-left: 10px;" >' + dt.data.addressInfo.salesAddressTel + '</span></div><p>收货地址:' + dt.data.addressInfo.salesAddressInfo + '</p></div><div class="mui-table-cell mui-col-xs-1 mui-text-right table-middle addr"><p><span class="mui-icon mui-icon-arrowright"></span></p></div>');
  295. //给微信参数赋值
  296. wechatAddr.status = true;
  297. wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo;
  298. wechatAddr.userName = dt.data.addressInfo.salesAddressName;
  299. wechatAddr.userTel = dt.data.addressInfo.salesAddressTel;
  300. wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum;
  301. }
  302. $("#pro-count").text(dt.data.cartItems.length);
  303. setMoney();
  304. } else {
  305. mui.alert(dt.message, function() {
  306. location.href = "shopping-cart.html?dates=" + new Date().getTime(); // 前往购物车
  307. });
  308. }
  309. }
  310. },
  311. error: function(xhr, type, errorThrown) {
  312. console.log(xhr);
  313. mui.alert("获取数据失败,网络错误!")
  314. }
  315. });
  316. } else {
  317. mui.alert("sessionStorage异常!", function() {
  318. location.href = "index.html";
  319. })
  320. }
  321. }
  322. document.querySelector('.loading-bg').style.display = 'none';
  323. });
  324. //callback为用户点击蒙版时自动执行的回调;
  325. var mask = mui.createMask(function() {
  326. $(".my-picker").removeClass("active");
  327. });
  328. //点击弹出优惠券列表
  329. $(document).on('tap', '.btn-youhuiquan', function() {
  330. mask.show();
  331. $(".my-picker").addClass("active");
  332. });
  333. //选择优惠券
  334. $(document).on('click', '.my-picker input[name=checkbox]', function() {
  335. var th = $(this);
  336. if(th.prop("checked")) {
  337. // th.parent().parent().parent().siblings().css("opacity", .5).find("input").prop("checked", false);
  338. // th.parent().parent().parent().css("opacity", 1);
  339. th.parent().parent().parent().siblings().find("input").prop("checked", false);
  340. $('.my-btn-buy-know').removeAttr("disabled");
  341. } else {
  342. th.parent().parent().parent().css("opacity", .5);
  343. $('.my-btn-buy-know').attr("disabled", "disabled");
  344. }
  345. });
  346. //确认使用优惠券
  347. $(document).on('tap', '.my-btn-buy-know', function() {
  348. console.log("确认使用");
  349. yhq_id = $("input[name=checkbox]:checked").attr('id');
  350. // var cout = 0;
  351. // if(typeof(yhq_id) != "undefined") {
  352. // if(!isEmpty(yhq_id)){
  353. // $(".btn-youhuiquan>span").text("").show();
  354. // }else{
  355. // $(".btn-youhuiquan>span").text("-¥" + $("input[name=checkbox]:checked").attr("val")).show();
  356. // }
  357. // cout = $("input[name=checkbox]:checked").attr("val");
  358. // }
  359. $(".my-picker").removeClass("active");
  360. $(".mui-backdrop").css("opacity", 0).remove();
  361. setMoney();
  362. // var count_price = payTotal - cout * 100;
  363. // if(count_price <= 0) {
  364. // count_price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
  365. // }
  366. // $(".count_price").text((count_price / 100).toFixed(2));
  367. });
  368. // 获取微信共享地址
  369. $(document).on('tap', '#user-address-div', function() {
  370. editAddrV1(
  371. function(res) {
  372. // 用户成功拉出地址
  373. var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo;
  374. wechatAddr.status = true;
  375. wechatAddr.detailInfo = address;
  376. wechatAddr.postalCode = res.postalCode;
  377. wechatAddr.userName = res.userName;
  378. wechatAddr.userTel = res.telNumber;
  379. wechatAddr.nationalCode = res.nationalCode;
  380. $("#user-address-div .addr").remove();
  381. $(".btn-add-address").parent().hide();
  382. $("#user-address-div").append('<div class="mui-table-cell mui-col-xs-1 mui-text-left table-middle addr"><p><span class="iconfont icon-dingwei"></span></p></div><div class="mui-table-cell mui-col-xs-10 mui-text-left table-middle addr"><div>收货人:' + wechatAddr.userName + ' <span class="" style="padding-left: 10px;">' + wechatAddr.userTel + '</span></div><p>收货地址:' + wechatAddr.detailInfo + '</p></div><div class="mui-table-cell mui-col-xs-1 mui-text-right table-middle addr"><p><span class="mui-icon mui-icon-arrowright"></span></p></div>');
  383. },
  384. function() {
  385. if($('#user-address-div .addr').html() != null && $('#user-address-div .addr').html() != '') {
  386. wechatAddr.status = true;
  387. } else {
  388. wechatAddr.status = false;
  389. // 用户取消拉出地址
  390. mui.alert("您没有选择收货地址!");
  391. }
  392. }
  393. );
  394. });
  395. // 去支付
  396. $(document).on('tap', '#go-pay', function() {
  397. var couponTypeId = $("input[name=checkbox]:checked").attr('couponid');
  398. if(!isEmpty(couponTypeId)){
  399. couponTypeId = '';
  400. useCouponPrizeColorId = 0;
  401. }else{
  402. couponTypeId = parseInt(couponTypeId);
  403. }
  404. var remark = $("#textarea").val();
  405. var ch_en_num = /^[A-Za-z0-9 _\[\]\【\】\{\}\{\}\(\)\(\)\《\》\<\>\,\,\.\。\、\!\!\~\·\@\#\¥\$\%\^\…\&\—\:\:\;\;\‘\’\'\'\"\"\“\”\?\?\-\=\|\*\+\-\u4e00-\u9fa5]{0,100}$/;
  406. if(ch_en_num.test(remark)) {
  407. console.log("备注验证通过")
  408. } else {
  409. mui.alert("备注格式错误!仅支持中/英文,数字,普通符号");
  410. return false;
  411. }
  412. if(wechatAddr.status) {
  413. if(isPay) {
  414. var orderIntegralNum = 0;
  415. if(userIntegralUsed == 1){
  416. orderIntegralNum = $('.integral_money').text();
  417. orderIntegralNum = accMul(orderIntegralNum,10)
  418. }
  419. isPay = false; // 锁定请求按钮
  420. /* 组装数据 */
  421. var dataArgs = {
  422. "orderAddressInfo": wechatAddr.detailInfo,
  423. "orderAddressPostNum": wechatAddr.postalCode,
  424. "orderAddressMoblie": wechatAddr.userTel,
  425. "orderAddressName": wechatAddr.userName,
  426. "cartIdStr": cartIdStr,
  427. "orderIntegralNum": orderIntegralNum,
  428. "orderUserRemark": remark,
  429. "couponId": yhq_id,
  430. "useCouponPrizeColorId": useCouponPrizeColorId,
  431. "couponTypeId": couponTypeId,
  432. "balancePayAmount": 0
  433. };
  434. $.ajax(base_path + '/wechat/order/pay', { // 提交订单,准备支付
  435. data: dataArgs,
  436. dataType: 'json',
  437. type: 'POST',
  438. xhrFields: {
  439. withCredentials: true
  440. },
  441. crossDomain: true,
  442. timeout: 15000,
  443. success: function(dt) {
  444. // layer.closeAll();
  445. //mui.alert(dt.resultCode=="500");
  446. if(dt.resultCode == "500") {
  447. mui.alert(dt.message);
  448. isPay = true;
  449. return;
  450. };
  451. if(dt.data.info == "isOK") {
  452. location.href = 'pay-win.html?orderId=' + dt.data.orderId + "&dates=" + new Date().getTime();
  453. return;
  454. };
  455. var orderId = dt.data.orderId;
  456. if(dt.status) {
  457. var str = dt.data.info;
  458. var obj = JSON.parse("{" + str + "}");
  459. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  460. //console.log(res)
  461. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  462. $.ajax(base_path + '/wechat/order/checkOrderPaySuccess?dates=' + new Date().getTime(), {
  463. data: {
  464. "orderId": orderId
  465. },
  466. dataType: 'json',
  467. xhrFields: {
  468. withCredentials: true
  469. },
  470. crossDomain: true,
  471. type: 'get',
  472. timeout: 15000,
  473. success: function(dataobj) {
  474. if(dataobj.isRedirect) {
  475. location.href = dataobj.redirectURL;
  476. } else {
  477. if(dataobj.status == true) { // 支付成功
  478. location.href = "pay-win.html?orderId=" + orderId + "&dates=" + new Date().getTime();
  479. } else {
  480. location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  481. }
  482. }
  483. },
  484. error: function(xhr, type, errorThrown) {
  485. console.log(xhr);
  486. isPay = true;
  487. mui.alert("支付失败!网络错误");
  488. }
  489. });
  490. // var orderIds = {
  491. // "orderId": dt.data.orderId
  492. // };
  493. // var url =base_path+"/wechat/order/checkOrderPaySuccess";
  494. // $.getJSON(url, {
  495. // "s": new Date().getTime(),
  496. // "orderId": dt.data.orderId
  497. // }, function(data) {
  498. // if(data.status == true) { // 支付成功
  499. // location.href = "pay-win.html?orderId=" + orderIds.orderId + "&dates=" + new Date().getTime();
  500. // } else {
  501. // setTimeout("checkOrderStatus('" + dt.data.orderId + "')", 1000);
  502. // }
  503. // });
  504. } else {
  505. isPay = true;
  506. mui.alert("支付失败!请稍后重试!", function() {
  507. location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  508. });
  509. }
  510. });
  511. } else {
  512. isPay = true;
  513. mui.alert(dt.message);
  514. location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  515. }
  516. },
  517. error: function(xhr, type, errorThrown) {
  518. isPay = true;
  519. // layer.closeAll();
  520. mui.alert("您的网络异常,请刷新重试!");
  521. return;
  522. }
  523. });
  524. } else {
  525. mui.alert("正在请求支付中~~请稍后!");
  526. return;
  527. }
  528. } else {
  529. mui.alert("请选择收货地址!");
  530. return;
  531. }
  532. });
  533. //实时监听文本框字数
  534. document.getElementById("textarea").addEventListener("input", function() {
  535. if(this.value.length > 140) {
  536. $("#tips").text("超出长度" + (this.value.length - 140) + "字");
  537. } else {
  538. $("#tips").text("还可输入" + (140 - this.value.length) + "字");
  539. }
  540. });
  541. // 积分开关事件
  542. document.getElementById("mySwitch").addEventListener("toggle", function(e) {
  543. if(e.detail.isActive) {
  544. // console.log("你启动了开关");
  545. userIntegralUsed = 1;
  546. setMoney()
  547. } else {
  548. // console.log("你关闭了开关");
  549. userIntegralUsed = 2;
  550. setMoney()
  551. }
  552. })
  553. function setMoney(){
  554. // var count_price = payTotal;
  555. var count_price = 0;
  556. //空气净化器数量
  557. var kqjhj_amount_50000 = 0;
  558. //获取优惠券类型id
  559. var couponid = parseInt($("input[name=checkbox]:checked").attr('couponid'));
  560. //1、购买除滤芯外产品,下单享受95折 2、购买滤芯产品,下单享受88折
  561. if(userIsVip == 2 && couponid != 40001 && couponid != 50000 && couponid != 50001){
  562. $('.shopping-cart-list').find(".mui-table-view-cell").each(function(){
  563. var colortype = $(this).attr('colortype');
  564. var productdiscount = $(this).attr('productdiscount');
  565. var num = $(this).attr('num');
  566. if(colortype == 1){
  567. productdiscount = accMul(productdiscount,0.95);
  568. count_price += accMul(productdiscount,num);
  569. }else if(colortype == 2 || colortype == 3){
  570. productdiscount = accMul(productdiscount,0.88);
  571. count_price += accMul(productdiscount,num);
  572. }else{
  573. count_price += accMul(productdiscount,num);
  574. }
  575. })
  576. $(".show_vip_youhui").show(); //展示滤芯88折,水机95折
  577. }else{
  578. $(".show_vip_youhui").hide(); //隐藏滤芯88折,水机95折
  579. $('.shopping-cart-list').find(".mui-table-view-cell").each(function(){
  580. var productdiscount = $(this).attr('productdiscount');
  581. var num = $(this).attr('num');
  582. count_price += accMul(productdiscount,num);
  583. })
  584. $(".shopping-cart-list").find('li').each(function(){
  585. var colorId = $(this).attr("colorId");
  586. var num = $(this).attr("num");
  587. var discount = $(this).attr("productdiscount");
  588. discount = accDiv(discount,100);
  589. var amount = accMul(discount,num);
  590. //空气净化器处理
  591. if(colorId == 58){
  592. kqjhj_amount_50000 = accAdd(amount,kqjhj_amount_50000);
  593. }
  594. })
  595. }
  596. //优惠券
  597. var cout = 0;
  598. yhq_id = $("input[name=checkbox]:checked").attr('id')
  599. console.log(yhq_id)
  600. if(typeof(yhq_id) != "undefined") {
  601. if(!isEmpty(yhq_id)){
  602. $(".btn-youhuiquan>span").text("").show();
  603. $(".prize_color").hide();
  604. useCouponPrizeColorId=0;
  605. }else{
  606. if(couponid != 40001){
  607. var couponType = $("input[name=checkbox]:checked").attr("coupontype");
  608. if(couponType == 1){
  609. $(".btn-youhuiquan>span").text("-¥" + $("input[name=checkbox]:checked").attr("val")).show();
  610. cout = $("input[name=checkbox]:checked").attr("val");
  611. }else if(couponType == 2){
  612. $(".btn-youhuiquan>span").text($("input[name=checkbox]:checked").attr("couponname")).show();
  613. var redu = $("input[name=checkbox]:checked").attr("val")
  614. redu = accAdd(1,-redu);
  615. if(couponid == 50000 || couponid == 50001){
  616. if(kqjhj_amount_50000 > 0){
  617. cout = accMul(kqjhj_amount_50000,redu);
  618. }
  619. }
  620. }
  621. //隐藏掉兑换滤芯的一系列操作
  622. useCouponPrizeColorId = 0;
  623. $(".prize_color").hide();
  624. }else{
  625. if(useCouponPrizeColorId == 0){
  626. var colortype,colorId,productdiscount;
  627. var flag = false;
  628. var html = '';
  629. $(".shopping-cart-list").find('li').each(function(){
  630. colortype = $(this).attr("colortype");
  631. if(colortype == 3){
  632. colorId = $(this).attr("colorId");
  633. productdiscount = $(this).attr("productdiscount");
  634. productdiscount = accDiv(productdiscount,100)
  635. useCouponPrizeColorId = colorId
  636. flag = true;
  637. html = $(this).html();
  638. }
  639. })
  640. if(flag){
  641. $(".shopping-cart-list").append('<li class="mui-table-view-cell prize_color" colorid="'+ colorId +'" colortype="'+ colortype +'" productdiscount="'+ accMul(productdiscount,100) +'" num="1">'+ html +'</li>');
  642. var productName = $(".prize_color").find('.li_product').html()
  643. $(".prize_color").find('.li_product').html('【赠送】'+productName);
  644. $(".prize_color").find('.li_discount').html(0);
  645. $(".prize_color").attr('productdiscount',0);
  646. $(".btn-youhuiquan>span").text("赠送一个滤芯").show();
  647. $("input[name=checkbox]:checked").attr("val",0);
  648. $(".prize_color").find('.color_num').html('数量:1');
  649. //
  650. }
  651. }else{
  652. $(".prize_color").show();
  653. $(".btn-youhuiquan>span").text("赠送一个滤芯").show();
  654. $("input[name=checkbox]:checked").attr("val",0);
  655. }
  656. }
  657. }
  658. }
  659. count_price = count_price - accMul(cout,100);
  660. if(count_price <= 0) {
  661. count_price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
  662. }
  663. //最后使用积分
  664. if(userIntegralUsed == 1){
  665. // myUserIntegral = parseInt(accDiv(userIntegral, 10));
  666. // var nowPrice = accDiv(count_price,100)
  667. // if(myUserIntegral > nowPrice){
  668. // myUserIntegral = nowPrice
  669. // }
  670. // $('.integral_money').text(myUserIntegral)
  671. var integral = $('.integral_money').text();
  672. var nowPrice = parseInt(accDiv(count_price,100))
  673. if(parseInt(integral) > nowPrice){
  674. $('.integral_money').text(nowPrice)
  675. $('.integral_num').text(accMul(nowPrice,10))
  676. integral = nowPrice;
  677. }
  678. count_price = count_price - accMul(integral,100);
  679. }
  680. $(".count_price").text(accDiv(count_price,100));
  681. }
  682. </script>
  683. </body>
  684. </html>