Files
peko-h5/view/peko/activity/2024-invitationFission/js/index.js
2024-03-18 11:13:22 +08:00

387 lines
16 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 inviteCode = '';
var typeStr = "1,3";//收益類型 1 直接邀請 2 間接邀請 3 直接邀請充值 4 間接邀請充值
var page = 1;
var isLock = true;
var obj = {};
var text = '直接';
// 初始化函數
$(function () {
getInfoFromClient()
setTimeout(function () {
// 頁面全屏
if (browser.app) {
if (browser.android) {
window.androidJsObj.initShowNav(false)
} else {
window.webkit.messageHandlers.initShowNav.postMessage(0)
}
};
// 頂部返回事件
$('.back').click(() => {
if (browser.android) {
window.androidJsObj.closeWebView()
} else {
window.webkit.messageHandlers.closeWebView.postMessage(null)
}
})
getConfig();
getMySelf();
profitPage();
}, 100)
})
// 獲取配置接口
function getConfig () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/user/invite/config',
success (res) {
if (res.code === 200) {
// 直接邀請規則
res.data.inviteLevelReward.forEach((res, i) => {
if (i == 0) {
$(`.bg .rule .rule2 .table1_2`).html(`
<div>${res.leftDiamond}鑽&lt;30天內儲值&lt;${res.rightDiamond}鑽 </div>
<div>直接邀請對象+2魔法棒妳+1魔法棒</div>
`)
} else {
$(`.bg .rule .rule2 .table1_${i + 2}`).html(`
<div>${res.leftDiamond}鉆&lt;=30天內儲值${res.rightDiamond ? `&lt;${res.rightDiamond}` : ''} </div>
<div>每儲值${res.numUnit}鉆,妳+${res.rewardNum}鉆(${((res.rewardNum / res.numUnit) * 100).toFixed(2)}%</div>
`)
}
})
// 間接邀請規則
res.data.indirectLevelReward.forEach((res, i) => {
$(`.bg .rule .rule2 .table2_${i + 2}`).html(`
<div>${res.leftDiamond}鉆&lt;=30天內儲值${res.rightDiamond ? `&lt;${res.rightDiamond}` : ''} </div>
<div>每儲值${res.numUnit}鉆,妳+${res.rewardNum}鉆(${((res.rewardNum / res.numUnit) * 100).toFixed(2)}%</div>
`)
})
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
console.log();
// 獲取收益接口
function getMySelf () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/user/invite/mySelf',
success (res) {
if (res.code === 200) {
inviteCode = res.data.inviteCode;
// 分享所需参数
obj = {
qrCodeUrl: res.data.qRCodeUrl,
text: '掃碼下載PiKO並填寫我的邀請碼\n立得 1000 鑽石!',
invitationCode: `${res.data.inviteCode}`,
shareTitle: '標題',
shareText: '分享文案',
shareImg: 'https://image.pekolive.com/pikolive.png',
toUrl: `${window.location.origin}/peko/activity/2024-invitationFission/share.html?inviteCode=${res.data.inviteCode}`,
type: 1//1:分享好友2:直接保存圖片
}
// 初始化复制
$.copy({
text: "復制成功", //分享提示文案
copyUrl: inviteCode, //自定義復制
tipTime: 1000, //分享提示消失時間
copyId: "#copy" //復制按鈕id
});
$('.bg .myInfo .invitationCode').text(inviteCode);
$('.bg .myIncome b').text(res.data.totalProfit);
$('.bg .incomeBox .tab .directProfit span').html(`<img src="./images/diamond.png" alt=""> ${res.data.directProfit}`);
$('.bg .incomeBox .tab .indirectProfit span').html(`<img src="./images/diamond.png" alt=""> ${res.data.indirectProfit}`);
$('.code .codeImg').attr('src', res.data.qRCodeUrl);
$('.bg .myInfo .tx').attr('src', res.data.avatar);
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
// 縮小二維碼
$('.code .rule_icon').click(function () {
$('.openShare').show();
$('.code').hide();
})
// 放大二維碼
$('.openShare').click(function () {
$('.code').show();
$('.openShare').hide();
})
// 分享調用
$('.bg .myInfo .skip').click(function () {
obj.type = 1;
if (browser.android) {
window.androidJsObj.savePictureShare(JSON.stringify(obj))
} else {
window.webkit.messageHandlers.savePictureShare.postMessage(JSON.stringify(obj))
}
})
// 保存圖片
$('.code .but').click(function () {
obj.type = 2;
if (browser.android) {
window.androidJsObj.savePictureShare(JSON.stringify(obj))
} else {
window.webkit.messageHandlers.savePictureShare.postMessage(JSON.stringify(obj))
}
})
// 復制邀請碼
$('.bg .myInfo .copy').click(function () {
$.copy({
text: "復制成功", //分享提示文案
copyUrl: inviteCode, //自定義復制
tipTime: 1000, //分享提示消失時間
copyId: "#copy" //復制按鈕id
});
})
// 切換收益大Tab
$('.bg .incomeBox .tab div').click(function () {
var i = $(this).index() + 1;
text = i == 1 ? '直接' : '間接';
$(this).addClass('act').siblings().removeClass('act');
$('.bg .incomeBox .sTab div').eq(0).text(`${text}邀請收益記錄`);
$('.bg .incomeBox .sTab div').eq(1).text(`${text}邀請用戶記錄`);
$('.bg .incomeBox .sTab div').removeClass('tab1').removeClass('tab2');
$('.bg .incomeBox .sTab div').eq(0).addClass(`tab1`);
page = 1;
$('.bg .incomeBox ul li').remove();
typeStr = i == 1 ? "1,3" : "2,4";
profitPage();
})
// 小tab切換
$('.bg .incomeBox .sTab div').click(function () {
var i = $(this).index() + 1;
$('.bg .incomeBox .sTab div').removeClass('tab1').removeClass('tab2');
$(this).addClass(`tab${i}`);
page = 1;
typeStr = (i == 1 && text == '直接') ? "1,3" : (i == 2 && text == '直接') ? "1" : (i == 1 && text == '間接') ? "2,4" : "2";
$('.bg .incomeBox ul li').remove();
if (i == 1) {
profitPage();
} else {
userPage();
}
})
// 滾動
$('.bg .incomeBox ul').scroll(function () {
let scrollTop = $(this).scrollTop()
let scrollHeight = $('.bg .incomeBox ul')[0].scrollHeight
let ulHeight = $(this).innerHeight()
if (scrollTop + ulHeight + 100 >= scrollHeight) {
if (isLock) {
// 請求下一頁
page = page + 1;
profitPage();
isLock = false;
}
}
})
// 獲取收益接口
function profitPage () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/userInviteFissionRewardRecord/profitPage',
data: { pageNum: page, pageSize: 10, typeStr },
success (res) {
if (res.code === 200) {
var str = '';
if (text == '直接' && typeStr == "1,3") {
$('.bg .incomeBox .tableTitle div').remove();
$('.bg .incomeBox .tableTitle').append(`<div>時間</div><div>收益</div><div>收益類型</div><div>直接請對象</div>`);
} else if (text == '間接' && typeStr == "2,4") {
$('.bg .incomeBox .tableTitle div').remove();
$('.bg .incomeBox .tableTitle').append(`<div>時間</div><div>收益</div><div>收益類型</div><div>間接邀請對象</div>`);
}
if (res.data.records.length == 0) {
if (page == 1) {
str += `
<li>
<div class="">暫無</div>
<div>暫無</div>
<div>暫無</div>
<div class="">暫無</div>
</li>
`}
isLock = false;
} else {
console.log(text);
if (text == '直接' && typeStr == "1,3") {
res.data.records.forEach(res => {
str += `
<li>
<div class="act">
<p>${dateFormat(res.createTime, 'yyyy-MM-dd')}</p>
<b>${dateFormat(res.createTime, 'hh:mm:ss')}</b>
</div>
<div>+${res.rewardNum} <img src="./images/${res.rewardType == 1 ? 'diamond' : 'magicStick'}.png" alt=""></div>
<div>${res.type == 1 && res.rewardType == 1 ? '邀請好友注冊' : res.type == 3 && res.rewardType == 1 ? '好友儲值返現' : res.type == 3 && res.rewardType == 2 ? '好友首次儲值' : '間接邀請儲值返現'}</div>
<div class="act">
<p>${res.inviteNick}</p>
<b>ID:${res.inviteErBanNo}</b>
</div>
</li>
`
});
} else if (text == '間接' && typeStr == "2,4") {
res.data.records.forEach(res => {
str += `
<li>
<div class="act">
<p>${dateFormat(res.createTime, 'yyyy-MM-dd')}</p>
<b>${dateFormat(res.createTime, 'hh:mm:ss')}</b>
</div>
<div>+${res.rewardNum} <img src="./images/${res.rewardType == 1 ? 'diamond' : 'magicStick'}.png" alt=""></div>
<div>${res.type == 1 && res.rewardType == 1 ? '邀請好友注冊' : res.type == 3 && res.rewardType == 1 ? '好友儲值返現' : res.type == 3 && res.rewardType == 2 ? '好友首次儲值' : '間接邀請儲值返現'}</div>
<div class="act">
<p>${res.inviteNick}</p>
<b>ID:${res.inviteErBanNo}</b>
</div>
</li>
`
});
}
isLock = true;
}
$('.bg .incomeBox ul').append(str);
} else {
isLock = true;
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
isLock = true;
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}
// 獲取收益接口
function userPage () {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/userInviteFissionRewardRecord/userPage',
data: { pageNum: page, pageSize: 10, type: typeStr },
success (res) {
if (res.code === 200) {
var str = '';
if (text == '直接' && typeStr == "1") {
$('.bg .incomeBox .tableTitle div').remove();
$('.bg .incomeBox .tableTitle').append(`<div>時間</div><div>直接邀請對象</div><div>30天內充值</div>`);
} else if (text == '間接' && typeStr == "2") {
$('.bg .incomeBox .tableTitle div').remove();
$('.bg .incomeBox .tableTitle').append(`<div>時間</div><div>直接邀請對象</div><div>間接邀請對象</div><div>30天內充值</div>`);
}
if (res.data.records.length == 0) {
if (page == 1) {
str += `
<li>
<div class="">暫無</div>
<div>暫無</div>
<div>暫無</div>
<div class="">暫無</div>
</li>
`}
isLock = false;
} else {
if (text == '直接' && typeStr == "1") {
res.data.records.forEach(res => {
str += `
<li>
<div class="act">
<p>${dateFormat(res.createTime, 'yyyy-MM-dd')}</p>
<b>${dateFormat(res.createTime, 'hh:mm:ss')}</b>
</div>
<div class="act">
<p>${res.inviteNick}</p>
<b>ID:${res.inviteErBanNo}</b>
</div>
<div>${res.charge30Amount ? res.charge30Amount : 0} <img src="./images/diamond.png" alt=""></div>
</li>
`
});
} else if (text == '間接' && typeStr == "2") {
res.data.records.forEach(res => {
str += `
<li>
<div class="act">
<p>${dateFormat(res.createTime, 'yyyy-MM-dd')}</p>
<b>${dateFormat(res.createTime, 'hh:mm:ss')}</b>
</div>
<div class="act">
<p>${res.inviteNick}</p>
<b>ID:${res.inviteErBanNo}</b>
</div>
<div class="act">
<p>${res.indirectNick}</p>
<b>ID:${res.indirectErBanNo}</b>
</div>
<div>${res.charge30Amount ? res.charge30Amount : 0} <img src="./images/diamond.png" alt=""></div>
</li>
`
});
}
isLock = true;
}
$('.bg .incomeBox ul').append(str);
} else {
isLock = true;
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
isLock = true;
hideLoading(layerIndex)
toastMsg('網路錯誤,請退出重進')
}
})
}