Files
peko-h5/view/peko/modules/h5Income/js/withdrawal.js

378 lines
14 KiB
JavaScript
Raw Normal View History

let urlPrefix = getUrlPrefix()
let browser = checkVersion()
let env = EnvCheck();
if (env == 'test') {
new VConsole();
}
2023-07-12 17:00:34 +08:00
// 封裝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'
})
}
2023-07-12 17:00:34 +08:00
var accountType;//1 其它賬戶 2 中國大陸銀聯 4 馬來西亞銀行 8 新加坡銀行
var minValue;//最小提領金币数量
var golds;//当前剩余金币
var weekLimitCount;//本周剩余次数
var weekMaxValue;//本周剩余最大金额
$(function () {
setTimeout(function () {
getInfoFromClient()
if (browser.app) {
$('.back').hide();
}
setTimeout(function () {
2023-07-12 17:00:34 +08:00
getUser();
}, 100)
})
})
2023-07-12 17:00:34 +08:00
// 提領配置接口接口
function getConfig () {
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 = `
2024-01-08 11:53:36 +08:00
<p>1收益金幣達到${res.data.minValue}或以上可以申請提領</p>
<p>2提領金幣必須為1000的整倍數</p>
2024-01-08 12:03:49 +08:00
<p>3每周可提領次數<i>${res.data.weekLimitCount}</i>, 提領手續費:<i>${res.data.chargeRate}%</i></p>
2024-01-08 11:53:36 +08:00
<p>4台幣提領請聯繫客服微信sd245376</p>
<p>5如您使用Payoneer帳戶提領因Payoneer要求付款最少50美元需要滿足55000金幣後發起不滿足的提領將會被駁回</p>
2023-07-12 17:00:34 +08:00
`
$('.withdrawal').append(str);
getAccounts();
2023-08-18 19:27:54 +08:00
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
2023-07-12 17:00:34 +08:00
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();
2023-08-18 19:27:54 +08:00
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
2023-07-12 17:00:34 +08:00
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()
2023-08-18 19:27:54 +08:00
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
2023-07-12 17:00:34 +08:00
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 提領賬戶管理接口
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 accountType=${res.accountType} isBind=${res.isBind}>${res.accountName}${res.isBind == 0 ? "(未綁定)" : ''}</li>
`
if (res.isPrev == 1) {
accountType = res.accountType
$('.account span').text(res.accountName);
$('.account span').addClass('active');
} else {
if (res.isBind == 1) {
accountType = res.accountType
$('.account span').text(res.accountName);
$('.account span').addClass('active');
}
}
});
$('.accountPub .accountPub_in ul').append(str);
// 跳轉綁定賬戶或選擇賬戶
$('.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('是否切換到新加坡銀行提領 ');
}
$('.switch .pub_in .ok').attr('accounttype', accountTypes);
$('.switch .pub_in .ok').attr('text', $(this).text());
$('.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('需要先綁定新加坡銀行賬戶資料');
}
$('.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}`;
}
})
}
return false;
})
if (golds < minValue) {
$('.withdrawal input').attr('placeholder', '可提領金幣不足');
} else if ($('.account span').text() != '未绑定') {
$(`.withdrawal input`).text('請輸入提領金幣數額');
$(`.withdrawal .withdrawalBox`).attr('click', 1);
}
2023-08-18 19:27:54 +08:00
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
2023-07-12 17:00:34 +08:00
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();
2023-07-14 15:27:25 +08:00
calculate();
2023-07-12 17:00:34 +08:00
})
// 确定输入提領弹窗按钮
$('.goldPub .goldPub_in .but').click(function () {
var num = $('.goldPub .goldPub_in input').val();
if (num == '') {
toastMsg('請輸入提領金幣數額');
return
}
if (num < minValue) {
toastMsg(`最少申請金幣为${minValue}`);
return
}
2024-01-08 11:12:20 +08:00
if (num % 1000 != 0) {
toastMsg(`提領金幣必須為1000的整倍數`);
2023-07-12 17:00:34 +08:00
return
}
2023-07-14 15:27:25 +08:00
calculate();
return false;
})
// 计算汇率接口
function calculate () {
var num = $('.goldPub .goldPub_in input').val();
num.length == 0 ? num = $('.withdrawal input').val() : num;
2023-07-12 17:00:34 +08:00
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} ${res.data.currencyAmount}`);
$('.goldPub').hide();
$('.goldPub .goldPub_in input').val('');
$('.butBig').addClass('butBigActive');
$('.butBig').attr('click', 1);
2023-08-18 19:27:54 +08:00
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
2023-07-12 17:00:34 +08:00
window.location.href = './login.html'
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網絡錯誤,請退出重進')
}
})
2023-07-14 15:27:25 +08:00
}
2023-07-12 17:00:34 +08:00
// 关闭二次确认提領按钮
$('.withDrawalPub').click(function () {
$('.withDrawalPub').hide();
return false;
})
// 确定提領按钮
$('.butBig').click(function () {
var num = $('.withdrawal input').val();
var status = $(this).attr("click");
if (status != 1) {
return
}
if (weekLimitCount <= 0) {
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();
2023-08-18 19:27:54 +08:00
} else if (res.code ? res.code == 1444 : JSON.parse(res).code == 401) {
2023-07-12 17:00:34 +08:00
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 (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)
2023-07-12 17:00:34 +08:00
})
// 跳转提領规则页面
$('.income .rule').click(function () {
window.location.href = './rule.html';
2023-07-14 15:27:25 +08:00
})
//返回页面 重新请求接口
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);