346 lines
14 KiB
JavaScript
346 lines
14 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 = "";//选择区号
|
||
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
|
||
|
||
$(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";
|
||
// $('.area 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";
|
||
// $('.area 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)
|
||
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.replace(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 = ``;
|
||
res.data.forEach(res => {
|
||
str += `
|
||
<p countryCode="${res.areaCode}" id="pop_up_in_p2">${res.areaName}</p>
|
||
`
|
||
})
|
||
let localCode = JSON.parse(localStorage.getItem('localCode'));
|
||
if (localCode) {
|
||
console.log(localCode, 'localCode');
|
||
$('.area b').text(localCode.areaName);
|
||
$('.pop_up_in').append(str)
|
||
getChargePageInfoForH5(localCode.countryCode);
|
||
} else {
|
||
countryCode = res.data[0].areaCode;
|
||
areaName = res.data[0].areaName;
|
||
localStorage.setItem('localCode', JSON.stringify({countryCode,areaName}))
|
||
$('.area b').text(res.data[0].areaName);
|
||
$('.pop_up_in').append(str)
|
||
getChargePageInfoForH5(res.data[0].areaCode);
|
||
}
|
||
|
||
$('.pop_up_in p').click(function () {
|
||
$('.area b').text($(this).text());
|
||
countryCode = $(this).attr("countryCode");
|
||
areaName = $(this).text();
|
||
localStorage.setItem('localCode', JSON.stringify({countryCode,areaName}))
|
||
$('.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)
|
||
}
|
||
}
|
||
});
|
||
}
|
||
$('.area').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}" 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');
|
||
$(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 () {
|
||
$(document).ready(function () {
|
||
var deviceWidth = document.documentElement.clientWidth;
|
||
document.documentElement.style.fontSize = deviceWidth / 19.20 + 'px';
|
||
});
|
||
window.onresize = function () {
|
||
var deviceWidth = document.documentElement.clientWidth;
|
||
// var deviceWidth = document.body.clientWidth;
|
||
document.documentElement.style.fontSize = deviceWidth / 19.20 + 'px';
|
||
// alert(document.documentElement.style.fontSize)
|
||
}
|
||
dragMoveX('.methodBox');
|
||
dragMoveX('.number');
|
||
})
|
||
|
||
/**
|
||
* 拖动内容横向滚动
|
||
* @param {string} container 需要拖动的面板
|
||
*/
|
||
function dragMoveX(container) {
|
||
var flag;
|
||
var downX;
|
||
var scrollLeft;
|
||
//鼠标按下
|
||
$(document.body).on("mousedown", container, function (event) {
|
||
// console.log('mousedown')
|
||
flag = true;
|
||
downX = event.clientX;
|
||
scrollLeft = $(this).scrollLeft();
|
||
});
|
||
//鼠标移动
|
||
$(container).on("mousemove", function (event) {
|
||
// console.log('mousemove',flag)
|
||
if (flag) {
|
||
var moveX = event.clientX;
|
||
var scrollX = moveX - downX;
|
||
// console.log("moveX" + moveX);
|
||
// console.log("scrollX" + scrollX);
|
||
if (scrollX < 0 && scrollLeft > 0) {
|
||
$(this).scrollLeft(scrollLeft - scrollX)
|
||
}
|
||
else {
|
||
$(this).scrollLeft(scrollLeft - scrollX)
|
||
}
|
||
}
|
||
});
|
||
//鼠标释放
|
||
$(container).on("mouseup", function () {
|
||
// console.log('mouseup')
|
||
flag = false;
|
||
});
|
||
/**
|
||
* 注意:与 mouseout 事件不同,mouseleave 事件只有在鼠标指针离开被选元素时被触发,mouseout 事件在鼠标指针离开任意子元素时也会被触发。参见页面底部演示实例。
|
||
* 所以:如果mouseout的子元素存在溢出,并添加了超出加滚动,那么刚进入也会触发该事件,所以这里就不能使用。
|
||
* */
|
||
//鼠标移出元素
|
||
$(container).on("mouseleave", function (event) {
|
||
// console.log('mouseleave',event.pageX,document.body.offsetWidth)
|
||
flag = false;
|
||
if (event.pageX < 0 || event.pageX > document.body.offsetWidth) {
|
||
console.log('在元素上移出')
|
||
flag = false;
|
||
}
|
||
});
|
||
} |