clearing.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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_youhui" style="display: none;">
  117. 会员购买滤芯产品享88折优惠,购买其他产品享95折优惠
  118. </li>
  119. <li class="mui-table-view-cell">
  120. <div class="mui-input-row">
  121. <label style="width:20%;padding:13px 0;">订单备注</label>
  122. <input style="width: 79%;font-size: 12px;" maxlength="140" id="textarea" type="text" placeholder="您对订单有特殊要求,可以在此备注" />
  123. </div>
  124. <!--<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>-->
  125. <p id="tips" style="text-align: right"></p>
  126. </li>
  127. </ul>
  128. <!-- <div style="padding:14px 14px 50px 14px;font-size: 12px;color: #999;background: #f2f2f2;">由于购买人数较多,下单后,订单将会按下单顺序依次发货,敬请谅解</div> -->
  129. </div>
  130. <div class="buy-footer1">
  131. <table class="tb-clearing">
  132. <tr>
  133. <td class="quanxuan">
  134. 共<span class="cl-red"><span id="pro-count">0</span>件</span>商品
  135. </td>
  136. <td class="mui-text-center">合计:<span class="count_price_box">¥<span class="count_price">0.00</span></span>元</td>
  137. <td>
  138. <a id="go-pay" class="mui-btn mui-pull-right add_gwc">立即支付</a>
  139. </td>
  140. </tr>
  141. </table>
  142. </div>
  143. </div>
  144. <script src="js/mui.min.js"></script>
  145. <script src="js/jquery-2.1.1.min.js"></script>
  146. <script src="js/main.js"></script>
  147. <script src="js/wechat-utils-1.0.js"></script>
  148. <script>
  149. var userIntegral = 0; // 用户可用积分
  150. var meonyProportion = 0; // 兑换比例:1个积分=?分钱
  151. var payTotal = 0.0; // 支付总金额
  152. var userInputIntegral = 0; // 抵扣积分
  153. var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
  154. var cartIdStr = ""; // 购物车ID
  155. var usePayMoney = 0;
  156. var ipt_balance = 0;
  157. var yhq_val = 0;
  158. var used_balance = 0;
  159. var yhq_type = 1;
  160. var yhq_id = '';
  161. var userIntegralUsed = 1; // 是否使用积分 1:使用 2:不使用
  162. var userIsVip = 1; // 是否为vip :1:非vip 2:vip
  163. mui.ready(function() {
  164. var parameter = {}; //ajax参数json集合
  165. var cartidList = '';
  166. if(!window.sessionStorage) {
  167. mui.alert("您的浏览器不支持sessionStorage");
  168. } else {
  169. //读取上一个页面带过来的sessionStorage
  170. pay_data = JSON.parse(sessionStorage.getItem('pay_data'));
  171. if(pay_data != null) {
  172. cartidList = pay_data.text[0]; //购物项id集合
  173. parameter["cartIds"] = cartidList;
  174. $.ajax(base_path + '/wechat/order/payBefore', {
  175. data: parameter,
  176. dataType: 'json',
  177. type: 'POST',
  178. xhrFields: {
  179. withCredentials: true
  180. },
  181. crossDomain: true,
  182. timeout: 15000,
  183. success: function(dt) {
  184. if(dt.isRedirect) {
  185. location.href = dt.redirectURL;
  186. } else {
  187. console.log(dt);
  188. if(dt.status == true) {
  189. // 购物项遍历
  190. console.log(dt)
  191. var liNote = "";
  192. var yhq_str = "";
  193. payTotal = dt.data.payTotal; // 支付金额,单位分
  194. if(dt.data.couponItems.length > 0) {
  195. $("#ul-youhuiquan").show();
  196. //console.log("有优惠券" + dt.data.couponItems.length + "张")
  197. var str = '';
  198. mui.each(dt.data.couponItems, function(index) {
  199. var opacity = 1,
  200. checked = 'checked',
  201. disabled = '';
  202. if(index > 0) {
  203. opacity = 0.5;
  204. checked = '';
  205. }
  206. if(payTotal < this.couponConsumeEnough) {
  207. opacity = 0.5;
  208. checked = '';
  209. disabled = 'disabled="disabled"';
  210. }
  211. 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">优惠券:¥' + ((this.couponReduce) / 100).toFixed(2) + '<h6>有效期至:' + this.couponUseEndDate + '</h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="checkbox" val="' + (this.couponReduce / 100).toFixed(2) + '" type="checkbox" ' + checked + ' ' + disabled + ' class="mui-pull-left" id="' + this.couponItemId + '"/></div></div></li>';
  212. });
  213. 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>';
  214. $("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>');
  215. }
  216. mui.each(dt.data.cartItems, function(index) {
  217. var num = this.cartNum;
  218. var total = (num * this.productDiscount / 100).toFixed(2); //购物车小计,单位分,保留两位小数
  219. var productId = this.cartProductId;
  220. var zeng = '';
  221. if(typeof(this.salesUserGiftList) != "undefined") {
  222. $.each(this.salesUserGiftList, function() {
  223. zeng += this.giftName + '*' + (num * this.userGiftCount) + '件 '
  224. });
  225. }
  226. if(zeng != '') {
  227. zeng = '<p style="font-size:12px;">(赠品:' + zeng + ')</p>';
  228. }
  229. liNote += '<li class="mui-table-view-cell" 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">' + this.productName + '<h6><span class="center" style="line-height: 15px;">颜色:' + this.productColor + '</span></br><span class="center" style="line-height: 15px;">数量:' + num + '</span></h6><div>单价 ¥' + (this.productDiscount / 100).toFixed(2) + '</div></div></div><div>' + zeng + '</div></li>';
  230. });
  231. var $productListUl = $(".shopping-cart-list");
  232. $productListUl.empty();
  233. $productListUl.append(liNote);
  234. // 保存数据
  235. cartIdStr = dt.data.cartId; // 购物车ID
  236. userIsVip = dt.data.userIsVip;
  237. userIntegral = dt.data.userIntegral; // 用户可用积分
  238. //计算积分能换算的钱
  239. var myUserIntegral = 0;
  240. if(dt.data.userIsVip == 2 && dt.data.userIntegral > 0){
  241. $('.show_integral').show();
  242. //积分赋值
  243. $('.integral_num').text(dt.data.userIntegral);
  244. var myUserIntegral = dt.data.userIntegral;
  245. myUserIntegral = parseInt(accDiv(myUserIntegral, 10));
  246. userIntegralUsedNumber = myUserIntegral
  247. $('.integral_money').text(myUserIntegral)
  248. }else{
  249. $('.show_integral').hide();
  250. userIntegralUsed = 2;
  251. }
  252. //默认自己拉出地址
  253. if(dt.data.addressInfo != undefined && dt.data.addressInfo != null) {
  254. $(".btn-add-address").parent().hide();
  255. $("#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>');
  256. //给微信参数赋值
  257. wechatAddr.status = true;
  258. wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo;
  259. wechatAddr.userName = dt.data.addressInfo.salesAddressName;
  260. wechatAddr.userTel = dt.data.addressInfo.salesAddressTel;
  261. wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum;
  262. }
  263. $("#pro-count").text(dt.data.cartItems.length);
  264. setMoney();
  265. } else {
  266. mui.alert(dt.message, function() {
  267. location.href = "shopping-cart.html?dates=" + new Date().getTime(); // 前往购物车
  268. });
  269. }
  270. }
  271. },
  272. error: function(xhr, type, errorThrown) {
  273. console.log(xhr);
  274. mui.alert("获取数据失败,网络错误!")
  275. }
  276. });
  277. } else {
  278. mui.alert("sessionStorage异常!", function() {
  279. location.href = "index.html";
  280. })
  281. }
  282. }
  283. document.querySelector('.loading-bg').style.display = 'none';
  284. });
  285. //callback为用户点击蒙版时自动执行的回调;
  286. var mask = mui.createMask(function() {
  287. $(".my-picker").removeClass("active");
  288. });
  289. //点击弹出优惠券列表
  290. $(document).on('tap', '.btn-youhuiquan', function() {
  291. mask.show();
  292. $(".my-picker").addClass("active");
  293. });
  294. //选择优惠券
  295. $(document).on('click', '.my-picker input[name=checkbox]', function() {
  296. var th = $(this);
  297. if(th.prop("checked")) {
  298. th.parent().parent().parent().siblings().css("opacity", .5).find("input").prop("checked", false);
  299. th.parent().parent().parent().css("opacity", 1);
  300. $('.my-btn-buy-know').removeAttr("disabled");
  301. } else {
  302. th.parent().parent().parent().css("opacity", .5);
  303. $('.my-btn-buy-know').attr("disabled", "disabled");
  304. }
  305. });
  306. //确认使用优惠券
  307. $(document).on('tap', '.my-btn-buy-know', function() {
  308. console.log("确认使用");
  309. yhq_id = $("input[name=checkbox]:checked").attr('id');
  310. // var cout = 0;
  311. // if(typeof(yhq_id) != "undefined") {
  312. // if(!isEmpty(yhq_id)){
  313. // $(".btn-youhuiquan>span").text("").show();
  314. // }else{
  315. // $(".btn-youhuiquan>span").text("-¥" + $("input[name=checkbox]:checked").attr("val")).show();
  316. // }
  317. // cout = $("input[name=checkbox]:checked").attr("val");
  318. // }
  319. $(".my-picker").removeClass("active");
  320. $(".mui-backdrop").css("opacity", 0).remove();
  321. setMoney();
  322. // var count_price = payTotal - cout * 100;
  323. // if(count_price <= 0) {
  324. // count_price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
  325. // }
  326. // $(".count_price").text((count_price / 100).toFixed(2));
  327. });
  328. // 获取微信共享地址
  329. $(document).on('tap', '#user-address-div', function() {
  330. editAddrV1(
  331. function(res) {
  332. // 用户成功拉出地址
  333. var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo;
  334. wechatAddr.status = true;
  335. wechatAddr.detailInfo = address;
  336. wechatAddr.postalCode = res.postalCode;
  337. wechatAddr.userName = res.userName;
  338. wechatAddr.userTel = res.telNumber;
  339. wechatAddr.nationalCode = res.nationalCode;
  340. $("#user-address-div .addr").remove();
  341. $(".btn-add-address").parent().hide();
  342. $("#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>');
  343. },
  344. function() {
  345. if($('#user-address-div .addr').html() != null && $('#user-address-div .addr').html() != '') {
  346. wechatAddr.status = true;
  347. } else {
  348. wechatAddr.status = false;
  349. // 用户取消拉出地址
  350. mui.alert("您没有选择收货地址!");
  351. }
  352. }
  353. );
  354. });
  355. // 去支付
  356. $(document).on('tap', '#go-pay', function() {
  357. var remark = $("#textarea").val();
  358. var ch_en_num = /^[A-Za-z0-9 _\[\]\【\】\{\}\{\}\(\)\(\)\《\》\<\>\,\,\.\。\、\!\!\~\·\@\#\¥\$\%\^\…\&\—\:\:\;\;\‘\’\'\'\"\"\“\”\?\?\-\=\|\*\+\-\u4e00-\u9fa5]{0,100}$/;
  359. if(ch_en_num.test(remark)) {
  360. console.log("备注验证通过")
  361. } else {
  362. mui.alert("备注格式错误!仅支持中/英文,数字,普通符号");
  363. return false;
  364. }
  365. if(wechatAddr.status) {
  366. if(isPay) {
  367. var orderIntegralNum = 0;
  368. if(userIntegralUsed == 1){
  369. orderIntegralNum = $('.integral_money').text();
  370. orderIntegralNum = accMul(orderIntegralNum,10)
  371. }
  372. isPay = false; // 锁定请求按钮
  373. /* 组装数据 */
  374. var dataArgs = {
  375. "orderAddressInfo": wechatAddr.detailInfo,
  376. "orderAddressPostNum": wechatAddr.postalCode,
  377. "orderAddressMoblie": wechatAddr.userTel,
  378. "orderAddressName": wechatAddr.userName,
  379. "cartIdStr": cartIdStr,
  380. "orderIntegralNum": orderIntegralNum,
  381. "orderUserRemark": remark,
  382. "couponId": yhq_id,
  383. "balancePayAmount": 0
  384. };
  385. $.ajax(base_path + '/wechat/order/pay', { // 提交订单,准备支付
  386. data: dataArgs,
  387. dataType: 'json',
  388. type: 'POST',
  389. xhrFields: {
  390. withCredentials: true
  391. },
  392. crossDomain: true,
  393. timeout: 15000,
  394. success: function(dt) {
  395. // layer.closeAll();
  396. //mui.alert(dt.resultCode=="500");
  397. if(dt.resultCode == "500") {
  398. mui.alert(dt.message);
  399. isPay = true;
  400. return;
  401. };
  402. if(dt.data.info == "isOK") {
  403. location.href = 'pay-win.html?orderId=' + dt.data.orderId + "&dates=" + new Date().getTime();
  404. return;
  405. };
  406. var orderId = dt.data.orderId;
  407. if(dt.status) {
  408. var str = dt.data.info;
  409. var obj = JSON.parse("{" + str + "}");
  410. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  411. //console.log(res)
  412. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  413. $.ajax(base_path + '/wechat/order/checkOrderPaySuccess?dates=' + new Date().getTime(), {
  414. data: {
  415. "orderId": orderId
  416. },
  417. dataType: 'json',
  418. xhrFields: {
  419. withCredentials: true
  420. },
  421. crossDomain: true,
  422. type: 'get',
  423. timeout: 15000,
  424. success: function(dataobj) {
  425. if(dataobj.isRedirect) {
  426. location.href = dataobj.redirectURL;
  427. } else {
  428. if(dataobj.status == true) { // 支付成功
  429. location.href = "pay-win.html?orderId=" + orderId + "&dates=" + new Date().getTime();
  430. } else {
  431. location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  432. }
  433. }
  434. },
  435. error: function(xhr, type, errorThrown) {
  436. console.log(xhr);
  437. isPay = true;
  438. mui.alert("支付失败!网络错误");
  439. }
  440. });
  441. // var orderIds = {
  442. // "orderId": dt.data.orderId
  443. // };
  444. // var url =base_path+"/wechat/order/checkOrderPaySuccess";
  445. // $.getJSON(url, {
  446. // "s": new Date().getTime(),
  447. // "orderId": dt.data.orderId
  448. // }, function(data) {
  449. // if(data.status == true) { // 支付成功
  450. // location.href = "pay-win.html?orderId=" + orderIds.orderId + "&dates=" + new Date().getTime();
  451. // } else {
  452. // setTimeout("checkOrderStatus('" + dt.data.orderId + "')", 1000);
  453. // }
  454. // });
  455. } else {
  456. isPay = true;
  457. mui.alert("支付失败!请稍后重试!", function() {
  458. location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  459. });
  460. }
  461. });
  462. } else {
  463. isPay = true;
  464. mui.alert(dt.message);
  465. location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  466. }
  467. },
  468. error: function(xhr, type, errorThrown) {
  469. isPay = true;
  470. // layer.closeAll();
  471. mui.alert("您的网络异常,请刷新重试!");
  472. return;
  473. }
  474. });
  475. } else {
  476. mui.alert("正在请求支付中~~请稍后!");
  477. return;
  478. }
  479. } else {
  480. mui.alert("请选择收货地址!");
  481. return;
  482. }
  483. });
  484. //实时监听文本框字数
  485. document.getElementById("textarea").addEventListener("input", function() {
  486. if(this.value.length > 140) {
  487. $("#tips").text("超出长度" + (this.value.length - 140) + "字");
  488. } else {
  489. $("#tips").text("还可输入" + (140 - this.value.length) + "字");
  490. }
  491. });
  492. // 积分开关事件
  493. document.getElementById("mySwitch").addEventListener("toggle", function(e) {
  494. if(e.detail.isActive) {
  495. // console.log("你启动了开关");
  496. userIntegralUsed = 1;
  497. setMoney()
  498. } else {
  499. // console.log("你关闭了开关");
  500. userIntegralUsed = 2;
  501. setMoney()
  502. }
  503. })
  504. function setMoney(){
  505. // var count_price = payTotal;
  506. if(userIsVip == 1){
  507. $(".show_vip_youhui").hide();
  508. }else{
  509. $(".show_vip_youhui").show();
  510. }
  511. var count_price = 0;
  512. //1、购买除滤芯外产品,下单享受95折 2、购买滤芯产品,下单享受88折
  513. if(userIsVip == 2){
  514. $('.shopping-cart-list').find(".mui-table-view-cell").each(function(){
  515. var colortype = $(this).attr('colortype');
  516. var productdiscount = $(this).attr('productdiscount');
  517. var num = $(this).attr('num');
  518. if(colortype == 1){
  519. productdiscount = accMul(productdiscount,0.95);
  520. count_price += accMul(productdiscount,num);
  521. }else if(colortype == 2){
  522. productdiscount = accMul(productdiscount,0.88);
  523. count_price += accMul(productdiscount,num);
  524. }else{
  525. count_price += accMul(productdiscount,num);
  526. }
  527. })
  528. }else{
  529. $('.shopping-cart-list').find(".mui-table-view-cell").each(function(){
  530. var productdiscount = $(this).attr('productdiscount');
  531. var num = $(this).attr('num');
  532. count_price += accMul(productdiscount,num);
  533. })
  534. }
  535. //优惠券
  536. yhq_id = $("input[name=checkbox]:checked").attr('id');
  537. var cout = 0;
  538. console.log(yhq_id)
  539. if(typeof(yhq_id) != "undefined") {
  540. if(!isEmpty(yhq_id)){
  541. $(".btn-youhuiquan>span").text("").show();
  542. }else{
  543. $(".btn-youhuiquan>span").text("-¥" + $("input[name=checkbox]:checked").attr("val")).show();
  544. }
  545. cout = $("input[name=checkbox]:checked").attr("val");
  546. }
  547. count_price = count_price - accMul(cout,100);
  548. if(count_price <= 0) {
  549. count_price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
  550. }
  551. //最后使用积分
  552. if(userIntegralUsed == 1){
  553. var integral = $('.integral_money').text();
  554. if(parseInt(integral) > count_price){
  555. $('.integral_money').text(count_price)
  556. $('.integral_num').text(accMul(count_price,10))
  557. integral = count_price;
  558. }
  559. count_price = count_price - accMul(integral,100);
  560. }
  561. $(".count_price").text(accDiv(count_price,100));
  562. }
  563. </script>
  564. </body>
  565. </html>