//$('.pay_info  .row_left').eq(0).html('桔子链账号');
var wxChannel = null; // 微信支付
var aliChannel = null; // 支付宝支付  
var channel = null; //支付通道 
mui.init();
mui.plusReady(function() {
	window.addEventListener('setAddress', function(e) {
		var addressId = localStorage.getItem('addressId') ? localStorage.getItem('addressId') : 0;
		if (addressId == 0) {
			return;
		}
		mui.ajax(hyhUrl('app/useraddress/getById'), {
			data: {
				addressId: addressId
			},
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒；  
			success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
				data = toJson(data);
				if (data.status == 1) {
					data = data.data;
					//					for(i in data.data){
					//						//console.log(i)
					//						//console.log(data.data[i])
					//					}
					var html =
						'<div class="add_l"><img src="../img/dingwei1.png" /></div><div class="add_r"><div class="add_r_t clearfix"><div class="add_r_t_l">收货人：' +
						data.userName + '</div><div class="add_r_t_r">' + data.userPhone +
						'</div></div><div class="add_r_b">收货地址：' + data.areaName + ' ' + data.userAddress + '</div></div>';
					$('.address').html(html);
					$('.address').attr('data-addressId', data.addressId);
					$('.address').attr('data-areaId', data.areaId2);

				} else {
					mui.alert(data.msg);
					//							location.reload();
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理；  
				//																mui.alert(type);      
			}
		});
	});

	$('.con').on('tap', '.address', function() {
		var addressId = $(this).attr('data-addressId');
		localStorage.setItem('addressId', addressId);
		var isOrder = true;
		mui.openWindow({
			url: 'setting_address.html',
			id: 'setting_address.html',
			styles: {
				top: '0px', //新页面顶部位置
				bottom: '0px', //新页面底部位置
				width: '100%', //新页面宽度，默认为100%
				height: '100%' //新页面高度，默认为100%
			},
			extras: {
				data_addressId: addressId,
				data_isOrder: isOrder

				//						data_href: data_href
				//					..... //自定义扩展参数，可以用来处理页面间传值
			},
			createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
			show: {
				//					autoShow: true, //页面loaded事件发生后自动显示，默认为true
				//					aniShow: animationType, //页面显示动画，默认为”slide-in-right“；
				//					duration: animationTime, //页面动画持续时间，Android平台默认100毫秒，iOS平台默认200毫秒；
				//					event: 'titleUpdate', //页面显示时机，默认为titleUpdate事件时显示
				//					extras: {} //窗口动画是否使用图片加速
			},
			waiting: {
				autoShow: true, //自动显示等待框，默认为true
				title: '正在加载...', //等待对话框上显示的提示内容
				options: {
					//						width: waiting - dialog - widht, //等待框背景区域宽度，默认根据内容自动计算合适宽度
					//						height: waiting - dialog - height, //等待框背景区域高度，默认根据内容自动计算合适高度
					//						......
				}
			}
		})

	})
	//支付插件
	plus.payment.getChannels(function(channels) {
		for (var i in channels) {
			if (channels[i].id == "wxpay") {
				wxChannel = channels[i];
			} else {
				aliChannel = channels[i];
			}
		}
	}, function(e) {
		mui.alert("获取支付通道失败：" + e.message);
	});
	//				var ALIPAYSERVER = 'http://demo.dcloud.net.cn/helloh5/payment/alipay.php?total=';
	var ALIPAYSERVER = hyhUrl('app/Alipays/toAlipay?isBatch=1&orderNo=');
	// 2. 发起支付请求
	function pay(id, orderNo) {
		// 从服务器请求支付订单  
		var PAYSERVER = '';
		if (id == 'alipay') {
			PAYSERVER = ALIPAYSERVER;
			channel = aliChannel;
		} else if (id == 'wxpay') {
			PAYSERVER = WXPAYSERVER;
			channel = wxChannel;
		} else {
			plus.nativeUI.alert("不支持此支付通道！", null, "捐赠");
			return;
		}
		var xhr = new XMLHttpRequest();
		//				var amount = 1;

		xhr.onreadystatechange = function() {
			switch (xhr.readyState) {
				case 4:
					if (xhr.status == 200) {
						plus.payment.request(channel, xhr.responseText, function(result) {
							plus.nativeUI.alert("支付成功！", function() {
								//								back();

							});
						}, function(error) {
							//									plus.nativeUI.alert("支付失败：" + error.code);
							plus.webview.getWebviewById('confirmOrder.html').close();
						});
					} else {
						mui.alert("获取订单信息失败！");
						////console.log(xhr.status)
					}
					break;
				default:
					break;
			}
		}
		xhr.open('GET', PAYSERVER + orderNo);
		xhr.send();

	}
	var self = plus.webview.currentWebview();
	var type = self.type;
	var data_1 = {};
	var isUseScore = 0;
	var orderNo;
	var priceT = 0;
	var payCode = '';
	var userCoupon = '';
	var couponIds = [];
	var areaId2 = '';
	//				//console.log(type)

	mui.ajax(qlgUrl('app/carts/settlement'), {
		data: {
			type: type
		},
		dataType: 'json', //服务器返回json格式数据  
		type: 'post', //HTTP请求类型  
		timeout: 10000, //超时时间设置为10秒；  
		success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
			//						//console.log(data)
			var data = toJson(data);
			// //console.log(JSON.stringify(data));
			if (data.status == 1) {
				var allallnum = 0;
				data = data.data;
				data_1 = data;
				if (data.userAddress.addressId) {
					var html = '<div class="address clearfix" data-addressId="' + data.userAddress.addressId + '" data-areaId2="' +
						data.userAddress.areaId2 +
						'"><div class="add_l"><img src="../img/dingwei1.png" /></div><div class="add_r"><div class="add_r_t clearfix"><div class="add_r_t_l">收货人：' +
						data.userAddress.userName + '</div><div class="add_r_t_r">' + data.userAddress.userPhone +
						'</div></div><div class="add_r_b">收货地址：' + data.userAddress.areaName + ' ' + data.userAddress.userAddress +
						'</div></div></div>';
				} else {
					var html =
						'<div class="address clearfix" ><div class="add_l"><img src="../img/dingwei1.png" /></div><div class="add_r"><div class="add_r_t clearfix"><div class="add_r_t_l" style="height:60px;line-height:60px;font-size:14.4px;color:black">请选择收货地址</div></div></div></div>';
				}
				$.each(data.carts, function() {
					var allNum = 0;
					html += '<div class="shop_info"><div class="row_title"><div class="store_name">' + this.shopName +
						'</div></div><div class="row_con clearfix">';
					$.each(this.list, function() {
						allNum += this.cartNum;
						var price = '';
						if (this.isWhsle == 1) {
							price = this.whslePrice;
						} else if (this.specPrice != 'null') {
							price = this.shopPrice;
						} else {
							price = this.specPrice;
						}
						var specNames = '';
						for (var i in this.specNames[0]) {
							if (i == "catName") {
								specNames = this.specNames[0][i] + ':';
							} else if (i == "itemName") {
								specNames += this.specNames[0][i]
							}
						}

						html += '<div class="row_block clearfix" data-id="' + this.goodsId + '"><img src="' + hyhImgUrl(this.goodsImg) +
							'" /><div class="rcr clearfix"><div class="rcrc"><p>' + this.goodsName + ' </p><p class="leibie">';
						$.each(this.specNames, function() {
							html += this.catName + ':' + this.itemName + ';';
						});

						html += '</p></div><div class="rcrr"><p>￥' + price + '</p><del>￥' + this.marketPrice + '</del><span>x' +
							this.cartNum + '</span></div></div></div>'
					});
					allallnum += allNum;
					html +=
						'<div class="cost"><div class="c2 clearfix"><div class="c1_l">买家留言：</div><div class="c1_r"><input class="remark" data-shopId="' +
						this.shopId + '" type="text" name="" id="" value="" placeholder="选填：填写内容已和卖家协商确认" /></div></div></div>';
					// if (this.coupons != '') {
					// 	couponName = '<option value="0">请选择优惠券</option>';
					// 	html +=
					// 		'<div class="cost"><div class="c2 clearfix"><div class="c1_l">选择优惠券：</div><div class="c1_r"><select name="" data-shopId="' +
					// 		this.shopId + '" class="yhq yhq_">' + couponName;
					// 	$.each(this.coupons, function() {
					// 		html += '<option value="' + this.couponId + '">满' + this.useMoney + '元减' + this.couponValue +
					// 			'元</option>';
					// 	});
					// 	html += '</select></div></div></div>';
					// } else {
						html += '<div class="c1_r" style="display:none"><select name="" data-shopId="' + this.shopId +
							'" class="yhq yhq_"><option value="0"></option></select></div>';
					//}

					html += '<div class="cost"><div class="c2 clearfix"><div class="c1_r">共' + allNum +
						'件商品 小计：<o class="on">￥' + this.goodsMoney + '</o> + 运费：<o class="on">￥' + this.shippingMoney +
						'</o></div></div></div></div></div>';
				});
				html += '<div class="cost"><div class="c2 clearfix"><div class="c1_l">发货方式：</div><div class="c1_r"><select name="" id="deliverType" class="yhq"><option value="0" selected>快递发货</option><option value="1" >门店自提【免运费】</option>';
						
				//双11优惠券
				//				html += '<div class="cost"><div class="c2 clearfix"><div class="c1_l">选择优惠券：</div><div class="c1_r"><select name="" id="userCoupon" class="yhq"><option value="0">不使用优惠券</option>';
				//				$.each(data.userCoupon, function() {
				//					html += '<option value="' + this.recordId + '">满' + this.man + '元减' + this.price + '元</option>';
				//				});
				//				html += '</select></div></div></div>'
				//木吉抵扣
				if (data.is_seckilling == 1 || data.promotion_goods == 1 || data.ect_pay == 1) {
					// data.useOrderScore=0;
				} else {
					// html += '<div class="isHb clearfix"><div  class="h_left">木吉抵用&nbsp;&nbsp;&nbsp;&nbsp;<o id="huibao">可抵用木吉：' + data.useOrderScore + '</o></div><div class="he_right"><div class="checkout"><div class="check_btn"></div></div></div></div>'

				}
				// html+='<div class="num"><span>购买数量</span><div class="change_num"><span class="jian">-</span><input type="text" name="" id="" value="1" /><span class="jia">+</span></div></div>'
				// html += '<div class="jf_info clearfix"><div class="jf_jf">木吉</div><div class="jf_p">成交后奖励成交价20%的木吉</div></div>';
				priceT = (Math.floor((+data.goodsTotalMoney - (+data.promotionMoney)) * 100)) / 100;
				priceT = priceT >= 0 ? priceT : 0;
				var html1 = '<span>共' + allallnum + '件商品  合计：<j>￥' + priceT +
					'</j></span>&nbsp;&nbsp;<button class="btn_tj">提交订单</button>';
				// 				if(data.ect_pay == 1) {
				// 					var htmlpay = '<div class="row clearfix select_payway" data-payCode="ect"><p class="row_left">ECT余额：<o class="userECT">' + data.userECT + '</o></p></div>';
				// 
				// 					$('.pay_info .con_1').append(htmlpay);
				// 					//					$('.pay_info .con_1 .row').eq(0).attr('style','display: none;');
				// 					$('.pay_info .con_1 .row').eq(1).remove();
				// 				};
				$.each(data.payments, function(i, v) {
					$.each(v, function() {
						$('#pay_way,.pay_info .con_1').append('<div class="row clearfix select_payway" data-payCode="' + this.payCode +
							'"><p class="row_left">付款方式</p><p class="row_right">' + this.payName + '</p></div>');
					})
				})
				$('.con').html(html);
				$('.js_r').html(html1);
				$('#loginName').html(data.loginName);
				$('.userMoney').html(data.userMoney);
				
				// 助购层级获取
				// TODO: ajax
				var _zgData = [
					{level_id:1, user_id:2, user_name: "UID2名称", level_name: "第一层"},
					{level_id:2, user_id:4, user_name: "UID4名称", level_name: "第二层"},
					{level_id:3, user_id:6, user_name: "konodioda~~~~~~~~~~~~~6", level_name: "第三层"},
				]
				let _zgHtml = ""
				_zgData.forEach(function(each){
					_zgHtml += '<div class="row clearfix" data-level_id="'+each.level_id+'" data-user_id="'+each.user_id+'" data-user_name="'+each.user_name+'" data-level_name="'+each.level_name+'">'+
					'<p class="row_left">'+each.level_name+'：</p>'+'<p class="row_right">'+each.user_name.substr(0, 12)+'</p></div>'
				})
				$("#pay_select_level .con_1").html(_zgHtml)
				$('#goodsTotalMoney').html(priceT);
			} else {
				mui.alert(data.msg);
				//							location.reload();
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；  
			//																						mui.alert(type);      
		}
	});
	//店铺优惠券
	$('.con').on('change', '.yhq_', function() {
		userCoupon = $('#userCoupon').val();
		areaId2 = $('.address').attr('data-areaId2');
		couponIds = [];
		$('select').each(function() {
			couponIds.push($(this).attr('data-shopId') + ':' + $(this).val());
		})
		//		var addressId = $('.address').attr('data-addressId')
		var areaId2 = $('.address').attr('data-areaId2')
		var couponIdsArr = couponIds.join(',');
		mui.ajax(qlgUrl('app/carts/getMoney'), {
			data: {
				type: type,
				areaId2: areaId2,
				isUseScore: isUseScore,
				useScore: data_1.useOrderScore,
				couponIds: couponIdsArr,
				recordId: userCoupon

			},
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒；  
			success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  

				data = toJson(data);
				//				//console.log(data.msg)
				if (data.status == 1) {
					data_1.useOrderScore = data.data.maxScore;
					$('#huibao').html('可抵用木吉：' + data_1.useOrderScore);
					priceT = data.data.realTotalMoney;
					$('.js_r span j').html('￥' + data.data.realTotalMoney)
					$('#goodsTotalMoney').html(data.data.realTotalMoney);
				} else {
					mui.alert('发生错误请刷新后重试！');
					//							location.reload();
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理；  
				//																										mui.alert(errorThrown);      
			}
		});
	});
	//订单优惠券
	$('body').on('change', '#userCoupon,#deliverType', function() {
		userCoupon = $('#userCoupon').val();
		areaId2 = $('.address').attr('data-areaId2');
		couponIds = [];
		$('select').each(function() {
			couponIds.push($(this).attr('data-shopId') + ':' + $(this).val());
		})
		//		var addressId = $('.address').attr('data-addressId')
		var areaId2 = $('.address').attr('data-areaId2')
		var couponIdsArr = couponIds.join(',');
		mui.ajax(hyhUrl('app/carts/getMoney'), {
			data: {
				type: type,
				deliverType:$('#deliverType').val(),
				areaId2: areaId2,
				//isUseScore: isUseScore,
				useScore: data_1.useOrderScore,
				//couponIds: couponIdsArr,
				//recordId: userCoupon

			},
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒；  
			success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
				//console.log(JSON.stringify( data))
				data = toJson(data);
				//				//console.log(data.msg)
				if (data.status == 1) {
					data_1.useOrderScore = data.data.maxScore;
					$('#huibao').html('可抵用木吉：' + data_1.useOrderScore);
					$('.js_r span j').html('￥' + data.data.realTotalMoney);
					priceT = data.data.realTotalMoney;
					$('#goodsTotalMoney').html(data.data.realTotalMoney);
				} else {
					mui.alert('发生错误请刷新后重试！');
					//							location.reload();
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理；  
				//																										mui.alert(errorThrown);      
			}
		});
	});
	//是否使用木吉
// 	$('.con').on('tap', '.checkout', function() {
// 		userCoupon = $('#userCoupon').val();
// 		$(this).toggleClass('on');
// 		if ($(this).hasClass('on')) {
// 			isUseScore = 1;
// 		} else {
// 			isUseScore = 0;
// 		}
// 		couponIds = [];
// 		$('select').each(function() {
// 			couponIds.push($(this).attr('data-shopId') + ':' + $(this).val());
// 		})
// 		couponIdsArr = couponIds.join(',');
// 		areaId2 = $('.address').attr('data-areaId2');
// 		//		//console.log(areaId2)
// 		//		//console.log(couponIdsArr)
// 		//		//console.log(data_1.userAddress.areaId2)
// 		//					//console.log(data_1.userAddress)
// 
// 		//		//console.log( areaId2)
// 		//		//console.log(isUseScore)
// 		//		//console.log( data_1.useOrderScore)
// 		//		//console.log(couponIdsArr)
// 		//		//console.log(userCoupon);
// 		mui.ajax(hyhUrl('app/carts/getMoney'), {
// 			data: {
// 				type: type,
// 				areaId2: areaId2,
// 				isUseScore: isUseScore,
// 				useScore: data_1.useOrderScore,
// 				couponIds: couponIdsArr,
// 				recordId: userCoupon
// 
// 			},
// 			dataType: 'json', //服务器返回json格式数据  
// 			type: 'post', //HTTP请求类型  
// 			timeout: 10000, //超时时间设置为10秒；  
// 			success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
// 
// 				data = toJson(data);
// 
// 				if (data.status == 1) {
// 					data_1.useOrderScore = data.data.maxScore;
// 					$('#huibao').html('可抵用木吉：' + data_1.useOrderScore);
// 					//							//console.log(data)
// 					//					//console.log(data.data.shopFreight)
// 					//					for(i in data.data){
// 					//						//console.log(i)
// 					//						//console.log(data.data[i])
// 					//					}
// 					priceT = data.data.realTotalMoney;
// 					$('.js_r span j').html('￥' + data.data.realTotalMoney)
// 					$('#goodsTotalMoney').html(data.data.realTotalMoney);
// 				} else {
// 					mui.alert('发生错误请刷新后重试！');
// 					//							location.reload();
// 				}
// 			},
// 			error: function(xhr, type, errorThrown) { //异常处理；  																				
// 				//alert(errorThrown);      
// 			}
// 		});
// 	})
	$('.footer').on('tap', '.btn_tj', function() {
		payCode = $('.select_payway').attr('data-payCode');
		var that = $(this);
		if (payCode == 'ect') {
			that.attr('disabled', 'disabled');
			mui.ajax(hyhUrl('app/ect/getToEctNum'), {

				data: {
					total_money: priceT
				},
				dataType: 'json', //服务器返回json格式数据  
				type: 'post', //HTTP请求类型  
				timeout: 10000, //超时时间设置为10秒；
				success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功； 
					var data = toJson(data);
					if (data.status == 1) {
						var btnArray = ['是', '否'];
						mui.confirm(data.msg, 'ECT确认支付', btnArray, function(e) {
							if (e.index == 1) {
								that.removeAttr('disabled');
								return;

							} else {
								var addressId = $('.address').attr('data-addressId');
								if (addressId) {
									$('.bg').css('display', 'block');
									$(".pay").slideDown(300);
								} else {
									mui.alert('未设置收货地址!')
								}
								that.removeAttr('disabled');
							}
						})
					} else {
						mui.alert(data.msg);
						return;
					}

				}
			})
		} else {
			var addressId = $('.address').attr('data-addressId');
			if (addressId) {
				$('.bg').css('display', 'block');
				$(".pay").slideDown(300);
			} else {
				mui.alert('未设置收货地址!')
			}
		}

	})

	$('.bg').on('tap', '.mui-icon-left-nav', function() {
		$('.pay').css('display', 'block');
		$('.pay_way').css('display', 'none');
	})
	$('.bg').on('tap', '.mui-icon-closeempty', function() {
		$('.bg').css('display', 'none');
		$(".pay").slideUp(300, function() {

		});
	})

	$('#pay_way').on('tap', '.row', function() {
		$('#pay_way .row .mui-icon').removeClass('mui-icon-checkmarkempty');
		$(this).children('.mui-icon').addClass('mui-icon-checkmarkempty');
		$('.select_payway .row_right o').html($(this).children('.row_left').html());
		$('.select_payway').attr('data-payCode', $(this).attr('data-payCode'))
		$('.pay').css('display', 'block');
		$('#pay_way').css('display', 'none');

	})
	$('.pay').on('tap', '.select_payway', function() {
		if ($(this).attr('data-payCode') == 'ect') {} else {
			$('.pay').css('display', 'none');
			$('#pay_way').css('display', 'block');
		}

	})
	// 助购层级选择
	$('.pay').on('tap', '#selectHelpLevel', function() {
		$("#pay_select_level").show();
	})
	$("#pay_select_level .con_1").on('tap', '.row', function(e){
		$("#pay_select_level").hide();
		$("#displayHelpLevel").text((this.dataset.user_name + "(" + this.dataset.level_name + ")").substr(0,12))
		for(var _k in this.dataset){document.getElementById("displayHelpLevel").dataset[_k] = this.dataset[_k]}
	})
	var click = false;
	$('.pay_btn').on('tap', function() {

		var addressId = $('.address').attr('data-addressId');
		var areaId = $('.address').attr('data-areaId');
		var that = $(this);
		payCode = $('.select_payway').attr('data-payCode');
		var data_send = {
			type: type,
			s_addressId: addressId,
			s_areaId: areaId,
			payCode: payCode,
			payType: 1,
			isUseScore: isUseScore,
			useScore: data_1.useOrderScore,
			deliverType: $('#deliverType').val(),
			isInvoice: 0,
			invoiceId: 0,
			invoiceClient: '',
			recordId: userCoupon,
		}
		if(document.getElementById("displayHelpLevel").dataset["level_id"] !== undefined){
			data_send["helpLevel"] = document.getElementById("displayHelpLevel").dataset["level_id"]
		}
		if(document.getElementById("displayHelpLevel").dataset["user_id"] !== undefined){
			data_send["helpUserId"] = document.getElementById("displayHelpLevel").dataset["user_id"]
		}
		$('.remark').each(function() {
			data_send['remark_' + ($(this).attr('data-shopid'))] = $(this).val();
		});
		$('select').each(function() {
			data_send['couponId_' + ($(this).attr('data-shopid'))] = $(this).val();
		})
		if (true == click) return;
		click = true;
		that.attr('disabled', 'disabled');
		mui.ajax(qlgUrl('app/orders/submit'), {
			data: data_send,
			dataType: 'json', //服务器返回json格式数据  
			type: 'post', //HTTP请求类型  
			timeout: 10000, //超时时间设置为10秒；  
			success: function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
				////console.log(JSON.stringify(data))
				data = toJson(data);
				if (data.status == 1) {
					orderNo = data.data;
					if (payCode == 'qlgpay') {
						JZL.ajax(hyhUrl('app/' + payCode + '/payment'), {
							orderNo: orderNo,
							isBatch: 1
						}, function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
							// //console.log(JSON.stringify(data));
							var data = toJson(data);
							// //console.log(JSON.stringify(data))
							if (data.status == 1) {
								$('.pay').css('display', 'none');
								$('#qlg_pay_pwd').css('display', 'block');
								if (data.data.payPwd == '0') {
									mui.alert('还未设置支付密码请先设置操作密码!');
									var url = 'setting_fogetPayPwd';
									JZL.openWindow(url + '.html', url + '.html');
									//return;
								}
								$('#totalMoney').html('付款总额：￥<o>' + data.data.needPay + '</o>');
								$('#productNum').val(data.data.product.useProduct);
								if (data.data.product.useProduct > 0) {
									var html1 = '<p id="" class="p1"><span>抵扣额</span><span>' + data.data.product.useProductOk +
										'</span> </p><p id="" class="p1"><span>扣税</span> <span>' + data.data.product.useProductTaxFee +
										'</span></p><p id="" class="p1"><span>手续费</span> <span>' + data.data.product.useProductHandlingFee +
										'</span></p>';
									$('.productInfo_').html(html1)
									// 									$('#productInfo').html('产品券[抵扣额:'+data.data.product.useProductOk+',扣税:'+data.data.product.useProductTaxFee+',手续费:'+data.data.product.useProductHandlingFee+']');
								}
								$('#couponsNum').val(data.data.coupons.useCoupons);
								if (data.data.coupons.useCoupons > 0) {
									var html2 = '<p id="" class="p1"><span>抵扣额</span><span>' + data.data.coupons.useCouponsOk +
										'</span> </p><p id="" class="p1"><span>扣税</span> <span>' + data.data.coupons.useCouponsTaxFee +
										'</span></p><p id="" class="p1"><span>手续费</span> <span>' + data.data.coupons.useCouponsHandlingFee +
										'</span></p>';
									$('.couponsInfo_').html(html2)
									// 															$('#coupousInfo').html('优惠券[抵扣额:' + data.data.coupons.useCouponsOk + ',扣税:' + data.data.coupons.useCouponsTaxFee +
									// 																',手续费:' + data.data.coupons.useCouponsHandlingFee + ']');
								}
								$('#wangNum').val(data.data.wang.useWang);
								$('#moneyNum').val(data.data.money.useMoney);

							} else {
								mui.alert(data.msg)
							}
						});
						//显示支付页面
					} else if (payCode == 'wallets' || payCode == 'ect') {
						//跳输入密码的页面
						JZL.ajax(hyhUrl('app/' + payCode + '/payment'), {
							orderNo: data.data,
							isBatch: 1
						}, function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
							var data = toJson(data);
							if (data.status == 1) {
								$('.pay').css('display', 'none');
								$('#pay_pwd').css('display', 'block');
								if (data.data.payPwd == '0') {
									mui.alert('还未设置支付密码请先设置支付密码!');
									var url = 'setting_fogetPayPwd';
									JZL.openWindow(url + '.html', url + '.html');
								}
							}
						});

					} else if (payCode == 'alipays') {
						pay('alipay', data.data);
						//									plus.nativeUI.showWaiting();
						//									mui.post(hyhUrl('app/Alipays/payment'), {
						//									orderNo: data.data,
						//										isBatch: 1
						//									var ALIPAYSERVER = hyhUrl('app/Alipays/payment?orderNo=' + data.data + '&isBatch=1');

					}
				} else {
					mui.alert(data.msg); //'发生错误请刷新后重试！');
					if (-2 == data.status) {
						JZL.openWindow('indent.html', 'waitPay', {
							data_href: 'waitPay'
						});
						setTimeout(function() {
							JZL.closeWindow(plus.webview.currentWebview().id);
						}, 500)
					} else {
						//location.reload();
					}

					//mui.back();

				}
				click = false;
				that.removeAttr('disabled');
			},
			error: function(xhr, type, errorThrown) { //异常处理；  
				// 				//console.log(type)
				// 				//console.log(errorThrown)
				//mui.alert(errorThrown);      
			}
		})
	})
	$('#pay_pwd,#qlg_pay_pwd').on('tap', '.p9', function() {
		var url = 'setting_fogetPayPwd';
		JZL.openWindow(url + '.html', url + '.html');
	})
	 $('#pay_pwd,#qlg_pay_pwd').on('tap', '.pay_btn_pwd', function() {
		var payPwd = $('#payPwd').val();
		if (payPwd == '') {
			mui.alert('支付密码不能为空！');
			return;
		}
		var that = $(this);
		that.attr('disabled', 'disabled');
		var srcc = ''
		if (payCode == 'qlgpay') {
			srcc = 'payByQlg';
		} else if (payCode == 'ect') {
			srcc = 'payByEct';
		} else {
			srcc = 'payByWallet';
		}
		JZL.ajax(hyhUrl('app/' + payCode + '/' + srcc), {
			orderNo: orderNo,
			isBatch: 1,
			payPwd: payPwd
		}, function(data) { //服务器返回响应，根据响应结果，分析是否登录成功；  
			// //console.log(JSON.stringify(data));
			var data = toJson(data);
			mui.alert(data.msg);
			if (data.status == 1) {
				JZL.openWindow('indent.html', 'waitDeliver', {
					data_href: 'waitDeliver'
				});
				setTimeout(function() {
					JZL.closeWindow(plus.webview.currentWebview().id);
				}, 700)

			} else {
				if (-1 == data.status) {
					JZL.openWindow('indent.html', 'waitPay', {
						data_href: 'waitPay'
					});
					setTimeout(function() {
						JZL.closeWindow(plus.webview.currentWebview().id);
					}, 700)
				} else if (-2 == data.status) {
					var url = 'setting_fogetPayPwd';
					JZL.openWindow(url + '.html', url + '.html');
				} else if (-3 == data.status) {

				} else if (-4 == data.status) {
					JZL.openWindow('indent.html', 'waitDeliver', {
						data_href: 'waitDeliver'
					});
					setTimeout(function() {
						JZL.closeWindow(plus.webview.currentWebview().id);
					}, 700)
				}

			}
			that.removeAttr('disabled');
		});
	})
})
