angular.module('push') .controller('resourceLibraryHomeCtrl', function ($scope, ResourceLibraryService, UtilService, $timeout, $ionicListDelegate, SqliteStorageService, UserService, HandleService, resourceLibraryTempData, SynchroService, ConfigService, ConstantService, $ionicScrollDelegate) { document.title = '资源库'; if (UserService.defaultLan == 'English') { document.title = 'Database'; } $scope.resourcelibrarylist = []; var uploadresliblist = []; var resourcelist = []; $scope.user = UserService.user.user; $scope.viplevel = UserService.viplevel; $scope.keyword = "";// 搜索关键词 $scope.node = UserService.node;//节点号 $scope.nodename = UserService.nodename;//节点号名称 $scope.resinfocount = 0;//资源总数 $scope.resexpertcount = 0;//专家总数 $scope.resorgcount = 0;//企业总数 $scope.resresearchfindingcount = 0;//成果总数 $scope.techrequirementcount = 0;//需求总数 $scope.defaultLan = UserService.defaultLan; $scope.comfromWeb = sessionStorage.comfrom == 'web'; var updateHandleData = function (res) { if (res.insertList) { // console.log("-------------------res.insertList------------------------"); // console.log(res.insertList); for (key in res.insertList) { SqliteStorageService.insertBatchData(key, res.insertList[key]).then(function () { // console.log("批量insert成功"); }, function () { }) } } if (res.updateList) { // console.log("-------------------res.updateList------------------------"); // console.log(res.updateList); for (key in res.updateList) { SqliteStorageService.updateBatchData(key, res.updateList[key]).then(function () { // console.log("批量修改成功"); }, function () { }) } } if (res.deleteList) { // console.log("-------------------res.deleteList------------------------"); // console.log(res.deleteList); for (key in res.deleteList) { SqliteStorageService.deleteBatchData(key, res.deleteList[key]).then(function () { // console.log("批量delete成功"); }, function () { }) } } $timeout(function () { UtilService.showMess("同步完成"); ConfigService.ressynchroflg = false; initResourceLibraryList(); $scope.hideLoadingToast(); }, 300); }; var handleResponseData = function (tempresponse) { //--第一次,本地没有数据,server数据全部返回处理 if (tempresponse.responsetype == 1) { if (angular.isDefined(tempresponse.folderlist)) { HandleService.handleFirstServerResourceData(tempresponse.folderlist).then(function (res) { // console.log("处理返回数据,按表划分"); // console.log(res); for (key in res) { SqliteStorageService.insertBatchData(key, res[key]).then(function (res) { // console.log("OK") }, function () { }) } $timeout(function () { UtilService.showMess("同步完成"); ConfigService.ressynchroflg = false; initResourceLibraryList(); $scope.hideLoadingToast(); }, 300); }, function () { }); } else { $scope.hideLoadingToast(); } } //--第二及之后,本地有数据,server数据部分返回处理 if (tempresponse.responsetype == 2) { HandleService.handleSecondServerResourceData(tempresponse.folderReturnList, tempresponse.recordReturnList, uploadresliblist).then(function (res) { // console.log("按增删改处理同步返回的数据"); // console.log(res); updateHandleData(res); }, function () { $scope.hideLoadingToast(); }); } }; //资源同步 var synchroResource = function () { uploadresliblist.sort(function (a, b) { return a.level - b.level;//置顶(level)升序 }); // console.log("------------------------------------"); // console.log(uploadresliblist); // console.log(resourcelist); SynchroService.synchroResourceData(uploadresliblist, resourcelist).then(function (response) { // console.log("同步成功,返回的数据"); // console.log(response); handleResponseData(response); }, function () { $scope.hideLoadingToast(); }) }; //取本地资源 var getResourceList = function () { var claidlist = ""; angular.forEach(uploadresliblist, function (value) { var tempstr = "'" + value.localid + "'"; claidlist = claidlist + tempstr + ","; }); claidlist = claidlist.substring(0, claidlist.length - 1); var sql = "select * from resource where localclaid in (" + claidlist + ")"; SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); resourcelist = response; synchroResource(); }, function () { }) }; //初始化资源库列表 $scope.rescontactflg = 0;//0:本地/云资源库开始查询 2:查询结束 var tempLocalResourceLibrarylist = []; var tempCloudResourceLibrarylist = []; $scope.resinfocount = 0;//资源总数 var initResourceLibraryList = function () { // $scope.showLoadingToast(); /*//--查询本地资源库 tempLocalResourceLibrarylist = []; uploadresliblist = []; var sql = "select * from conninfofolder where userid = " + UserService.id + " and isCloud = 0 and type = 2 order by updatetime desc"; SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); angular.forEach(response, function (value, index) { if (value.localparentid == "0") { tempLocalResourceLibrarylist.push(value); } uploadresliblist.push(value); }); $scope.rescontactflg++; //同步标志为true,去同步 if (ConfigService.ressynchroflg) { if (uploadresliblist.length > 0) { getResourceList(); } else { resourcelist = []; synchroResource(); } } }, function () { tempLocalResourceLibrarylist = []; $scope.rescontactflg++; });*/ //--查询云资源库; ResourceLibraryService.getResourceLibrary($scope.keyword, $scope.node).then(function (response) { if (UtilService.isDefined(response.data)) { console.log(response.data); // 配置图片 tempCloudResourceLibrarylist = response.data; angular.forEach(tempCloudResourceLibrarylist, function (val) { val.logo = []; val.logo = val.name == '企业库' ? ['./img/2018/company1.png', './img/2018/company2.jpeg', './img/2018/company3.png'] : val.name == '高校库' ? ['./img/2018/university1.png', './img/2018/university2.png', './img/2018/university3.png'] : val.name == '人才库' || val.name == '技术经纪人库' ? ['./img/2018/person1.png', './img/2018/person2.png', './img/2018/person3.png'] : val.name == '需求库' ? ['./img/2018/demand1.jpg', './img/2018/demand2.jpg'] : val.name == '成果库' ? ['./img/2018/product1.jpg', './img/2018/product2.jpg', './img/2018/product3.jpg'] : ['./img/2018/other1-1.jpg', './img/2018/other1-2.jpg', './img/2018/other1-3.jpg']; if ($scope.isLiyangApp && val.name == '企业库') { val.logo = ['./img/2018/liyang1.jpg', './img/2018/liyang2.jpg', './img/2018/liyang3.jpg']; } }) } else { tempCloudResourceLibrarylist = []; } $scope.rescontactflg++; $scope.rescontactflg++; }, function () { tempCloudResourceLibrarylist = []; $scope.rescontactflg++; $scope.rescontactflg++; }) }; initResourceLibraryList(); //拼接本地与云文件夹(按sort、updatetime排序) var connectLocalAndCloud = function () { HandleService.connectLocalAndCloud(tempLocalResourceLibrarylist, tempCloudResourceLibrarylist).then(function (response) { $scope.resourcelibrarylist = response; console.log(response); if ($scope.resourcelibrarylist.length == 0) { $scope.shownone = true; } else { $scope.shownone = false; $scope.resinfocount = 0;//资源总数 // 节点资源总数 angular.forEach($scope.resourcelibrarylist, function (value) { $scope.resinfocount += value.infocount;//资源总数 if (value.moduleid == ConstantService.CATEGORY_MODULE_8) { $scope.resexpertcount = value.infocount;//专家总数 } if (value.moduleid == ConstantService.CATEGORY_MODULE_6) { $scope.resorgcount = value.infocount;//企业总数 } if (value.moduleid == ConstantService.CATEGORY_MODULE_2) { $scope.resresearchfindingcount = value.infocount;//成果总数 } if (value.moduleid == ConstantService.CATEGORY_MODULE_1) { $scope.techrequirementcount = value.infocount;//需求总数 } }); } resourceLibraryTempData.setResourceLibraryList($scope.resourcelibrarylist); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }) }; connectLocalAndCloud(); //--监听本地与云文件夹查询是否结束 $scope.$watch("rescontactflg", function (newValue) { if (newValue == 2) { //本地与云均无,显示缺省页 if (tempCloudResourceLibrarylist.length == 0 && tempLocalResourceLibrarylist.length == 0) { $scope.shownone = true; $scope.resourcelibrarylist = []; $scope.hideLoadingToast(); } else { //无云文件夹显示本地 if (tempCloudResourceLibrarylist.length < 1) { $scope.resourcelibrarylist = tempLocalResourceLibrarylist; console.log($scope.resourcelibrarylist); $scope.hideLoadingToast(); } //无本地文件夹显示云 if (tempLocalResourceLibrarylist.length < 1) { $scope.resourcelibrarylist = tempCloudResourceLibrarylist; // 节点资源总数 $scope.resinfocount = 0; angular.forEach($scope.resourcelibrarylist, function (value) { $scope.resinfocount += value.infocount;//资源总数 if (value.moduleid == ConstantService.CATEGORY_MODULE_8) { $scope.resexpertcount = value.infocount;//专家总数 } if (value.moduleid == ConstantService.CATEGORY_MODULE_6) { $scope.resorgcount = value.infocount;//企业总数 } if (value.moduleid == ConstantService.CATEGORY_MODULE_2) { $scope.resresearchfindingcount = value.infocount;//成果总数 } if (value.moduleid == ConstantService.CATEGORY_MODULE_1) { $scope.techrequirementcount = value.infocount;//需求总数 } }); $scope.hideLoadingToast(); } //本地与云均有去拼接 if (tempCloudResourceLibrarylist.length > 0 && tempLocalResourceLibrarylist.length > 0) { connectLocalAndCloud(); } $scope.shownone = false; } $scope.rescontactflg = 0; resourceLibraryTempData.setResourceLibraryList($scope.resourcelibrarylist); // console.log($scope.resourcelibrarylist); } }); $scope.$on("$ionicView.beforeEnter", function () { //TODO if ($scope.app) { $scope.setStatusBar(1); } $scope.node = UserService.node;//节点号 $scope.nodename = UserService.nodename;//节点号名称 $scope.resinfocount = 0;//资源总数 $ionicScrollDelegate.$getByHandle('calenderContent').scrollTop(); initResourceLibraryList(); initResourceLibraryNodeBg(); }); //资源库搜索 $scope.goResourceSearch = function () { $timeout(function () { $scope.go('resourceSearch'); }, 350); }; //获取定位 $scope.getPosition = function () { // console.log("获取位置"); }; //进入资源库列表 $scope.goResorceLibaryDetail = function (res) { resourceLibraryTempData.setCategoryIndex(0); resourceLibraryTempData.resetChecked(); if (res.moduleid == false && UserService.node == '330122000') { window.open("http://app.zjumap.com:7736/#/index", "_blank"); } else if (res.moduleid == 44) { $scope.go('wujingTeacher'); } else if (res.moduleid == 43) { $scope.go('wujingTechnical'); } else if (res.moduleid == 33) { //通知公告库 $scope.go("notification"); } else { //进入公共资源库列表 if (res.fixtype == 1) { $scope.go('publicResource', { libtype: reclibc.moduleid, name: reclibc.name, reclibid: $scope.reclib.id, modlibid: reclibc.id }); } else if (res.fixtype == 2) { //进入私人资源库列表 $scope.go('privateResource', { res: angular.toJson(res), privateName: res.name, groupid: res.parentid, restype: res.moduleid, privateContent: res.content, authority: res.by5 }); } } }; //进入设置资源库页面 $scope.goResourceSet = function (reclib) { $timeout(function () { $ionicListDelegate.closeOptionButtons(); }, 10); if (UtilService.isDefined(reclib.localid)) { $scope.go("authorityLocalSet", {authoritydata: angular.toJson(reclib), type: 1, goflg: 0}); } else { $scope.go("authoritySet", { reclibid: reclib.id, authorityid: reclib.authorityid, authoritycomefrom: reclib.authoritycomefrom, name: reclib.name, content: reclib.content, sort: reclib.sort, type: 1, parentid: reclib.parentid }); } }; //网络异常时点击屏幕重新加载 $scope.repeatLoad = function () { ConfigService.ressynchroflg = true; initResourceLibraryList(); initResourceLibraryNodeBg(); }; //新建资源库 $scope.createResLib = function () { $scope.go("authorityResourceCreate"); }; //下拉刷新数据 $scope.refreshData = function () { $scope.repeatLoad(); $scope.$broadcast('scroll.refreshComplete'); var trHtml = "