<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>结算</title>
		<link rel="stylesheet" type="text/css" href="css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="css/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="css/main.css" />
		<style>
			input[type="checkbox"] {
				/*pointer-events: none;*/
			}
			.mui-switch {
				background: #bbb;
				height: 20px;
				border: 1px solid #bbb;
				padding: 0 5px;
			}

			.mui-switch:before {
				content: '';
			}

			.mui-switch.mui-active:before {
				content: '';
			}

			.mui-switch .mui-switch-handle {
				top: -6px;
				width: 30px;
				height: 30px;
				margin-left: 2px;
			}

			.clearing-box .mui-table-view-cell.mui-active,
			.mui-navigate-right.mui-active {
				background: #fff !important;
			}

			.mui-switch.mui-active {
				background: #79b3f3;
				border-color: #79b3f3;
			}

			.clearing-box .mui-table-view-cell {
				border-bottom: 8px solid #f2f2f2;
			}

			.clearing-box .mui-table-view-cell:after,
			.my-view-no-top:after {
				left: 0;
				display: none;
			}

			.shopping-cart-list {
				border-bottom: 8px solid #f2f2f2;
			}

			.clearing-box {
				margin: 0;
				padding-bottom: 0;
			}

			.icon-dingwei {
				font-size: 22px;
				color: #e06974;
			}
			.my-view-no-top .mui-navigate-right:after{
				right: 7px;
			}
		</style>
		<script type="text/javascript">
			// 屏蔽分享
			window.hiddenAllWechatMenu = true;
		</script>
	</head>

	<body style="background: #f2f2f2;">
		<div class="loading-bg">
			<div class="mui-loading">
				<div class="mui-spinner">
				</div>
				&nbsp;&nbsp;加载中...
			</div>
		</div>
		<div class="mui-content">
			<div style="padding:0 14px 0 14px;background-color: #fff;text-align: center;border-bottom:8px solid #f2f2f2;">
				<ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed">
					<li class="mui-table-view-cell" style="background-color: #fff;border-radius: 5px;padding: 11px 8px;">
						<div class="mui-table" id="user-address-div" style="height: 80px;">
							<div class="mui-table-cell mui-col-xs-12 table-middle" style="display: table-cell;">
								<div class="btn-add-address"><span class="iconfont icon-jia"></span>添加收货地址</div>
							</div>
							<!--<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>收货人:林笑笑 <span class="mui-pull-right">16899996678</span></div>
								<p>收货地址:广东省深圳市福田区莲花街道深圳特区 报业大厦12b</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>
					</li>
				</ul>
			</div>
			<ul class="mui-table-view mui-table-view-striped my-grid-view-no mui-table-view-condensed shopping-cart-list">

			</ul>
			<div class="clearing-box">

				<ul class="mui-table-view my-view-no-top">
					<li class="mui-table-view-cell" id="ul-youhuiquan" style="display: none;">
						<a class="mui-navigate-right btn-youhuiquan">
							优惠券<span class="mui-pull-right cl-red" style="margin-right: 10px;display: none;">-¥0.0</span>
						</a>
					</li>
					<li class="mui-table-view-cell show_integral">
						可用积分 <span style="margin-left: 10px;" class="integral_num">0</span>,抵扣¥<span class="integral_money">0</span>
						<!-- 开关打开状态,多了一个.mui-active类 -->
						<div class="mui-switch mui-switch-mini mui-active" id="mySwitch">
							<div class="mui-switch-handle"></div>
						</div>
					</li>
					<li class="mui-table-view-cell show_vip_zengsong" style="display: none;">
						会员首次购买单支滤芯产品赠送同款滤芯
					</li>
					<li class="mui-table-view-cell show_vip_youhui" style="display: none;">
						会员购买滤芯产品享88折优惠,购买其他产品享95折优惠
					</li>
					<li class="mui-table-view-cell" style="margin-bottom: 60px;">
						<div class="mui-input-row">
							<label style="width:20%;padding:13px 0;">订单备注</label>
							<input style="width: 79%;font-size: 12px;" maxlength="140" id="textarea" type="text" placeholder="您对订单有特殊要求,可以在此备注" />
						</div>
						<!--<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>-->
						<p id="tips" style="text-align: right"></p>
					</li>
				</ul>
				<!-- <div style="padding:14px 14px 50px 14px;font-size: 12px;color: #999;background: #f2f2f2;">由于购买人数较多,下单后,订单将会按下单顺序依次发货,敬请谅解</div> -->
			</div>

			<div class="buy-footer1">
				<table class="tb-clearing">
					<tr>
						<td class="quanxuan">
							共<span class="cl-red"><span id="pro-count">0</span>件</span>商品
						</td>
						<td class="mui-text-center">合计:<span class="count_price_box">¥<span class="count_price">0.00</span></span>元</td>
						<td>
							<a id="go-pay" class="mui-btn mui-pull-right add_gwc">立即支付</a>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery-2.1.1.min.js"></script>
		<script src="js/main.js"></script>
		<script src="js/wechat-utils-1.0.js"></script>
		<script>
			var userIntegral = 0; // 用户可用积分
			var meonyProportion = 0; // 兑换比例:1个积分=?分钱
			var payTotal = 0.0; // 支付总金额
			var userInputIntegral = 0; // 抵扣积分
			var isPay = true; // 是否在请求支付,false表示正在请求,true可以请求
			var cartIdStr = ""; // 购物车ID
			var usePayMoney = 0;
			var ipt_balance = 0;
			var yhq_val = 0;
			var used_balance = 0;
			var yhq_type = 1;
			var yhq_id = '';
			var userIntegralUsed = 1; // 是否使用积分  1:使用   2:不使用
			var userIsVip = 1; // 是否为vip :1:非vip  2:vip
			var useCouponPrizeColorId = 0; // 
			mui.ready(function() {
				var parameter = {}; //ajax参数json集合
				var cartidList = '';
				if(!window.sessionStorage) {
					mui.alert("您的浏览器不支持sessionStorage");
				} else {
					//读取上一个页面带过来的sessionStorage
					pay_data = JSON.parse(sessionStorage.getItem('pay_data'));
					if(pay_data != null) {
						cartidList = pay_data.text[0]; //购物项id集合
						parameter["cartIds"] = cartidList;
						$.ajax(base_path + '/wechat/order/payBefore', {
							data: parameter,
							dataType: 'json',
							type: 'POST',
							xhrFields: {
								withCredentials: true
							},
							crossDomain: true,
							timeout: 15000,
							success: function(dt) {
								if(dt.isRedirect) {
									location.href = dt.redirectURL;
								} else {
									console.log(dt);
									if(dt.status == true) {
										// 购物项遍历
										console.log(dt)
										var liNote = "";
										var yhq_str = "";
										payTotal = dt.data.payTotal; // 支付金额,单位分

										var hasPrize = false;	//判断订单项中是否含有滤芯
										var hasKqjhq = false;	//判断订单项中是否含有空气净化器
										mui.each(dt.data.cartItems, function(index) {
											var num = this.cartNum;
											var total = (num * this.productDiscount / 100).toFixed(2); //购物车小计,单位分,保留两位小数
											var productId = this.cartProductId;
											var zeng = '';
											if(typeof(this.salesUserGiftList) != "undefined") {
												$.each(this.salesUserGiftList, function() {
													zeng += this.giftName + '*' + (num * this.userGiftCount) + '件 '
												});
											}
											if(zeng != '') {
												zeng = '<p style="font-size:12px;">(赠品:' + zeng + ')</p>';
											}
											if(this.colorType == 3){
												hasPrize = true;
											}
											if(this.cartColorId == 58){
												hasKqjhq = true;
											}
											liNote += '<li class="mui-table-view-cell" colorId="'+ this.cartColorId +'" colorType="'+ this.colorType +'" productDiscount="'+ this.productDiscount +'" num="'+ this.cartNum +'"><div class="mui-table"><div class="mui-table-cell mui-col-xs-4"><img class="mui-media-object wh-100" src="' + this.productIntroduceImg + '"></div><div class="mui-table-cell table-middle mui-col-xs-8" style="line-height:2.5"><div class="li_product">' + this.productName + '</div><h6><span class="center" style="line-height: 15px;">颜色:' + this.productColor + '</span></br><span class="center color_num" style="line-height: 15px;">数量:' + num + '</span></h6><div>单价 ¥<span class="li_discount">' + (this.productDiscount / 100).toFixed(2) + '</span></div></div></div><div>' + zeng + '</div></li>';
										});
										
										var selectcounpon = false;
										if(dt.data.couponItems.length > 0) {
											$("#ul-youhuiquan").show();
											//console.log("有优惠券" + dt.data.couponItems.length + "张")
											var str = '';
											mui.each(dt.data.couponItems, function(index) {
												var opacity = 1,
													checked = 'checked',
													disabled = '';
												if(selectcounpon){
													checked = ''
												}
												if(payTotal < this.couponConsumeEnough && this.couponId != 40001) {
													checked = '';
													disabled = 'disabled="disabled"';
												}
												var couponReduce =  this.couponName;
												var valCouponReduce = (this.couponReduce / 100).toFixed(2) 
												
												switch (this.couponId){
													case 40001:
														if(!hasPrize){
															disabled = 'disabled="disabled"'
															checked = '';
														}
														break;
													case 50001:
													case 50000:
														if(!hasKqjhq){
															disabled = 'disabled="disabled"'
															checked = '';
														}
														break
													default:
														break
												}
												
												if(checked!=''){
													selectcounpon = true;
												}
												if(isEmpty(disabled)){
													opacity = 0.5
												}
												str += '<li class="my-table-view-cell" style="opacity:' + opacity + '" ><div class="mui-table"><div class="mui-table-cell table-middle mui-col-xs-11">' + couponReduce + '<h6>有效期至:' + this.couponUseEndDate + '</h6></div><div class="mui-table-cell table-middle mui-col-xs-1"><input name="checkbox" val="' + valCouponReduce + '" type="checkbox" ' + checked + ' ' + disabled + ' class="mui-pull-left" id="' + this.couponItemId + '" couponId="'+ this.couponId +'" coupontype="'+ this.couponType+'" couponname="'+ this.couponName+'" /></div></div></li>';
											});
											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>';
											$("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>');
										}
										
										var $productListUl = $(".shopping-cart-list");
										$productListUl.empty();
										$productListUl.append(liNote);
										// 保存数据

										cartIdStr = dt.data.cartId; // 购物车ID

										userIsVip = dt.data.userIsVip;
										userIntegral = dt.data.userIntegral; // 用户可用积分
										//计算积分能换算的钱
										var myUserIntegral =  0;
										if(dt.data.userIsVip == 2 && dt.data.userIntegral >= 10){
											$('.show_integral').show();
											//积分赋值
											$('.integral_num').text(dt.data.userIntegral);
											var myUserIntegral = dt.data.userIntegral;
											myUserIntegral = parseInt(accDiv(myUserIntegral, 10));
											userIntegralUsedNumber = myUserIntegral
											$('.integral_money').text(myUserIntegral)
										}else{
											$('.show_integral').hide();
											userIntegralUsed = 2;
										}
										
										if(dt.data.hasPreFerential){
											$('.show_vip_zengsong').show();
										}
										
										//默认自己拉出地址
										if(dt.data.addressInfo != undefined && dt.data.addressInfo != null) {
											$(".btn-add-address").parent().hide();
											$("#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>');
											//给微信参数赋值
											wechatAddr.status = true;
											wechatAddr.detailInfo = dt.data.addressInfo.salesAddressInfo;
											wechatAddr.userName = dt.data.addressInfo.salesAddressName;
											wechatAddr.userTel = dt.data.addressInfo.salesAddressTel;
											wechatAddr.postalCode = dt.data.addressInfo.salesAddressPostnum;
										}

										$("#pro-count").text(dt.data.cartItems.length);
										
										setMoney();
									} else {
										mui.alert(dt.message, function() {
											location.href = "shopping-cart.html?dates=" + new Date().getTime(); // 前往购物车
										});
									}
								}
							},
							error: function(xhr, type, errorThrown) {
								console.log(xhr);
								mui.alert("获取数据失败,网络错误!")
							}
						});
					} else {
						mui.alert("sessionStorage异常!", function() {
							location.href = "index.html";
						})
					}
				}
				document.querySelector('.loading-bg').style.display = 'none';

			});
			//callback为用户点击蒙版时自动执行的回调;
			var mask = mui.createMask(function() {
				$(".my-picker").removeClass("active");
			});
			//点击弹出优惠券列表
			$(document).on('tap', '.btn-youhuiquan', function() {
				mask.show();
				$(".my-picker").addClass("active");
			});
			//选择优惠券
			$(document).on('click', '.my-picker input[name=checkbox]', function() {
				var th = $(this);
				if(th.prop("checked")) {
					// th.parent().parent().parent().siblings().css("opacity", .5).find("input").prop("checked", false);
					// th.parent().parent().parent().css("opacity", 1);
					
					th.parent().parent().parent().siblings().find("input").prop("checked", false);
					$('.my-btn-buy-know').removeAttr("disabled");
				} else {
					th.parent().parent().parent().css("opacity", .5);
					$('.my-btn-buy-know').attr("disabled", "disabled");
				}
			});
			//确认使用优惠券
			$(document).on('tap', '.my-btn-buy-know', function() {
				console.log("确认使用");
				yhq_id = $("input[name=checkbox]:checked").attr('id');
				
				// var cout = 0;
				// if(typeof(yhq_id) != "undefined") {
				// 	if(!isEmpty(yhq_id)){
				// 		$(".btn-youhuiquan>span").text("").show();
				// 	}else{
				// 		$(".btn-youhuiquan>span").text("-¥" + $("input[name=checkbox]:checked").attr("val")).show();
				// 	}
				// 	cout = $("input[name=checkbox]:checked").attr("val");
				// }
				$(".my-picker").removeClass("active");
				$(".mui-backdrop").css("opacity", 0).remove();
				
				setMoney();
				// var count_price = payTotal - cout * 100;
				// if(count_price <= 0) {
				// 	count_price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
				// }
				// $(".count_price").text((count_price / 100).toFixed(2));
			});
			// 获取微信共享地址
			$(document).on('tap', '#user-address-div', function() {
				editAddrV1(
					function(res) {
						// 用户成功拉出地址
						var address = res.provinceName + "-" + res.cityName + "-" + res.countryName + "-" + res.detailInfo;
						wechatAddr.status = true;
						wechatAddr.detailInfo = address;
						wechatAddr.postalCode = res.postalCode;
						wechatAddr.userName = res.userName;
						wechatAddr.userTel = res.telNumber;
						wechatAddr.nationalCode = res.nationalCode;
						$("#user-address-div .addr").remove();
						$(".btn-add-address").parent().hide();
						$("#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>');
					},
					function() {
						if($('#user-address-div .addr').html() != null && $('#user-address-div .addr').html() != '') {
							wechatAddr.status = true;
						} else {
							wechatAddr.status = false;
							// 用户取消拉出地址
							mui.alert("您没有选择收货地址!");
						}
					}
				);

			});
			// 去支付
			$(document).on('tap', '#go-pay', function() {
				var couponTypeId = $("input[name=checkbox]:checked").attr('couponid');
				if(!isEmpty(couponTypeId)){
					couponTypeId = '';
					useCouponPrizeColorId = 0;
				}else{
					couponTypeId = parseInt(couponTypeId);
				}	
				var remark = $("#textarea").val();
				var ch_en_num = /^[A-Za-z0-9 _\[\]\【\】\{\}\{\}\(\)\(\)\《\》\<\>\,\,\.\。\、\!\!\~\·\@\#\¥\$\%\^\…\&\—\:\:\;\;\‘\’\'\'\"\"\“\”\?\?\-\=\|\*\+\-\u4e00-\u9fa5]{0,100}$/;
				if(ch_en_num.test(remark)) {
					console.log("备注验证通过")
				} else {
					mui.alert("备注格式错误!仅支持中/英文,数字,普通符号");
					return false;
				}
				if(wechatAddr.status) {
					if(isPay) {
						var orderIntegralNum = 0;
						if(userIntegralUsed == 1){
							orderIntegralNum = $('.integral_money').text();
							orderIntegralNum = accMul(orderIntegralNum,10)
						}

						isPay = false; // 锁定请求按钮

						/* 组装数据 */
						var dataArgs = {
							"orderAddressInfo": wechatAddr.detailInfo,
							"orderAddressPostNum": wechatAddr.postalCode,
							"orderAddressMoblie": wechatAddr.userTel,
							"orderAddressName": wechatAddr.userName,
							"cartIdStr": cartIdStr,
							"orderIntegralNum": orderIntegralNum,
							"orderUserRemark": remark,
							"couponId": yhq_id,
							"useCouponPrizeColorId": useCouponPrizeColorId,
							"couponTypeId": couponTypeId,
							"balancePayAmount": 0
						};

						$.ajax(base_path + '/wechat/order/pay', { // 提交订单,准备支付
							data: dataArgs,
							dataType: 'json',
							type: 'POST',
							xhrFields: {
								withCredentials: true
							},
							crossDomain: true,
							timeout: 15000,
							success: function(dt) {
								//						layer.closeAll();

								//mui.alert(dt.resultCode=="500");
								if(dt.resultCode == "500") {
									mui.alert(dt.message);
									isPay = true;
									return;
								};
								if(dt.data.info == "isOK") {
									location.href = 'pay-win.html?orderId=' + dt.data.orderId + "&dates=" + new Date().getTime();
									return;
								};
								var orderId = dt.data.orderId;
								if(dt.status) {
									var str = dt.data.info;
									var obj = JSON.parse("{" + str + "}");
									WeixinJSBridge.invoke('getBrandWCPayRequest', obj, function(res) {
										//console.log(res)
										if(res.err_msg == 'get_brand_wcpay_request:ok') {
											$.ajax(base_path + '/wechat/order/checkOrderPaySuccess?dates=' + new Date().getTime(), {
												data: {
													"orderId": orderId
												},
												dataType: 'json',
												xhrFields: {
													withCredentials: true
												},
												crossDomain: true,
												type: 'get',
												timeout: 15000,
												success: function(dataobj) {
													if(dataobj.isRedirect) {
														location.href = dataobj.redirectURL;
													} else {
														if(dataobj.status == true) { // 支付成功
															location.href = "pay-win.html?orderId=" + orderId + "&dates=" + new Date().getTime();
														} else {
															location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
														}
													}
												},
												error: function(xhr, type, errorThrown) {
													console.log(xhr);
													isPay = true;
													mui.alert("支付失败!网络错误");
												}
											});
											//									var orderIds = {
											//										"orderId": dt.data.orderId
											//									};
											//									var url =base_path+"/wechat/order/checkOrderPaySuccess";
											//									$.getJSON(url, {
											//										"s": new Date().getTime(),
											//										"orderId": dt.data.orderId
											//									}, function(data) {
											//										if(data.status == true) { // 支付成功
											//											location.href = "pay-win.html?orderId=" + orderIds.orderId + "&dates=" + new Date().getTime();
											//										} else {
											//											setTimeout("checkOrderStatus('" + dt.data.orderId + "')", 1000);
											//										}
											//									});
										} else {
											isPay = true;
											mui.alert("支付失败!请稍后重试!", function() {
												location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
											});
										}
									});
								} else {
									isPay = true;
									mui.alert(dt.message);
									location.href = "order-details.html?orderId=" + orderId + "&dates=" + new Date().getTime(); // 前往订单详情
								}
							},
							error: function(xhr, type, errorThrown) {
								isPay = true;
								//						layer.closeAll();
								mui.alert("您的网络异常,请刷新重试!");
								return;
							}
						});
					} else {
						mui.alert("正在请求支付中~~请稍后!");
						return;
					}
				} else {
					mui.alert("请选择收货地址!");
					return;
				}
			});
			//实时监听文本框字数
			document.getElementById("textarea").addEventListener("input", function() {
				if(this.value.length > 140) {
					$("#tips").text("超出长度" + (this.value.length - 140) + "字");
				} else {
					$("#tips").text("还可输入" + (140 - this.value.length) + "字");
				}
			});
			// 积分开关事件
			document.getElementById("mySwitch").addEventListener("toggle", function(e) {
				if(e.detail.isActive) {
					// console.log("你启动了开关");
					userIntegralUsed = 1;
					setMoney()
				} else {
					// console.log("你关闭了开关");
					userIntegralUsed = 2;
					setMoney()
				}
			})
			
			function setMoney(){
				// var count_price = payTotal;
				
				var count_price = 0;
				
				//空气净化器数量
				var kqjhj_amount_50000 = 0;
				
				//获取优惠券类型id
				var couponid = parseInt($("input[name=checkbox]:checked").attr('couponid'));
				
				//1、购买除滤芯外产品,下单享受95折   2、购买滤芯产品,下单享受88折
				if(userIsVip == 2 && couponid != 40001 && couponid != 50000 && couponid != 50001){
					$('.shopping-cart-list').find(".mui-table-view-cell").each(function(){
						var colortype = $(this).attr('colortype');
						var productdiscount = $(this).attr('productdiscount');
						var num = $(this).attr('num');
						if(colortype == 1){
							productdiscount = accMul(productdiscount,0.95); 
							count_price += accMul(productdiscount,num); 
						}else if(colortype == 2 || colortype == 3){
							productdiscount = accMul(productdiscount,0.88);
							count_price += accMul(productdiscount,num); 
						}else{
							count_price += accMul(productdiscount,num); 
						}
					})
					$(".show_vip_youhui").show();		//展示滤芯88折,水机95折
				}else{
					$(".show_vip_youhui").hide();	//隐藏滤芯88折,水机95折
					$('.shopping-cart-list').find(".mui-table-view-cell").each(function(){
						var productdiscount = $(this).attr('productdiscount');
						var num = $(this).attr('num');
						count_price += accMul(productdiscount,num); 
					})
					
					$(".shopping-cart-list").find('li').each(function(){
						var colorId = $(this).attr("colorId");
						var num = $(this).attr("num");
						var discount = $(this).attr("productdiscount");
						discount = accDiv(discount,100);
						var amount = accMul(discount,num);
						
						//空气净化器处理
						if(colorId == 58){
							kqjhj_amount_50000 = accAdd(amount,kqjhj_amount_50000);
						}
						
					})
				}
				
				//优惠券
				var cout = 0;
				yhq_id = $("input[name=checkbox]:checked").attr('id')
				console.log(yhq_id)
				if(typeof(yhq_id) != "undefined") {
					if(!isEmpty(yhq_id)){
						$(".btn-youhuiquan>span").text("").show();
						$(".prize_color").hide();
						useCouponPrizeColorId=0;
					}else{
						if(couponid != 40001){
							var couponType = $("input[name=checkbox]:checked").attr("coupontype");
							if(couponType == 1){
								$(".btn-youhuiquan>span").text("-¥" + $("input[name=checkbox]:checked").attr("val")).show();
								cout = $("input[name=checkbox]:checked").attr("val");
							}else if(couponType == 2){
								$(".btn-youhuiquan>span").text($("input[name=checkbox]:checked").attr("couponname")).show();
								var redu = $("input[name=checkbox]:checked").attr("val")
								redu = accAdd(1,-redu);
								
								if(couponid == 50000 || couponid == 50001){
									if(kqjhj_amount_50000 > 0){
										cout = accMul(kqjhj_amount_50000,redu);
									}
								}
								
							}
							//隐藏掉兑换滤芯的一系列操作
							useCouponPrizeColorId = 0;
							$(".prize_color").hide();
						}else{
							if(useCouponPrizeColorId == 0){
								var colortype,colorId,productdiscount;
								var flag = false;
								var html = '';
								$(".shopping-cart-list").find('li').each(function(){
									colortype = $(this).attr("colortype");
									if(colortype == 3){
										colorId = $(this).attr("colorId");
										productdiscount = $(this).attr("productdiscount");
										productdiscount = accDiv(productdiscount,100)
										useCouponPrizeColorId = colorId
										flag = true;
										html = $(this).html();
									}
								})
								if(flag){
									$(".shopping-cart-list").append('<li class="mui-table-view-cell prize_color" colorid="'+ colorId +'" colortype="'+ colortype +'" productdiscount="'+ accMul(productdiscount,100) +'" num="1">'+ html +'</li>');
									var productName = $(".prize_color").find('.li_product').html()
									$(".prize_color").find('.li_product').html('【赠送】'+productName);
									$(".prize_color").find('.li_discount').html(0);
									$(".prize_color").attr('productdiscount',0);
									$(".btn-youhuiquan>span").text("赠送一个滤芯").show();
									$("input[name=checkbox]:checked").attr("val",0);
									$(".prize_color").find('.color_num').html('数量:1');
									// 
								}
							}else{
								$(".prize_color").show();
								$(".btn-youhuiquan>span").text("赠送一个滤芯").show();
								$("input[name=checkbox]:checked").attr("val",0);
							}
						}
					}
				}
				count_price = count_price - accMul(cout,100);
				if(count_price <= 0) {
					count_price = 0.0; //判断商品价格减去现金券价格若<0 则显示0
				}
				
				//最后使用积分
				if(userIntegralUsed == 1){
					// myUserIntegral = parseInt(accDiv(userIntegral, 10));
					// var nowPrice = accDiv(count_price,100)
					// if(myUserIntegral > nowPrice){
					// 	myUserIntegral = nowPrice
					// }
					// $('.integral_money').text(myUserIntegral)
					
					var integral = $('.integral_money').text();
					var nowPrice = parseInt(accDiv(count_price,100))
					
					if(parseInt(integral) > nowPrice){
						$('.integral_money').text(nowPrice)
						$('.integral_num').text(accMul(nowPrice,10))
						integral = nowPrice;
					}
					count_price = count_price - accMul(integral,100);
				}
				
				$(".count_price").text(accDiv(count_price,100));
				
			}
		</script>
	</body>

</html>