angular.module('push')
.controller('publicResourceCtrl', function ($scope, $ionicActionSheet, $ionicSlideBoxDelegate, ResourceLibraryService, $stateParams, $timeout, $ionicScrollDelegate,
UtilService, $ionicPopup, resourceLibraryTempData, ShareService, $ionicListDelegate, AuthorityService, UserService) {
if($scope.app){
$scope.setStatusBar(0);
}
//1:需求,2:成果,6:企业,8:人才
var libtype = $stateParams.libtype;
var modlibid = $stateParams.modlibid;
$scope.libtype = libtype;
$scope.name = $stateParams.name;
var checkedresource = {};//单个分享时选中的资源
var checkedindex = -1;//多个分享时第一个选择的索引
$scope.checkedresourcelist = [];//多个分享时选中的资源
$scope.tabs = [];
var chooseIndex = resourceLibraryTempData.getCategoryIndex();//当前频道索引
$scope.index = chooseIndex;
$scope.checked = resourceLibraryTempData.getChecked();
$scope.checked.classificationType = libtype;
//排序初始化
$scope.sorts = [
{name: "热门", type: 0, value: "popular,DESC"},
{name: "最新", type: 1, value: "time,DESC"},
{name: "综合", type: 2, value: "complex,DESC"}
];
var checkedsort = $scope.sorts[0].value;
//地区初始化
/*$scope.checkedlocationtype = 1;
$scope.chooeslocation = [
{name: "不限"},
{name: "常州"},
{name: "定位"}
];*/
if (libtype == 2) {
// $scope.contentlist = resourceLibraryTempData.getAchievementList();
//成熟度初始化
$scope.chooesMaturity = [
{name: "不限", type: 0},
{name: "正在研发", type: 1},
{name: "已有小样", type: 2},
{name: "通过小试", type: 3},
{name: "通过中试", type: 4},
{name: "可以量产", type: 5}
];
//知识产权初始化
$scope.chooesRight = [
{name: "不限", type: 0},
{name: "有", type: 1},
{name: "无", type: 2}
];
//合作模式初始化
$scope.chooesModel = [
{name: "不限", type: 0},
{name: "委托开发", type: 1},
{name: "合作研发", type: 2},
{name: "成果转让", type: 3},
{name: "技术入股", type: 4},
{name: "技术咨询", type: 5},
{name: "其他", type: 6}
];
} else if (libtype == 1) {
// $scope.contentlist = resourceLibraryTempData.getRequirementList();
//合作模式初始化
$scope.chooesModel = [
{name: "不限", type: 0},
{name: "委托开发", type: 1},
{name: "合作研发", type: 2},
{name: "成果转让", type: 3},
{name: "技术入股", type: 4},
{name: "技术咨询", type: 5},
{name: "其他", type: 6}
];
//投入预算
$scope.inputBudget = [
{name: "不限", type: 0},
{name: "1000万以上", type: 9},
{name: "500万-1000万", type: 8},
{name: "200万-500万", type: 7},
{name: "100万-200万", type: 6},
{name: "50万-100万", type: 5},
{name: "10万-50万", type: 4},
{name: "10万以下", type: 3},
{name: "面议", type: 2}
]
} else if (libtype == 6) {
// $scope.contentlist = resourceLibraryTempData.getEenterpriseList();
//企业规模
$scope.enterpriseScale = [
{name: "不限", type: 0},
{name: "少于50人", type: 1},
{name: "50-150人", type: 2},
{name: "150-500人", type: 3},
{name: "500-1000人", type: 4},
{name: "1000-5000人", type: 5},
{name: "5000-10000人", type: 6},
{name: "10000人以上", type: 7}
];
//企业类型
$scope.enterpriseType = [
{name: "不限", type: 0},
{name: "国有企业", type: 1},
{name: "集体所有制企业", type: 2},
{name: "私营企业", type: 3},
{name: "股份制企业", type: 4},
{name: "联营企业", type: 5},
{name: "外商投资企业", type: 6},
{name: "港澳台企业", type: 7},
{name: "股份合作企业", type: 8}
];
} else if (libtype == 8) {
// $scope.contentlist = resourceLibraryTempData.getPersonnelList();
//学位
$scope.academicDegree = [
{name: "不限", type: 0},
{name: "博士后", type: 7},
{name: "博士", type: 6},
{name: "硕士", type: 5},
{name: "学士", type: 4},
{name: "其他", type: 8}
];
//职称
$scope.occupationalTitle = [
{name: "不限", type: 0},
{name: "正高", type: 1},
{name: "副高", type: 2},
{name: "中级", type: 3},
{name: "副级", type: 4},
{name: "无", type: 5}
];
} else if (libtype == 7) {
//学校类别
$scope.universitytype = [
{name: "不限", type: 0},
{name: "985工程院校暨211工程院校", type: 600},
{name: "985工程院校", type: 601},
{name: "211工程院校", type: 602},
{name: "普通本科院校", type: 604},
{name: "高职专科院校", type: 606}
];
}
$scope.contentlist = [];
// 获取资源库下行业分类列表
var getCategoryList = function () {
ResourceLibraryService.getCategoryList(libtype, $stateParams.reclibid, modlibid).then(function (response) {
// console.log(response);
$scope.categorylist = response.channelList;
// resourceLibraryTempData.setCategoryList(response.channelList);
angular.forEach(response.channelList, function (value, index) {
$scope.contentlist.push({isload: false, currentPage: 1, reslist: []});
});
// resourceLibraryTempData.initContent(libtype, response.channelList);
if ($scope.categorylist.length > 0) {
$timeout(function () {
$ionicSlideBoxDelegate.slide(chooseIndex);
$scope.getPublicResourceList();
}, 100);
}
}, function () {
UtilService.showMess("网络不给力,请重试");
})
};
//获取资源列表
$scope.getPublicResourceList = function () {
$scope.showLoadingToast();
var category = "";
if (libtype != 7) {
category = $scope.categorylist[chooseIndex].by1
}
ResourceLibraryService.getFirstResourceList(libtype, $scope.checked, checkedsort, category, "", 0, 0).then(function (response) {
// console.log(response);
var tempreslib = angular.fromJson(response.resourcelibrary);
// console.log(tempreslib);
var temppage = angular.fromJson(response.page);
var totalPage = Math.ceil(temppage.totalCount / 10);
$scope.contentlist[chooseIndex].reslist = tempreslib;
var trHtml = "
更新了" + $scope.contentlist[chooseIndex].reslist.length + "条内容
";
$timeout(function () {
$(".resourcelistDiv .list").prepend(trHtml);
$(".refresh_tip_div").animate({width: 100 + "%"}, 150);
}, 800);
$timeout(function () {
$(".refresh_tip_div").slideUp();
}, 1200);
//判断是否有下一页
$timeout(function () {
$timeout(function () {
if ($scope.contentlist[chooseIndex].currentPage >= totalPage) {
$scope.contentlist[chooseIndex].isload = false;
} else {
$scope.contentlist[chooseIndex].isload = true;
}
$scope.contentlist[chooseIndex].currentPage = 2;
}, 1000);
$scope.hideLoadingToast();
$ionicSlideBoxDelegate.update();
$ionicScrollDelegate.$getByHandle("resourceContent").scrollTo(0, 0);
}, 50);
}, function () {
$scope.hideLoadingToast();
}).finally(function () {
$scope.$broadcast('scroll.refreshComplete');
});
};
//加载更多资源列表
$scope.loadMore = function () {
$scope.contentlist[chooseIndex].isload = false;
$scope.loadmore = true;
// $scope.showLoadingToast();
var category = "";
if (libtype != 7) {
category = $scope.categorylist[chooseIndex].by1
}
ResourceLibraryService.getSecondResourceList(libtype, $scope.checked, checkedsort, category, "", $scope.contentlist[chooseIndex].currentPage, 0, 0).then(function (response) {
// console.log(response);
var tempreslib = angular.fromJson(response.resourcelibrary);
var temppage = angular.fromJson(response.page);
var totalPage = Math.ceil(temppage.totalCount / 10);
//加载数据,更新当前页数
$timeout(function () {
if (tempreslib.length > 0) {
$scope.contentlist[chooseIndex].reslist = $scope.contentlist[chooseIndex].reslist.concat(tempreslib);
}
$scope.loadmore = false;
}, 2000);
// $scope.hideLoadingToast();
//判断是否有下一页
$timeout(function () {
if ($scope.contentlist[chooseIndex].currentPage >= totalPage) {
$scope.contentlist[chooseIndex].isload = false;
} else {
$scope.contentlist[chooseIndex].isload = true;
}
$scope.contentlist[chooseIndex].currentPage++;
}, 2000);
if (selectflg) {
$timeout(function () {
$(".item-options").addClass("invisible");
$(".resource_wrap").css("left", "10%");
$(".pay_list_c2").css("left", "4%");
$(".item-content").css("transform", "translate3d(0px, 0px, 0px)");
$("#collect-bottom").css("display", "block");
}, 20);
}
}, function () {
// $scope.hideLoadingToast();
$scope.loadmore = false;
}).finally(function () {
$scope.$broadcast('scroll.infiniteScrollComplete');
});
};
if (libtype == 7) {
$scope.listtop = "0px";
$scope.contentlist = [{isload: false, currentPage: 1, reslist: []}];
$scope.getPublicResourceList();
} else {
$scope.listtop = "33px";
getCategoryList();
}
$scope.goResourceDetail = function (resource, ind) {
if (selectflg) {
selectResource(resource, ind);
} else {
resourceLibraryTempData.setCategoryIndex(chooseIndex);
resourceLibraryTempData.setChecked($scope.checked);
var category = "";
if (libtype != 7) {
category = $scope.categorylist[chooseIndex].by1
}
$scope.go('resourceDetails', {
recourceid: resource.unique,
recourcetype: resource.type,
recourcecomefrom: resource.source,
categorylabel: category
});
}
};
var editSlide = function (index) {
var tablength = $scope.categorylist.length;//标题个数
var middlewidth = $(window).width() / 2;//获取当前手机屏幕宽度一般
var OffLeft = $(".Chanel_scroll_a").eq(index).offset().left;//获取当前点击标题距离父容器左边框的距离
var SelfWidth = $(".Chanel_scroll_a").eq(index).width();//获取当前点击标题宽度
var startTranform = $("#p_Chanel .scroll").offset().left;
var movewidth = OffLeft - middlewidth + SelfWidth / 2;
startTranform -= movewidth;
if (startTranform <= 0) {
if (index < tablength - 2) {
$('#p_Chanel .scroll').css({
'transform': 'translate3d(' + startTranform + 'px,0,0)'
});
}
} else if (index < 4) {
$('#p_Chanel .scroll').css({
'transform': 'translate3d(0,0,0)'
});
}
$(".Chanel_scroll_a").eq(index).addClass("scroll_a_on").siblings().removeClass("scroll_a_on");
};
$scope.selectCategory = function (index) {
if (selectflg) {
UtilService.showMess("当前处于编辑状态,无法切换行业");
return;
}
editSlide(index);
$(".Chanel_scroll_a").eq(index).addClass("scroll_a_on").siblings().removeClass("scroll_a_on");
if (index == chooseIndex) {
return;
}
chooseIndex = index;
editSlide(index);
// $(".Chanel_scroll_a").eq(index).addClass("scroll_a_on").siblings().removeClass("scroll_a_on");
$scope.index = chooseIndex;
$scope.getPublicResourceList();
// $ionicSlideBoxDelegate.slide(index);
};
//资源库搜索
$scope.goResourceSearch = function () {
resourceLibraryTempData.setCategoryIndex(chooseIndex);
resourceLibraryTempData.setChecked($scope.checked);
//1:需求,2:成果,6:企业,8:人才
var tabindex = 3;
if (libtype == 1) {
tabindex = 4;
} else if (libtype == 2) {
tabindex = 3;
} else if (libtype == 6) {
tabindex = 5;
} else if (libtype == 8) {
tabindex = 6;
}
$timeout(function () {
$scope.go('resourceSearch', {resourcetype: libtype, tabindex: tabindex});
}, 350);
};
$scope.shareflg = false;
$scope.openShare = function (tempobj, ind) {
$scope.go('chooseShareResource', {
chereslist: angular.toJson([tempobj.unique]),
folderid: $stateParams.reclibid,
isCloud: 1,
recourcetype: tempobj.type,
recourcecomefrom: tempobj.source
});
/*$scope.shareflg = true;
$(".resource_wrap").css("left", "0%");
$(".pay_list_c2").css("left", "-35px");
$("#collect-bottom").css("display", "none");
checkedresource = tempobj;
checkedindex = ind;*/
};
$scope.closeShare = function () {
$timeout(function () {
$ionicListDelegate.closeOptionButtons();
}, 10);
$scope.shareflg = false;
};
//选择排序
$scope.chooseSort = function (b) {
$scope.checked.SortType = b.type;
checkedsort = b.value;
};
//地区
/*$scope.chooseActionlocation = function (index) {
$(".locationclassfile ul li").eq(index).addClass("specialSpan").siblings().removeClass("specialSpan");
if (index != 0) {
$(".locationclassfile ul li:first-child").css({"color": "#000", "border": "none"});
} else {
$(".locationclassfile ul li:first-child").css({"color": "#3385ff", "border": "#3385ff .5px solid"});
$(".locationclassfile ul li").removeClass("specialSpan");
}
};*/
//选择成熟度
$scope.chooseActionMaturity = function (s) {
$scope.checked.MaturityType = s.type;
};
//选择知识产产权
$scope.chooseActionRight = function (r) {
$scope.checked.RightType = r.type;
};
//选择合作模式
$scope.chooseActionModel = function (m) {
$scope.checked.ModelType = m.type;
};
//选择投入预算
$scope.chooseInputBudget = function (budget) {
$scope.checked.BudgetType = budget.type;
};
//选择企业规模
$scope.chooseEenterpriseScale = function (scale) {
$scope.checked.ScaleType = scale.type;
};
//选择企业类型
$scope.chooseEnterpriseType = function (enterprise) {
$scope.checked.EnterpriseType = enterprise.type;
};
//选择学位
$scope.chooseAcademicDegree = function (degree) {
$scope.checked.DegreeType = degree.type;
};
//选择职称
$scope.chooseOccupationalTitle = function (title) {
$scope.checked.TitleType = title.type;
};
//选择学校类别
$scope.chooseUniversityType = function (university) {
$scope.checked.UniversityType = university.type;
};
//展开/收起排序
$scope.toggleSort = function () {
$(".sort ul").toggle();
$(".sort h3 i").toggleClass("transformArrow");
};
//展开/收起地区
/*$scope.toggleClassfilelocation = function () {
$(".locationclassfile ul").toggle();
$(".locationclassfile h3 i").toggleClass("transformArrow");
};*/
//展开/收起成熟度
$scope.toggleClassfileMaturity = function () {
$(".Maturityclassfile ul").toggle();
$(".Maturityclassfile h3 i").toggleClass("transformArrow");
};
//展开/收起知识产权
$scope.toggleClassfileRight = function () {
$(".Rightclassfile ul").toggle();
$(".Rightclassfile h3 i").toggleClass("transformArrow");
};
//展开/收起合作模式
$scope.toggleClassfileModel = function () {
$(".Modelclassfile ul").toggle();
$(".Modelclassfile h3 i").toggleClass("transformArrow");
};
//展开/收起投入预算
$scope.toggleInputBudget = function () {
$(".InputBudget ul").toggle();
$(".InputBudget h3 i").toggleClass("transformArrow");
};
//展开/收起企业规模
$scope.toggleEenterpriseScale = function () {
$(".EenterpriseScale ul").toggle();
$(".EenterpriseScale h3 i").toggleClass("transformArrow");
};
//展开/收起企业类型
$scope.toggleEnterpriseType = function () {
$(".EnterpriseType ul").toggle();
$(".EnterpriseType h3 i").toggleClass("transformArrow");
};
//展开/收起学位
$scope.toggleAcademicDegree = function () {
$(".AcademicDegree ul").toggle();
$(".AcademicDegree h3 i").toggleClass("transformArrow");
};
//展开/收起职称
$scope.toggleOccupationalTitle = function () {
$(".OccupationalTitle ul").toggle();
$(".OccupationalTitle h3 i").toggleClass("transformArrow");
};
//展开/收起学校类别
$scope.toggleUniversityType = function () {
$(".UniversityType ul").toggle();
$(".UniversityType h3 i").toggleClass("transformArrow");
};
$scope.finishShow = false;
//展开筛选
$scope.menueFilter = function () {
$scope.finishShow = true;
};
//完成选择,刷新数据
$scope.finishDone = function () {
$scope.finishShow = false;
$scope.getPublicResourceList();
};
//重置选择数据
$scope.reseChecked = function () {
$scope.checked = {
SortType: 0,
classificationType: libtype,
starType: 0,
MaturityType: 0,
RightType: 0,
ModelType: 0,
BudgetType: 0,
ScaleType: 0,
EnterpriseType: 0,
DegreeType: 0,
sexType: 0,
TitleType: 0,
UniversityType: 0
};
checkedsort = $scope.sorts[0].value;
};
//点击空白灰色选择条件隐藏
$scope.hideSortDiv = function () {
$scope.finishShow = false;
$scope.getPublicResourceList();
};
//分享选择操作表
var selectflg = false;//列表选择打开标志
$scope.openCollectShare = function () {
selectflg = true;
$scope.contentlist[$scope.index].reslist[checkedindex].value = true;
var tempres = {
infoid: checkedresource.unique,
infocomefrom: checkedresource.source,
infoType: checkedresource.type
};
$scope.checkedresourcelist.push(tempres);
$(".item-options").addClass("invisible");
$(".resource_wrap").css("left", "10%");
$(".pay_list_c2").css("left", "4%");
$(".item-content").css("transform", "translate3d(0px, 0px, 0px)");
$("#collect-bottom").css("display", "block");
$scope.closeShare();
};
//取消分享
$scope.cancelShare = function () {
angular.forEach($scope.contentlist[$scope.index].reslist, function (value, ind) {
$scope.contentlist[$scope.index].reslist[ind].value = false;
});
$scope.checkedresourcelist = [];
$(".resource_wrap").css("left", "0%");
$(".pay_list_c2").css("left", "-35px");
$("#collect-bottom").css("display", "none");
selectflg = false;
};
var selectResource = function (resource, ind) {
var tempres = {
infoid: resource.unique,
infocomefrom: resource.source,
infoType: resource.type
};
var chind = -1;
angular.forEach($scope.checkedresourcelist, function (value, index) {
if (value.infoid == resource.unique) {
chind = index;
}
});
if (chind == -1) {
$scope.contentlist[$scope.index].reslist[ind].value = true;
$scope.checkedresourcelist.unshift(tempres);
} else {
$scope.contentlist[$scope.index].reslist[ind].value = false;
$scope.checkedresourcelist.splice(chind, 1);
}
// console.log($scope.checkedresourcelist);
};
$scope.shareResourceToPrilib = function () {
$scope.go('chooseShareResource', {chereslist: angular.toJson($scope.checkedresourcelist)});
};
//0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博
$scope.shareMessage = function (type) {
$scope.shareflg = false;
$scope.showLoadingToast();
var message = {
title: checkedresource.title,
description: checkedresource.title.substring(0, 19),
url: checkedresource.sharelink,
imageurl: $scope.imgUrl + checkedresource.logo
};
switch (type) {
case 0:
case 1:
ShareService.shareToQQ(type, message).then(function () {
UtilService.showMess("QQ分享成功");
$scope.hideLoadingToast();
}, function (error) {
UtilService.showMess(error);
$scope.hideLoadingToast();
});
break;
case 2:
case 3:
ShareService.shareToWechat(0, message).then(function () {
UtilService.showMess("微信分享成功");
$scope.hideLoadingToast();
}, function (error) {
UtilService.showMess(error);
$scope.hideLoadingToast();
});
break;
default:
break;
}
$timeout(function () {
$scope.hideLoadingToast();
}, 10000);
};
});