clearing.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
  9. <meta http-equiv="Pragma" content="no-cache" />
  10. <meta http-equiv="Expires" content="0" />
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12. <meta http-equiv="X-UA-Compatible" content="IE=8">
  13. <meta http-equiv="Cache" content="no-cache">
  14. <title>结算</title>
  15. <link rel="stylesheet" type="text/css" href="css/mui.min.css" />
  16. <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  17. <link rel="stylesheet" type="text/css" href="css/main.css" />
  18. <script type="text/javascript">
  19. // 屏蔽分享
  20. window.hiddenAllWechatMenu = true;
  21. </script>
  22. <style>
  23. .mui-table-view-cell>a:not(.mui-btn) {margin-left: -12px;}
  24. .no-after:after,.no-line:after{display: none;}
  25. .mui-table-view-cell.no-line{padding: 7px;}
  26. .add_gwc{display: block;width: 100%;}
  27. .mui-h6{margin-right: 6px;}
  28. .center{float: right;margin-right: 7px;}
  29. </style>
  30. </head>
  31. <body>
  32. <div class="mui-content" style="padding-bottom: 56px;">
  33. <div class="address-cantainner">
  34. <ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed">
  35. <li class="mui-table-view-cell">
  36. <div class="mui-table">
  37. <div class="mui-table-cell mui-col-xs-12 table-middle btn-add-address">
  38. <div class="add-address"><span class="iconfont icon-jia"></span>添加收货地址</div>
  39. </div>
  40. <div id="user-address-div" style="display: none;">
  41. </div>
  42. </div>
  43. </li>
  44. </ul>
  45. </div>
  46. <div class="clearing-box">
  47. <ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed shopping-cart-list">
  48. </ul>
  49. <!--<div class="mui-content-padded mui-text-right">合计:<span class="pro-price">¥<span class="count_price">0.0</span></span>
  50. </div>-->
  51. <ul class="mui-table-view no-after">
  52. <li class="mui-table-view-cell" id="ul-youhuiquan" style="padding-left:7px;display: none;">
  53. <a class="mui-navigate-right btn-youhuiquan">
  54. 优惠券<span class="mui-pull-right cl-red">未选择优惠券</span>
  55. </a>
  56. </li>
  57. <!--<li class="mui-table-view-cell " id="" style="padding-left:7px;">
  58. <a class=" ">
  59. 总价<span class="mui-pull-right cl-red ">¥<span class="all_price"></span></span>
  60. </a>
  61. </li>
  62. <li class="mui-table-view-cell" id="" style="padding-left:7px;">
  63. <a class=" ">
  64. 邮费 <span style=" font-size: 12px;color: #8f8f94;">(总价满30元包邮)</span><span class="mui-pull-right cl-red">
  65. ¥<span class="sales_postage"></span>
  66. </span>
  67. </a>
  68. </li>-->
  69. <li class="mui-table-view-cell" style="padding-left:3px;">
  70. <div class="mui-input-row">
  71. <label class="lbl-remarks">订单备注</label>
  72. <input class="ipt-remarks" id="textarea" type="text" placeholder="选填:您对订单有特殊要求,可以在此备注">
  73. </div>
  74. </li>
  75. <li class="mui-table-view-cell no-line" style="padding-left:7px;">
  76. <a>
  77. <span class="mui-h6">商品金额</span><span class="mui-pull-right">
  78. <span class="mui-h6">¥<span class="count_price">0.0</span></span>
  79. </span>
  80. </a>
  81. </li>
  82. <li class="mui-table-view-cell no-line" style="padding-left:7px;display: none;">
  83. <a>
  84. <span class="mui-h6" id="coupon-name"></span><span class="mui-pull-right">
  85. <span class="mui-h6" id="coupon-val"></span>
  86. </span>
  87. </a>
  88. </li>
  89. <li class="mui-table-view-cell no-line" style="padding-left:7px;display: none;">
  90. <a>
  91. <span class="mui-h6" id="full-sub-name"></span><span class="mui-pull-right">
  92. <span class="mui-h6">- ¥<span id="full-sub-count">0</span></span>
  93. </span>
  94. </a>
  95. </li>
  96. <li class="mui-table-view-cell no-line" style="padding-left:7px;">
  97. <a>
  98. <span class="mui-h6">邮费(满30包邮)</span><span class="mui-pull-right">
  99. <span class="mui-h6">¥ <span class="sales_postage">0.0</span></span>
  100. </span>
  101. </a>
  102. </li>
  103. <li class="mui-table-view-cell no-line" style="padding-left:7px;">
  104. <span class="mui-pull-right">订单合计:<span class="count_price_box">¥<span class="pay_price">0.0</span></span></span>
  105. </li>
  106. </ul>
  107. </div>
  108. <div class="buy-footer1">
  109. <table class="tb-clearing">
  110. <tr>
  111. <!--<td class="quanxuan">
  112. 共<span id="pro-count" class="cl-red">0</span>件商品
  113. </td>
  114. <td class="mui-text-center">需支付:<span class="count_price_box">¥<span class="pay_price">0.0</span></span>
  115. </td>-->
  116. <td>
  117. <a id="go-pay" class="mui-btn mui-pull-right add_gwc go-clearing">立即支付</a>
  118. </td>
  119. </tr>
  120. </table>
  121. </div>
  122. </div>
  123. <div class="loading covers">
  124. <div class="loading-bj"></div>
  125. <p>正在加载...</p>
  126. </div>
  127. <script src="js/mui.min.js"></script>
  128. <script src="js/jquery-2.1.1.min.js"></script>
  129. <script src="js/main.js"></script>
  130. <script src="js/wechat-utils-1.0.js"></script>
  131. <script>
  132. window.addEventListener('pageshow', function(e) {
  133. // 通过persisted属性判断是否存在 BF Cache
  134. if(e.persisted) {
  135. location.reload();
  136. }
  137. });
  138. var userIntegral = 0; // 用户可用积分
  139. var meonyProportion = 0; // 兑换比例:1个积分=?分钱
  140. var payTotal = 0.0; // 支付总金额 任何地方不允许更改 payTotal
  141. var userInputIntegral = 0; // 抵扣积分
  142. var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
  143. var cartIdStr = ""; // 购物车ID
  144. var usePayMoney = 0;
  145. var ipt_balance = 0;
  146. var yhq_val = 0;
  147. var used_balance = 0;
  148. var yhq_type = 1;
  149. var yhq_id = '';
  150. var full_sb='';
  151. var orderItem; //获取订单项信息
  152. var channelType = getParam("channelType"); //渠道类型
  153. var channelId = getParam("channelId"); //渠道id
  154. if(channelType == null || channelId == null ){
  155. channelType = 0;
  156. channelId=0;
  157. }
  158. if(channelType > 0 || channelId>0){
  159. location.href = 'channel-clearing.html?channelType='+channelType+'&channelId='+channelId; //跳转结算页面
  160. }
  161. var wechatAddr = new Object();
  162. mui.ready(function() {
  163. var parameter = {}; //ajax参数json集合
  164. var cartidList = '';
  165. if(!window.sessionStorage) {
  166. mui.alert("您的浏览器不支持sessionStorage");
  167. } else {
  168. //读取上一个页面带过来的sessionStorage
  169. pay_data = JSON.parse(sessionStorage.getItem('pay_data'));
  170. if(pay_data != null) {
  171. cartidList = pay_data.text[0]; //购物项id集合
  172. parameter["cartIds"] = cartidList;
  173. parameter["isCustomize"] = 1;
  174. parameter["channelType"] = channelType;
  175. parameter["channelId"] = channelId;
  176. $.ajax(base_path + '/wechat/order/payBefore', {
  177. data: parameter,
  178. dataType: 'json',
  179. type: 'get',
  180. xhrFields: {
  181. withCredentials: true
  182. },
  183. crossDomain: true,
  184. timeout: 15000,
  185. success: function(dt) {
  186. if(dt.isRedirect) {
  187. location.href = dt.redirectURL;
  188. } else {
  189. if(dt.status == true) {
  190. // 购物项遍历
  191. full_sb=dt.data.activityDate;
  192. orderItem = dt.data.cartItems; //订单项信息
  193. var liNote = "";
  194. var yhq_str = "";
  195. if(dt.data.couponItems!=null && typeof(dt.data.couponItems)!=undefined &&
  196. dt.data.couponItems.length > 0 && channelType==0 && channelId ==0) {
  197. $("#ul-youhuiquan").show();
  198. var str = '';
  199. mui.each(dt.data.couponItems, function() {
  200. var couponReduce = this.couponReduce,val='';
  201. if(this.couponType==2){
  202. val=(couponReduce/10).toFixed(1)+"折";
  203. }else{
  204. val='¥' + ((couponReduce) / 100).toFixed(2);
  205. }
  206. str += '<li class="my-table-view-cell" style="opacity:.5;margin:20px 0;"><div class="mui-table"><div class="mui-table-cell table-middle mui-col-xs-11">'+ this.couponName +':'+val+'<h6>有效期至:' + this.couponUseEndDate + '</h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="radio" type="radio" class="mui-pull-left" val="' + this.couponReduce + '" couponname="'+this.couponName+'" couponid="' + this.couponItemId + '" couponType="' + this.couponId + '" zhekou="'+this.couponType+'" couponIsNewPeople="'+ this.couponIsNewPeople +'"/></div></div></li>';
  207. });
  208. str += '<li class="my-table-view-cell" style="opacity:.5;margin:20px 0;"><div class="mui-table"><div class="mui-table-cell table-middle mui-col-xs-11">不使用优惠券<h6></h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="radio" type="radio" class="mui-pull-left" val="0"/></div></div></li>';
  209. $("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: 25px 15px; overflow: scroll;max-height: 420px;">' + str + '</ul><button class="mui-btn my-btn-block my-btn-user-know" disabled="disabled">确认</button><span class="iconfont icon-guanbi"></span></div>');
  210. }
  211. //展示订单项
  212. mui.each(orderItem, function(index) {
  213. var num = this.cartNum;
  214. var total = (num * this.productPrice / 100).toFixed(2); //购物车小计,单位分,保留两位小数
  215. var productId = this.cartProductId;
  216. liNote += '<div class="mui-table" colorid="'+ this.cartColorId +'" productprice="'+ this.productPrice +'" num="'+ this.cartNum +'"><div class="mui-table-cell mui-col-xs-5"><img class="mui-media-object wh-100" src="' + this.productIntroduceImg + '"></div><div class="mui-table-cell table-middle mui-col-xs-7" style="line-height:2.5">' + this.productName + '<h6>颜色:' + this.productColor + '<span class="center">数量:' + num + '</span></h6><div>单价¥' + (this.productPrice / 100).toFixed(2) + '</div></div></div>';
  217. });
  218. var $productListUl = $(".shopping-cart-list");
  219. $productListUl.empty();
  220. $productListUl.append(liNote);
  221. // 保存数据
  222. payTotal = dt.data.payTotal; // 支付金额,单位分
  223. cartIdStr = dt.data.cartId; // 购物车ID
  224. $(".count_price").text(accDiv(payTotal,100));
  225. //计算价格
  226. paymoney(cartIdStr);
  227. //默认自己拉出地址
  228. if(dt.data.addressInfo != undefined && dt.data.addressInfo != null) {
  229. $(".btn-add-address").hide();
  230. $("#user-address-div").html('<div class="mui-table"><div class="mui-table-cell mui-col-xs-1 mui-text-left table-middle"><p><span class="iconfont icon-dingwei"></span></p></div><div class="mui-table-cell mui-col-xs-10 mui-text-left table-middle"><div>收货人:' + dt.data.addressInfo.salesAddressName + ' <span class="mui-pull-right">' + 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"><p><span class="mui-icon mui-icon-arrowright"></span></p></div></div>').show();
  231. //给微信参数赋值
  232. wechatAddr.status = true;
  233. wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo;
  234. wechatAddr.userName = dt.data.addressInfo.salesAddressName;
  235. wechatAddr.userTel = dt.data.addressInfo.salesAddressTel;
  236. wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum;
  237. }else{
  238. wechatAddr.status = false;
  239. }
  240. $(".loading").hide().css("opacity", "0"); //隐藏(正在加载...)
  241. } else {
  242. mui.alert("获取数据失败!", function() {
  243. location.href = "shopping-cart.html";
  244. });
  245. }
  246. }
  247. },
  248. error: function(xhr, type, errorThrown) {
  249. console.log(xhr);
  250. mui.alert("获取数据失败,网络错误!")
  251. }
  252. });
  253. } else {
  254. mui.alert("sessionStorage异常!", function() {
  255. location.href = "index.html";
  256. })
  257. }
  258. }
  259. });
  260. //callback为用户点击蒙版时自动执行的回调;
  261. var mask = mui.createMask(function() {
  262. $(".my-picker").removeClass("active"); //隐藏弹窗
  263. });
  264. //优惠券弹窗
  265. $(document).on('tap', '.btn-youhuiquan', function() {
  266. mask.show();
  267. if($(".my-picker").length > 0) {
  268. $(".my-picker").addClass("active");
  269. }
  270. });
  271. //确认使用
  272. $(document).on('tap', '.my-btn-user-know', function() {
  273. paymoney();
  274. if(typeof($(".my-picker input[name=radio]:checked").attr("couponid")) != "undefined") {
  275. $(".btn-youhuiquan").attr("couponid", $(".my-picker input[name=radio]:checked").attr("couponid"));
  276. yhq_id = $(".my-picker input[name=radio]:checked").attr("couponid");
  277. }else{
  278. yhq_id = '';
  279. $(".btn-youhuiquan").removeAttr("couponid");
  280. $(".btn-youhuiquan span").text("不使用现金券");
  281. $("#coupon-name").parent().parent().hide();
  282. }
  283. $(".my-picker").removeClass("active"); //隐藏弹窗
  284. $(".mui-backdrop").remove(); //移除遮罩层
  285. });
  286. //单选事件
  287. $(document).on('tap', '.my-picker .my-table-view-cell', function() {
  288. $(this).find("input[name=radio]").prop("checked", true);
  289. $(this).css("opacity", "1");
  290. $(this).siblings().css("opacity", ".5");
  291. $(".my-btn-user-know").removeAttr("disabled").addClass("active");
  292. });
  293. //关闭弹窗
  294. $(document).on('tap', '.icon-guanbi', function() {
  295. $(".mui-backdrop").remove(); //移除遮罩层
  296. $(".my-picker").removeClass("active"); //隐藏弹窗
  297. });
  298. // 获取微信共享地址
  299. $(document).on('tap', '.btn-add-address,#user-address-div', function() {
  300. editAddrV1(
  301. function(res) {
  302. // 用户成功拉出地址
  303. var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo;
  304. wechatAddr.status = true;
  305. wechatAddr.detailInfo = address;
  306. wechatAddr.postalCode = res.postalCode;
  307. wechatAddr.userName = res.userName;
  308. wechatAddr.userTel = res.telNumber;
  309. wechatAddr.nationalCode = res.nationalCode;
  310. $(".btn-add-address").hide();
  311. $("#user-address-div").html('<div class="mui-table"><div class="mui-table-cell mui-col-xs-1 mui-text-left table-middle"><p><span class="iconfont icon-dingwei"></span></p></div><div class="mui-table-cell mui-col-xs-10 mui-text-left table-middle"><div>收货人:' + wechatAddr.userName + ' <span class="mui-pull-right">' + wechatAddr.userTel + '</span></div><p>收货地址:' + wechatAddr.detailInfo + '</p></div><div class="mui-table-cell mui-col-xs-1 mui-text-right table-middle"><p><span class="mui-icon mui-icon-arrowright"></span></p></div></div>').show();
  312. },
  313. function() {
  314. if($('#user-address-div').html() != null && $('#user-address-div').html() != '') {
  315. wechatAddr.status = true;
  316. } else {
  317. wechatAddr.status = false;
  318. // 用户取消拉出地址
  319. mui.alert("您没有选择收货地址!");
  320. }
  321. }
  322. );
  323. });
  324. //满减活动
  325. function fullSub(a) {
  326. var time=new Date(),sum=0;
  327. if(full_sb!=''){
  328. var beginDate = parseDate(full_sb.beginDate,"yyyy-MM-dd hh:mm:ss");
  329. var endDate = parseDate(full_sb.endDate,"yyyy-MM-dd hh:mm:ss");
  330. var ispreferential = false;
  331. if(time>beginDate && time<endDate){
  332. $.each(full_sb.salesActivitiesList, function() {
  333. if(a>=this.salesActivitiesFull && sum==0){
  334. if(this.salesActivitiesId == 10){
  335. var rNum = 0;
  336. var price = 0;
  337. var couponPrice = 0;
  338. $('.shopping-cart-list').find('.mui-table').each(function(){
  339. var colorId = $(this).attr('colorid');
  340. var onceNum = parseInt($(this).attr('num'));
  341. var productprice = $(this).attr('productprice');
  342. if(colorId == 60 || colorId == 61 || colorId == 62
  343. || colorId == 63){ //60,61,62,63
  344. rNum += onceNum;
  345. price += accMul(onceNum,productprice)
  346. }
  347. })
  348. if(parseInt(rNum) == 1){
  349. couponPrice = 9000;
  350. }else if(parseInt(rNum) >= 2){
  351. couponPrice = price
  352. couponPrice -= 29900
  353. couponPrice = accMul(couponPrice,0.35);
  354. couponPrice += 9000
  355. }
  356. sum=a-couponPrice;
  357. $("#full-sub-name").text(this.salesActivitiesName);
  358. $("#full-sub-count").text(accDiv(couponPrice,100));
  359. $("#full-sub-name").parent().parent().show();
  360. ispreferential = false;
  361. return false;
  362. }else{
  363. sum=a-this.salesActivitiesReduction;
  364. $("#full-sub-name").text(this.salesActivitiesName);
  365. $("#full-sub-count").text(accDiv(this.salesActivitiesReduction,100));
  366. $("#full-sub-name").parent().parent().show();
  367. ispreferential = true;
  368. return false;
  369. }
  370. }
  371. });
  372. if(ispreferential){
  373. $("#ul-youhuiquan").hide();
  374. }
  375. if(sum == 0){
  376. return a;
  377. }else{
  378. return sum;
  379. }
  380. }else{
  381. return a;
  382. }
  383. }
  384. }
  385. // 去支付
  386. $(document).on('tap', '#go-pay', function() {
  387. var remark = $("#textarea").val();
  388. var ch_en_num = /^[A-Za-z0-9 _\[\]\【\】\{\}\{\}\(\)\(\)\《\》\<\>\,\,\.\。\、\!\!\~\·\@\#\¥\$\%\^\…\&\—\:\:\;\;\‘\’\'\'\"\"\“\”\?\?\-\=\|\*\+\-\u4e00-\u9fa5]{0,100}$/;
  389. if(ch_en_num.test(remark)) {
  390. //console.log("备注验证通过")
  391. } else {
  392. mui.alert("备注格式错误!仅支持中/英文,数字,普通符号");
  393. return false;
  394. }
  395. if(wechatAddr.status) {
  396. if($('#user-address-div').html() == null || $('#user-address-div').html() == '') {
  397. wechatAddr.status = false;
  398. mui.toast("请选择收货信息!");
  399. return ;
  400. }
  401. if(isPay) {
  402. isPay = false; // 锁定请求按钮
  403. /* 组装数据 */
  404. var dataArgs = {
  405. "orderAddressInfo": wechatAddr.detailInfo,
  406. "orderAddressPostNum": wechatAddr.postalCode,
  407. "orderAddressMoblie": wechatAddr.userTel,
  408. "orderAddressName": wechatAddr.userName,
  409. "cartIdStr": cartIdStr
  410. };
  411. if(yhq_id != '') {
  412. dataArgs["couponId"] = yhq_id;
  413. }
  414. if(remark != '') {
  415. dataArgs["orderUserRemark"] = remark;
  416. }
  417. dataArgs["isCustomize"] = 1;
  418. dataArgs["channelType"] = channelType;
  419. dataArgs["channelId"] = channelId;
  420. $.ajax(base_path + '/wechat/order/pay', { // 提交订单,准备支付
  421. data: dataArgs,
  422. dataType: 'json',
  423. type: 'post',
  424. xhrFields: {
  425. withCredentials: true
  426. },
  427. crossDomain: true,
  428. timeout: 15000,
  429. success: function(dt) {
  430. // layer.closeAll();
  431. //mui.alert(dt.resultCode=="500");
  432. if(dt.resultCode == "500") {
  433. isPay = true;
  434. var newOrderId = dt.data.orderId;
  435. if(newOrderId != null && newOrderId != "" && typeof(newOrderId) != "undefined"){
  436. mui.alert("对不起,支付失败!请稍后重试!" + dt.data.orderId + "支付失败!", function() {
  437. location.href = "order-details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  438. });
  439. return;
  440. }
  441. mui.alert("支付失败,"+ dt.message, function() {
  442. location.href = "shopping-cart.html"; // 前往订单详情
  443. });
  444. return;
  445. };
  446. if(dt.data.info == "isOK") {
  447. location.href = 'pay-win.html?orderId=' + dt.data.orderId + "&dates=" + new Date().getTime()
  448. return;
  449. };
  450. if(dt.status) {
  451. var str = dt.data.info;
  452. var obj = JSON.parse("{" + str + "}");
  453. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  454. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  455. $.ajax(base_path + '/wechat/order/checkOrderPaySuccess?dates=' + new Date().getTime(), {
  456. data: {
  457. "orderId": dt.data.orderId
  458. },
  459. dataType: 'json',
  460. xhrFields: {
  461. withCredentials: true
  462. },
  463. crossDomain: true,
  464. type: 'get',
  465. timeout: 15000,
  466. success: function(dataobj) {
  467. if(dataobj.isRedirect) {
  468. location.href = dataobj.redirectURL;
  469. } else {
  470. if(dataobj.status == true) { // 支付成功
  471. location.href = "pay-win.html?orderId=" + dataobj.data + "&dates=" + new Date().getTime();
  472. } else {
  473. location.href = "order-details.html?orderId=" + dataobj.data + "&dates=" + new Date().getTime(); // 前往订单详情
  474. }
  475. }
  476. },
  477. error: function(xhr, type, errorThrown) {
  478. console.log(xhr);
  479. }
  480. });
  481. } else {
  482. isPay = true;
  483. mui.alert("对不起,支付失败!请稍后重试!" + dt.data.orderId + "支付失败!", function() {
  484. location.href = "order-details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  485. });
  486. }
  487. });
  488. } else {
  489. isPay = true;
  490. mui.alert(dt.message);
  491. location.href = "order-details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  492. }
  493. },
  494. error: function(xhr, type, errorThrown) {
  495. isPay = true;
  496. // layer.closeAll();
  497. mui.alert("您的网络异常,请刷新重试!");
  498. return;
  499. }
  500. });
  501. } else {
  502. mui.alert("正在请求支付中~~请稍后!");
  503. return;
  504. }
  505. } else {
  506. mui.alert("请选择收货地址!");
  507. return;
  508. }
  509. });
  510. /**
  511. * 所有优惠活动都经过此方法计算
  512. */
  513. function paymoney(){
  514. var allAmount = payTotal; //总金额(单位为分) ,任何地方不允许更改 payTotal
  515. //遍历订单项,获取所需要的金额
  516. var toothbrush = 0, toothbrush_head = 0;
  517. mui.each(orderItem, function(index) {
  518. var brPrice = this.productPrice; //优惠券金额
  519. var num = this.cartNum;
  520. var total = accMul(num,brPrice);
  521. switch (this.productType){
  522. case 100: //牙刷
  523. toothbrush = accAdd(toothbrush,total);
  524. break;
  525. case 101: //刷头类
  526. toothbrush_head = accAdd(toothbrush_head,total);
  527. break;
  528. default:
  529. break;
  530. }
  531. });
  532. //计算优惠券 - 开始
  533. var coupon_reduce = 0; //优惠金额
  534. if(typeof($(".my-picker input[name=radio]:checked").attr("couponid")) != "undefined") {
  535. var item_amount = allAmount; // 临时总金额
  536. var couponIsNewPeople = $(".my-picker input[name=radio]:checked").attr("couponIsNewPeople");
  537. var couponType = $(".my-picker input[name=radio]:checked").attr("couponType");
  538. couponType = parseInt(couponType);
  539. /*只减去刷头的钱*/
  540. switch (couponType){
  541. case 20000: //刷头抵扣卷
  542. var brushCouponPrice = 0; //刷头优惠总金额
  543. var couponPrice = $(".my-picker input[name=radio]:checked").attr("val"); //优惠券金额
  544. mui.each(orderItem,function(index){
  545. if(this.productType == 101 && (this.colorToothType == 5 || this.colorToothType == 6 || this.colorToothType == 7)){ //刷头类 牙刷分类 5:刷头(lips) 6:刷头(儿童) 7:刷头(北欧+轻奢) 8:(套装)
  546. if(brushCouponPrice == 0 || brushCouponPrice < this.productPrice){
  547. brushCouponPrice = this.productPrice;
  548. }
  549. }
  550. });
  551. allAmount = accSub(allAmount,brushCouponPrice); //刷头减去优惠券
  552. coupon_reduce = brushCouponPrice;
  553. break;
  554. case 20004: //lips刷头抵扣卷
  555. var brushCouponPrice = 0; //刷头优惠总金额
  556. var couponPrice = $(".my-picker input[name=radio]:checked").attr("val"); //优惠券金额
  557. mui.each(orderItem,function(index){
  558. if(this.productType == 101 && (this.colorToothType == 5)){ //刷头类 牙刷分类 5:刷头(lips) 6:刷头(儿童) 7:刷头(北欧+轻奢) 8:(套装)
  559. if(brushCouponPrice == 0 || brushCouponPrice < this.productPrice){
  560. brushCouponPrice = this.productPrice;
  561. }
  562. }
  563. });
  564. allAmount = accSub(allAmount,brushCouponPrice); //刷头减去优惠券
  565. coupon_reduce = brushCouponPrice;
  566. break;
  567. case 40000:
  568. var brushPrice = 0; //刷头总金额
  569. var otherPrice = 0;//其他商品总金额
  570. var couponPrice = $(".my-picker input[name=radio]:checked").attr("val"); //优惠券金额
  571. mui.each(orderItem,function(index){
  572. if(this.productType == 101 && (this.colorToothType == 6 || this.colorToothType == 7)){
  573. brushPrice = accAdd(brushPrice,this.productPrice*this.cartNum);
  574. }else{
  575. otherPrice = accAdd(otherPrice,this.productPrice*this.cartNum);
  576. }
  577. });
  578. brushPrice = accSub(brushPrice,couponPrice); //刷头减去优惠券
  579. if(brushPrice <= 0){
  580. brushPrice = 0;
  581. }
  582. allAmount = accAdd(brushPrice,otherPrice);
  583. coupon_reduce = 6000;
  584. break;
  585. case 110000: //上朵年货节-电动牙刷8折券
  586. var once_disc = $(".my-picker input[name=radio]:checked").attr("val");
  587. once_disc = accDiv(once_disc,100);
  588. var reduce_disc = accSub(1,once_disc);
  589. coupon_reduce = accMul(toothbrush,reduce_disc); //减去的金额
  590. allAmount = accSub(allAmount,coupon_reduce);
  591. break;
  592. case 110001: //上朵年货节-刷头9折券
  593. case 110002: //上朵年货节-刷头8.5折券
  594. case 110003: //上朵年货节-刷头8折券
  595. case 110004: //上朵年货节-刷头7.5折券
  596. var once_disc = $(".my-picker input[name=radio]:checked").attr("val");
  597. once_disc = accDiv(once_disc,100);
  598. var reduce_disc = accSub(1,once_disc);
  599. coupon_reduce = accMul(toothbrush_head,reduce_disc); //减去的金额
  600. allAmount = accSub(allAmount,coupon_reduce);
  601. break;
  602. default:
  603. if($(".my-picker input[name=radio]:checked").attr("zhekou")==2){ //折扣
  604. var once_disc = $(".my-picker input[name=radio]:checked").attr("val");
  605. once_disc = accDiv(once_disc,100);
  606. allAmount = accMul(allAmount,once_disc);
  607. coupon_reduce = accAdd(item_amount,-allAmount);
  608. }else{ //满减
  609. coupon_reduce = $(".my-picker input[name=radio]:checked").attr("val") //减少金额
  610. allAmount = accSub(allAmount,coupon_reduce);
  611. }
  612. break
  613. }
  614. if(allAmount <= 0) {
  615. allAmount = 0.0; //判断商品价格减去现金券价格若<0 则显示0
  616. }
  617. coupon_reduce = accDiv(coupon_reduce,100);
  618. $(".btn-youhuiquan span,#coupon-val").text("-¥" + coupon_reduce);
  619. $("#coupon-name").text($(".my-picker input[name=radio]:checked").attr("couponname"));
  620. $("#coupon-name").parent().parent().show();
  621. }
  622. //计算优惠券 - 结束
  623. //满减
  624. allAmount = fullSub(allAmount);
  625. //计算邮费
  626. var oldTotal = accDiv(fullSub(allAmount),100);
  627. if(accDiv(fullSub(allAmount),100) < 30){
  628. $(".sales_postage").text(10);
  629. oldTotal = accAdd(oldTotal,10);
  630. }else{
  631. $(".sales_postage").text(0);
  632. }
  633. $(".pay_price,.all_price").text(oldTotal);
  634. }
  635. </script>
  636. </body>
  637. </html>