Files
peko-h5/view/peko/modules/tarot/js/index.js
2022-10-22 15:17:05 +08:00

669 lines
25 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.

var browser = checkVersion();
const urlPrefix = getUrlPrefix();//判断正式环境或者测试环境
let prizeRecord = [];//中奖记录
let headwearArr = [];//获取头饰
let prodIDArr = [];//卡片等级综合
let prodID = "taro_1";//卡片等级
let roomUid = null;//房间id
let cardID = [];//所选卡片
let newLotteryObj = [];
let time = null;
let index = 0;
let chargeRecordId;
let isShow = false;
// 下拉加载更多所需变量
var itemIndex = 0;
var tab1LoadEnd = false;
var page = 0;// 页数
var size = 10;// 每页展示n个
let luckyDrawFunc;
let setTartDom = [];// 塔罗牌渲染dom
setTartDom[0] = {
tarotNature: [0, 1, 2, 3, 9, 4, 5, 6, 7, 8],
tarotClassNum: [1, 2, 3, 4, 5, 6, 10, 9, 8, 7]
}
let goldCoin = 100;//等级所选命中卡片鉆石数量默认100
let setPosition = [];// 发牌定位
setPosition[0] = {
position: { top: '0rem', left: '0rem' },
};
setPosition[1] = {
position: { top: '0rem', left: '2.25rem' },
};
setPosition[2] = {
position: { top: '0rem', left: '4.5rem' },
};
setPosition[3] = {
position: { top: '0rem', left: '6.8rem' },
};
setPosition[4] = {
position: { top: '3.52rem', left: '0rem' },
};
setPosition[5] = {
position: { top: '3.52rem', left: '6.8rem' },
};
setPosition[6] = {
position: { top: '7rem', left: '0rem' },
};
setPosition[7] = {
position: { top: '7rem', left: '2.25rem' },
};
setPosition[8] = {
position: { top: '7rem', left: '4.5rem' },
};
setPosition[9] = {
position: { top: '7rem', left: '6.8rem' },
};
let prizeRecordTime = null;
let requestStatus = false;
let clickStatus = false;
getInfoFromClient();
$(function () {
if (EnvCheck() == 'test') {
new VConsole();
}
let roomId = null;
if (browser.app) {
console.log('从客户端获取了用户信息设备信息此信息来源common.js');
if (browser.android) {
roomId = window.androidJsObj.getRoomUid()
} else {
window.webkit.messageHandlers.getRoomUid.postMessage(null)
setTimeout(() => {
roomId = pubInfo.roomUid;
console.log(roomId)
}, 200);
}
}
// 渲染塔罗牌
setTartDomFun();
function setTartDomFun() {
let TarotResult = ''
setTartDom[0].tarotNature.forEach((res, index) => {
TarotResult += `
<h3 index1="${res}" class="smallbox${res}"></h3>
<div index="${res}" class="primary${setTartDom[0].tarotClassNum[index]}">${res} <b class="a${res}"></b></div>
`
})
$('.card').append(TarotResult)
}
// tab切换
$('.rule_record .title').click(function () {
$(this).css({ color: '#CD8AFC' }).siblings().css({ color: '#fff' })
$(this).children('i').css({ color: '#CD8AFC' }).parent().siblings().children('i').css({ color: '#fff' })
$('.layer').css({ display: 'block' })
$('.conent').css({ height: '13.3066666667rem' })
if ($(this).index() == 0) {
tabCut('block', 'none', 'none')
acrtiveLineFun('block', 'none')
$('.dropload-refresh').css({ display: 'none' })
clickStatus = false;
} else {
if (clickStatus == 1) {
console.log('你已经重复点击')
} else {
page = 0;
$('.dropload-refresh').css({ display: 'block' })
tabCut('none', 'block', 'none')
$('.line').css({ display: 'block' })
$('.dropload-down').remove()
prizeRecord = [];
$('.dom').remove();
prizeRecordFun();//中奖记录请求
clickStatus = 1;
acrtiveLineFun('none', 'block')
}
}
})
// 关闭列表按钮
$('.cancel').click(function () {
tabCut('none', 'none', 'none')
$('.conent').css({ height: '0rem' })
$('.cancel').css({ display: 'none' })
$('.layer').css({ display: 'none' })
$('.bigBox .rule_record .rule, .bigBox .rule_record .record').css({ color: '#fff' })
$('.bigBox .rule_record .rule i, .bigBox .rule_record .record i').css({ color: '#fff' })
clickStatus = false;
})
// tab切换函数
function tabCut(value, value2, value3) {
$('.text').css({ display: value });
$('.table-wrap').css({ display: value2 })
$('.table').css({ display: value2 })
$('.noData').css({ display: value3 })
$(".cancel").css({ display: 'block' })
$('.line').css({ display: 'none' })
}
// 控制中奖和规则切换当前类
function acrtiveLineFun(Lval, Rval) {
$('.rule .line').css({ display: Lval });
$('.record .line').css({ display: Rval });
}
//卡片等级切换
$('.bigBox .cardGrade div').click(function () {
initialize()
cardID = [];
// 设置卡片产品等级id
prodID = prodIDArr[$(this).index()];
console.log(prodID)
$('.smallbox0,.smallbox1,.smallbox2,.smallbox3,.smallbox9,.smallbox4,.smallbox5,.smallbox6,.smallbox7,.smallbox8').css({ display: 'none', })
// 当前不执行动画
if ($(this).index() != index) { cardAnimation() }
index = $(this).index();
$(this).addClass('cardGradeActive').siblings().removeClass('cardGradeActive')
})
// 发牌动画
cardAnimation();
function cardAnimation() {
$(`.card h3`).css({ display: 'none' })
$(`.card div b`).css({ display: 'none' })
$('.bigBox .card div').css({ transition: 'all 0.3s', color: '#5B1522' })
$('.card .primary1,.primary2,.primary3,.primary4,.primary5,.primary6,.primary7,.primary8,.primary9,.primary10').css({ top: '3.5rem', left: '3.5rem' })
setPosition.forEach((res, index) => {
setTimeout(function () { $(`.card .primary${index + 1}`).css(res.position) }, 200 * index)
})
setTimeout(function () {
// 卡片点击事件
Array.prototype.indexOf = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function (val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
$('.card div').click(function () {
if (cardID.length == $('.card div').length - 1) {//选择卡片的长度
console.log('最多只能选9张卡片')
} else {
if ($('.drawBut')[0].innerHTML == '再来一次') {
let cardIndex = $(this)[0].innerText;
if (newLotteryObj.indexOf(cardIndex) == -1) {
console.log('当前中奖不存在此卡牌')
} else {
mySwiperfun(newLotteryObj.indexOf(cardIndex))
setTimeout(function () {
isSwiperFun('block')
}, 100)
}
return
} else {
cardID.remove($(this).attr('index1'));
if (cardID.indexOf($(this).attr('index')) == -1) {
cardID.push(parseInt($(this).attr('index')))
console.log(cardID)
// console.log(`.smallbox${$(this).attr('index')}`)
$(`.smallbox${$(this).attr('index')}`).css({ display: 'block' })
}
}
getGold()
setButCss()
cardIDFun();
}
})
$('.card h3').click(function () {
cardID.remove($(this).attr('index1'));
console.log(cardID.length)
$(`.smallbox${$(this).attr('index1')}`).css({ display: 'none' })
getGold()
setButCss()
cardIDFun();
})
}, 2100)
cardID = [];
toggerBg()
}
function cardIDFun() {
$('.cardtext').text(`您选中的塔罗牌命中${goldCoin}鉆石概率为${cardID.length == 0 ? '' : cardID.length}0%`)
}
function setButCss() {
if (cardID.length != []) {
$('.drawBut').css({ background: '#652DAD' })
} else {
$('.drawBut').css({ background: '#DBDBDB' })
}
}
// 不同等级不同背景
function toggerBg() {
if (prodID == 'taro_1') {
$('.card div').css({ "background-image": "url(./image/cardPrimary.png)" })
goldCoin = 100;
} else if (prodID == 'taro_2') {
$('.card div').css({ "background-image": "url(./image/cardMiddle.png)" })
goldCoin = 1000;
} else if (prodID == 'taro_3') {
$('.card div').css({ "background-image": "url(./image/cardHigh.png)" })
goldCoin = 10000;
}
}
//占卜奖励说明关闭按钮
$('.bigBox .illustrate_centent b').click(function () {
$('.layer').css({ display: 'none', 'z-index': 1 })
$('.bigBox .illustrate_centent').css({ display: 'none' });
})
//占卜奖励说明打开按钮
$('.bigBox .illustrate').click(function () {
$('.layer').css({ display: 'block', 'z-index': 3 })
$('.bigBox .illustrate_centent').css({ display: 'block' });
})
// 广告轮播
function advertising() {
networkRequest({
type: 'GET',
url: urlPrefix + '/lucky/tarot/draw/list',
data: {
count: 20
},
success: function (res) {
if (res.code == 200) {
// console.log(res.data)
let result = ''
res.data.forEach(res => {
result += `
<li>恭喜! ${res.nick}抽中${res.goldNum}鉆石</li>
`
})
$('.ul1').append(result)
var num = $(".ul1").find("li").length;
if (num > 1) {
setInterval(function () {
$('.ul1').animate({
marginTop: "-0.6666666667rem"
}, 200, function () {
$(this).css({
marginTop: "0"
}).find("li:first").appendTo(this);
});
}, 2000);
}
}
},
error: function (res) {
console.log(res, '报错啦');
}
})
}
//中奖记录请求
// prizeRecordFun();
function prizeRecordFun() {
var dropload = $('.table-wrap').dropload({
scrollArea: $('.table-wrap'),
loadDownFn: function (me) {
var result = '';
if (!requestStatus) {
requestStatus = true;
page++;
networkRequest({
type: 'GET',
url: urlPrefix + '/lucky/tarot/user/record?page=' + page + '&pageSize=' + size,
data: {
uid: pubInfo.uid,
},
success: function (res) {
requestStatus = false;
if (res.code == 200) {
prizeRecord = res.data;
var arrLen = res.data.length;
if (arrLen < size) {
// console.log(page)
page = 0;
me.lock(); // 锁定
me.noData(); // 无数据
}
if (arrLen > 0) {
result = prizeRecordDom();
$('.table').append(result)// 插入数据到页面,放到最后面
me.resetload();// 每次数据加载完,必须重置
} else {// 如果没有数据
me.resetload();
me.lock(); // 锁定
me.noData(); // 无数据
console.log($('.rule_record .conent .table tr').length)
if (page == 0 && $('.rule_record .conent .table tr').length == 1) {
$('.dropload-noData').remove();
$('.table').css({ display: 'none' })
$('.noData').css({ display: 'block' })
}
}
}
},
error: function (res) {
requestStatus = false;
console.log(res, '报错啦');
me.lock(); // 锁定
me.noData(); // 无数据
me.resetload();// 即使加载出错,也得重置
$('.table').css({ display: 'none' })
$('.noData').css({ display: 'block' })
}
})
}
}
})
};
// 中奖记录渲染
function prizeRecordDom() {
let result = ''
prizeRecord.forEach((res, i) => {
// console.log(res);
result += `
<tr class='dom'>
<td>${res.chargeProdName}</td>
<td style="max-width: 1rem;"><span>${res.selectdNo}</span></td>
<td>${res.drawNum == undefined ? 0 : res.drawNum}</td>
<td>${res.drawStatus == 2 ? '是,' + res.goldNum + '鉆石' : '否,' + 0 + '鉆石'}</td>
<td>${timeFormat(res.createTime)}</td>
</tr>`
});
return result
};
// 获取头饰请求
function headwearFun() {
networkRequest({
type: 'GET',
url: urlPrefix + '/lucky/tarot/headwear',
success: function (res) {
if (res.code == 200) {
// console.log(res.data)
res.data.forEach(res => {
if (res.chargeProdId == 'taro_1') {
prodIDArr[0] = res.chargeProdId
} else if (res.chargeProdId == 'taro_2') {
prodIDArr[1] = res.chargeProdId
} else {
prodIDArr[2] = res.chargeProdId
}
})
headwearArr = res.data;
console.log(headwearArr)
// console.log(prodIDArr)
// 设置头饰
$('.illustrate_centent .class1 img').attr("src", headwearArr[0].headwear.pic);
$('.illustrate_centent .class2 img').attr("src", headwearArr[1].headwear.pic);
$('.illustrate_centent .class3 img').attr("src", headwearArr[2].headwear.pic);
}
},
error: function (res) {
console.log(res, '报错啦');
}
})
}
// 判断所需金额
function getGold() {
let Gold = 0;
if (prodID == 'taro_1') {
Gold = 1;
} else if (prodID == 'taro_2') {
Gold = 10;
} else {
Gold = 100;
}
$('.allGold b').text(cardID.length * Gold)
}
// 翻转动画
function overturnAnimation(domindex, imgIndex) {
// console.log($(`.card div[index$='${domindex}']`))
$(`.card div[index$='${domindex}']`).css({ transform: 'rotateY(360deg)', transition: 'all 1s', "background-image": `url(./image/${imgIndex}.png)`, color: 'rgba(0,0,0,0)' })
}
// 时间格式转换
function add0(m) { return m < 10 ? '0' + m : m }
function timeFormat(timestamp) {
//timestamp是整数否则要parseInt转换,不会出现少个0的情况
var time = new Date(timestamp);
var year = time.getFullYear();
var month = time.getMonth() + 1;
var date = time.getDate();
var hours = time.getHours();
var minutes = time.getMinutes();
var seconds = time.getSeconds();
return year + '.' + add0(month) + '.' + add0(date) + ' ' + add0(hours) + ':' + add0(minutes) + ':' + add0(seconds);
}
function initialize() {
$('.allGold b').text('0');
$('.drawBut').text('试试手气')
$('.drawBut').css({ background: '#DBDBDB' })
$('.cardtext').text('请凭直觉选择1到9张塔罗牌')
}
// 打开新页面进行支付
function toWxH5Pay(url) {
const browser = checkVersion();
if (browser.app) {
if (browser.android) {
window.androidJsObj.openDialogWebview(url);
} else {
window.webkit.messageHandlers.openDialogWebview.postMessage(url);;
}
} else {
window.location.href = url;
}
}
function initPage() {
console.debug('-----init page');
advertising()//通告栏滚动调用
headwearFun();
}
setTimeout(() => {
initPage();
}, 500);
// 关闭认证弹窗
$('.button-cancel').on('click', function () {
$(this).parents('.identity-mask').hide();
});
$('.button-agree').on('click', function () {
$(this).parents('.identity-mask').hide();
});
// 抽奖支付按钮点击事件
$('.js-draw-btn').click(function () {
clearTimeout(time)
time = setTimeout(function () {
if (cardID.length == 0 && $('.drawBut')[0].innerHTML != '再来一次') {
$('.drawBut').css({ background: '#DBDBDB' })
toastMsg('请选择卡片');
} else {
newLotteryObj = [];
if ($('.drawBut')[0].innerHTML == '再来一次') {
initialize()
cardAnimation()//发牌动画
$('.drawBut').text('试试手气')
} else {
const prodId = prodID;
const roomUid = roomId;
const cardList = cardID;
requestTaroCharge(prodId, roomUid, cardList, res => {
let data = res.data;
chargeRecordId = data.chargeRecordId;
toWxH5Pay(data.payRet.mweb_url);
}, res => {
console.log('试试手气按钮')
console.log(res)
if (res.code == 10108) {
$('.identity-mask').css({ display: 'block' })
} else {
toastMsg(res.message);
}
});
}
}
}, 300)
});
luckyDrawFunc = function luckyDraw(lotteryObj) {
let num = null;
if (lotteryObj.drawStatus == 2) {
num = 1;
} else {
num = 0
}
function sjNum(num) {
var arr = [];
for (var i = num; i <= 9; i++) {
arr.push(i);
}
arr.sort(
function () {
return 0.5 - Math.random();
}
);
// console.log(arr);
return arr
}
let itemIndex = sjNum(num);
itemIndex.push(0)
lotteryObj.selectdNo = JSON.parse(lotteryObj.selectdNo)
// 中奖的时候
if (lotteryObj.drawStatus == 2) {
let a = lotteryObj.selectdNo.indexOf(lotteryObj.drawNum)
lotteryObj.selectdNo.splice(a, 1)
let str = ''
lotteryObj.selectdNo.sort(function (a, b) { return a > b ? 1 : -1 });//从小到大排序)
lotteryObj.selectdNo.forEach((res, index) => {
// console.log(index)
overturnAnimation(res, itemIndex[index])
str += `
<div class="swiper-slide" style="background:url(./image/${itemIndex[index]}.png) 0px 5px / 100% 99% no-repeat"></div>
`
})
let fist = `<div class="swiper-slide" style="background:url(./image/0.png) 0px 5px / 100% 99% no-repeat"></div>`
overturnAnimation(lotteryObj.drawNum, 0)
lotteryObj.selectdNo.push("" + lotteryObj.drawNum + "")
lotteryObj.selectdNo.sort(function (a, b) { return a > b ? 1 : -1 });//从小到大排序)
let indexDom = lotteryObj.selectdNo.indexOf(lotteryObj.drawNum);
if (lotteryObj.selectdNo.length == 1) {
$('.swiper .swiper-container .swiper-wrapper').append(fist)
} else {
$('.swiper .swiper-container .swiper-wrapper').append(str)
let dom = $('.swiper .swiper-container .swiper-wrapper .swiper-slide');
// console.log(dom.length)
// console.log(indexDom)
dom.eq(indexDom).before(fist)
if (dom.length <= indexDom) {
dom.eq(indexDom - 1).after(fist)
}
}
mySwiperfun(indexDom)
timeSwiperFun()
$('.cardtext').text(`获得${lotteryObj.goldNum}鉆石愿好运常伴您左右`)
newLotteryObj = lotteryObj.selectdNo; cardID = [];
} else if (lotteryObj.drawStatus == 3) {//没中奖的时候
let a = itemIndex.indexOf(0)
itemIndex.splice(a, 1)
itemIndex.splice(itemIndex.length - 1, 1)
// console.log(itemIndex)
let str = ''
lotteryObj.selectdNo.sort(function (a, b) { return a > b ? 1 : -1 });//从小到大排序)
lotteryObj.selectdNo.forEach((res, index) => {
overturnAnimation(res, itemIndex[index]);
str += `
<div class="swiper-slide" style=" background:url(./image/${itemIndex[index]}.png) 0px 5px / 100% 99% no-repeat"></div>
`
// margin:0 1rem;
})
$(`.card div .a${lotteryObj.drawNum}`).css({ display: 'block' })
$('.swiper .swiper-container .swiper-wrapper').append(str)
mySwiperfun(0)
timeSwiperFun()
$('.cardtext').text(`幸运号码为${lotteryObj.drawNum}就差那么一点点运气了`)
newLotteryObj = lotteryObj.selectdNo;
cardID = [];
}
}
let mySwiper;
// swiper
function timeSwiperFun() {
setTimeout(function () {
isSwiperFun('block')
}, 1200)
}
function mySwiperfun(index) {
console.log(index);
if (!mySwiper) {
mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal', // 水平切换选项
effect: "coverflow",
coverflowEffect: {
rotate: 0,
stretch: 0,
depth: 60,
modifier: 5,
slideShadows: false
},
spaceBetween: 50,
width: 250,
height: 400,
autoHeight: true,
initialSlide: index,
loop: false, // 循环模式选项
setWrapperSize: true,
centeredSlides: true,
slidesPerView: 1.3,
observer: true,//修改swiper自己或子元素时自动初始化swiper
observeParents: true,//修改swiper的父元素时自动初始化swiper
// 如果需要分页器
pagination: {
el: '.swiper-pagination',
},
})
}
// mySwiper.init()
mySwiper.update(true)
mySwiper.slideTo(index)
}
$('.outSwiper').click(function () {
isSwiperFun('none')
})
//开关swiper
function isSwiperFun(value) {
$('.swiper').css({ display: value })
$('.layer1').css({ display: value })
}
})
// 客户端回调通知支付成功。
function taroPayResultCallback(result) {
console.log('----taroPaysuccessCallback called', result);
if (result == PAY_STATUS_SUCCESS) {
console.log('----taroPaysuccessCallback do requestTaroTDrawStatus');
requestTaroTDrawStatus(chargeRecordId, res => {
console.log('----taroPaysuccessCallback requestTaroTDrawStatus result', res);
$('.swiper-slide').remove();
$('.drawBut').css({ background: '#E74B81' })
$('.smallbox0,.smallbox1,.smallbox2,.smallbox3,.smallbox9,.smallbox4,.smallbox5,.smallbox6,.smallbox7,.smallbox8').css({ display: 'none', })
luckyDrawFunc(res.data);
$('.drawBut').text('再来一次')
})
}
}