//收藏作品全局变量
var list = [];
var collect_add_flag = false;
var collect_edit_flag = false;
var collect_del_flag = false;
var nBuild = 1;
var edit = 0; //用来判断是修改分组还是新建分组 0是新增,1是修改
//关闭弹框
function closePop() {
//收藏分组添加,编辑,删除任一成功,关闭弹框,都刷新页面,更新页面数据
if(collect_add_flag || collect_edit_flag || collect_del_flag){
window.location.reload();
}
$(".mask").hide();
$(".pop").hide();
}
//删除更新弹框
function delPop(obj) {
console.log('collect_add_flag='+collect_add_flag);
console.log('collect_edit_flag='+collect_edit_flag);
console.log('collect_del_flag='+collect_del_flag);
//收藏分组添加,编辑,删除任一成功,关闭弹框,都刷新页面,更新页面数据
if(collect_add_flag || collect_edit_flag || collect_del_flag){
window.location.reload();
}
$(".mask").css("display","none");
$(obj).parents(".pop").remove();
}
var collect_handle_lock = 1;
function collection(aid,type) {
var group = $(".collection_pop select option:selected").attr("data-id");
if(collect_handle_lock == 1) {
$.ajax({
type: "post",
url: "/index/ajax/handle_stow",
data: {
"aid": aid,
"gid": group,
"type": type
},
beforeSend: function() {
collect_handle_lock = 0;
},
success: function(data) {
var status = data.status,
msg = data.msg;
if(status == 1) {
msgBox.show(msg, msgBox.ok);
closePop();
if(type == 2){
setTimeout(window.location.reload(), 2000);
}
} else {
msgBox.show(msg, msgBox.warn);
}
collect_handle_lock = 1;
},
error: function() {
collect_handle_lock = 1;
msgBox.show("网络错误请重试", msgBox.warn);
}
});
}
}
//收藏分组管理
function collectManage(tYpe) {
nBuild = 1;
$.ajax({
type: "post",
dataType: "json",
url: "/index/ajax/stow_group",
async:false,
beforeSend: function() {
},
success: function(data) {
list = data.list;
},
});
var _num = list.length;
var _html1 = '
管理分组
';
var _li = '';
var _lilast = '
+ 新建分组';
if (tYpe == 0) {
var _html2 = '返回 ';
} else {
var _html2 = '返回';
}
if(_num<=1){
_li = '';
}else {
for(var i=0; i<_num-1;i++) {
_li += ''+ list[i].name +'
';
}
}
$(".collection_pop").remove();
if($(".mgroup_pop").length>0){
$(".mgroup_pop").show();
$(".mgroup_pop ul").html(_li + _lilast);
}else{
$("body").append(_html1 + _li + _lilast + _html2);
}
}
//添加分组
var collect_add_lock = 1;
var collect_add_lock1 = 1;
function addGroup(obj) {
var arr = [];
var val = $(obj).siblings("input").val();
var v = $(obj).parent("li").siblings("li").children("input").val();
var num = $(obj).parent("li").siblings("li").size();
var aid = $(obj).siblings("input").attr("data-id");
for (var i=0; i 6){
msgBox.show("分组名最多只能6位数哦", msgBox.warn);
$(obj).siblings("input").trigger("focus");
return false;
}else {
nBuild = 1;
}
if(edit == 0){
if(collect_add_lock == 1){
$.ajax({
type:"post",
url:"/index/ajax/stow_group_add",
data: {"name":val},
beforeSend:function(){
collect_add_lock = 0;
},
success:function(data){
var status = data.status,
msg = data.msg,
id = data.id;
if(status == 1){
collect_add_flag = true;
$(obj).css("display","none").siblings("span").css("display","inline-block");
$(obj).siblings("p").html(val).css("display","inline-block");
$(obj).siblings("input").attr("data-id",id).css("display","none");
msgBox.show(msg, msgBox.ok);
}else {
msgBox.show(msg, msgBox.ok);
$(obj).siblings("input").trigger("focus");
return false;
}
collect_add_lock = 1;
},
error:function(){
collect_add_lock = 1;
}
});
}
}else {
if(collect_add_lock1 == 1){
if(aid>0){
$.ajax({
type:"post",
url:"/index/ajax/modify_group",
data: {"gid":aid,"name":val},
beforeSend:function(){
collect_add_lock1 = 0;
},
success:function(data){
var status = data.status,
msg = data.msg,
id = data.id;
if(status == 1){
$(obj).css("display","none").siblings("span").css("display","inline-block");
$(obj).siblings("p").html(val).css("display","inline-block");
$(obj).siblings("input").attr("data-id",id).css("display","none");
msgBox.show(msg, msgBox.ok);
}else {
$(obj).siblings("input").trigger("focus");
msgBox.show(msg, msgBox.warn);
return false;
}
collect_add_lock1 = 1;
},
error:function(){
collect_add_lock1 = 1;
}
});
}
}
}
}
//编辑分组
var collect_edit_lock = 1;
function editGroup(obj){
edit = 1;
if(nBuild != 1){
// if($(".mgroup_pop .cont ul.groupLists li input").css("display") != "none"){
//
// }
msgBox.show("当前分组编辑状态未完成", msgBox.warn);
return false;
}
$(obj).siblings("input").css("display","inline-block").siblings("p").css("display","none").siblings(".add_group").css("display","inline-block").siblings(".edit_group").css("display","none").siblings(".del_group").css("display","none");
nBuild = 0;
}
function newlyBuild (obj) {
edit = 0;
var groupNum = $(obj).siblings("li").size();
if(groupNum > 5){
msgBox.show("分组最多只能拥有六个,抱歉", msgBox.warn);
return false;
}
if(nBuild != 1){
msgBox.show("当前分组编辑状态未完成", msgBox.warn);
return false;
}
var _html = '';
$(obj).before(_html);
$(obj).prev().find("input").trigger("focus");
nBuild = 0;
}
function onBlur(obj){
var arr = [];
var that = obj;
var _val = $(that).val();
var v = $(that).parent("li").siblings("li").children("input").val();
var num = $(that).parent("li").siblings("li").size();
var aid = $(that).attr("data-id");
if(_val.length <= 0){
nBuild = 0;
$(that).trigger("focus");
return false;
}else if(_val.length > 6){
nBuild = 0;
$(that).trigger("focus");
return false;
}
for (var i=0; i' + list[i].name + '';
}
if($(".collection_pop").length > 0) {
$(".collection_pop select").html(opt);
$(".mask").show();
$(".collection_pop").show();
} else {
_html = '' +
'
移动分组
' +
'
' +
'
' +
'
' +
'
管理分组' +
'
移动' +
'
' +
'
';
$(".mask").show();
$("body").append(_html + opt + _html1);
}
} else {
msgBox.show(msg, msgBox.warn);
}
collection_lock = 1;
},
error: function() {
collection_lock = 1;
msgBox.show("网络错误请重试", msgBox.warn);
}
});
}
});
function modify_stow_gid(aid) {
var type = type;
var gid = $(".collection_pop select option:selected").attr("data-id");
if(collection_lock1 == 1) {
$.ajax({
type: "post",
url: "/index/ajax/modify_stow_gid",
data: {
"aid": aid,
"gid": gid,
},
beforeSend: function() {
collection_lock1 = 0;
},
success: function(data) {
var status = data.status,
msg = data.msg;
if(status == 1) {
msgBox.show(msg, msgBox.ok);
closePop();
$(".functionBar .fl a.collection").html("已收藏");
setTimeout(function () {
window.location.reload();
},1000)
} else {
msgBox.show(msg, msgBox.warn);
}
collection_lock1 = 1;
},
error: function() {
collection_lock1 = 1;
msgBox.show("网络错误请重试", msgBox.warn);
}
});
}
}
//返回分组
function backGroup() {
if($(".collection_pop").length>0){
$(".collection_pop").show();
}else {
$("ul.imageTextItem li .info .anv .grouping").trigger("click");
}
$(".mgroup_pop").remove();
if(nBuild == 0){
msgBox.show("当前分组编辑状态未完成", msgBox.warn);
}
return false;
}