//$('.pay_info .row_left').eq(0).html('桔子链账号');
var wxChannel = null; // 微信支付
var aliChannel = null; // 支付宝支付
var channel = null; //支付通道
mui.init();
function copyToClip (text) {
var Context = plus.android.importClass("android.content.Context");
var main = plus.android.runtimeMainActivity();
var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
plus.android.invoke(clip,"setText",text.toString());
mui.toast("复制成功");
}
let payPics = [];
mui.plusReady(function() {
var self = plus.webview.currentWebview();
from_id = self.from?self.from:1
if(from_id==3){
$("#selectHelpLevel").show();
}else{
$("#selectHelpLevel").hide();
}
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 =
'

收货人:' +
data.userName + '
' + data.userPhone +
'
收货地址:' + data.areaName + ' ' + data.userAddress + '
';
$('.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);
}
});
});
$("#shopRecieveInfo")
.on('click', '.copy_name', function(){copyToClip($("#shopRecieveInfo > ._name").text())})
.on('click', '.copy_card', function(){copyToClip($("#shopRecieveInfo > ._card").text())});
$('.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)
$("#shopRecieveInfo")
.on('click', '.copy_name', function(){copyToClip($("#shopRecieveInfo > ._name").text())})
.on('click', '.copy_card', function(){copyToClip($("#shopRecieveInfo > ._card").text())})
.on('click', 'img', function(){
var index = $(this).parent().index();
if (payPics.length < index) return;
plus.nativeUI.previewImage(payPics, {
current: index,
loop: true,
indicator: 'number'
});
});
mui.ajax(qlgUrl('app/carts/settlement'), {
data: {
type: type,
from: from_id
},
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 = '收货人:' +
data.userAddress.userName + '
' + data.userAddress.userPhone +
'
收货地址:' + data.userAddress.areaName + ' ' + data.userAddress.userAddress +
'
';
} else {
var html =
'';
}
$.each(data.carts, function() {
var allNum = 0;
html += '';
$.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 += '
 +
')
' + this.goodsName + '
';
$.each(this.specNames, function() {
html += this.catName + ':' + this.itemName + ';';
});
html += '
¥' + price + '
¥' + this.marketPrice + 'x' +
this.cartNum + ''
});
allallnum += allNum;
html +=
'
';
// if (this.coupons != '') {
// couponName = '
';
// html +=
// '
选择优惠券:
';
// } else {
html += '
';
//}
html += '
共' + allNum +
'件商品 小计:¥' + this.goodsMoney + ' + 运费:¥' + this.shippingMoney +
'
';
});
html += '发货方式: