Files
peko-h5/view/peko/modules/h5Income/js/withdrawal.js
2024-02-19 18:05:17 +08:00

516 lines
20 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

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.

let urlPrefix = getUrlPrefix()
let browser = checkVersion()
let env = EnvCheck();
if (env == 'test') {
new VConsole();
}
// 封裝layer消息提醒框
let layerIndex
const showLoading = (content = '加載中...') => {
layer.open({
type: 2,
shadeClose: false,
content,
success (e) {
layerIndex = $(e).attr('index')
}
})
}
const hideLoading = (index) => {
layer.close(index)
}
const toastMsg = (content = '操作完成', time = 2) => {
layer.open({
content,
time,
skin: 'msg'
})
}
var accountType;//1 其它賬戶 2 中國大陸銀聯 4 馬來西亞銀行 8 新加坡銀行
var minValue;//最小提領金币数量
var golds;//当前剩余金币
var weekLimitCount;//本周剩余次数
var weekMaxValue;//本周剩余最大金额
var realName = false;//默认大陆未实名
var modifyId = null;
var userInfo = {}//账户信息暂存
var idCard;//获取大陆身份证号
$(function () {
setTimeout(function () {
getInfoFromClient()
if (browser.app) {
$('.back').hide();
}
setTimeout(function () {
getUser();
}, 100)
})
})
// 提領配置接口接口
function getConfig () {
$('.withdrawal p').remove();
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/withdrawUser/config',
data: { uid: pubInfo.uid },
success (res) {
if (res.code === 200) {
minValue = res.data.minValue;
weekLimitCount = res.data.weekLimitCount;
weekMaxValue = res.data.weekMaxValue;
var str = `
<p>1、收益金幣達到${res.data.minValue}或以上可以申請提領</p>
<p>2、提領金幣必須為1000的整倍數</p>
<p>3、每周可提領次數<i>${res.data.weekLimitCount}</i>次, &nbsp;&nbsp;提領手續費:<i>${res.data.chargeRate}%</i></p>
<p>4、台幣提領請聯繫客服微信sd245376</p>
<p>5、如您使用Payoneer帳戶提領因Payoneer要求付款最少50美元需要滿足55000金幣後發起不滿足的提領將會被駁回</p>
`
$('.withdrawal').append(str);
getAccounts();
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
console.log();
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 用戶錢包接口
function query () {
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/purse/query',
data: { uid: pubInfo.uid },
success (res) {
if (res.code === 200) {
$('.income p').text(`金幣 ${res.data.golds}`);
golds = res.data.golds;
getConfig();
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
console.log();
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 用戶基本信息接口
function getUser () {
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/user/get',
data: { uid: pubInfo.uid },
success (res) {
if (res.code === 200) {
$('.myInfo img').attr('src', res.data.avatar);
$('.myInfo div p').text(res.data.nick);
$('.myInfo div b').text("ID:" + res.data.erbanNo);
query()
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 提領賬戶管理接口
var isPrevBool = false;
var isRealCertifyBool = 1;
var updateNums = 0;
function getAccounts () {
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/withdrawAccountDtl/getAccounts',
data: { uid: pubInfo.uid },
success (res) {
if (res.code === 200) {
var str = '';
res.data.forEach((res) => {
str += `
<li backPhoto=${res.backPhoto} frontPhoto=${res.frontPhoto} address=${res.address} thirdAccountNo=${res.thirdAccountNo} contact=${res.contact} accountNo=${res.accountNo} idCardNo=${res.idCardNo} name=${res.name} id=${res.id} accountTypesText=${res.accountName} accountType=${res.accountType} isBind=${res.isBind}>${res.accountName}${res.isBind == 0 ? "(未綁定)" : ''}<i>${res.accountType == 2 ? '修改&nbsp;&nbsp;>' : ''}</i></li>
`
// if (res.isPrev == 1) {
// isPrevBool = true;
// accountType = res.accountType
// $('.account span').text(res.accountName);
// $('.account span').addClass('active');
// } else {
// if (res.isBind == 1 && isPrevBool == false) {
// accountType = res.accountType
// $('.account span').text(res.accountName);
// $('.account span').addClass('active');
// }
// }
// if (res.isPrev == 1) {
// isPrevBool = true;
// accountType = res.accountType
// $('.account span').text(res.accountName);
// $('.account span').addClass('active');
// }
if (res.isPrev == 1) {
isPrevBool = true;
accountType = res.accountType
$('.account span').text(res.accountName);
$('.account span').addClass('active');
}
if (res.isBind == 1 && isPrevBool == false) {
accountType = res.accountType
$('.account span').text(res.accountName);
$('.account span').addClass('active');
}
if (res.accountType == 2) {
idCard = res.idCardNo;
updateNums = res.updateNum;
isRealCertifyBool = res.isRealCertify;
// 判断是否认证
if (isRealCertifyBool == 0) {
$('.withdrawal input').attr('placeholder', '請先進行實名認證');
$('.authentication span').text('未實名');
realName = false;
} else {
realName = true;
$('.withdrawal input').attr('placeholder', '請輸入提領金幣數額');
$('.authentication span').text('已實名');
}
} else {
$('.withdrawal input').attr('placeholder', '請輸入提領金幣數額');
}
if (accountType == 2) {
$('.authentication').show();
} else {
$('.authentication').hide();
}
});
$('.accountPub .accountPub_in ul').append(str);
// 判断是否展示修改
if (updateNums >= 1) {
$('.mainlandInfo .mainlandInfo_in p span').text(updateNums + '次');
$('.accountPub .accountPub_in ul li i').show();
} else {
$('.accountPub .accountPub_in ul li i').hide();
}
// 修改大陆银行卡按钮
$('.accountPub .accountPub_in ul li i').click(function () {
modifyId = $(this).parents('li').attr('id');
userInfo.name = $(this).parents('li').attr('name');
userInfo.idCardNo = $(this).parents('li').attr('idCardNo');
userInfo.accountNo = $(this).parents('li').attr('accountNo');
userInfo.contact = $(this).parents('li').attr('contact');
userInfo.thirdAccountNo = $(this).parents('li').attr('thirdAccountNo');
userInfo.address = $(this).parents('li').attr('address');
userInfo.frontPhoto = $(this).parents('li').attr('frontPhoto');
userInfo.backPhoto = $(this).parents('li').attr('backPhoto');
$('.mainlandInfo').show();
return false;
})
// 跳轉綁定賬戶或選擇賬戶
$('.accountPub .accountPub_in ul li').click(function () {
var isBind = $(this).attr('isBind');//是否綁定 0 否 1 是
if (isBind == 1) {
var accountTypes = $(this).attr('accounttype');//1 其它賬戶 2 中國大陸銀聯 4 馬來西亞銀行 8 新加坡銀行
if (accountTypes == 1) {
$('.switch .pub_in p').text('是否切換到其它賬戶提領 ');
} else if (accountTypes == 2) {
$('.switch .pub_in p').text('是否切換到中國大陸銀聯提領 ');
} else if (accountTypes == 4) {
$('.switch .pub_in p').text('是否切換到馬來西亞銀行提領 ');
} else if (accountTypes == 8) {
$('.switch .pub_in p').text('是否切換到新加坡銀行提領 ');
} else if (accountTypes == 16) {
$('.switch .pub_in p').text('是否切換到臺灣地區銀行提領 ');
}
$('.switch .pub_in .ok').attr('accounttype', accountTypes);
$('.switch .pub_in .ok').attr('text', $(this).attr('accountTypesText'));
$('.switch').show();
} else {
var accountTypes = $(this).attr('accounttype');//1 其它賬戶 2 中國大陸銀聯 4 馬來西亞銀行 8 新加坡銀行
if (accountTypes == 1) {
$('.binding .pub_in p').text('需要先綁定賬戶資料');
} else if (accountTypes == 2) {
$('.binding .pub_in p').text('需要先綁定中國大陸銀聯賬戶資料');
} else if (accountTypes == 4) {
$('.binding .pub_in p').text('需要先綁定馬來西亞銀行賬戶資料');
} else if (accountTypes == 8) {
$('.binding .pub_in p').text('需要先綁定新加坡銀行賬戶資料');
}else if (accountTypes == 16) {
$('.binding .pub_in p').text('需要先綁定臺灣地區銀行賬戶資料 ');
}
$('.binding').show();
// 確認跳轉綁定頁面按鈕
$('.binding .pub_in .ok').click(function () {
if (accountTypes == 1) {
window.location.href = `./other.html?accountType=${accountTypes}`;
} else if (accountTypes == 2) {
window.location.href = `./chainBank.html?accountType=${accountTypes}`;
} else if (accountTypes == 4) {
window.location.href = `./malaysia.html?accountType=${accountTypes}`;
} else if (accountTypes == 8) {
window.location.href = `./singapore.html?accountType=${accountTypes}`;
}else if (accountTypes == 16) {
window.location.href = `./taiwan.html?accountType=${accountTypes}`;
}
return false;
})
}
if (accountTypes == 2) {
$('.authentication').show();
} else {
$('.authentication').hide();
}
console.log(accountTypes);
return false;
})
if (golds < minValue) {
$('.withdrawal input').attr('placeholder', '可提領金幣不足');
} else if ($('.account span').text() != '未绑定') {
$(`.withdrawal input`).text('請輸入提領金幣數額');
$(`.withdrawal .withdrawalBox`).attr('click', 1);
}
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 取消切换按钮
$('.switch .pub_in .close').click(function () {
$('.switch').hide();
})
// 确认切换按钮
$('.switch .pub_in .ok').click(function () {
accountType = $(this).attr('accounttype');//1 其它賬戶 2 中國大陸銀聯 4 馬來西亞銀行 8 新加坡銀行
$('.account span').text($(this).attr("text"));
$('.account span').addClass('active');
$('.accountPub').hide();
$('.switch').hide();
calculate();
if (accountType == 2) {
// 判断是否认证
if (isRealCertifyBool == 0) {
$('.withdrawal input').attr('placeholder', '請先進行實名認證');
$('.authentication span').text('未實名');
realName = false;
} else {
realName = true;
$('.withdrawal input').attr('placeholder', '請輸入提領金幣數額');
$('.authentication span').text('已實名');
}
} else {
$('.withdrawal input').attr('placeholder', '請輸入提領金幣數額');
}
})
// 确定输入提領弹窗按钮
$('.goldPub .goldPub_in .but').click(function () {
var num = $('.goldPub .goldPub_in input').val();
if (num == '') {
toastMsg('請輸入提領金幣數額');
return
}
if (num < minValue) {
toastMsg(`最少申請金幣为${minValue}`);
return
}
if (num % 1000 != 0) {
toastMsg(`提領金幣必須為1000的整倍數`);
return
}
calculate();
return false;
})
// 计算汇率接口
function calculate () {
var num = $('.goldPub .goldPub_in input').val();
num.length == 0 ? num = $('.withdrawal input').val() : num;
showLoading()
networkRequest({
type: 'GET',
url: urlPrefix + '/withdrawUserAccount/calculate',
data: { uid: pubInfo.uid, accountType, goldNum: num, },
success (res) {
if (res.code === 200) {
$('.withdrawal .numBox b').addClass('active');
$('.withdrawal input').val(num);
$('.withdrawal .numBox b').text(`${res.data.currency == undefined ? '' : res.data.currency} ${res.data.currencyAmount}`);
$('.goldPub').hide();
$('.goldPub .goldPub_in input').val('');
$('.butBig').addClass('butBigActive');
$('.butBig').attr('click', 1);
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 关闭二次确认提領按钮
$('.withDrawalPub').click(function () {
$('.withDrawalPub').hide();
return false;
})
// 确定提領按钮
let birthday;
let nowTime;
$('.butBig').click(function () {
var num = $('.withdrawal input').val();
var status = $(this).attr("click");
if (status != 1) {
return
}
if (weekLimitCount <= 0) {
toastMsg('超出本周最大提领次数')
return
}
// return
if (accountType == 2 && isRealCertifyBool == 0) {
toastMsg('請先進行實名認證')
return
}
// console.log(isAdult(idCard));
if (accountType == 2) {
birthday = idCard.substring(6, 14);
nowTime = moment(new Date()).format('YYYY-MM-DD');
birthday = moment(birthday).format('YYYY-MM-DD');
}
if (accountType == 2 && (moment(nowTime).isBefore(moment(birthday).add(18, 'years')))) {//
toastMsg('申請提現失敗,不支援未成年人提現');
return
}
$('.withDrawalPub .withDrawalPub_in p ').html(`確認通過 <b>${$('.account .active').text()}</b> 提領 <b>${num}</b>金幣?`)
$('.withDrawalPub .withDrawalPub_in span b ').html(`${$('.withdrawal .numBox b').text()}`)
$('.withDrawalPub').show();
})
// 二次确认提領按钮
$('.withDrawalPub .withDrawalPub_in .but').click(function () {
var num = $('.withdrawal input').val();
showLoading()
networkRequest({
type: 'POST',
url: urlPrefix + '/withdrawUserAccount/apply',
data: { uid: pubInfo.uid, accountType, goldNum: num, },
success (res) {
if (res.code === 200) {
getUser();
$('.withDrawalPub').hide();
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
console.log();
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
return false;
})
// 点击输入提領数额按钮
$('.withdrawal .withdrawalBox').click(function () {
var status = $(this).attr('click');
if (accountType == null || accountType == undefined) {
toastMsg('請先選擇提領賬戶');
return false;
}
console.log(realName);
if (realName == false && accountType == 2) {
toastMsg('請先進行實名認證');
return false;
}
if (status == 1) {
$('.goldPub .goldPub_in .num').text(golds);
$('.goldPub').show();
}
});
// 防止提領输入事件冒泡
$('.goldPub .goldPub_in').click(function () {
return false;
})
// 取消输入提領弹窗
$('.goldPub').click(function () {
$('.goldPub').hide();
})
// 點擊綁定賬戶
$('.account').click(function () {
$('.accountPub').show();
})
// 關閉綁定賬戶彈窗
$('.accountPub').click(function () {
$('.accountPub').hide();
})
// 關閉跳轉綁定頁面按鈕
$('.binding .pub_in .close').click(function () {
$('.binding ').hide();
})
// 返回按鈕
$('.back').click(function () {
window.history.go(-1)
})
// 跳转提領规则页面
$('.income .rule').click(function () {
window.location.href = './rule.html';
})
// 确认修改大陆信息按钮
$('.mainlandInfo .mainlandInfo_in .ok').click(function () {
window.location.href = `./chainBank.html?accountType=${2}&modifyId=${modifyId}&userInfo=${JSON.stringify(userInfo)}`;
})
// 取消修改大陆信息按钮
$('.mainlandInfo .mainlandInfo_in .close').click(function () {
$('.mainlandInfo').hide();
})
// 跳转实名认证按钮
$('.authentication').click(function () {
if (realName == false) {
window.location.href = `../identity/new.html`
}
})
//返回页面 重新请求接口
// var hiddenProperty = 'hidden' in document ? 'hidden' :
// 'webkitHidden' in document ? 'webkitHidden' :
// 'mozHidden' in document ? 'mozHidden' : null;
// var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
// var onVisibilityChange = function () {
// if (!document[hiddenProperty]) {
// location.reload()
// }
// }
// document.addEventListener(visibilityChangeEvent, onVisibilityChange);