chooseShareResourceCtrl.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. angular.module('push')
  2. .controller('chooseShareResourceCtrl', function ($scope, $ionicPopup, $timeout, $stateParams, resourceLibraryTempData, DockingService, SqliteStorageService,
  3. HandleService, ConfigService, UserService, UtilService, ResourceLibraryService, AuthorityService) {
  4. if($scope.app){
  5. $scope.setStatusBar(0);
  6. }
  7. var chereslist = angular.fromJson($stateParams.chereslist);
  8. var recourcetype = $stateParams.recourcetype;
  9. var recourcecomefrom = $stateParams.recourcecomefrom;
  10. var folderid = $stateParams.folderid;//被选择的资源所在资源库ID
  11. var isCloud = $stateParams.isCloud;//区别本地与云
  12. $scope.resliblist = angular.copy(resourceLibraryTempData.getResourceLibraryList());
  13. $scope.checkreslib = "";//被选中的资源库id
  14. var checkreslibtype = -1;//0:本地,1:云
  15. $scope.search = {searchkey: ""};
  16. //剔除被选择的资源所在资源库
  17. angular.forEach($scope.resliblist, function (value, index) {
  18. if (isCloud == 0) {
  19. if (value.localid == folderid) {
  20. $scope.resliblist.splice(index, 1);
  21. }
  22. } else if (isCloud == 1) {
  23. if (value.id == folderid) {
  24. $scope.resliblist.splice(index, 1);
  25. }
  26. }
  27. });
  28. //筛选资源库
  29. $scope.chooseFolder = function (reclib, index) {
  30. angular.forEach($scope.resliblist, function (value, ind) {
  31. $scope.resliblist[ind].value = false;
  32. });
  33. if (reclib.isCloud == 0) {
  34. $scope.checkreslib = reclib.localid;
  35. checkreslibtype = 0;
  36. }
  37. if (reclib.isCloud == 1) {
  38. $scope.checkreslib = reclib.id + "";
  39. checkreslibtype = 1;
  40. }
  41. $scope.resliblist[index].value = true;
  42. //本地资源库选择
  43. /*if (reclib.isCloud == 0) {
  44. var localindex = chooselocalfolderidlist.indexOf(reclib.localid);
  45. if (localindex == -1) {
  46. chooselocalfolderidlist.push(reclib.localid);
  47. } else {
  48. chooselocalfolderidlist.splice(localindex, 1);
  49. }
  50. }
  51. console.log(chooselocalfolderidlist);
  52. //云资源库选择
  53. if (reclib.isCloud == 1) {
  54. var cloudindex = choosecloudfolderidlist.indexOf(reclib.id);
  55. if (cloudindex == -1) {
  56. choosecloudfolderidlist.push(reclib.id);
  57. } else {
  58. choosecloudfolderidlist.splice(cloudindex, 1);
  59. }
  60. }*/
  61. };
  62. //检测选中资源库总数
  63. /*var checklength = function () {
  64. if (choosecloudfolderidlist.length > 0 || chooselocalfolderidlist.length > 0) {
  65. $scope.blue = "toolReleaseButton_blue";
  66. } else {
  67. $scope.blue = "";
  68. }
  69. };*/
  70. //复制资源至资源库
  71. var clickflg = 0;
  72. $scope.copyRecordToFolder = function () {
  73. //未选中资源库则不操作
  74. if ($scope.checkreslib.length <= 0) {
  75. return;
  76. }
  77. if (clickflg != 0) {
  78. return;
  79. }
  80. clickflg = 1;
  81. //选中资源为本地资源
  82. if (isCloud == 0) {
  83. getLocalResourceDetail();
  84. }
  85. //选中资源为云资源
  86. if (isCloud == 1) {
  87. getCloudResourceDetail();
  88. }
  89. $timeout(function () {
  90. clickflg = 0;
  91. }, 2500);
  92. };
  93. $scope.queryisover = 0;//0:本地对接信息开始查询 4:查询结束
  94. var resource = {};
  95. //取本地资源信息
  96. var getLocalResourceDetail = function () {
  97. var sql = "select * from resource where localid = " + chereslist[0];
  98. SqliteStorageService.queryData(sql).then(function (response) {
  99. // console.log(response);
  100. resource = response[0];
  101. if (checkreslibtype == 0) {
  102. saveResourceToLocal();
  103. }
  104. //云有资源库选中操作-->
  105. if (checkreslibtype == 1) {
  106. if (UserService.viplevel == 1) {
  107. AuthorityService.isHasEnoughCount(3).then(function (response) {
  108. if (response.isHasEnoughCount == 1) {
  109. copyResInfo();
  110. } else {
  111. UtilService.showMess("本月复制次数已用完");
  112. }
  113. }, function () {
  114. UtilService.showMess("网络不给力,请重试");
  115. });
  116. } else {
  117. copyResInfo();
  118. }
  119. }
  120. }, function (err) {
  121. // console.log(err);
  122. });
  123. };
  124. //取云资源信息
  125. var getCloudResourceDetail = function () {
  126. ResourceLibraryService.getPrivateResourceDetail(chereslist[0], recourcetype, recourcecomefrom).then(function (response) {
  127. // console.log(response);
  128. resource = response.res;
  129. //本地有资源库选中操作-->
  130. if (checkreslibtype == 0) {
  131. saveResourceToLocal();
  132. }
  133. //云有资源库选中操作-->
  134. if (checkreslibtype == 1) {
  135. if (UserService.viplevel == 1) {
  136. AuthorityService.isHasEnoughCount(3).then(function (response) {
  137. if (response.isHasEnoughCount == 1) {
  138. copyResInfo();
  139. } else {
  140. UtilService.showMess("本月复制次数已用完");
  141. }
  142. }, function () {
  143. UtilService.showMess("网络不给力,请重试");
  144. });
  145. } else {
  146. copyResInfo();
  147. }
  148. }
  149. }, function () {
  150. })
  151. };
  152. //本地资源新增
  153. var saveResourceToLocal = function () {
  154. try {
  155. var conninfodate = UtilService.formatDate();
  156. var conninfodatelocalid = conninfodate.timestamp;
  157. //对接信息数据生成
  158. resource.localid = conninfodatelocalid + "";
  159. resource.localclaid = $scope.checkreslib;
  160. resource.claid = 0;
  161. resource.id = resource.unique;
  162. resource.creator = UserService.id;
  163. resource.synchrotype = 1;
  164. resource.timestamp = conninfodate.formattime;
  165. resource.createTime = conninfodate.formattime;
  166. resource.updateTime = conninfodate.formattime;
  167. resource.creatorcomefrom = ConfigService.comefrom;
  168. resource.favourcount = 0;//点赞数
  169. resource.visitcount = 0;//浏览数
  170. resource.commcount = 0;//评论数
  171. // console.log("===========================================");
  172. // console.log(resource);
  173. // console.log("===========================================");
  174. SqliteStorageService.insertSingleData("resource", resource).then(function () {
  175. UtilService.showMess("复制成功");
  176. $timeout(function () {
  177. $scope.goback();
  178. }, 1000);
  179. ConfigService.isedit = 1;
  180. SqliteStorageService.updateEditFlg(1);
  181. }, function () {
  182. $scope.hideLoadingToast();
  183. });
  184. } catch (e) {
  185. $scope.hideLoadingToast();
  186. }
  187. };
  188. var copyResInfo = function () {
  189. DockingService.copyResInfo(1, folderid, $scope.checkreslib, chereslist[0], recourcetype).then(function () {
  190. UtilService.showMess("复制成功");
  191. if (UserService.viplevel == 1) {
  192. $scope.deductUserMemberCount(3);
  193. }
  194. $timeout(function () {
  195. $scope.goback();
  196. }, 1000);
  197. }, function () {
  198. })
  199. };
  200. });