angular.module('push') .controller('AbutmentHomeCtrl', function ($scope, $timeout, $rootScope, SqliteStorageService, SynchroService, UserService, HandleService, $ionicPopup, UtilService, ConfigService, ModelService, $ionicListDelegate, HomeService, DockingService) { $scope.user = UserService.user.user; $scope.shownone = false;//是否显示无网络页面 var loadflg = false; //进入云文件夹详情 $scope.goSpecifyFolder = function (folder) { $scope.go('cloudFolderDetail', {folder: angular.toJson(folder)}); }; /*==============================以上为版本更新内容,以下为数据显示及同步内容==============================*/ /*TODO--9、server数据回写*/ 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 () { }) } } if (res.conninfopicture.length > 0) { // console.log("-------------------res.conninfopicture------------------------"); // console.log(res.conninfopicture); angular.forEach(res.conninfopicture, function (value, index) { var del_pic_sql = "delete from conninfopicture where localinfoid = " + value.localinfoid; SqliteStorageService.deleteData(del_pic_sql).then(function () { // console.log("依据localinfoid删除图片成功"); if (value.picturelist.length > 0) { SqliteStorageService.insertBatchData("conninfopicture", value.picturelist).then(function () { // console.log("批量修改图片成功"); }, function () { }) } }, function () { }) }); } if (res.conninfoperson.length > 0) { // console.log("-------------------res.conninfoperson------------------------"); // console.log(res.conninfoperson); angular.forEach(res.conninfoperson, function (value, index) { var del_pic_sql = "delete from conninfoperson where localuid = " + value.localuid; SqliteStorageService.deleteData(del_pic_sql).then(function () { // console.log("依据localuid删除人员成功"); if (value.personlist.length > 0) { SqliteStorageService.insertBatchData("conninfoperson", value.personlist).then(function () { // console.log("批量修改人员成功"); }, function () { }) } }, function () { }) }); } if (res.conninfotheme.length > 0) { // console.log("-------------------res.conninfotheme------------------------"); // console.log(res.conninfotheme); angular.forEach(res.conninfotheme, function (value, index) { var del_pic_sql = "delete from conninfotheme where localuid = " + value.localuid; SqliteStorageService.deleteData(del_pic_sql).then(function () { // console.log("依据localuid删除主题成功"); if (value.themelist.length > 0) { SqliteStorageService.insertBatchData("conninfotheme", value.themelist).then(function () { // console.log("批量修改主题成功"); }, function () { }) } }, function () { }) }); } if (res.conninfoproduct.length > 0) { // console.log("-------------------res.conninfoproduct------------------------"); // console.log(res.conninfoproduct); angular.forEach(res.conninfoproduct, function (value, index) { var del_pro_sql = "delete from conninfoproduct where localuid = " + value.localuid; SqliteStorageService.deleteData(del_pro_sql).then(function () { // console.log("依据localuid删除产品成功"); if (value.productlist.length > 0) { SqliteStorageService.insertBatchData("conninfoproduct", value.productlist).then(function () { // console.log("批量修改产品成功"); }, function () { }) } }, function () { }) }); } if (res.conninfoiur.length > 0) { // console.log("-------------------res.conninfoiur------------------------"); // console.log(res.conninfoiur); angular.forEach(res.conninfoiur, function (value, index) { var del_iur1_sql = "delete from conninfoiur where localuid = " + value.localuid; SqliteStorageService.deleteData(del_iur1_sql).then(function () { // console.log("依据localuid删除产学研经历成功"); if (value.iur1list.length > 0) { SqliteStorageService.insertBatchData("conninfoiur", value.iur1list).then(function () { // console.log("批量修改产学研经历成功"); }, function () { }) } }, function () { }) }); } if (res.conninforesearch.length > 0) { // console.log("-------------------res.conninforesearch------------------------"); // console.log(res.conninforesearch); angular.forEach(res.conninforesearch, function (value, index) { var del_iur2_sql = "delete from conninforesearch where localuid = " + value.localuid; SqliteStorageService.deleteData(del_iur2_sql).then(function () { // console.log("依据localuid删除重大科研项目成功"); if (value.iur2list.length > 0) { SqliteStorageService.insertBatchData("conninforesearch", value.iur2list).then(function () { // console.log("批量修改重大科研项目成功"); }, function () { }) } }, function () { }) }); } $timeout(function () { if (ConfigService.synchroflg || loadflg) { UtilService.showMess("同步完成"); loadflg = false; ConfigService.synchroflg = false; } ConfigService.isedit = 0; SqliteStorageService.updateEditFlg(0); $scope.hideLoadingToast(); $scope.initFolderList(); }, 300); }; /*TODO--8、处理server返回数据,按表划分*/ var handleResponseData = function (tempresponse) { //--第一次,本地没有数据,server数据全部返回处理 if (tempresponse.responsetype == 1) { if (angular.isDefined(tempresponse.folderlist) && tempresponse.folderlist.length > 0) { HandleService.handleFirstServerData(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 () { if (ConfigService.synchroflg || loadflg) { UtilService.showMess("同步完成"); loadflg = false; ConfigService.synchroflg = false; } ConfigService.isedit = 0; SqliteStorageService.updateEditFlg(0); $scope.hideLoadingToast(); $scope.initFolderList(); }, 300); }, function () { $scope.hideLoadingToast(); }); } else { $scope.hideLoadingToast(); } } //--第二及之后,本地有数据,server数据部分返回处理 if (tempresponse.responsetype == 2) { HandleService.handleSecondServerData(tempresponse.folderReturnList, tempresponse.recordReturnList, tempresponse.cardReturnList).then(function (res) { // console.log("按增删改处理同步返回的数据"); // console.log(res); updateHandleData(res); }, function () { $scope.hideLoadingToast(); }); } }; /*TODO--7、同步本地数据*/ var uplocalfolderlist = [];//本地查询的所有文件夹 var Synchro = function (tempconninfolist, tempcardlist) { // console.log("-------------------请求同步----------------"); uplocalfolderlist.sort(function (a, b) { return a.level - b.level;//置顶(level)升序 }); // console.log(uplocalfolderlist); // console.log(tempconninfolist); // console.log(tempcardlist); SynchroService.synchroAllData(uplocalfolderlist, tempconninfolist, tempcardlist).then(function (response) { // console.log("-------------------同步返回的数据----------------"); // console.log(response); handleResponseData(response); }, function () { // $scope.hideLoadingToast(); }) }; /*TODO--6、若有图片,同步上传图片*/ var uploadImages = function (responsedata) { SynchroService.uploadImages(responsedata.conninfolist).then(function (res_conninfolist) { Synchro(res_conninfolist, responsedata.cardlist); }, function () { // $scope.hideLoadingToast(); }); }; /*TODO--5、处理本地记录相关信息:conninfolist,cardlist*/ var handleRequestData = function () { HandleService.handleRequestData(conninfolist, picturelist, cardlist, persionlist, themelist, productlist, iur1list, iur2list).then(function (response) { // console.log("-------------------记录、名片分别拼接,返回结果如下----------------"); // console.log(response); if (picturelist.length > 0) { //检测本地图片是否均已上传,若未上传则去上传,否则直接去同步 var count = 0; for (var i = 0; i < picturelist.length; i++) { if (picturelist[i].photo_name.indexOf("file:") != -1) { count++; break; } } if (count > 0) { uploadImages(response); } else { Synchro(response.conninfolist, response.cardlist) } } else { //无图片,直接去同步 Synchro(response.conninfolist, response.cardlist) } }, function () { $scope.hideLoadingToast(); }); }; var checknum = 1; $scope.isover = 0;//0:本地对接记录开始查询 4:查询结束 var conninfolist = []; var picturelist = []; var cardlist = []; var persionlist = []; var themelist = []; var productlist = []; var iur1list = []; var iur2list = []; /*TODO--2、获取本地对接记录列表*/ var getConninfoList = function () { var folderidlist = ""; angular.forEach(templocalfolderlist, function (value) { if (value.localparentid == null || value.localparentid == "0") { var tempstr = "'" + value.localid + "'"; folderidlist = folderidlist + tempstr + ","; } }); folderidlist = folderidlist.substring(0, folderidlist.length - 1); var sql = "select * from conninfo where localclaid in (" + folderidlist + ") or creator = " + UserService.id + " order by conntime desc"; SqliteStorageService.queryData(sql).then(function (response) { // console.log("获取本地对接记录列表:"); // console.log(response); conninfolist = response; //计算本地文件夹下信息总数 HandleService.computeFolderCounts(templocalfolderlist, conninfolist).then(function (respp) { templocalfolderlist = respp; $scope.contactflg++; }, function () { $scope.contactflg++; }); //存在对接记录时,查询对接记录下各信息 if (conninfolist.length > 0) { checknum++; /*--2.2、拼接对接记录localid*/ var infoidlist = ""; angular.forEach(conninfolist, function (value) { var tempstr = "'" + value.localid + "'"; infoidlist = infoidlist + tempstr + ","; }); infoidlist = infoidlist.substring(0, infoidlist.length - 1); /*--2.3、查询对接记录下名片列表*/ var q_com_sql = "select * from conninfounit where localinfoid in (" + infoidlist + ")"; SqliteStorageService.queryData(q_com_sql).then(function (res) { // console.log("查询本地名片信息:"); // console.log(res); cardlist = res; //存在名片时,查询名片下各信息 if (cardlist.length > 0) { checknum = checknum + 4; /*--2.3.1、拼接本地名片id*/ var uidlist = ""; angular.forEach(cardlist, function (value) { var tempstr = "'" + value.localid + "'"; uidlist = uidlist + tempstr + ","; }); uidlist = uidlist.substring(0, uidlist.length - 1); /*--2.3.2、查询名片下人员列表*/ var q_per_sql = "select * from conninfoperson where localuid in (" + uidlist + ")"; SqliteStorageService.queryData(q_per_sql).then(function (resp) { // console.log("查询本地人员信息:"); // console.log(resp); persionlist = resp; $scope.isover++; }, function () { $scope.isover++; }); /*--2.3.3、查询名片下主题列表*/ var q_the_sql = "select * from conninfotheme where localuid in (" + uidlist + ")"; SqliteStorageService.queryData(q_the_sql).then(function (resp) { // console.log("查询本地主题信息:"); // console.log(resp); themelist = resp; $scope.isover++; }, function () { $scope.isover++; }); //--2.3.4、查询产品信息 var q_pro_sql = "select * from conninfoproduct where localuid in (" + uidlist + ")"; SqliteStorageService.queryData(q_pro_sql).then(function (resp) { // console.log(resp); productlist = resp; $scope.isover++; }, function () { $scope.isover++; }); //--2.3.5、查询产学研经历信息 var q_iur1_sql = "select * from conninfoiur where localuid in (" + uidlist + ")"; SqliteStorageService.queryData(q_iur1_sql).then(function (resp) { // console.log(resp); iur1list = resp; $scope.isover++; }, function () { $scope.isover++; }); //--2.3.6、查询重大科研项目信息 var q_iur2_sql = "select * from conninforesearch where localuid in (" + uidlist + ")"; SqliteStorageService.queryData(q_iur2_sql).then(function (resp) { // console.log(resp); iur2list = resp; $scope.isover++; }, function () { $scope.isover++; }); } else { //无名片去请求同步 $scope.isover++; } }, function () { $scope.isover++; }); /*--2.4、查询对接记录下图片列表*/ var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")"; SqliteStorageService.queryData(q_pic_sql).then(function (res) { // console.log("查询本地图片信息:"); // console.log(res); picturelist = res; $scope.isover++; }, function () { $scope.isover++; }); } else { //无对接记录(1、无需计算folder--counts,2、去请求同步) $scope.isover++; } }, function (err) { //--ERROR:对接记录请求失败,单独处理分类 // console.log(err); $scope.contactflg++; }); }; //--监听查询是否结束 $scope.$watch("isover", function (newValue) { if (newValue == checknum) { if (UtilService.checkNetWork() != "None") { /*--2.6、所有数据查询结束后,汇总处理,组装同步请求数据*/ if (ConfigService.synchroflg || ConfigService.isedit == 1) { if (conninfolist.length < 1) { Synchro([], []); } else { handleRequestData(); } } } checknum = 1; $scope.isover = 0; } }); //初始化文件夹列表 $scope.contactflg = 0;//0:本地/云文件夹开始查询 4:查询结束 var templocalfolderlist = []; var tempcloudfolderlist = []; $scope.initFolderList = function () { $scope.contactflg = 0; $scope.showLoadingToast(); //--查询本地文件夹 var sql = "select * from conninfofolder where userid = " + UserService.id + " and isCloud = 0 and type = 1 order by updatetime desc"; SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); templocalfolderlist = response; uplocalfolderlist = angular.copy(response); if (response.length > 0) { getConninfoList(); } else { if (ConfigService.isedit == 1) { Synchro([], []); } $scope.contactflg++; } }, function () { templocalfolderlist = []; $scope.contactflg++; }); //--查询云文件夹 DockingService.newGetFolderList().then(function (response) { if (UtilService.isDefined(response.folderlist)) { tempcloudfolderlist = response.folderlist; } else { tempcloudfolderlist = []; } $scope.contactflg++; }, function () { tempcloudfolderlist = []; $scope.contactflg++; }) }; //拼接本地与云文件夹(按sort、updatetime排序) var connectLocalAndCloud = function () { HandleService.connectLocalAndCloud(templocalfolderlist, tempcloudfolderlist).then(function (response) { $scope.folderlist = response; if ($scope.folderlist.length == 0) { $scope.shownone = true; } else { $scope.shownone = false; } ModelService.setFolderList(response); $scope.hideLoadingToast(); }, function () { $scope.hideLoadingToast(); }) }; //--监听本地与云文件夹查询是否结束 $scope.$watch("contactflg", function (newValue) { if (newValue == 2) { //本地与云均无,显示缺省页 if (tempcloudfolderlist.length == 0 && templocalfolderlist.length == 0) { $scope.shownone = true; $scope.folderlist = []; // Synchro([], []); $scope.hideLoadingToast(); } else { //无云文件夹显示本地 if (tempcloudfolderlist.length < 1) { $scope.folderlist = templocalfolderlist; ModelService.setFolderList($scope.folderlist); $scope.hideLoadingToast(); } //无本地文件夹显示云 if (templocalfolderlist.length < 1) { $scope.folderlist = tempcloudfolderlist; ModelService.setFolderList($scope.folderlist); $scope.hideLoadingToast(); } //本地与云均有去拼接 if (tempcloudfolderlist.length > 0 && templocalfolderlist.length > 0) { connectLocalAndCloud(); } $scope.shownone = false; } ModelService.setLocalFolderList(templocalfolderlist); ModelService.setCloudFolderList(tempcloudfolderlist); $scope.contactflg = 0; } }); //页面缓存,每次进入刷选数据 $scope.$on('$ionicView.beforeEnter', function () { $scope.showMoreAction = true; $scope.initFolderList(); if($scope.app){ $scope.setStatusBar(1); } }); //下拉刷新数据 $scope.refreshData = function () { ConfigService.isedit = 1; loadflg = true; $scope.initFolderList(); $scope.$broadcast('scroll.refreshComplete'); var trHtml = "
更新了" + $scope.folderlist.length + "条内容
"; $timeout(function () { $(".calendarList-content-ul .list").prepend(trHtml); $(".refresh_tip_div").animate({width: 100 + "%"}, 150); }, 800); $timeout(function () { $(".refresh_tip_div").slideUp(); }, 1200); }; //新建记录 $scope.addRecord = function () { if ($scope.folderlist.length < 1) { UtilService.showMess("您还没有文件夹,去新建文件夹吧"); return; } ModelService.setCreateType(0); ModelService.setCheckdeFolder($scope.folderlist[0]); $scope.go('cloudAddConnInfo'); }; //进入分类详情,记录列表 $scope.queryFolder = function (folder) { ModelService.setCheckdeFolder(folder); if (UtilService.isDefined(folder.localid)) { //本地文件夹记录列表 $scope.go('conninfolist', {folder: angular.toJson(folder)}); } else { //云文件夹记录列表 $scope.go('cloudFolderDetail', {folder: angular.toJson(folder)}); } }; //展开按钮 $scope.showAction = function () { $scope.showMoreAction = !$scope.showMoreAction; }; //关闭按钮 $scope.actionButton_three = function () { $scope.showMoreAction = !$scope.showMoreAction; }; //新建文件夹 $scope.buildNewFolder = function () { $scope.go("authorityCreate", {templettype: 2}); }; //进入设置资源库页面 $scope.goAutoritySet = function (reclib) { $timeout(function () { $ionicListDelegate.closeOptionButtons(); }, 10); if (UtilService.isDefined(reclib.localid)) { $scope.go("authorityLocalSet", {authoritydata: angular.toJson(reclib), type: 0, 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: 0, parentid: reclib.parentid }); } }; //跳转工具搜索 $scope.goToolsSearch = function () { $timeout(function () { $scope.go("connsearch"); }, 300); } });