Files
mew-h5/view/mew/activity/2022-newYear/js/friends.js
2023-11-08 11:26:13 +08:00

168 lines
4.9 KiB
JavaScript

// 封装layer消息提醒框
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'
})
}
let urlPrefix = getUrlPrefix();
let url = getQueryString();
let browser = checkVersion();
let env = EnvCheck();
var targetUid;//当前选择对象
if (env == 'test') {
new VConsole();
}
var time;
$(function () {
getInfoFromClient()
setTimeout(function () {
// 页面全屏
// if (browser.app) {
// if (browser.android) {
// window.androidJsObj.initShowNav(false)
// } else {
// window.webkit.messageHandlers.initShowNav.postMessage(0)
// }
// };
// 顶部返回事件
$('.back').click(() => {
window.history.go(-1)
})
getInFo(null)
}, 100)
})
// 初始化接口
function getInFo (nick) {
showLoading()
$('ul li').remove();
networkRequest({
type: 'get',
url: urlPrefix + '/act/spring-festival/2023/friend/list',
data: { nick },
success (res) {
if (res.code === 200) {
var str = ''
res.data.forEach(res => {
str += `
<li uid="${res.uid}">
<div class="left">
<img src="${res.avatar}" alt="">
</div>
<div class="right">
<p>${res.nick}</p>
<span>${res.userDesc ? res.userDesc : res.erbanNo}</span>
</div>
</li>
`
});
$('ul').append(str)
$("ul li").on("click", function () {
targetUid = $(this).attr('uid');
if (url.type == 1) {
$('.confirmTheGift .confirmTheGift_in .confirmTheGift_in_title b').text($(this).children().children('p').text());
$('.confirmTheGift .confirmTheGift_in .confirmTheGift_in_title i').text(url.giftName);
$(`.confirmTheGift .confirmTheGift_in .gift`).attr('src',`./images/${url.cardId}.png`)
$('.confirmTheGift').show();
bodyScroolFun(true)
} else {
//索要
request(url.cardId, targetUid);
}
});
hideLoading(layerIndex)
clearInterval(time)
} else {
clearInterval(time)
toastMsg(res.message)
hideLoading(layerIndex)
}
},
error (err) {
hideLoading(layerIndex)
toastMsg('网络错误,请退出重进')
clearInterval(time)
}
})
}
// 赠送接口
function give (cardId, targetUid) {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/act/spring-festival/2023/card/send',
data: { cardId, targetUid },
success (res) {
if (res.code === 200) {
toastMsg('赠送成功');
hideLoading(layerIndex)
} else {
toastMsg(res.message)
hideLoading(layerIndex)
}
bodyScroolFun(false);
$(".confirmTheGift").hide();
},
error (err) {
hideLoading(layerIndex)
toastMsg('网络错误,请退出重进')
}
})
}
// 索要接口
function request (cardId, targetUid) {
showLoading()
networkRequest({
type: 'get',
url: urlPrefix + '/act/spring-festival/2023/card/ask',
data: { cardId, targetUid },
success (res) {
if (res.code === 200) {
toastMsg('已向好友发送索要信息');
hideLoading(layerIndex)
} else {
toastMsg(res.message)
hideLoading(layerIndex)
}
},
error (err) {
hideLoading(layerIndex)
toastMsg('网络错误,请退出重进')
}
})
}
// 页面一确认赠送 取消按钮
$('.confirmTheGift .confirmTheGift_in .but1').click(function () {
bodyScroolFun(false);
$(".confirmTheGift").hide();
})
// 页面一确认赠送 确认按钮
$('.confirmTheGift .confirmTheGift_in .but2').click(function () {
give(url.cardId, targetUid);
})
// 监听输入框
$("input").bind('input propertychange', function () {
var val = $(this).val();
clearInterval(time)
time = setInterval(function () {
getInFo(val)
console.log(val);
}, 500)
});