angular.module('push') .controller('connInfoListCtrl', function ($scope, UserService, $timeout, $stateParams, DockingService, $ionicPopup, UtilService, ModelService, $ionicListDelegate, SqliteStorageService, HandleService, $ionicActionSheet) { if($scope.app){ $scope.setStatusBar(0); } var cloudfolder = angular.fromJson($stateParams.folder); $scope.name = cloudfolder.name; $scope.user = UserService.user.user; var checkedresource = {};//单个分享时选中的资源 var checkedindex = -1;//多个分享时第一个选择的索引 $scope.checkedresourcelist = [];//多个分享时选中的资源 $scope.userid = UserService.id; $scope.isload = false; var pageindex = 0; //--本地记录列表提取第一张图为列表显示图 var extractConninfoPicture = function (conninfolist, picturelist, flg) { HandleService.extractConninfoPicture(conninfolist, picturelist).then(function (response) { if (flg) { $scope.recordList = response; } else { $scope.recordList = $scope.recordList.concat(response); } //判读是否有下一页 $scope.isload = response.length >= 10; if ($scope.isload) { if (flg) { pageindex = 10; } else { pageindex += 10; } } // console.log($scope.recordList); }, function () { }) }; //取本地记录 $scope.initConninfoList = function () { var q_sql = "select c1.*,foldercounts,infocounts from " + "(select * from conninfofolder where localparentid = '" + cloudfolder.localid + "') c1 " + "LEFT JOIN " + "(" + "select localparentid,count(1) foldercounts from " + "conninfofolder where localparentid in " + "(select localid from conninfofolder where localparentid = '" + cloudfolder.localid + "') " + "GROUP BY localparentid " + ") c2 " + "ON c1.localid = c2.localparentid " + "LEFT JOIN " + "(" + "select localclaid, count(1) infocounts " + "from conninfo where localclaid in " + "(select localid from conninfofolder where localparentid = '" + cloudfolder.localid + "') " + "GROUP BY localclaid " + ") c3" + " ON c1.localid = c3.localclaid"; // var sql1 = "select * from conninfofolder where localparentid = order by updatetime desc"; SqliteStorageService.queryData(q_sql).then(function (response) { // console.log(response); $scope.smallfolderlist = response; angular.forEach($scope.smallfolderlist, function (value, index) { $scope.smallfolderlist[index].counts = Number(value.foldercounts) + Number(value.infocounts); }); }, function () { }); var sql = "select * from conninfo where localclaid = '" + cloudfolder.localid + "' and synchrotype != 4 order by conntime desc";// limit 10 offset 0 SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); if (response.length > 0) { //拼接记录localid var infoidlist = ""; angular.forEach(response, function (value) { var tempstr = "'" + value.localid + "'"; infoidlist = infoidlist + tempstr + ","; }); infoidlist = infoidlist.substring(0, infoidlist.length - 1); //--查询图片信息 var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")"; SqliteStorageService.queryData(q_pic_sql).then(function (res) { // console.log(res); if (res.length > 0) { extractConninfoPicture(response, res, true); } else { $scope.recordList = response; //判读是否有下一页 $scope.isload = response.length >= 10; if ($scope.isload) { pageindex = 10; } } }, function () { $scope.recordList = response; //判读是否有下一页 $scope.isload = response.length >= 10; if ($scope.isload) { pageindex = 10; } }); } else { $scope.isload = false; $scope.recordList = []; } }, function () { $scope.recordList = []; }).finally(function () { $scope.$broadcast('scroll.refreshComplete'); }); }; $scope.initConninfoList(); //加载更多记录 $scope.loadMore = function () { $scope.isload = false; var sql = "select * from conninfo where localclaid = " + cloudfolder.localid + " and creator = " + UserService.id + " order by conntime desc limit 10 offset " + pageindex; SqliteStorageService.queryData(sql).then(function (response) { // console.log(response); if (response.length > 0) { //拼接记录localid var infoidlist = ""; angular.forEach(response, function (value) { var tempstr = "'" + value.localid + "'"; infoidlist = infoidlist + tempstr + ","; }); infoidlist = infoidlist.substring(0, infoidlist.length - 1); //--查询图片信息 var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")"; SqliteStorageService.queryData(q_pic_sql).then(function (res) { // console.log(res); if (res.length > 0) { extractConninfoPicture(response, res, false); } else { $scope.recordList = $scope.recordList.concat(response); //判读是否有下一页 $scope.isload = response.length >= 10; if ($scope.isload) { pageindex += 10; } } }, function () { $scope.recordList = $scope.recordList.concat(response); //判读是否有下一页 $scope.isload = response.length >= 10; if ($scope.isload) { pageindex += 10; } }); } else { $scope.isload = false; } }, function () { }).finally(function () { $scope.$broadcast('scroll.infiniteScrollComplete'); }); }; $scope.showMoreAction = true; $scope.showAction = function () { $scope.showMoreAction = !$scope.showMoreAction; }; //新建记录 $scope.createConninfo = function () { ModelService.setCreateType(1); $scope.go('cloudAddConnInfo'); }; //创建子文件夹 $scope.createFolder = function () { $scope.go("authorityCreate", {localparentid: cloudfolder.localid, level: cloudfolder.level, templettype:1}); }; //进入分类详情,记录列表 $scope.queryFolder = function (folder) { $scope.go('conninfolist', {folder: angular.toJson(folder)}); }; //点击进入对接详情 $scope.goDockingdetails = function (rec) { $scope.go("Dockingdetails", {infoid: rec.localid, creator: rec.creator}); }; //进入设置文件夹页面 $scope.goAutoritySet = function (reclib) { $timeout(function () { $ionicListDelegate.closeOptionButtons(); }, 10); $scope.go("authorityLocalSet", {authoritydata: angular.toJson(reclib), type: 0, goflg: 1}); if (UtilService.isDefined(reclib.localid)) { } else { $scope.go("authoritySet", { reclibid: reclib.id, authorityid: reclib.authorityid, authoritycomefrom: reclib.authoritycomefrom, name: reclib.name, content: reclib.content, sort: reclib.sort, type: 0 }); } }; //修改云文件夹 $scope.editCloudFolder = function () { $ionicActionSheet.show({ buttons: [{text: '设置'}], cancelText: '取消', buttonClicked: function (index) { if (index == 0) { $scope.go("authorityLocalSet", {authoritydata: angular.toJson(cloudfolder), type: 0, goflg: 1}); } return true; } }); }; $scope.shareflg = false; $scope.openShare = function (tempobj, ind) { $scope.go('chooseShareFolder', { chereslist: angular.toJson([tempobj.localid]), folderid: cloudfolder.localid, isCloud: cloudfolder.isCloud }); /*$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; }; //分享选择操作表 var selectflg = false;//列表选择打开标志 $scope.openCollectShare = function () { selectflg = true; $scope.recordList[checkedindex].value = true; var tempres = { infoid: checkedresource.id, infocomefrom: checkedresource.creatorcomefrom, infoType: 81, claid: cloudfolder.id }; $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.recordList, function (value, ind) { $scope.recordList[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 (rec, ind) { var tempres = { infoid: rec.id, infocomefrom: rec.creatorcomefrom, infoType: 81, claid: cloudfolder.id }; var chind = -1; angular.forEach($scope.checkedresourcelist, function (value, index) { if (value.infoid == rec.id) { chind = index; } }); if (chind == -1) { $scope.recordList[ind].value = true; $scope.checkedresourcelist.unshift(tempres); } else { $scope.recordList[ind].value = false; $scope.checkedresourcelist.splice(chind, 1); } // console.log($scope.checkedresourcelist); }; $scope.shareResourceToPrilib = function () { $scope.go('chooseShareFolder', { chereslist: angular.toJson($scope.checkedresourcelist), folderid: cloudfolder.id }); }; //跳转工具搜索 $scope.goToolsSearch = function () { $timeout(function () { $scope.go("connsearch", {localfolderid: cloudfolder.localid}); }, 300); }; //0:QQ,1:QQ空间,2:微信,3:微信朋友圈,4:新浪微博 $scope.shareMessage = function (type) { $scope.shareflg = false; $scope.showLoadingToast(); var imagurl = "http://test.ubitech.cn/000000000/themes/avatar_save/1490753632823.jpg"; if (checkedresource.image.length > 0) { imagurl = $scope.imgUrl + checkedresource.image; } var message = { title: checkedresource.title, description: checkedresource.content.substring(0, 19), url: checkedresource.share_url, imageurl: imagurl }; 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); }; $scope.refreshDate = function () { $scope.initConninfoList(); $scope.$broadcast('scroll.refreshComplete'); var trHtml = "
更新了" + $scope.recordList.length + "条内容
"; $timeout(function () { $(".resourcelistDiv").prepend(trHtml); $(".refresh_tip_div").animate({width: 100 + "%"}, 150); }, 800); $timeout(function () { $(".refresh_tip_div").slideUp(); }, 1200); }; //页面加载完成,设置当前文件夹为选中文件夹 $scope.$on('$ionicView.afterEnter', function () { ModelService.setCheckdeFolder(cloudfolder); }); });