clearing.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. <script type="text/javascript">
  13. // 屏蔽分享
  14. window.hiddenAllWechatMenu = true;
  15. </script>
  16. <style>
  17. .mui-table-view-cell>a:not(.mui-btn) {margin-left: -12px;}
  18. </style>
  19. </head>
  20. <body>
  21. <div class="mui-content" style="padding-bottom: 56px;">
  22. <div class="address-cantainner">
  23. <ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed">
  24. <li class="mui-table-view-cell">
  25. <div class="mui-table">
  26. <!--没有选地址时显示的div-->
  27. <div class="mui-table-cell mui-col-xs-12 table-middle btn-add-address">
  28. <div class="add-address"><span class="iconfont icon-jia"></span>添加收货地址</div>
  29. </div>
  30. <!--选择微信地址后显示的div-->
  31. <div id="user-address-div" style="display: none;">
  32. <!--<div class="mui-table-cell mui-col-xs-1 mui-text-left table-middle">
  33. <p><span class="iconfont icon-dingwei"></span></p>
  34. </div>
  35. <div class="mui-table-cell mui-col-xs-10 mui-text-left table-middle">
  36. <div>收货人:林笑笑 <span class="mui-pull-right">16899996678</span></div>
  37. <p>收货地址:广东省深圳市福田区莲花街道深圳特区 报业大厦12b</p>
  38. </div>
  39. <div class="mui-table-cell mui-col-xs-1 mui-text-right table-middle">
  40. <p><span class="mui-icon mui-icon-arrowright"></span></p>
  41. </div>-->
  42. </div>
  43. </div>
  44. </li>
  45. </ul>
  46. </div>
  47. <div class="clearing-box">
  48. <ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed shopping-cart-list">
  49. </ul>
  50. <div class="mui-content-padded mui-text-right">合计:<span class="pro-price">¥<span class="count_price">0.0</span></span>
  51. </div>
  52. <ul class="mui-table-view">
  53. <li class="mui-table-view-cell" id="ul-youhuiquan" style="padding-left:7px;display: none;">
  54. <a class="mui-navigate-right btn-youhuiquan">
  55. 优惠券<span class="mui-pull-right cl-red">未选择优惠券</span>
  56. </a>
  57. </li>
  58. <li class="mui-table-view-cell " id="" style="padding-left:7px;">
  59. <a class=" ">
  60. 总价<span class="mui-pull-right cl-red ">¥<span class="all_price"></span></span>
  61. </a>
  62. </li>
  63. <li class="mui-table-view-cell" id="" style="padding-left:7px; ">
  64. <a class=" " >
  65. 邮费 <span style=" font-size: 12px;color: #8f8f94;">(总价满30元包邮)</span><span class="mui-pull-right cl-red">
  66. ¥<span class="sales_postage"></span>
  67. </span>
  68. </a>
  69. </li>
  70. <li>
  71. <div class="mui-input-row">
  72. <label class="lbl-remarks">订单备注</label>
  73. <input class="ipt-remarks" id="textarea" type="text" placeholder="选填:您对订单有特殊要求,可以在此备注">
  74. </div>
  75. </li>
  76. </ul>
  77. </div>
  78. <div class="buy-footer1">
  79. <table class="tb-clearing">
  80. <tr>
  81. <td class="quanxuan">
  82. 共<span id="pro-count" class="cl-red">0</span>件商品
  83. </td>
  84. <td class="mui-text-center">需支付:<span class="count_price_box">¥<span class="pay_price">0.0</span></span>
  85. </td>
  86. <td>
  87. <a id="go-pay" class="mui-btn mui-pull-right add_gwc go-clearing">立即支付</a>
  88. </td>
  89. </tr>
  90. </table>
  91. </div>
  92. </div>
  93. <!-- 加载ing begin-->
  94. <div class="loading covers">
  95. <div class="loading-bj"></div>
  96. <p>正在加载...</p>
  97. </div>
  98. <!-- 加载ing end -->
  99. <script src="js/mui.min.js"></script>
  100. <script src="js/jquery-2.1.1.min.js"></script>
  101. <script src="js/main.js"></script>
  102. <script src="js/wechat-utils-1.0.js"></script>
  103. <script>
  104. window.addEventListener('pageshow', function(e) {
  105. // 通过persisted属性判断是否存在 BF Cache
  106. if(e.persisted) {
  107. location.reload();
  108. }
  109. });
  110. var userIntegral = 0; // 用户可用积分
  111. var meonyProportion = 0; // 兑换比例:1个积分=?分钱
  112. var payTotal = 0.0; // 支付总金额
  113. var userInputIntegral = 0; // 抵扣积分
  114. var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
  115. var cartIdStr = ""; // 购物车ID
  116. var usePayMoney = 0;
  117. var ipt_balance = 0;
  118. var yhq_val = 0;
  119. var used_balance = 0;
  120. var yhq_type = 1;
  121. var yhq_id = '';
  122. var orderItem; //获取订单项信息
  123. var couponMoney = 0; //新人卷 - 优惠金额
  124. var channelType = getParam("channelType"); //渠道类型
  125. var channelId = getParam("channelId"); //渠道id
  126. if(channelType == null || channelId == null ){
  127. channelType = 0;
  128. channelId=0;
  129. }
  130. if(channelType > 0 || channelId>0){
  131. location.href = 'channel-clearing.html?channelType='+channelType+'&channelId='+channelId; //跳转结算页面
  132. }
  133. var wechatAddr = new Object();
  134. mui.ready(function() {
  135. var parameter = {}; //ajax参数json集合
  136. var cartidList = '';
  137. if(!window.sessionStorage) {
  138. mui.alert("您的浏览器不支持sessionStorage");
  139. } else {
  140. //读取上一个页面带过来的sessionStorage
  141. pay_data = JSON.parse(sessionStorage.getItem('pay_data'));
  142. if(pay_data != null) {
  143. cartidList = pay_data.text[0]; //购物项id集合
  144. parameter["cartIds"] = cartidList;
  145. parameter["isCustomize"] = 1;
  146. parameter["channelType"] = channelType;
  147. parameter["channelId"] = channelId;
  148. $.ajax(base_path + '/wechat/order/payBefore', {
  149. data: parameter,
  150. dataType: 'json',
  151. type: 'get',
  152. xhrFields: {
  153. withCredentials: true
  154. },
  155. crossDomain: true,
  156. timeout: 15000,
  157. success: function(dt) {
  158. if(dt.isRedirect) {
  159. location.href = dt.redirectURL;
  160. } else {
  161. if(dt.status == true) {
  162. // 购物项遍历
  163. console.log(dt);
  164. orderItem = dt.data.cartItems; //订单项信息
  165. mui.each(dt.data.cartItems, function(index) {
  166. if(this.productType == 101){ //刷头类
  167. var brPrice = this.productPrice; //优惠券金额
  168. if(couponMoney == 0 || couponMoney < brPrice){
  169. couponMoney = brPrice;
  170. }
  171. }
  172. })
  173. var liNote = "";
  174. var yhq_str = "";
  175. if(dt.data.couponItems!=null && typeof(dt.data.couponItems)!=undefined &&
  176. dt.data.couponItems.length > 0 && channelType==0 && channelId ==0) {
  177. $("#ul-youhuiquan").show();
  178. var str = '';
  179. mui.each(dt.data.couponItems, function() {
  180. var couponReduce = this.couponReduce,val='';
  181. //if(this.couponIsNewPeople == 1){ //新人卷
  182. // couponReduce = couponMoney;
  183. //}
  184. if(this.couponType==2){
  185. val=(couponReduce/10).toFixed(1)+"折";
  186. }else{
  187. val='¥' + ((couponReduce) / 100).toFixed(2);
  188. }
  189. 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 / 100).toFixed(2) + '" couponid="' + this.couponItemId + '" couponType="' + this.couponId + '" zhekou="'+this.couponType+'" couponIsNewPeople="'+ this.couponIsNewPeople +'"/></div></div></li>';
  190. });
  191. 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"/></div></div></li>';
  192. $("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>');
  193. }
  194. var proCount = 0;
  195. mui.each(dt.data.cartItems, function(index) {
  196. if(this.productType == 101){ //刷头类
  197. var brPrice = this.productPrice; //优惠券金额
  198. if(couponMoney == 0 || couponMoney < brPrice){
  199. couponMoney = brPrice;
  200. }
  201. }
  202. var num = this.cartNum;
  203. proCount += num;
  204. var total = (num * this.productPrice / 100).toFixed(2); //购物车小计,单位分,保留两位小数
  205. var productId = this.cartProductId;
  206. liNote += '<div class="mui-table"><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>';
  207. });
  208. var $productListUl = $(".shopping-cart-list");
  209. $productListUl.empty();
  210. $productListUl.append(liNote);
  211. // 保存数据
  212. payTotal = dt.data.payTotal; // 支付金额,单位分
  213. cartIdStr = dt.data.cartId; // 购物车ID
  214. //默认自己拉出地址
  215. if(dt.data.addressInfo != undefined && dt.data.addressInfo != null) {
  216. $(".btn-add-address").hide();
  217. $("#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();
  218. //给微信参数赋值
  219. wechatAddr.status = true;
  220. wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo;
  221. wechatAddr.userName = dt.data.addressInfo.salesAddressName;
  222. wechatAddr.userTel = dt.data.addressInfo.salesAddressTel;
  223. wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum;
  224. }else{
  225. wechatAddr.status = false;
  226. }
  227. $(".count_price,.pay_price,.all_price").text(accDiv(dt.data.payTotal,100));
  228. if(accDiv(dt.data.payTotal,100) < 30){
  229. $(".sales_postage").text(10);
  230. }else{
  231. $(".sales_postage").text(0);
  232. }
  233. $("#pro-count").text(proCount);
  234. $(".loading").hide().css("opacity", "0"); //隐藏(正在加载...)
  235. } else {
  236. mui.alert("获取数据失败!", function() {
  237. location.href = "shopping-cart.html";
  238. });
  239. }
  240. }
  241. },
  242. error: function(xhr, type, errorThrown) {
  243. console.log(xhr);
  244. mui.alert("获取数据失败,网络错误!")
  245. }
  246. });
  247. } else {
  248. mui.alert("sessionStorage异常!", function() {
  249. location.href = "index.html";
  250. })
  251. }
  252. }
  253. // var str = "";
  254. // for(i = 0; i < 3; i++) {
  255. // str += '<div class="mui-table"><div class="mui-table-cell mui-col-xs-5"><img class="mui-media-object wh-100" src="images/pro-bai.png"></div><div class="mui-table-cell table-middle mui-col-xs-7" style="line-height:2.5">柔性声波牙刷<h6>颜色:极光白<span class="center">数量:2</span></h6><div>¥2999.00</div></div></div>';
  256. // }
  257. // document.querySelector('.shopping-cart-list').innerHTML = str;
  258. });
  259. //callback为用户点击蒙版时自动执行的回调;
  260. var mask = mui.createMask(function() {
  261. $(".my-picker").removeClass("active"); //隐藏弹窗
  262. });
  263. //现金券弹窗
  264. $(document).on('tap', '.btn-youhuiquan', function() {
  265. mask.show();
  266. // if($(".my-picker").length==0){
  267. // var li = '<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">现金券:¥99.9<h6>有效期至:2017-12-12</h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="radio" type="radio" class="mui-pull-left" /></div></div></li>';
  268. // var str = '';
  269. // for(i = 0; i < 17; i++) {
  270. // str += li;
  271. // }
  272. // $("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>');
  273. // }
  274. // setTimeout(function() {
  275. if($(".my-picker").length > 0) {
  276. $(".my-picker").addClass("active");
  277. }
  278. // }, 500);
  279. });
  280. //确认使用
  281. $(document).on('tap', '.my-btn-user-know', function() {
  282. //console.log("确认使用");
  283. if(typeof($(".my-picker input[name=radio]:checked").attr("couponid")) != "undefined") {
  284. $(".btn-youhuiquan").attr("couponid", $(".my-picker input[name=radio]:checked").attr("couponid"));
  285. yhq_id = $(".my-picker input[name=radio]:checked").attr("couponid");
  286. $(".btn-youhuiquan span").text("-¥" + $(".my-picker input[name=radio]:checked").attr("val"));
  287. var couponIsNewPeople = $(".my-picker input[name=radio]:checked").attr("couponIsNewPeople");
  288. var couponType = $(".my-picker input[name=radio]:checked").attr("couponType");
  289. var price = 0;
  290. /*只减去刷头的钱*/
  291. if(couponIsNewPeople == 1){ //标识为新人卷
  292. if(couponType == 20000){
  293. var brushCouponPrice = 0; //刷头优惠总金额
  294. var otherPrice = 0;//其他商品总金额
  295. var couponPrice = $(".my-picker input[name=radio]:checked").attr("val"); //优惠券金额
  296. mui.each(orderItem,function(index){
  297. if(this.productType == 101){ //刷头类
  298. var brPrice = this.productPrice; //优惠券金额
  299. if(brushCouponPrice == 0 || brushCouponPrice < brPrice){
  300. brushCouponPrice = brPrice;
  301. }
  302. }
  303. });
  304. brushCouponPrice = accDiv(brushCouponPrice,100);
  305. price = accSub($(".count_price").text(),brushCouponPrice); //刷头减去优惠券
  306. $(".btn-youhuiquan span").text("-¥" + brushCouponPrice); //减去优惠金额赋值
  307. }else if(couponType == 40000){
  308. var brushPrice = 0; //刷头总金额
  309. var otherPrice = 0;//其他商品总金额
  310. var couponPrice = $(".my-picker input[name=radio]:checked").attr("val"); //优惠券金额
  311. mui.each(orderItem,function(index){
  312. if(this.productType == 101){
  313. brushPrice = accAdd(brushPrice,this.productPrice*this.cartNum);
  314. }else{
  315. otherPrice = accAdd(otherPrice,this.productPrice*this.cartNum);
  316. }
  317. });
  318. brushPrice = accDiv(brushPrice,100);
  319. otherPrice = accDiv(otherPrice,100);
  320. brushPrice = accSub(brushPrice,couponPrice); //刷头减去优惠券
  321. if(brushPrice <= 0){
  322. brushPrice = 0;
  323. }
  324. price = accAdd(brushPrice,otherPrice);
  325. }
  326. }else{
  327. if($(".my-picker input[name=radio]:checked").attr("zhekou")==2){
  328. price = accMul($(".count_price").text(),$(".my-picker input[name=radio]:checked").attr("val"));
  329. // price =parseInt($(".count_price").text()*$(".my-picker input[name=radio]:checked").attr("val"));
  330. $(".btn-youhuiquan span").text("-¥"+accSub($(".count_price").text(),price)); //减去折扣优惠金额赋值
  331. }else{
  332. price = accSub($(".count_price").text(),$(".my-picker input[name=radio]:checked").attr("val"));
  333. }
  334. }
  335. if(price <= 0) {
  336. price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
  337. }
  338. $(".all_price").text(price);
  339. var postage = 0;
  340. if(price<30){
  341. $(".sales_postage").text(10);
  342. postage = 10;
  343. }else{
  344. $(".sales_postage").text(0);
  345. }
  346. price = parseFloat(price + postage);
  347. $(".pay_price").text(price);
  348. } else {
  349. yhq_id = '';
  350. $(".btn-youhuiquan").removeAttr("couponid");
  351. $(".btn-youhuiquan span").text("不使用现金券");
  352. $(".all_price").text($(".count_price").text());
  353. var salesPostage = $(".count_price").text();
  354. if(salesPostage < 30 ){
  355. $(".sales_postage").text(10);
  356. salesPostage += 10;
  357. }else{
  358. $(".sales_postage").text(0);
  359. }
  360. $(".pay_price").text(parseFloat(salesPostage));
  361. }
  362. $(".my-picker").removeClass("active"); //隐藏弹窗
  363. $(".mui-backdrop").remove(); //移除遮罩层
  364. });
  365. //单选事件
  366. $(document).on('tap', '.my-picker .my-table-view-cell', function() {
  367. $(this).find("input[name=radio]").prop("checked", true);
  368. $(this).css("opacity", "1");
  369. $(this).siblings().css("opacity", ".5");
  370. $(".my-btn-user-know").removeAttr("disabled").addClass("active");
  371. });
  372. //关闭弹窗
  373. $(document).on('tap', '.icon-guanbi', function() {
  374. $(".mui-backdrop").remove(); //移除遮罩层
  375. $(".my-picker").removeClass("active"); //隐藏弹窗
  376. });
  377. // 获取微信共享地址
  378. $(document).on('tap', '.btn-add-address,#user-address-div', function() {
  379. editAddrV1(
  380. function(res) {
  381. // 用户成功拉出地址
  382. var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo;
  383. wechatAddr.status = true;
  384. wechatAddr.detailInfo = address;
  385. wechatAddr.postalCode = res.postalCode;
  386. wechatAddr.userName = res.userName;
  387. wechatAddr.userTel = res.telNumber;
  388. wechatAddr.nationalCode = res.nationalCode;
  389. $(".btn-add-address").hide();
  390. $("#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();
  391. },
  392. function() {
  393. if($('#user-address-div').html() != null && $('#user-address-div').html() != '') {
  394. wechatAddr.status = true;
  395. } else {
  396. wechatAddr.status = false;
  397. // 用户取消拉出地址
  398. mui.alert("您没有选择收货地址!");
  399. }
  400. }
  401. );
  402. });
  403. // 去支付
  404. $(document).on('tap', '#go-pay', function() {
  405. var remark = $("#textarea").val();
  406. var ch_en_num = /^[A-Za-z0-9 _\[\]\【\】\{\}\{\}\(\)\(\)\《\》\<\>\,\,\.\。\、\!\!\~\·\@\#\¥\$\%\^\…\&\—\:\:\;\;\‘\’\'\'\"\"\“\”\?\?\-\=\|\*\+\-\u4e00-\u9fa5]{0,100}$/;
  407. if(ch_en_num.test(remark)) {
  408. //console.log("备注验证通过")
  409. } else {
  410. mui.alert("备注格式错误!仅支持中/英文,数字,普通符号");
  411. return false;
  412. }
  413. if(wechatAddr.status) {
  414. if($('#user-address-div').html() == null || $('#user-address-div').html() == '') {
  415. wechatAddr.status = false;
  416. mui.toast("请选择收货信息!");
  417. return ;
  418. }
  419. if(isPay) {
  420. isPay = false; // 锁定请求按钮
  421. /* 组装数据 */
  422. var dataArgs = {
  423. "orderAddressInfo": wechatAddr.detailInfo,
  424. "orderAddressPostNum": wechatAddr.postalCode,
  425. "orderAddressMoblie": wechatAddr.userTel,
  426. "orderAddressName": wechatAddr.userName,
  427. "cartIdStr": cartIdStr
  428. };
  429. if(yhq_id != '') {
  430. dataArgs["couponId"] = yhq_id;
  431. }
  432. if(remark != '') {
  433. dataArgs["orderUserRemark"] = remark;
  434. }
  435. dataArgs["isCustomize"] = 1;
  436. dataArgs["channelType"] = channelType;
  437. dataArgs["channelId"] = channelId;
  438. $.ajax(base_path + '/wechat/order/pay', { // 提交订单,准备支付
  439. data: dataArgs,
  440. dataType: 'json',
  441. type: 'post',
  442. xhrFields: {
  443. withCredentials: true
  444. },
  445. crossDomain: true,
  446. timeout: 15000,
  447. success: function(dt) {
  448. // layer.closeAll();
  449. //mui.alert(dt.resultCode=="500");
  450. if(dt.resultCode == "500") {
  451. mui.alert(dt.message);
  452. isPay = true;
  453. return;
  454. };
  455. if(dt.data.info == "isOK") {
  456. location.href = 'pay-win.html?orderId=' + dt.data.orderId + "&dates=" + new Date().getTime()
  457. return;
  458. };
  459. if(dt.status) {
  460. var str = dt.data.info;
  461. var obj = JSON.parse("{" + str + "}");
  462. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  463. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  464. $.ajax(base_path + '/wechat/order/checkOrderPaySuccess?dates=' + new Date().getTime(), {
  465. data: {
  466. "orderId": dt.data.orderId
  467. },
  468. dataType: 'json',
  469. xhrFields: {
  470. withCredentials: true
  471. },
  472. crossDomain: true,
  473. type: 'get',
  474. timeout: 15000,
  475. success: function(dataobj) {
  476. if(dataobj.isRedirect) {
  477. location.href = dataobj.redirectURL;
  478. } else {
  479. if(dataobj.status == true) { // 支付成功
  480. location.href = "pay-win.html?orderId=" + dataobj.data + "&dates=" + new Date().getTime();
  481. } else {
  482. location.href = "order-details.html?orderId=" + dataobj.data + "&dates=" + new Date().getTime(); // 前往订单详情
  483. }
  484. }
  485. },
  486. error: function(xhr, type, errorThrown) {
  487. console.log(xhr);
  488. }
  489. });
  490. } else {
  491. isPay = true;
  492. mui.alert("对不起,支付失败!请稍后重试!" + dt.data.orderId + "支付失败!", function() {
  493. location.href = "order-details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  494. });
  495. }
  496. });
  497. } else {
  498. isPay = true;
  499. mui.alert(dt.message);
  500. location.href = "order-details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  501. }
  502. },
  503. error: function(xhr, type, errorThrown) {
  504. isPay = true;
  505. // layer.closeAll();
  506. mui.alert("您的网络异常,请刷新重试!");
  507. return;
  508. }
  509. });
  510. } else {
  511. mui.alert("正在请求支付中~~请稍后!");
  512. return;
  513. }
  514. } else {
  515. mui.alert("请选择收货地址!");
  516. return;
  517. }
  518. });
  519. </script>
  520. </body>
  521. </html>