clearing.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. var userIntegral = 0; // 用户可用积分
  2. var meonyProportion = 0; // 兑换比例:1个积分=?分钱
  3. var payTotal = 0.0; // 支付总金额
  4. var userInputIntegral = 0; // 抵扣积分
  5. var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
  6. var cartIdStr = ""; // 购物车ID
  7. var usePayMoney = 0;
  8. var ipt_balance = 0;
  9. var yhq_val = 0;
  10. var used_balance = 0;
  11. var yhq_type = 1;
  12. var showIs = false;
  13. mui.ready(function() {
  14. var name,value;
  15. var str=location.href; //取得整个地址栏
  16. var num=str.indexOf("?")
  17. str=str.substr(num+1); //取得所有参数
  18. $.ajax(base_path+'/order/payBefore?'+str, {
  19. dataType: 'json',
  20. type: 'POST',
  21. timeout: 15000,
  22. xhrFields: {
  23. withCredentials: true
  24. },
  25. crossDomain: true,
  26. success: function(dt) {
  27. if (dt.isRedirect) {
  28. location.href = dt.redirectURL;
  29. } else {
  30. if(dt.status == true) {
  31. // 购物项遍历
  32. //console.log(dt)
  33. var liNote = "";
  34. var cNum = 0;
  35. if(dt.data.balance == 0) {
  36. $(".pay_ipt_box").hide();
  37. } else {
  38. used_balance = accDiv(dt.data.balance, 100);
  39. $('#used_balance').html("¥ " + accDiv(dt.data.balance, 100));
  40. }
  41. var yhq_str = "";
  42. if(dt.data.couponItems.length == 0 || !dt.data.disable) {
  43. $(".forward").hide();
  44. } else {
  45. $("#yhq_count").html(dt.data.couponItems.length);
  46. //如果购买商品只有饮水机滤芯,则不能使用优惠券
  47. if (dt.data.disable) {
  48. mui(dt.data.couponItems).each(function(index) {
  49. yhq_str += '<div class="mui-input-row mui-radio"><label>' + this.couponName + '</label><input name="radio1" value="' + accDiv(this.couponReduce, 100) + '" type="radio" id="' + this.couponItemId + '" yhq_type="' + this.couponType + '"></div>';
  50. });
  51. $(".my-popover").html(yhq_str + '<div class="mui-input-row mui-radio"><label>不使用优惠券</label><input name="radio1" value="1" type="radio"></div>');
  52. }
  53. }
  54. for(var i = 0; i < dt.data.cartItems.length; i++) {
  55. var total = dt.data.cartItems[i].cartNum * dt.data.cartItems[i].productPrice / 100; // 购物车小计,分-->元
  56. var pro_color = switchcolor(dt.data.cartItems[i].cartColorId);
  57. var colorImg = switchColorImg(dt.data.cartItems[i].cartColorId);
  58. total = total.toFixed(2); // 保留两位小数
  59. var productId = dt.data.cartItems[i].cartProductId;
  60. var colorId=dt.data.cartItems[i].cartColorId;
  61. var price = dt.data.cartItems[i].productPrice;
  62. var num = dt.data.cartItems[i].cartNum;
  63. if (dt.data.cartItems[i].productPrice / 100 == 3280) {
  64. liNote = liNote +
  65. "<li class='mui-table-view-cell mui-media'>" +
  66. "<a>" +
  67. "<span class='mui-media-object mui-pull-left wh-100'> <img src='" + colorImg + "'></span>" +
  68. "<div class='mui-media-body'>" +
  69. "<div class='wt-space gwc_tit'>" + dt.data.cartItems[i].productName + "<span class='price_sp cl-gwc mui-pull-right' id='product-" + productId + "' price='" + price + "'>¥" + total + "</span></div>" +
  70. "<small class='gwc_pp'>颜色:" + pro_color + "</small>" +
  71. "<div class='mui-numbox'><button class='mui-btn mui-btn-numbox-minus' onclick='shoppSubEvent(" + productId + ","+colorId+")' type='button'>-</button>" +
  72. "<input class='mui-input-numbox' readonly='readonly' type='tel' id='shoppNum-" + productId + "' value='" + num + "'/>" +
  73. "<button class='mui-btn mui-btn-numbox-plus' onclick='shoppAddEvent(" + productId + ","+colorId+")' type='button'>+</button></div>" +
  74. "</div>" +
  75. "</a>" +
  76. "</li>";
  77. cNum = cNum + num ;
  78. showIs = true;
  79. } else {
  80. liNote = liNote +
  81. "<li class='mui-table-view-cell mui-media'>" +
  82. "<a>" +
  83. "<span class='mui-media-object mui-pull-left wh-100'> <img src='" + colorImg + "'></span>" +
  84. "<div class='mui-media-body'>" +
  85. "<div class='wt-space gwc_tit'>" + dt.data.cartItems[i].productName + "<span class='price_sp cl-gwc mui-pull-right' id='product-" + productId + "' price='" + price + "'>¥" + total + "</span></div>" +
  86. "<small class='gwc_pp'>颜色:" + pro_color + "</small>" +
  87. "<div class='mui-numbox'><button class='mui-btn mui-btn-numbox-minus' onclick='shoppSubEvent(" + productId + ","+colorId+")' type='button'>-</button>" +
  88. "<input class='mui-input-numbox' readonly='readonly' type='tel' id='shoppNum-" + productId + "' value='" + num + "'/>" +
  89. // "<span class='price cl-6'>x" + num + "</span>" +
  90. "<button class='mui-btn mui-btn-numbox-plus' onclick='shoppAddEvent(" + productId + ","+colorId+")' type='button'>+</button></div>" +
  91. "</div>" +
  92. "</a>" +
  93. "</li>";
  94. }
  95. }
  96. if (showIs)
  97. {
  98. liNote = liNote +
  99. "<li class='mui-table-view-cell mui-media'>" +
  100. "<a>" +
  101. "<span class='mui-media-object mui-pull-left wh-100'> <img src='//s.iamberry.com/watero/wechat/images/2C83538AC3039E693358_20161202182946_8118.jpg'></span>" +
  102. "<div class='mui-media-body'>" +
  103. "<div class='wt-space gwc_tit'>" +
  104. '赠送' + "<span id='giveNum'>" + cNum + '</span>' + '套三年滤芯' +
  105. "<span class='price_sp cl-gwc mui-pull-right' id='product-39' price='39'>¥" + 0 + "</span></div>" +
  106. "<small class='gwc_pp'>颜色:" + '无' + "</small>" +
  107. "</div>" +
  108. "</a>" +
  109. "</li>"
  110. }
  111. var $productListUl = $("#products-list-ul");
  112. $productListUl.empty();
  113. $productListUl.append(liNote);
  114. dt.data.userIntegral = dt.data.userIntegral - 1;
  115. // 保存数据
  116. meonyProportion = dt.data.meonyProportion; // 兑换比例
  117. payTotal = dt.data.payTotal; // 支付金额,单位分
  118. userIntegral = dt.data.userIntegral; // 用户可用积分
  119. cartIdStr = dt.data.cartId; // 购物车ID
  120. // 替换数据
  121. usePayMoney = accDiv(dt.data.payTotal, 100);
  122. $("#user-integral-span").html(dt.data.userIntegral);
  123. $("#user-pay-money-span").html(usePayMoney + " 元");
  124. //默认自己拉出地址
  125. if(dt.data.addressInfo != undefined && dt.data.addressInfo != null) {
  126. $("#user-address-div").empty().append(
  127. "收货人:" + dt.data.addressInfo.salesAddressName + "<span class='ml-5'>" + dt.data.addressInfo.salesAddressTel + "</span>" +
  128. "<a>" +
  129. "<p class='shipping_address wt-space'>" + dt.data.addressInfo.salesAddressInfo + "<span class='mui-icon mui-icon-arrowright icon-r-c'></span></p>" +
  130. "</a>");
  131. $("#user-address-div").show();
  132. $("#open-wechat-addres-a").hide();
  133. //给微信参数赋值
  134. wechatAddr.status = true;
  135. wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo;
  136. wechatAddr.userName = dt.data.addressInfo.salesAddressName;
  137. wechatAddr.userTel = dt.data.addressInfo.salesAddressTel;
  138. wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum;
  139. }
  140. } else {
  141. mui.alert(dt.message);
  142. }
  143. }
  144. },
  145. error: function(xhr, type, errorThrown) {
  146. errorfn(xhr);
  147. }
  148. });
  149. // 获取微信共享地址
  150. mui('body').on('tap', '#open-wechat-addres-a,#user-address-div', function() {
  151. editAddrV1(
  152. function(res) {
  153. // 用户成功拉出地址
  154. var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo;
  155. wechatAddr.status = true;
  156. wechatAddr.detailInfo = address;
  157. wechatAddr.postalCode = res.postalCode;
  158. wechatAddr.userName = res.userName;
  159. wechatAddr.userTel = res.telNumber;
  160. wechatAddr.nationalCode = res.nationalCode;
  161. $("#user-address-div").empty().append(
  162. "收货人:" + wechatAddr.userName + "<span class='ml-5'>" + wechatAddr.userTel + "</span>" +
  163. "<a>" +
  164. "<p class='shipping_address wt-space'>" + wechatAddr.detailInfo + "<span class='mui-icon mui-icon-arrowright icon-r-c'></span></p>" +
  165. "</a>");
  166. $("#user-address-div").show();
  167. $("#open-wechat-addres-a").hide();
  168. },
  169. function() {
  170. if($('#user-address-div').html() != null && $('#user-address-div').html() != '') {
  171. wechatAddr.status = true;
  172. } else {
  173. wechatAddr.status = false;
  174. // 用户取消拉出地址
  175. mui.alert("您没有选择收货地址!");
  176. }
  177. }
  178. );
  179. });
  180. // 积分数量改变时
  181. mui('body').on('change', '#input-user-integral', function() {
  182. var inputUserIntegral = $("#input-user-integral").val();
  183. $.trim(inputUserIntegral);
  184. var r = /^[1-9]+\d*$/;
  185. if(!r.test(inputUserIntegral)) {
  186. $("#input-user-integral").val(userInputIntegral);
  187. return false;
  188. }
  189. inputUserIntegral = parseInt(inputUserIntegral);
  190. if(inputUserIntegral > userIntegral) {
  191. $("#input-user-integral").val(userInputIntegral);
  192. return false;
  193. }
  194. if((inputUserIntegral * meonyProportion) > payTotal) {
  195. $("#input-user-integral").val(userInputIntegral);
  196. return false;
  197. }
  198. // 置换数据
  199. userInputIntegral = inputUserIntegral;
  200. var temp = (userInputIntegral * meonyProportion / 100).toFixed(2);
  201. $("#integral-money-span").html(temp);
  202. temp = ((payTotal - (userInputIntegral * meonyProportion)) / 100).toFixed(2);
  203. $("#user-pay-money-span").html(temp);
  204. });
  205. // 去支付
  206. mui('body').on('tap', '.btn-weixin-pay', function() {
  207. var yhq_id = $("input[name=radio1]:checked").attr('id');
  208. if(yhq_id == undefined) {
  209. yhq_id = "";
  210. }
  211. var remark = $("#textarea").val();
  212. var pattern = new RegExp("[ `~!@#$^&*()=|{}':;'\\[\\]<>/?~!@#¥……&*()——|{}【】‘;:”“'、?]")
  213. if(remark != "") {
  214. $.trim(remark);
  215. if(pattern.test(remark)) {
  216. mui.alert("请不要输入中文、字母、数字以外的特殊字符!");
  217. return;
  218. }
  219. if(!(remark.length >= 0 && remark.length <= 100)) {
  220. mui.alert("备注字数长度在0-100之间!");
  221. return;
  222. }
  223. }
  224. if(wechatAddr.status) {
  225. if(isPay) {
  226. isPay = false; // 锁定请求按钮
  227. layer.open({
  228. type: 2,
  229. shadeClose: false,
  230. content: "正在请求加载订单信息..."
  231. }); // 调用加载弹出层
  232. /* 组装数据 */
  233. var dataArgs = {
  234. "orderAddressInfo": wechatAddr.detailInfo,
  235. "orderAddressPostNum": wechatAddr.postalCode,
  236. "orderAddressMoblie": wechatAddr.userTel,
  237. "orderAddressName": wechatAddr.userName,
  238. "cartIdStr": cartIdStr,
  239. "orderIntegralNum": userInputIntegral,
  240. "orderUserRemark": remark,
  241. "couponId": yhq_id,
  242. "balancePayAmount": accMul(ipt_balance, 100)
  243. };
  244. $.ajax('/watero/wechat/order/pay', { // 提交订单,准备支付
  245. data: dataArgs,
  246. dataType: 'json',
  247. type: 'POST',
  248. timeout: 15000,
  249. xhrFields: {
  250. withCredentials: true
  251. },
  252. crossDomain: true,
  253. success: function(dt) {
  254. if (dt.isRedirect) {
  255. location.href = dt.redirectURL;
  256. } else {
  257. layer.closeAll();
  258. //mui.alert(dt.resultCode=="500");
  259. if(dt.resultCode == "500") {
  260. mui.alert(dt.message);
  261. isPay = true;
  262. return;
  263. };
  264. if(dt.data.info == "isOK") {
  265. mui.openWindow({
  266. url: domanUrl + base_path+"/order/paySuccess?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime()
  267. });
  268. return;
  269. };
  270. if(dt.status) {
  271. var str = dt.data.info;
  272. var obj = JSON.parse("{" + str + "}");
  273. WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
  274. if(res.err_msg == 'get_brand_wcpay_request:ok') {
  275. var orderIds = {
  276. "orderId": dt.data.orderId
  277. };
  278. layer.open({
  279. type: 2,
  280. shadeClose: false,
  281. content: "正在请求加载订单信息..."
  282. }); // 调用加载弹出层
  283. var url = base_path+"/order/checkOrderPaySuccess";
  284. $.getJSON(url, {
  285. "s": new Date().getTime(),
  286. "orderId": dt.data.orderId
  287. }, function(data) {
  288. if(data.status == true) { // 支付成功
  289. window.location.href = base_path + "/order/paySuccess?orderId=" + orderIds.orderId + "&dates=" + new Date().getTime();
  290. } else {
  291. setTimeout("checkOrderStatus('" + dt.data.orderId + "')", 1000);
  292. }
  293. });
  294. } else {
  295. isPay = true;
  296. // mui.alert("对不起,支付失败!请稍后重试!" + dt.data.orderId + "支付失败!");
  297. window.location.href = "order_details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  298. }
  299. });
  300. } else {
  301. isPay = true;
  302. mui.alert(dt.message);
  303. window.location.href = "order_details.html?orderId=" + dt.data.orderId + "&dates=" + new Date().getTime(); // 前往订单详情
  304. }
  305. }
  306. },
  307. error: function(xhr, type, errorThrown) {
  308. isPay = true;
  309. layer.closeAll();
  310. mui.alert("您的网络异常,请刷新重试!");
  311. return;
  312. }
  313. });
  314. } else {
  315. mui.alert("正在请求支付中~~请稍后!");
  316. return;
  317. }
  318. } else {
  319. mui.alert("请选择收货地址!");
  320. return;
  321. }
  322. });
  323. mui('body').on('tap', '.mui-popover-action li>a', function() {
  324. var a = this,
  325. parent;
  326. //根据点击按钮,反推当前是哪个actionsheet
  327. for(parent = a.parentNode; parent != document.body; parent = parent.parentNode) {
  328. if(parent.classList.contains('mui-popover-action')) {
  329. break;
  330. }
  331. }
  332. //关闭actionsheet
  333. mui('#' + parent.id).popover('toggle');
  334. yhq_val = $("input[name=radio1]:checked").val();
  335. yhq_type = $("input[name=radio1]:checked").attr("yhq_type");
  336. if(yhq_val == undefined) {
  337. yhq_val = 0
  338. } else {
  339. if(yhq_type == 1) {
  340. if(yhq_val > (usePayMoney - ipt_balance)) {
  341. $("input[name=radio1]:checked").removeAttr("checked");
  342. yhq_val = 0;
  343. mui.alert(' ', '当前优惠券不可用', function() {});
  344. }
  345. $("#yhq_price").html(yhq_val);
  346. $("#accSub,#accSub>div:first-child").show();
  347. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2));
  348. } else {
  349. yhq_val = accSub(usePayMoney, Math.floor(accMul($("input[name=radio1]:checked").val(), usePayMoney) * 100) / 100);
  350. $("#yhq_price").html(yhq_val);
  351. $("#accSub,#accSub>div:first-child").show();
  352. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2));
  353. }
  354. }
  355. });
  356. mui.os.ios ? listener_ipt() : keyup_fn();
  357. var reg = /^(([1-9]\d*))$/;
  358. function keyup_fn() {
  359. $('body').on('blur', '#pay_ipt', function(e) {
  360. ipt_balance = $(this).val();
  361. if(reg.test(ipt_balance)) {
  362. if(ipt_balance > (usePayMoney - yhq_val)) {
  363. ipt_balance = (usePayMoney - yhq_val).toFixed(2);
  364. if(ipt_balance < 0) {
  365. ipt_balance = 0;
  366. $(this).val("");
  367. } else {
  368. $(this).val((usePayMoney - yhq_val).toFixed(2));
  369. }
  370. }
  371. if(ipt_balance > used_balance) {
  372. ipt_balance = used_balance;
  373. $(this).val(used_balance);
  374. }
  375. $('#used_buy').html(ipt_balance);
  376. var money = (usePayMoney - yhq_val).toFixed(2);
  377. money <= 0 ? money = 0 : money;
  378. $("#accSub,#accSub>div:last-child").show();
  379. $("#user-pay-money-span").html((money - ipt_balance).toFixed(2) + " 元");
  380. } else {
  381. mui.alert(' ', '您输入的数字有误,请重新输入', function() {
  382. $(this).val("");
  383. ipt_balance = 0;
  384. $('#used_buy').html(ipt_balance);
  385. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元");
  386. });
  387. }
  388. });
  389. }
  390. function listener_ipt() {
  391. document.getElementById('pay_ipt').onblur = function() {
  392. var th = this;
  393. ipt_balance = th.value;
  394. if(reg.test(ipt_balance)) {
  395. if(ipt_balance > (usePayMoney - yhq_val)) {
  396. ipt_balance = (usePayMoney - yhq_val).toFixed(2);
  397. if(ipt_balance < 0) {
  398. ipt_balance = 0;
  399. th.value = "";
  400. } else {
  401. th.value = (usePayMoney - yhq_val).toFixed(2);
  402. }
  403. }
  404. if(ipt_balance > used_balance) {
  405. th.value = used_balance;
  406. ipt_balance = used_balance;
  407. }
  408. $('#used_buy').html(ipt_balance);
  409. var money = (usePayMoney - yhq_val).toFixed(2);
  410. money <= 0 ? money = 0 : money;
  411. $("#accSub,#accSub>div:last-child").show();
  412. $("#user-pay-money-span").html((money - ipt_balance).toFixed(2) + " 元");
  413. } else {
  414. mui.alert(' ', '您输入的数字有误<br>请重新输入', function() {
  415. th.value = "";
  416. ipt_balance = 0;
  417. $('#used_buy').html(ipt_balance);
  418. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元");
  419. });
  420. }
  421. }
  422. }
  423. document.querySelector('.loading-bg').style.display = 'none';
  424. });
  425. // 校验订单状态
  426. function checkOrderStatus(orderId) {
  427. var url = base_path + "/order/checkOrderPaySuccess";
  428. var order = {
  429. "s": new Date().getTime(),
  430. "orderId": orderId
  431. };
  432. $.getJSON(url, order, function(data) {
  433. if(data.status == true) { // 支付成功
  434. window.location.href = base_path + "/order/paySuccess?orderId=" + orderId + "&dates=" + new Date().getTime();
  435. } else {
  436. window.location.href = 'order_details.html?orderId=' + orderId + "&dates=" + new Date().getTime();;
  437. }
  438. });
  439. }
  440. // 点击加号的事件
  441. function shoppAddEvent(productId,colorId) {
  442. $.ajax(base_path + '/cart/addCart', {
  443. data: {
  444. "productId": productId,
  445. "carNum": 1,
  446. "colorId":colorId
  447. },
  448. dataType: 'json',
  449. type: 'GET',
  450. timeout: 15000,
  451. xhrFields: {
  452. withCredentials: true
  453. },
  454. crossDomain: true,
  455. success: function(dt) {
  456. if (dt.isRedirect) {
  457. location.href = dt.redirectURL;
  458. } else {
  459. if(dt.status == true) {
  460. // 销售价
  461. var productObj = $("#product-" + productId);
  462. var price = parseInt(productObj.attr("price"));
  463. // total
  464. var total = payTotal + price;
  465. payTotal = total;
  466. // 修改数量
  467. var shoppNumObj = $("#shoppNum-" + productId);
  468. var num = parseInt(shoppNumObj.val());
  469. shoppNumObj.val(num + 1);
  470. /* $("#user-pay-money-span").html((payTotal / 100).toFixed(2)); */
  471. yhq_val = $("input[name=radio1]:checked").val();
  472. yhq_type = $("input[name=radio1]:checked").attr("yhq_type");
  473. usePayMoney = accDiv(payTotal, 100);
  474. if(yhq_val == undefined) {
  475. yhq_val = 0
  476. }
  477. if(yhq_type == 2) {
  478. yhq_val = accSub(usePayMoney, (Math.floor(accMul(yhq_val, usePayMoney) * 100) / 100));
  479. $("#yhq_price").html(accSub(usePayMoney, Math.floor(accMul($("input[name=radio1]:checked").val(), usePayMoney) * 100) / 100));
  480. }
  481. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元");
  482. // 修改小计
  483. productObj.html("¥" + ((num + 1) * price / 100).toFixed(2));
  484. var temp = new Number($("#shoppNum-all").val());
  485. temp = temp + 3;
  486. $("#shoppNum-all").val(temp);
  487. if(showIs){
  488. var gNum = $("#giveNum").html();
  489. var rNum = parseInt(gNum) + 1;
  490. $("#giveNum").html(rNum);
  491. }
  492. } else {
  493. // 失败之后的事件
  494. mui.alert(dt.message);
  495. }
  496. }
  497. },
  498. error: function(xhr, type, errorThrown) {}
  499. });
  500. }
  501. // 购物车减
  502. function shoppSubEvent(productId,colorId) {
  503. var shoppNumObj = $("#shoppNum-" + productId);
  504. var num = parseInt(shoppNumObj.val());
  505. if(num <= 1) {
  506. mui.alert("不能继续减少了哦!");
  507. return;
  508. }
  509. $.ajax(base_path + '/cart/deleteCart', {
  510. data: {
  511. "productId": productId,
  512. "cartNum": 1,
  513. "colorId":colorId
  514. },
  515. dataType: 'json',
  516. type: 'GET',
  517. timeout: 15000,
  518. xhrFields: {
  519. withCredentials: true
  520. },
  521. crossDomain: true,
  522. success: function(dt) {
  523. if (dt.isRedirect) {
  524. location.href = dt.redirectURL;
  525. } else {
  526. if(dt.status == true) {
  527. // 销售价
  528. var productObj = $("#product-" + productId);
  529. var price = parseInt(productObj.attr("price"));
  530. // total
  531. var total = payTotal - price;
  532. payTotal = total;
  533. // 修改数量
  534. var shoppNumObj = $("#shoppNum-" + productId);
  535. var num = parseInt(shoppNumObj.val());
  536. shoppNumObj.val(num - 1);
  537. /*$("#user-pay-money-span").html((payTotal / 100).toFixed(2));*/
  538. yhq_val = $("input[name=radio1]:checked").val();
  539. yhq_type = $("input[name=radio1]:checked").attr("yhq_type");
  540. usePayMoney = accDiv(payTotal, 100);
  541. if(yhq_val == undefined) {
  542. yhq_val = 0
  543. }
  544. if(yhq_type == 2) {
  545. yhq_val = accSub(usePayMoney, Math.floor(accMul(yhq_val, usePayMoney) * 100) / 100);
  546. $("#yhq_price").html(accSub(usePayMoney, Math.floor(accMul($("input[name=radio1]:checked").val(), usePayMoney) * 100) / 100));
  547. if(ipt_balance > (usePayMoney - yhq_val)) {
  548. if((usePayMoney - yhq_val) <= 0) {
  549. ipt_balance = 0;
  550. $('#used_buy').html(ipt_balance);
  551. $('#pay_ipt').val("");
  552. } else {
  553. ipt_balance = (usePayMoney - yhq_val).toFixed(2);
  554. $('#used_buy').html(ipt_balance);
  555. $('#pay_ipt').val(ipt_balance);
  556. }
  557. }
  558. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元");
  559. } else {
  560. if((usePayMoney - yhq_val) < ipt_balance) {
  561. if((usePayMoney - yhq_val) <= 0) {
  562. ipt_balance = 0;
  563. $('#used_buy').html(ipt_balance);
  564. $('#pay_ipt').val("");
  565. } else {
  566. ipt_balance = (usePayMoney - yhq_val).toFixed(2);
  567. $('#used_buy').html(ipt_balance);
  568. $('#pay_ipt').val(ipt_balance);
  569. }
  570. }
  571. if(yhq_val > (usePayMoney - ipt_balance)) {
  572. mui.alert(' ', '当前优惠券不可用', function() {
  573. $("input[name=radio1]:checked").removeAttr("checked");
  574. yhq_val = 0;
  575. $("#yhq_price").html(yhq_val);
  576. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元");
  577. });
  578. }
  579. $("#user-pay-money-span").html((usePayMoney - yhq_val - ipt_balance).toFixed(2) + " 元");
  580. }
  581. var temp = new Number($("#shoppNum-all").val());
  582. temp = temp - 3;
  583. $("#shoppNum-all").val(temp+"")
  584. productObj.html("¥" + ((num - 1) * price / 100).toFixed(2));
  585. if(showIs){
  586. var gNum = $("#giveNum").html();
  587. var rNum = parseInt(gNum) - 1;
  588. $("#giveNum").html(rNum);
  589. }
  590. } else {
  591. mui.alert(dt.message);
  592. }
  593. }
  594. },
  595. error: function(xhr, type, errorThrown) {
  596. errorfn(xhr);
  597. }
  598. });
  599. }