function closePop() {
$(".mask").hide();
$(".pop").hide();
}
//收藏ea作品
var collection_lock = 1,
collection_lock1 = 1,
collection_lock2 = 1,
collection_lock3 = 1,
list = [];
// ae类型的收藏
function aeCollection(obj, aid, group, type) {
if (collection_lock1 == 1) {
msgBox.show("请稍候……", msgBox.warn);
$.ajax({
type: "post",
url: "/index/ajax/handle_stow",
data: {
"aid": aid,
"gid": group,
"type": type
},
beforeSend: function () {
collection_lock1 = 0;
},
success: function (data) {
var status = data.status,
msg = data.msg;
collection_lock1 = 1;
if (status == 1) {
msgBox.show(msg, msgBox.ok);
} else {
msgBox.show(msg, msgBox.warn);
}
if (type == 1) {
console.log("已收藏");
$(obj).data("fav", 1);
$(obj).addClass("cur");
} else {
console.log("取消已收藏");
$(obj).data("fav", 0);
$(obj).removeClass("cur");
}
},
error: function () {
collection_lock1 = 1;
msgBox.show("网络错误请重试", msgBox.warn);
}
});
}
}
// 打开管理组弹层
function openManageGroup (list, obj, aid, type){
const otherList = list.filter(item => item.id !== 0)
var groups = ''
var saveBtn = ``
var deleteBtn = ``
var addGroupHtml = `
${saveBtn}
`
if(otherList && otherList.length){
for (var i in otherList) {
groups += `
${saveBtn}
${deleteBtn}
`;
}
} else {
groups += addGroupHtml
}
layer.open({
title: "管理分组",
content: `
`,
btn: ["确认", "返回"],
btnAlign: "c",
yes: function (index, layero, that) {
openCollectionGroup(obj, aid, type)
layer.close(index);
},
no: function (index, layero, that) {
openCollectionGroup(obj, aid, type)
layer.close(index);
},
success: function(layero, index, that){
// 监听新增分组按钮
$('#addGroupBtn').on('click', function(){
const hasAdd = $("#collectionGroup .group_item").hasClass('is_add')
if(hasAdd){
msgBox.show("请先保存新增分组", msgBox.warn);
return false
}
$("#collectionGroup").append(addGroupHtml)
})
$('#manageGroupPop').on('click', '.saveGroupBtn', function(){
var $this = $(this)
var $groupItem = $this.parents('.group_item')
var $input = $this.siblings('.from-input')
var isAdd = $groupItem .hasClass('is_add');
var gid = $groupItem .data('id');
var val = $input.val()
console.log('isAdd', isAdd, 'val', val, 'gid', gid)
if(!val){
msgBox.show("请输入分组名", msgBox.warn);
return false
} else if(val.length > 6){
msgBox.show("分组名最多只能6位数哦", msgBox.warn);
return false
} else {
const hasItem = list.find(item => item.name === val)
if(hasItem && hasItem.length){
msgBox.show("当前分组名已存在哦", msgBox.warn);
return false;
}
}
if(collection_lock3 === 1){
var data = {
name: val
}
if(!isAdd && gid){
data.gid = gid
}
console.log('data', data)
$.ajax({
type: "post",
url: `/index/ajax/${isAdd ? 'stow_group_add' : 'modify_group'}`,
data: data,
beforeSend: function () {
collection_lock3 = 0;
},
success: function (data) {
var status = data.status,
msg = data.msg,
id = data.id;
if (status == 1) {
$groupItem.removeClass('is_add').data('id', id);
if(isAdd){
$groupItem.append(deleteBtn)
}
msgBox.show(msg, msgBox.ok);
} else {
msgBox.show(msg, msgBox.warn);
return false;
}
collection_lock3 = 1;
},
error: function () {
msgBox.show("网络错误请重试", msgBox.warn);
collection_lock3 = 1;
}
});
}
})
$('#manageGroupPop').on('click', '.deleteGroupBtn', function(){
var $this = $(this)
var $groupItem = $this.parents('.group_item')
var gid = $groupItem .data('id');
if (collection_lock2 == 1) {
$.ajax({
type: "post",
url: "/index/ajax/stow_group_del",
data: { "gid": gid },
beforeSend: function () {
collection_lock2 = 0;
},
success: function (data) {
var status = data.status;
if (status == 1) {
$groupItem.remove();
}
collection_lock2 = 1;
},
error: function () {
collection_lock2 = 1;
}
});
}
})
}
});
}
// 打开选择收藏分组弹层
function openCollectionGroup (obj, aid, type){
$.ajax({
type: "post",
dataType: "json",
url: "/index/ajax/stow_group",
beforeSend: function () {
collection_lock = 0;
},
success: function (data) {
var status = data.status,
msg = data.msg;
list = data.list;
if (status == 1) {
let opt = ''
for (var i in list) {
opt += '';
}
layer.open({
title: "添加收藏",
content: `
`,
btn: ["确认", "取消"],
btnAlign: "c",
yes: function (index, layero, that) {
var group = $("#collectionGroup").val()
aeCollection(obj, aid, group, type)
layer.close(index)
},
success: function(layero, index, that){
$('#manageGroupBtn').on('click', function(){
openManageGroup(list, obj, aid, type)
layer.close(index)
})
}
});
} else {
msgBox.show(msg, msgBox.warn);
}
collection_lock = 1;
},
error: function () {
collection_lock = 1;
msgBox.show("网络错误请重试", msgBox.warn);
}
});
}
// 收藏
let favlock = 1;
function ex1_fav(obj, aid) {
if (!islogin) {
window.location.href="/joefy/mphjo/joefy";
return false;
}
let type = $(obj).data("fav") == 1 ? 2 : 1;
const role = $(obj).data("role");
if (favlock === 1) {
if (role === 'ae' && type === 1) {
// ae类型的收藏需要分组
console.log('ae类型的收藏需要分组');
openCollectionGroup(obj, aid, type)
} else {
// 非ae类型的收藏到默认分类下面
msgBox.show("请稍候……", msgBox.warn);
$.ajax({
type: "post",
url: "/index/ajax/handle_stow",
data: {
aid: aid,
type: type,
},
beforeSend: function () {
favlock = 0;
},
success: function (data) {
let status = data.status,
msg = data.msg;
if (status == 1) {
msgBox.show(msg, msgBox.ok);
} else {
msgBox.show(msg, msgBox.warn);
}
favlock = 1;
if (type == 1) {
console.log("已收藏");
$(obj).data("fav", 1);
$(obj).addClass("cur");
} else {
console.log("取消已收藏");
$(obj).data("fav", 0);
$(obj).removeClass("cur");
}
},
error: function () {
favlock = 1;
msgBox.show("网络错误请重试", msgBox.warn);
},
});
}
}
}
// 下载
let dllock = 1,
dllock1 = 1;
function ex1_down(aid, isFree=false) {
if (!islogin) {
window.location.href="/joefy/mphjo/joefy";
return false;
}
if (dllock == 1) {
$.ajax({
type: "post",
url: "/index/ex1/get_down_link",
data: {
aid: aid,
},
beforeSend: function () {
dllock = 0;
},
success: function (data) {
switch (data.code) {
case 403:
// 未购买
layer.open({
title: "下载提示",
content: data.msg,
btn: ["确认", "取消"],
btnAlign: "c",
yes: function () {
ex1_buy(aid);
},
});
break;
case 401:
layer.open({
title: "下载提示",
content: '您账户的像素不足,点击确认前往充值。',
btn: ["确认", "取消"],
btnAlign: "c",
closeBtn: true,
yes: function () {
location.href="/joefy/sfdibshf/joefy";
},
});
break;
case 0:
// 正常
if(isFree){
window.open(data.data.link, '_blank');
dllock = 1;
return;
}
layer.open({
title: "下载提示",
content: '您购买过此资源,本次下载无需再次消费。',
btn: ["确认", "取消"],
btnAlign: "c",
closeBtn: true,
yes: function () {
window.open(data.data.link, '_blank');
},
});
break;
default:
msgBox.show(data.msg, msgBox.warn);
}
dllock = 1;
},
error: function () {
dllock = 1;
msgBox.show("网络错误请重试", msgBox.warn);
},
});
}
}
// 购买
function ex1_buy(aid) {
if (dllock1 == 1) {
$.ajax({
type: "post",
url: "/index/consume/download_consume",
data: {
aid: aid,
type: 0,
},
beforeSend: function () {
dllock1 = 0;
},
success: function (data) {
var status = data.status,
list = data.list,
msg = data.msg;
if (status == 1) {
window.open(list[0]);
} else {
msgBox.show(msg, msgBox.warn);
}
dllock1 = 1;
},
error: function () {
dllock1 = 1;
msgBox.show("网络错误请重试", msgBox.warn);
},
});
}
}
//报错
var errors_lock = 1;
$(".report[data-name = 'report']").on("click", function () {
if (!islogin) {
window.location.href="/joefy/mphjo/joefy";
return false;
}
var _this = $(this);
var aid = $(this).attr("data-aid");
var _html =
'提交错误
提交 ';
if ($(".errors_pop").length > 0) {
$(".mask").show();
$(".errors_pop").show();
} else {
$(".mask").show();
$("body").append(_html);
}
});
function error(aid) {
var aid = aid;
var type = $(".errors_pop select option:selected").attr("data-type");
var content = $(".errors_pop textarea").val();
if (errors_lock == 1) {
if (content.length < 1) {
msgBox.show("请输入举报内容", msgBox.warn);
return false;
}
$.ajax({
type: "post",
dataType: "json",
url: "/index/ajax/handle_report",
data: {
aid: aid,
type: type,
content: content,
},
beforeSend: function () {
errors_lock = 0;
},
success: function (data) {
var status = data.status,
msg = data.msg;
if (status == 1) {
$(".mask").hide();
$(".errors_pop").hide();
$(".errors_pop textarea").val("");
msgBox.show(msg, msgBox.ok);
} else {
msgBox.show(msg, msgBox.warn);
}
errors_lock = 1;
},
error: function () {
errors_lock = 1;
msgBox.show("网络错误请重试", msgBox.warn);
},
});
}
}