qlg.tsgz.moe/static/app2/js/ect_address.js
2019-09-06 23:53:10 +08:00

159 lines
5.1 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

$('.add').css('display','none');
$('body').append('<button class="addAddress">添加地址</button>');
mui.plusReady(function() {
// function hyhUrl(url) {
// return 'http://192.168.1.101/hyh/' + url;
// }
var token = localStorage.getItem('token');
// alert(token);
mui.ajax(hyhUrl('app/Ectwallets/listQuery'), { 
headers: { 
"HYH-Token": token
},
dataType: 'json', //服务器返回json格式数据  
type: 'post', //HTTP请求类型  
timeout: 10000, //超时时间设置为10秒  
success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
var data = toJson(data, 1);
if(data.status == 1) {
var html = '';
if(data.data != '') {
$.each(data.data, function() {
html += '<div class="row shadown_wai"><div class="r_con"><p>钱包地址 ' + this.eAddress + '</p></div><div class="r_bottom " data-eWalletId="' + this.eWalletId + '" data-isDefault="' + this.isDefault + '"><div class="default "><div class="check mui-icon mui-icon-checkmarkempty"></div><p>设为默认</p></div><div class="del"><a class="mui-icon mui-icon-trash del_icon"></a><div class="del_text">删除</div></div></div></div>';
});
$('.mui-scroll').html(html);
$('.row').each(function() {
if($(this).children('.r_bottom').attr('data-isDefault') == 1) {
$(this).children('.r_bottom').children('.default').children('.check').addClass('on');
}
})
}
} else {
// console.log(data.status)
}
},
error: function(xhr, type, errorThrown) {           //异常处理;  
// alert(errorThrown);      
}  
}); 
//设为默认
$('.mui-scroll').on('tap', '.default', function() {
if($(this).parent().attr('data-isDefault') == 0) {
if(confirm('设为默认地址?')) {
var eWalletId = $(this).parent().attr('data-eWalletId');
// console.log(eWalletId)
mui.ajax(hyhUrl('app/Ectwallets/setDefault'), { 
headers: { 
"HYH-Token": token
},
data: {
eWalletId: eWalletId
},
dataType: 'json', //服务器返回json格式数据  
type: 'post', //HTTP请求类型  
timeout: 10000, //超时时间设置为10秒  
success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
var data = toJson(data, 1);
if(data.status == 1) {
plus.nativeUI.toast(data.msg);
location.reload();
} else {
// console.log(data.status)
}
},
error: function(xhr, type, errorThrown) {           //异常处理;  
// alert(errorThrown);      
}  
}); 
}
}
})
//删除地址
$('.mui-scroll').on('tap', '.del', function() {
if(confirm('删除地址?')) {
var eWalletId = $(this).parent().attr('data-eWalletId');
// console.log(eWalletId)
mui.ajax(hyhUrl('app/Ectwallets/del'), { 
headers: { 
"HYH-Token": token
},
data: {
eWalletId: eWalletId
},
dataType: 'json', //服务器返回json格式数据  
type: 'post', //HTTP请求类型  
timeout: 10000, //超时时间设置为10秒  
success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
var data = toJson(data, 1);
if(data.status == 1) {
plus.nativeUI.toast(data.msg);
location.reload();
} else {
// console.log(data.status)
}
},
error: function(xhr, type, errorThrown) {           //异常处理;  
// alert(errorThrown);      
}  
}); 
}
})
//添加地址
$('body').on('tap','.addAddress', function() {
var eAddress = '';
var eAddress_ = '';
if(eAddress = prompt('请输入钱包地址')) {
if(eAddress.length != 42) {
alert('钱包地址长度必须为42位');
return;
}
// if(eAddress_ = prompt('请再次输入钱包地址')) {
// if(eAddress == eAddress_) {
var isDefault = 0;
if(confirm('是否设为默认地址?')) {
isDefault = 1;
}
mui.ajax(hyhUrl('app/Ectwallets/add'), { 
headers: { 
"HYH-Token": token
},
data: {
eAddress: eAddress,
isDefault: isDefault
},
dataType: 'json', //服务器返回json格式数据  
type: 'post', //HTTP请求类型  
timeout: 10000, //超时时间设置为10秒  
success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
var data = toJson(data, 1);
if(data.status == 1) {
plus.nativeUI.toast(data.msg);
location.reload();
} else {
// console.log(data.status)
}
},
error: function(xhr, type, errorThrown) {           //异常处理;  
// alert(errorThrown);      
}  
}); 
// } else {
// alert('两次地址输入不一致!');
// }
// }
}
})
})