connSearchResultCtrl.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. angular.module('push')
  2. .controller('ConnSearchResultCtrl', function ($scope, $state, $timeout, $stateParams, ConnSearchService, $http, ModelService,
  3. UtilService, SqliteStorageService, HandleService, UserService, $sce) {
  4. $scope.key = $stateParams.key;
  5. $scope.choseTab = 0;
  6. $scope.showbaidu = false;
  7. $scope.user = UserService.user.user;
  8. var localfolderid = $stateParams.localfolderid;
  9. var folderid = $stateParams.folderid;
  10. var folderflg = 1;
  11. $scope.searchfolderflg = 0;
  12. //搜索本地文件夹
  13. var templcoalfolderlist = [];
  14. var searchLocalFolder = function (key) {
  15. // var q_sql = "select * from conninfofolder where localparentid = '" + localfolderid + "' and name like '%" + key + "%'";
  16. var q_sql = "select c1.*,foldercounts,infocounts from " +
  17. "(select * from conninfofolder where localparentid = '" + localfolderid + "' and name like '%" + key + "%') c1 " +
  18. "LEFT JOIN " +
  19. "(" +
  20. "select localparentid,count(1) foldercounts from " +
  21. "conninfofolder where localparentid in " +
  22. "(select localid from conninfofolder where localparentid = '" + localfolderid + "' and name like '%" + key + "%') " +
  23. "GROUP BY localparentid " +
  24. ") c2 " +
  25. "ON c1.localid = c2.localparentid " +
  26. "LEFT JOIN " +
  27. "(" +
  28. "select localclaid, count(1) infocounts " +
  29. "from conninfo where localclaid in " +
  30. "(select localid from conninfofolder where localparentid = '" + localfolderid + "' and name like '%" + key + "%') " +
  31. "GROUP BY localclaid " +
  32. ") c3" +
  33. " ON c1.localid = c3.localclaid";
  34. SqliteStorageService.queryData(q_sql).then(function (response) {
  35. templcoalfolderlist = response;
  36. angular.forEach(templcoalfolderlist, function (value, index) {
  37. templcoalfolderlist[index].counts = Number(value.foldercounts) + Number(value.infocounts);
  38. });
  39. $scope.searchfolderflg++;
  40. }, function () {
  41. templcoalfolderlist = [];
  42. $scope.searchfolderflg++;
  43. });
  44. };
  45. //搜索云文件夹
  46. var tempcloudfolderlist = [];
  47. var searchFolder = function (key) {
  48. ConnSearchService.searchCloudFolder(key, folderid).then(function (response) {
  49. tempcloudfolderlist = response.list;
  50. $scope.searchfolderflg++;
  51. }, function () {
  52. tempcloudfolderlist = [];
  53. $scope.searchfolderflg++;
  54. });
  55. };
  56. //--监听本地与云文件夹查询是否结束
  57. $scope.$watch("searchfolderflg", function (newValue) {
  58. if (newValue == folderflg) {
  59. $scope.folderlist = templcoalfolderlist.concat(tempcloudfolderlist);
  60. folderflg = 1;
  61. $scope.searchfolderflg = 0;
  62. }
  63. });
  64. var templocalconnlist = [];
  65. //--本地记录列表提取第一张图为列表显示图
  66. var extractConninfoPicture = function (conninfolist, picturelist) {
  67. HandleService.extractConninfoPicture(conninfolist, picturelist).then(function (response) {
  68. templocalconnlist = response;
  69. $scope.searchconnflg++;
  70. }, function () {
  71. $scope.searchconnflg++;
  72. })
  73. };
  74. var connflg = 1;
  75. $scope.searchconnflg = 0;
  76. //搜索本地记录
  77. var searchLocalConninfo = function (key) {
  78. var q_sql = "";
  79. if (localfolderid == '0') {
  80. q_sql = "select * from conninfo where title like '%" + key + "%'";
  81. } else {
  82. q_sql = "select * from conninfo where localclaid = '" + localfolderid + "' and title like '%" + key + "%'";
  83. }
  84. SqliteStorageService.queryData(q_sql).then(function (response) {
  85. if (response.length > 0) {
  86. //拼接记录localid
  87. var infoidlist = "";
  88. angular.forEach(response, function (value) {
  89. var tempstr = "'" + value.localid + "'";
  90. infoidlist = infoidlist + tempstr + ",";
  91. });
  92. infoidlist = infoidlist.substring(0, infoidlist.length - 1);
  93. //--查询图片信息
  94. var q_pic_sql = "select * from conninfopicture where localinfoid in (" + infoidlist + ")";
  95. SqliteStorageService.queryData(q_pic_sql).then(function (res) {
  96. if (res.length > 0) {
  97. extractConninfoPicture(response, res);
  98. } else {
  99. $scope.searchconnflg++;
  100. }
  101. }, function () {
  102. $scope.searchconnflg++;
  103. });
  104. } else {
  105. $scope.searchconnflg++;
  106. }
  107. }, function () {
  108. templocalconnlist = [];
  109. $scope.searchconnflg++;
  110. });
  111. };
  112. //搜索云记录
  113. var tempcloudconnlist = [];
  114. var searchConninfo = function (key) {
  115. // $scope.showLoadingToast();
  116. ConnSearchService.newNearchConnInfo(key, folderid).then(function (response) {
  117. tempcloudconnlist = response.list;
  118. $scope.searchconnflg++;
  119. }, function () {
  120. tempcloudconnlist = [];
  121. $scope.searchconnflg++;
  122. });
  123. };
  124. //--监听本地与云文件夹查询是否结束
  125. $scope.$watch("searchconnflg", function (newValue) {
  126. if (newValue == connflg) {
  127. $scope.recordList = templocalconnlist.concat(tempcloudconnlist);
  128. connflg = 1;
  129. $scope.searchconnflg = 0;
  130. }
  131. });
  132. //根据关键字搜索综合、用户信息
  133. $scope.searchResultByKey = function (key) {
  134. if (!UtilService.isDefined(key)) {
  135. return;
  136. }
  137. $scope.showbaidu = false;
  138. if ($scope.choseTab == 0) {
  139. //首页进入搜索
  140. if (localfolderid == '0' && folderid == 0) {
  141. folderflg = 2;
  142. searchLocalFolder(key);
  143. searchFolder(key);
  144. } else if (localfolderid != '0') {
  145. //本地文件夹下搜索
  146. searchLocalFolder(key);
  147. } else if (folderid != 0) {
  148. //云文件夹下搜索
  149. searchFolder(key);
  150. }
  151. } else if ($scope.choseTab == 1) {
  152. //首页进入搜索
  153. if (localfolderid == '0' && folderid == 0) {
  154. searchLocalConninfo(key);
  155. searchConninfo(key);
  156. } else if (localfolderid != '0') {
  157. //本地文件夹下搜索
  158. searchLocalConninfo(key);
  159. } else if (folderid != 0) {
  160. //云文件夹下搜索
  161. searchConninfo(key);
  162. }
  163. }
  164. };
  165. $scope.searchResultByKey($scope.key);
  166. //切换tab并搜索
  167. $scope.changeAct = function (index) {
  168. $scope.choseTab = index;
  169. $scope.searchResultByKey($scope.key);
  170. };
  171. //进入分类详情,记录列表
  172. $scope.queryFolder = function (folder) {
  173. ModelService.setCheckdeFolder(folder);
  174. if (UtilService.isDefined(folder.localid)) {
  175. //本地文件夹记录列表
  176. $scope.go('conninfolist', {folder: angular.toJson(folder)});
  177. } else {
  178. //云文件夹记录列表
  179. $scope.go('cloudFolderDetail', {folder: angular.toJson(folder)});
  180. }
  181. };
  182. //进入记录详情
  183. $scope.goDockingdetails = function (rec) {
  184. if (UtilService.isDefined(rec.localid)) {
  185. $scope.go("Dockingdetails", {infoid: rec.localid});
  186. } else {
  187. $scope.go("cloudDockingdetail", {infoid: rec.id, infocomefrom: rec.creatorcomefrom, creator: rec.creator});
  188. }
  189. };
  190. //清空搜索内容
  191. $scope.clearSearch = function () {
  192. $scope.key = "";
  193. };
  194. //显示热词
  195. $scope.showFunc = function () {
  196. $scope.showbaidu = true;
  197. };
  198. $scope.ttt = function (temptitle) {
  199. return $sce.trustAsHtml(temptitle)
  200. };
  201. $scope.gobackback = function () {
  202. $timeout(function () {
  203. $scope.goback();
  204. }, 310);
  205. };
  206. //监测key变化,即时匹配词库
  207. $scope.fixKey = function () {
  208. if (angular.isDefined($scope.key) && $scope.key.length > 0) {
  209. $scope.searchKey($scope.key);
  210. }
  211. };
  212. $scope.data = [];
  213. //百度词库
  214. $scope.searchKey = function (searchName) {
  215. var search_history = angular.element(document.getElementById("his_search"));
  216. if (search_history.val().length != 0) {
  217. var baidu = angular.element(document.getElementById("baidu_search"));
  218. baidu.css("display", "block");
  219. }
  220. $http({
  221. method: 'JSONP',
  222. url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=' + searchName + '&cb=JSON_CALLBACK'
  223. }).success(function (data) {
  224. $scope.data = data.s;
  225. });
  226. };
  227. //过滤未标记记录
  228. /*var filterRecord = function () {
  229. if ($scope.recordList.length > 0) {
  230. angular.forEach($scope.recordList, function (record, index) {
  231. for (var i = record.reclist.length - 1; i >= 0; i--) {
  232. if (record.reclist[i].flag == 0) {
  233. $scope.recordList[index].reclist.splice(i, 1);
  234. }
  235. }
  236. if (record.reclist.length == 0) {
  237. $scope.recordList.splice(index, 1);
  238. }
  239. });
  240. }
  241. if ($scope.localrecordList.length > 0) {
  242. angular.forEach($scope.localrecordList, function (record, index) {
  243. for (var i = record.reclist.length - 1; i >= 0; i--) {
  244. if (record.reclist[i].flag == 0) {
  245. $scope.localrecordList[index].reclist.splice(i, 1);
  246. }
  247. }
  248. if (record.reclist.length == 0) {
  249. $scope.localrecordList.splice(index, 1);
  250. }
  251. });
  252. }
  253. };*/
  254. });