2022-09-08 18:22:18 +08:00
|
|
|
const urlPrefix = getUrlPrefix()
|
|
|
|
|
|
|
|
const toastMsg = (content = '操作完成', time = 2) => {
|
|
|
|
layer.open({
|
|
|
|
content,
|
|
|
|
skin: 'msg',
|
|
|
|
time
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
EnvCheck() == 'test' ? new VConsole() : ''
|
|
|
|
|
|
|
|
let params = {
|
|
|
|
// payChannel: 'wx_wap',
|
|
|
|
successUrl: urlPrefix + '/payment.html',
|
|
|
|
}
|
|
|
|
let chargeList = []
|
|
|
|
let price
|
|
|
|
// 获取充值列表
|
|
|
|
const getChargeList = () => {
|
|
|
|
networkRequest({
|
|
|
|
type: 'GET',
|
|
|
|
url: urlPrefix + '/chargeprod/listV2?channelType=5&position=web',
|
|
|
|
success(res){
|
|
|
|
chargeList = res.data.list.concat(res.data.bigList)
|
|
|
|
renderChargeList()
|
|
|
|
},
|
|
|
|
error(){
|
2022-10-11 15:38:44 +08:00
|
|
|
toastMsg('網絡錯誤')
|
2022-09-08 18:22:18 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabIndex = 0
|
|
|
|
//渲染充值列表
|
|
|
|
const renderChargeList = () => {
|
|
|
|
let str = chargeList.map((item, index) => {
|
|
|
|
return `
|
|
|
|
<li data-prod-id=${item.chargeProdId} data-index=${index}>
|
|
|
|
<img src="./images/diamond.png" alt="">
|
2022-10-22 15:17:05 +08:00
|
|
|
<p class="product"><span>${item.prodName.slice(0,item.prodName.length-2)}</span>鉆石</p>
|
2022-09-08 18:22:18 +08:00
|
|
|
<span class="price">¥${item.money}</span>
|
|
|
|
</li>
|
|
|
|
`
|
|
|
|
}).join('')
|
|
|
|
$('ul.charge-panel').html(str)
|
|
|
|
|
|
|
|
params.chargeProdId = $('ul.charge-panel li').eq(0).data('prod-id')
|
|
|
|
price = chargeList[0].money
|
|
|
|
|
|
|
|
let len = $('ul.charge-panel li').length
|
|
|
|
for(let i=0; i<len; i++){
|
|
|
|
if(i === tabIndex){
|
|
|
|
$('ul.charge-panel li').eq(i).addClass('active')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let userInfo = {}
|
|
|
|
// 提交订单
|
|
|
|
const submitOrder = (params) => {
|
|
|
|
networkRequest({
|
|
|
|
type: 'POST',
|
2023-08-03 14:11:46 +08:00
|
|
|
url: urlPrefix + '/wx/submitPayForMiroMall?app=piko',
|
2022-09-08 18:22:18 +08:00
|
|
|
data: params,
|
|
|
|
success(res){
|
|
|
|
if(res.code === 200){
|
|
|
|
userInfo = res.data
|
|
|
|
renderPopup()
|
|
|
|
}else{
|
|
|
|
toastMsg(res.message)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error(){
|
2022-10-11 15:38:44 +08:00
|
|
|
toastMsg('網絡錯誤')
|
2022-09-08 18:22:18 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
// 渲染弹窗
|
|
|
|
const renderPopup = () => {
|
|
|
|
$('.pop .nickName').html(userInfo.nick)
|
|
|
|
$('.pop .erbanNo').html(userInfo.erban_no)
|
|
|
|
$('.pop .money').html(price)
|
|
|
|
$('.pop').fadeIn(100)
|
|
|
|
}
|
|
|
|
// 微信浏览器调起支付页面
|
|
|
|
const doPay = () => {
|
|
|
|
if($.isEmptyObject(userInfo)){
|
|
|
|
toastMsg('出错了,请刷新页面重试');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const { appid, timestamp, nonce_str, prepay_id, sign_type, sign } = userInfo
|
|
|
|
function onBridgeReady() {
|
|
|
|
WeixinJSBridge.invoke(
|
|
|
|
'getBrandWCPayRequest', {
|
|
|
|
"appId": appid,
|
|
|
|
"timeStamp": timestamp,
|
|
|
|
"nonceStr": nonce_str,
|
|
|
|
"package": prepay_id,
|
|
|
|
"signType": sign_type,
|
|
|
|
"paySign": sign
|
|
|
|
},
|
|
|
|
function (res) {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (typeof WeixinJSBridge == 'undefined') {
|
|
|
|
if (document.addEventListener) {
|
|
|
|
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
|
|
|
|
} else if (document.attachEvent) {
|
|
|
|
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
|
|
|
|
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
onBridgeReady();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$(function(){
|
|
|
|
getInfoFromClient()
|
|
|
|
setTimeout(() => {
|
|
|
|
getChargeList()
|
|
|
|
}, 50)
|
|
|
|
|
|
|
|
//监听点击充值列表事件
|
|
|
|
$('ul.charge-panel').on('click', 'li', function(){
|
|
|
|
let index = $(this).index()
|
|
|
|
$(this).addClass('active').siblings().removeClass('active')
|
|
|
|
params.chargeProdId = $(this).data('prod-id')
|
|
|
|
price = chargeList[index].money
|
|
|
|
})
|
|
|
|
|
|
|
|
//监听确认支付按钮点击事件,作各种验证
|
|
|
|
$('.confirm').click(function(){
|
|
|
|
let value = $('.phone').val()
|
|
|
|
$('.phone').val('')
|
|
|
|
let reg = /^[0-9]*$/
|
|
|
|
let regPhone = /^[1][3,4,5,7,8][0-9]{9}$/
|
|
|
|
let openid = window.sessionStorage.getItem('openid')
|
|
|
|
if(!value || !reg.test(value)){
|
|
|
|
toastMsg('请输入正确的手机号码或者平台')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if(regPhone.test(value)){
|
|
|
|
params.phone = value
|
|
|
|
delete params.erban_no
|
|
|
|
}else{
|
|
|
|
params.erban_no = value
|
|
|
|
delete params.phone
|
|
|
|
}
|
|
|
|
if(!openid){
|
|
|
|
toastMsg('页面未授权,请在公众号菜单进入本页面');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
params.openId = openid
|
|
|
|
// 提交订单
|
|
|
|
submitOrder(params)
|
|
|
|
})
|
|
|
|
|
|
|
|
// 关闭弹窗
|
|
|
|
$('.cancel').click(() => {
|
|
|
|
$('.pop').fadeOut(100)
|
|
|
|
})
|
|
|
|
|
|
|
|
// 确认支付
|
|
|
|
$('.final-confirm').click(() => {
|
|
|
|
$('.pop').fadeOut(100)
|
|
|
|
doPay()
|
|
|
|
})
|
|
|
|
})
|