249 lines
10 KiB
JavaScript
249 lines
10 KiB
JavaScript
var browser = checkVersion();
|
|
const urlPrefix = getUrlPrefix();
|
|
const urlTest = "https://api.pekolive.com";
|
|
const urlProduct = "https://beta.api.pekolive.com";
|
|
let arr = [];
|
|
let arr2 = [];
|
|
let countryCode = "";//选择区号
|
|
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 uid;
|
|
let modeOfPayment = false;//判断是否有选择支付方式
|
|
let paymentAmount = false;//判断是否有选择付款金额
|
|
$(function () {
|
|
console.log(host)
|
|
if (EnvCheck() == 'test') {//degBug
|
|
new VConsole();
|
|
}
|
|
getInfoFromClient();//请求依赖
|
|
setTimeout(function () {
|
|
listChargeAreaInfo();
|
|
}, 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) {
|
|
let is_CN = countryCode == "CN" ? true : false;
|
|
networkRequest({
|
|
type: 'GET',
|
|
url: urlPrefix + '/charge/getChargePageInfoForH5',
|
|
data: { countryCode },
|
|
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)
|
|
networkRequest({
|
|
type: 'POST',
|
|
url: urlPrefix + '/charge/apply2New',
|
|
data: { erbanNo, chargeProdId, countryCode, openId, payChannel, paymentType, successUrl, uid },
|
|
success: function (res) {
|
|
if (res.code == 200) {
|
|
console.log(res)
|
|
$('.logingActive').text("請稍等");//""
|
|
$('.logingActive').show();
|
|
window.location.href = res.data.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 = ``;
|
|
res.data.forEach(res => {
|
|
str += `
|
|
<p countryCode="${res.areaCode}" id="pop_up_in_p2">${res.areaName}</p>
|
|
`
|
|
})
|
|
$('.header_top_right b').text(res.data[0].areaName);
|
|
$('.pop_up_in').append(str)
|
|
getChargePageInfoForH5(res.data[0].areaCode);
|
|
$('.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;
|
|
// }
|
|
getChargePageInfoForH5(countryCode);
|
|
})
|
|
} else {
|
|
logingFun(res.message)
|
|
}
|
|
}
|
|
});
|
|
}
|
|
$('.header_top_right').click(function () {
|
|
$('.pop_up').show();
|
|
});
|
|
|
|
function coloursFun (index, type) {
|
|
$('.pay_number .number span').remove();
|
|
var str = '';
|
|
console.log(arr[type]);
|
|
arr[type].chargeWays[index].chargeProds.forEach(res => {//金幣
|
|
str += `
|
|
<span channel="${res.channel}" chargeProdId="${res.chargeProdId}" seqNo="${res.seqNo}">
|
|
<b>${res.chargeGoldNum.toLocaleString()} ${"金幣"}</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');
|
|
$(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;
|
|
}
|
|
}) |