312 lines
13 KiB
JavaScript
312 lines
13 KiB
JavaScript
var browser = checkVersion();
|
||
const urlPrefix = getUrlPrefix();
|
||
var getUrl = getQueryString();
|
||
const urlTest = "https://api.pekolive.com";
|
||
const urlProduct = "https://beta.api.pekolive.com";
|
||
let arr = [];
|
||
let arr2 = [];
|
||
let countryCode = "";//选择区号
|
||
var channelType;//参数值4:鉆石充值 || 参数值5:贵族vip充值 || 6:首充充值
|
||
let erbanNo;//账号
|
||
let chargeProdId;//金额:tw_payermax_1003_1000
|
||
let openId;
|
||
let payChannel;//付款方式
|
||
let paymentType;//付款码
|
||
var host = window.location.host;
|
||
// let successUrl = `${window.location.protocol}//${host}/peko/modules/pay/index.html`;//支付成功回调路径
|
||
let successUrl = window.location.href;//支付成功回调路径
|
||
let uid;
|
||
let modeOfPayment = false;//判断是否有选择支付方式
|
||
let paymentAmount = false;//判断是否有选择付款金额
|
||
var deviceId;//型号ID
|
||
var payMoney //充值金额
|
||
$(function () {
|
||
if (EnvCheck() == 'test') {//degBug
|
||
new VConsole();
|
||
}
|
||
getInfoFromClient();//请求依赖
|
||
setTimeout(function () {
|
||
listChargeAreaInfo();
|
||
if (browser.app) {
|
||
erbanNo == null;
|
||
$('body .pay_method, html .pay_method').css('margin', '-4.5rem auto 0');
|
||
$('body .header .user, html .header .user').hide();
|
||
$('.but1').hide();
|
||
$('.but2').show();
|
||
}
|
||
}, 100)
|
||
function get_param (param) {
|
||
var query = location.search.substring(1).split('&');
|
||
for (var i = 0; i < query.length; i++) {
|
||
var kv = query[i].split('=');
|
||
if (kv[0] == param) {
|
||
return kv[1];
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
// if (get_param('countryCodeURL') == "TW") {
|
||
// countryCode = "TW";
|
||
// $('.header_top_right b').text(langReplace(localLang.demoModule.pop_up_in_p1));//'臺灣'
|
||
// } else if (get_param('countryCodeURL') == "CN") {
|
||
// if (EnvCheck() == 'test') {
|
||
// if (host != "anan.uat.lecheng163.com") {
|
||
// window.location.href = ifCNFun() + '/peko/modules/pay/index.html?countryCodeURL=CN'
|
||
// }
|
||
// } else {
|
||
// if (host != "anan.lecheng163.com") {
|
||
// window.location.href = ifCNFun() + '/peko/modules/pay/index.html?countryCodeURL=CN'
|
||
// }
|
||
// }
|
||
// countryCode = "CN";
|
||
// $('.header_top_right b').text(langReplace(localLang.demoModule.pop_up_in_p2));//'大陸'
|
||
// }
|
||
$('.logingActive').hide();
|
||
if (browser.weixin) {
|
||
$('.wx_skip').show();
|
||
} else {
|
||
$('.wx_skip').hide();
|
||
}
|
||
function getChargePageInfoForH5 (countryCode) {
|
||
deviceId = get_param('deviceId')
|
||
channelType = get_param('channelType');
|
||
let is_CN = countryCode == "CN" ? true : false;
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/charge/getChargePageInfoForH5',
|
||
data: { countryCode, channelType, },
|
||
success: function (res) {
|
||
if (res.code == 200) {
|
||
$('.methods').remove();
|
||
$('.methods span').remove();
|
||
console.log(res)
|
||
let strT = '';
|
||
let strB = '';
|
||
// $('.methods0 p').text(res.data.chargeGroups[0].groupName ? res.data.chargeGroups[0].groupName : '');
|
||
// $('.methods1 p').text(res.data.chargeGroups[1] ? res.data.chargeGroups[1].groupName : '');
|
||
res.data.chargeGroups.forEach((res1, index1) => {
|
||
arr = res.data.chargeGroups;
|
||
// strB +=
|
||
$('.pay_method .methodBox').append(`
|
||
<div class="methods methods${index1}">
|
||
<p style="width: 100%;color: #000;height: 0.8rem;display: none;">${res1.groupName}</p>
|
||
</div>
|
||
`);
|
||
res.data.chargeGroups[index1].chargeWays.forEach((res, index) => {
|
||
// arr[index] = res.chargeProds;
|
||
// strT +=
|
||
$(`.methods${index1}`).append(`
|
||
<span index=${index} type='${index1}' desc="${res.desc}" paymentType="${res.paymentType}" payChannel="${res.payChannel}">
|
||
<img src="${res.logo}" alt="">
|
||
<p>${res.desc}</p>
|
||
</span>
|
||
`);
|
||
});
|
||
|
||
});
|
||
coloursFun(0, 0);
|
||
// 选择支付方式按钮
|
||
$('.methods span').click(function () {
|
||
modeOfPayment = true;
|
||
console.log($(this))
|
||
paymentType = $(this).attr('paymentType');
|
||
payChannel = $(this).attr('payChannel');
|
||
// $(this).parent().addClass('active').siblings().removeClass('active');
|
||
$('.methods span').removeClass('active');
|
||
$(this).addClass('active');
|
||
coloursFun($(this).attr('index'), $(this).attr('type'));
|
||
})
|
||
console.log(countryCode)
|
||
$('.but2').off();
|
||
$('.but2').on('click', function () {
|
||
console.log(countryCode)
|
||
if (modeOfPayment == false) {
|
||
logingFun("請選擇儲值方式")//''
|
||
} else if (paymentAmount == false) {
|
||
logingFun("請選擇您的儲值金額")//''
|
||
} else {
|
||
console.log(countryCode)
|
||
console.log('payMoney',payMoney);
|
||
// 点击充值埋点
|
||
chargeFinish(payMoney)
|
||
networkRequest({
|
||
type: 'POST',
|
||
url: urlPrefix + '/charge/apply2New',
|
||
data: { erbanNo, chargeProdId, countryCode, openId, payChannel, paymentType, successUrl, uid, deviceId: deviceId },
|
||
success: function (res) {
|
||
if (res.code == 200) {
|
||
console.log(res)
|
||
$('.logingActive').text("請稍等");//""
|
||
$('.logingActive').show();
|
||
window.location.href = res.data.payInfo.mweb_url;
|
||
} else {
|
||
logingFun(res.message)
|
||
}
|
||
}
|
||
});
|
||
}
|
||
})
|
||
} else if (res.code == 1900) {
|
||
countryCode = "TW";
|
||
getChargePageInfoForH5(countryCode);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
function listChargeAreaInfo () {
|
||
networkRequest({
|
||
type: 'GET',
|
||
url: urlPrefix + '/charge/listChargeAreaInfo',
|
||
success: function (res) {
|
||
if (res.code == 200) {
|
||
var str = ``;
|
||
var countryCodeIndexs = 0;
|
||
res.data.forEach((res, i) => {
|
||
str += `
|
||
<p countryCode="${res.areaCode}" id="pop_up_in_p2">${res.areaName}</p>
|
||
`
|
||
if (getUrl.countryCode && res.areaCode == getUrl.countryCode) {
|
||
countryCodeIndexs = i;
|
||
}
|
||
})
|
||
if (getUrl.countryCode) {
|
||
$('.header_top_right b').text(res.data[countryCodeIndexs].areaName);
|
||
countryCode = res.data[countryCodeIndexs].areaCode;
|
||
} else {
|
||
$('.header_top_right b').text(res.data[0].areaName);
|
||
countryCode = res.data[0].areaCode
|
||
}
|
||
$('.pop_up_in').append(str)
|
||
getChargePageInfoForH5(countryCode);
|
||
successUrl = updateQueryStringParameter(window.location.href, "countryCode", countryCode)
|
||
console.log(successUrl);
|
||
$('.pop_up_in p').click(function () {
|
||
$('.header_top_right b').text($(this).text());
|
||
countryCode = $(this).attr("countryCode");
|
||
$('.pop_up').hide();
|
||
// if (countryCode == "CN") {
|
||
// if (EnvCheck() == 'test') {
|
||
// if (host != "anan.uat.lecheng163.com") {
|
||
// window.location.href = ifCNFun() + '/peko/modules/pay/index.html?countryCodeURL=CN'
|
||
// }
|
||
// } else {
|
||
// if (host != "anan.lecheng163.com") {
|
||
// window.location.href = ifCNFun() + '/peko/modules/pay/index.html?countryCodeURL=CN'
|
||
// }
|
||
// }
|
||
// } else {
|
||
// window.location.href = urlPrefix + '/peko/modules/pay/index.html?countryCodeURL=' + countryCode;
|
||
// }
|
||
successUrl = updateQueryStringParameter(window.location.href, "countryCode", countryCode)
|
||
console.log(successUrl);
|
||
getChargePageInfoForH5(countryCode);
|
||
})
|
||
} else {
|
||
logingFun(res.message)
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
$('.header_top_right').click(function () {
|
||
$('.pop_up').show();
|
||
});
|
||
|
||
$('.pop_up').click(function(){
|
||
$('.pop_up').hide();
|
||
})
|
||
|
||
function coloursFun (index, type) {
|
||
$('.pay_number .number span').remove();
|
||
var str = '';
|
||
console.log(arr[type]);
|
||
arr[type].chargeWays[index].chargeProds.forEach(res => {//金幣
|
||
// <b>${res.chargeGoldNum.toLocaleString()} ${"金幣"}</b>
|
||
str += `
|
||
<span channel="${res.channel}" chargeProdId="${res.chargeProdId}" payMoney="${res.money}" seqNo="${res.seqNo}">
|
||
<b>${res.prodName}</b>
|
||
<i>${res.currencySign} ${res.money.toLocaleString()}</i>
|
||
</span>
|
||
`
|
||
})
|
||
$('.pay_number .number').append(str);
|
||
// 选择支付金额按钮
|
||
$('.pay_number .number span').click(function () {
|
||
paymentAmount = true;
|
||
console.log($(this));
|
||
chargeProdId = $(this).attr('chargeProdId');
|
||
payMoney = $(this).attr('payMoney');
|
||
$(this).addClass('active').siblings().removeClass('active');
|
||
})
|
||
}
|
||
$('.user').on('input', function () {
|
||
var val = $(this).val();
|
||
// console.log(val)
|
||
if (isNumber(val)) {
|
||
console.log('不是数字')
|
||
$(this).val("");
|
||
al = $(this).val();
|
||
$('.but1').show();
|
||
$('.but2').hide();
|
||
} else {
|
||
if (val != '') {
|
||
$('.but1').hide();
|
||
$('.but2').show();
|
||
erbanNo = val;
|
||
} else {
|
||
$('.but1').show();
|
||
$('.but2').hide();
|
||
}
|
||
}
|
||
})
|
||
function isNumber (string) {
|
||
var r = string.match(/^[0-9]*$/);
|
||
if (r == null) {
|
||
return true
|
||
} else {
|
||
return false
|
||
}
|
||
}
|
||
function logingFun (res) {
|
||
$('.logingActive').text(res.message == undefined ? res : res.message);
|
||
$('.logingActive').show();
|
||
setTimeout(function () {
|
||
$('.logingActive').hide();
|
||
}, 1500)
|
||
}
|
||
function ifCNFun () {
|
||
var envChecks;
|
||
const url = window.location.href;
|
||
console.log(url)
|
||
if (!url) return undefined;
|
||
if (url.match(/uat/) || url.match(/127.0.0.1:/) || (url.match(/beta.api/))) { envChecks = "test" } else { envChecks = "live" };
|
||
if (!envChecks) return undefined;
|
||
return envChecks === 'live' ? urlProduct : urlTest;
|
||
}
|
||
})
|
||
function updateQueryStringParameter (uri, key, value) {
|
||
if (!value) {
|
||
return uri;
|
||
}
|
||
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
|
||
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
|
||
if (uri.match(re)) {
|
||
return uri.replace(re, '$1' + key + "=" + value + '$2');
|
||
}
|
||
else {
|
||
return uri + separator + key + "=" + value;
|
||
}
|
||
}
|
||
|
||
// 点击支付之后埋点
|
||
function chargeFinish(payMoney) {
|
||
if(browser.app){
|
||
if(browser.android){
|
||
window.androidJsObj.chargePayPage(payMoney);
|
||
}else if(browser.ios){
|
||
window.webkit.messageHandlers.chargePayPage.postMessage(payMoney)
|
||
}
|
||
}else{
|
||
console.log('請在app內打開')
|
||
}
|
||
} |