var browser = checkVersion();
const urlPrefix = getUrlPrefix();//判断正式环境或者测试环境
// 封装layer消息提醒框 hideLoading(layerIndex)
let layerIndex
const showLoading = (content = '加載中...') => {
layer.open({
type: 2,
shadeClose: false,
content,
success (e) {
layerIndex = $(e).attr('index')
}
})
}
const hideLoading = (index) => {
layer.close(index)
}
const toastMsg = (content = '操作完成', time = 2) => {
layer.open({
content,
time,
skin: 'msg'
})
}
// 页面全屏
if (browser.app) {
if (browser.android) {
window.androidJsObj.initShowNav(false)
} else {
window.webkit.messageHandlers.initShowNav.postMessage(0)
}
}
let shareObj = {
type: 2,
data: {
msg: 'llllll',
title: '我的piko一周年报告',
imgUrl: 'https://beta.api.pekolive.com/peko/modules/wxPubPay/images/logo.png',
desc: '我的专属称号竟然是这样的!快来试试你的~',
}
}
var lock;
$(function () {
// debug
if (EnvCheck() == 'test') {
new VConsole();
}
getInfoFromClient()
setTimeout(function () {
getData();
statusFunction()
}, 50)
// 获取分享状态按钮
function statusFunction () {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/one/year/time/cinema/status',
// data:{},
success (res) {
if (res.code === 200) {
lock = res.data;
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 分享按钮
// 获取基本数据
function getData () {
networkRequest({
type: 'GET',
url: urlPrefix + '/act/one/year/time/cinema',
// data:{},
success (res) {
if (res.code === 200) {
$('.bg1 .p1').html(`还记得 ${dateFormat(res.data.signTime, 'yyyy')} 年 ${dateFormat(res.data.signTime, 'MM')} 月 ${dateFormat(res.data.signTime, 'dd')} 日`);
$('.bg1 .sp1').html(` ${res.data.signDay} `);
$('.bg2 .sp1').html(` ${res.data.loginDay} `);
$('.bg2 .sp2').html(` ${res.data.loginNum} `);
$('.bg2 .sp3').html(` ${res.data.inRoomNum} `);
console.log(res.data.inRoomNum > 0);
if (res.data.inRoomNum > 0) {
$('.bg2 .sp4').html(` ID:${res.data.longDayErbanNo} `);
$('.bg2 .sp5').html(` ${res.data.inRoomDay} `);
} else {
$('.bg2 .sp4').hide()
$('.bg2 .sp5').hide()
}
if (res.data.maxErbanNo != undefined) {
var time = Number(dateFormat(res.data.maxInRoomTime, 'hh'));
$('.isShow').show();
$('.bg2 .sp6').html(`ID:${res.data.maxErbanNo} `);
$('.bg2 .p1').html(`一直到 (${time >= 18 && time != 00 ? '晚上' : time >= 00 && time < 4 ? '深夜' : '凌晨'})${dateFormat(res.data.maxInRoomTime, 'hh')} 点 ${dateFormat(res.data.maxInRoomTime, 'mm')} 分`);
}
if (res.data.friendSize > 0) {
$('.bg3').show();
$('.bg3 .sp1').html(` ${res.data.friendSize} `);
if (res.data.sendGiftRecord == undefined) {
$(".bg3 .ps1").html('你暂时还没有送出过礼物');
$(".bg3 .ps2").html('快让TA知道TA对你很重要吧~');
$(".bg3 .ps3").hide();
$(".bg3 .ps4").hide();
} else {
console.log(res.data.sendGiftRecord.giftTime);
$('.bg3 .p1').html(`在 ${dateFormat(res.data.sendGiftRecord.giftTime, 'yyyy')} 年 ${dateFormat(res.data.sendGiftRecord.giftTime, 'MM')} 月 ${dateFormat(res.data.sendGiftRecord.giftTime, 'dd')} 日 这一天`);
$('.bg3 .sp2').html(` ${res.data.sendGiftRecord.giftUserNick} `);
$('.bg3 .sp3').html(` ${res.data.sendGiftRecord.goldPrice} `);
$('.bg3 .sp4').html(` ${res.data.sendGiftRecord.giftNum} `);
}
if (res.data.receiveGiftRecord == undefined) {
$(".bg3 .ps5").html('而在这一年');
$(".bg3 .ps6").html('你还没有收到过礼物');
$(".bg3 .ps7").html('快去寻找趣味相投的TA');
$(".bg3 .ps8").html('表达心中的想念吧~');
} else {
$('.bg3 .sp5').text(` ${res.data.receiveGiftRecord.giftUserNick} `);
$('.bg3 .sp6').text(` ${res.data.receiveGiftRecord.goldPrice} `);
$('.bg3 .sp7').text(` ${res.data.receiveGiftRecord.giftName} `);
$('.bg3 .sp8').text(` ${res.data.receiveGiftRecord.giftNum} `);
$('.bg3 .p2').html(`而在 ${dateFormat(res.data.receiveGiftRecord.giftTime, 'yyyy')} 年 ${dateFormat(res.data.receiveGiftRecord.giftTime, 'MM')} 月 ${dateFormat(res.data.receiveGiftRecord.giftTime, 'dd')} 日 `);
}
} else {
$('.bg4').show();
}
$('.bgBox .bg5 .text h3 span').html(`"${res.data.userMonicker}" `)
shareObj.data.link = urlPrefix + `/peko/activity/first_anniversary/share.html?avatar=${res.data.avatar}&nick=${res.data.nick}`;
shareObj.data.showUrl = urlPrefix + `/peko/activity/first_anniversary/share.html?avatar=${res.data.avatar}&nick=${res.data.nick}`;
// ;
console.log(shareObj.data.link);
//分享按钮
$('.bgBox .bg5 .but').click(function () {
console.log(lock == false);
if (lock == true) {
if (browser.app) {
if (browser.android) {
window.androidJsObj.openSharePage(JSON.stringify(shareObj));
} else if (browser.ios) {
window.webkit.messageHandlers.openSharePage.postMessage(JSON.stringify(shareObj));
}
}
} else {
// showLoading();
networkRequest({
type: 'GET',
url: urlPrefix + '/act/one/year/time/cinema/award',
// data:{},
success (res) {
if (res.code === 200) {
if (browser.app) {
if (browser.android) {
window.androidJsObj.openSharePage(JSON.stringify(shareObj));
} else if (browser.ios) {
window.webkit.messageHandlers.openSharePage.postMessage(JSON.stringify(shareObj));
}
}
statusFunction();
} else {
toastMsg(res.message)
}
hideLoading(layerIndex)
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
}
})
}
});
} else {
return toastMsg(res.message)
}
},
error (err) {
toastMsg('網絡錯誤,請退出重進')
}
})
}
// 顶部返回事件
$('.back').click(() => {
window.history.go(-1)
})
// 监听用户上滑
let startY
var length = $('.bgBox .bg').length - 1;
var index = 0;
var touchLength = 100;
$(document).on('touchstart', function (e) {
startY = e.touches[0].pageY
})
$(document).on('touchend', function (e) {
let endY = e.originalEvent.changedTouches[0].pageY
if (startY - endY >= 50) {
if (index < length - 1) {
index = index + 1
$('.bgBox').css("transform", `translateY(-${index * touchLength}%)`)
}
} else if (endY - startY >= 50) {
if (index > 0) {
index = index - 1
$('.bgBox').css("transform", `translateY(-${index * touchLength}%)`)
}
}
})
})