thirdPartyCompanyCtrl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. 'use strict';
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller('thirdPartyCompanyCtrl', ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_user_data", "api_login",'api_wechatfile', function ($rootScope, $scope, $state, $timeout, $interval, $modal, SweetAlert, i18nService, uiGridConstants, uiGridGroupingConstants, Restangular, api_user_data, api_login,api_wechatfile) {
  6. $scope.langs = i18nService.getAllLangs();
  7. $scope.lang = 'zh-cn';
  8. i18nService.setCurrentLang($scope.lang);
  9. var loginUser = $rootScope.user;
  10. $scope.xinzeng = false;
  11. $scope.shanchu = false;
  12. $scope.bianji = false;
  13. $scope.chongzhimima = false;
  14. for (var i = 0; i < loginUser.menu.length; i++) {
  15. if (loginUser.menu[i].link == "renyuanguanli_xinzeng") {
  16. $scope.xinzeng = true
  17. }
  18. if (loginUser.menu[i].link == "renyuanguanli_shanchu") {
  19. $scope.shanchu = true
  20. }
  21. if (loginUser.menu[i].link == "renyuanguanli_bianji") {
  22. $scope.bianji = true
  23. }
  24. if (loginUser.menu[i].link == "renyuanguanli_chongzhimima") {
  25. $scope.chongzhimima = true
  26. }
  27. }
  28. $scope.gridOptions = {};
  29. $scope.gridOptions.data = 'myData';
  30. $scope.gridOptions.enableColumnResizing = true;
  31. $scope.gridOptions.enableFiltering = true;
  32. $scope.gridOptions.enableGridMenu = true;
  33. $scope.gridOptions.enableRowSelection = true;
  34. $scope.gridOptions.showGridFooter = true;
  35. $scope.gridOptions.showColumnFooter = false;
  36. $scope.gridOptions.fastWatch = true;
  37. $scope.gridOptions.useExternalFiltering = true;
  38. $scope.gridOptions.useExternalPagination = true;
  39. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  40. $scope.gridOptions.paginationPageSize = 10;
  41. $scope.gridOptions.multiSelect = false;
  42. $scope.gridOptions.rowIdentity = function (row) {
  43. return row.id;
  44. };
  45. $scope.gridOptions.getRowIdentity = function (row) {
  46. return row.id;
  47. };
  48. //remote data
  49. $scope.gridOptions.columnDefs = [{
  50. name: 'item',
  51. displayName: '序号',
  52. width: '5%',
  53. minWidth: '70',
  54. enableFiltering: false,
  55. cellTemplate: '<div>' +
  56. '<div class="ui-grid-cell-contents">{{row.entity.item}}</div>' +
  57. '</div>'
  58. },
  59. {
  60. name: 'name',
  61. displayName: '公司名称',
  62. width: '20%',
  63. minWidth: '100',
  64. enableFiltering: false
  65. },
  66. {
  67. name: 'contacts',
  68. displayName: '公司联系人',
  69. width: '20%',
  70. minWidth: '100',
  71. enableFiltering: false
  72. },
  73. {
  74. name: 'mphone',
  75. displayName: '联系人电话',
  76. width: '20%',
  77. minWidth: '120',
  78. enableFiltering: false
  79. },
  80. {
  81. name: 'serviceTypeNames',
  82. displayName: '公司服务种类',
  83. width: '20%',
  84. minWidth: '120',
  85. enableFiltering: false,
  86. // cellTemplate: '<div>' +
  87. // '<div class="ui-grid-cell-contents">{{row.entity.userType.value == 2 ?row.entity.company.name:row.entity.userType.name}}</div>' +
  88. // '</div>'
  89. },
  90. {
  91. name: '操作',
  92. width: '10%',
  93. minWidth: '100',
  94. cellTemplate: '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left">' +
  95. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  96. '</div></div>',
  97. enableFiltering: false
  98. }
  99. ];
  100. $scope.groupdata = {};
  101. $scope.my_data = [];
  102. $scope.select_treedata = [];
  103. $scope.propTypeOptions = [];
  104. $scope.saveData = function (data) {
  105. var modelData = {
  106. model: {
  107. company: data
  108. }
  109. };
  110. modelData.model.company = {
  111. categoryTypeIds: data.categoryTypeIds,//事件分类
  112. contacts: data.contacts,//联系人
  113. id: data.id,//id
  114. mphone: data.mphone,//联系电话
  115. name: data.name,//公司名称
  116. startTime: data.startTime,//开始时间
  117. endTime: data.endTime,//结束时间
  118. serviceTypeIds: data.serviceTypeIds,//服务分类ids
  119. serviceTypeNames: data.serviceTypeNames//服务分类名称s
  120. }
  121. console.log(modelData)
  122. $state.go('app.system.form', {
  123. formKey: 'company_edit',
  124. service: 'api_user_data',
  125. model: JSON.stringify(modelData)
  126. });
  127. };
  128. $scope.addData = function () {
  129. var modelData = {
  130. model: {
  131. user: {}
  132. }
  133. };
  134. $state.go('app.system.form', {
  135. formKey: 'company_edit',
  136. service: 'api_user_data',
  137. model: JSON.stringify(modelData)
  138. });
  139. }
  140. $scope.removeData = function () {
  141. var modalInstance = $modal.open({
  142. templateUrl: 'assets/views/delete.html',
  143. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  144. var rmvList = [];
  145. $scope.title = '第三方公司删除';
  146. $scope.connect = '确定要删除此第三方公司?';
  147. angular.forEach(scope.selected.items, function (item) {
  148. rmvList.push(item.id);
  149. });
  150. $scope.ok = function () {
  151. $modalInstance.close(rmvList);
  152. };
  153. $scope.cancel = function () {
  154. $modalInstance.dismiss('cancel');
  155. };
  156. },
  157. size: 'sm',
  158. resolve: {
  159. scope: function () {
  160. return $scope;
  161. }
  162. }
  163. });
  164. modalInstance.result.then(function (selectedItem) {
  165. if (selectedItem) {
  166. if (selectedItem.length > 0) {
  167. api_user_data.rmvData('company', selectedItem).then(function (response) {
  168. if (response.data[0].deleteFlag != 0) {
  169. SweetAlert.swal({
  170. title: "删除成功!",
  171. type: "success",
  172. confirmButtonColor: "#007AFF"
  173. }, function () {
  174. $scope.myData = _.reject($scope.myData, function (o) {
  175. return _.includes(selectedItem, o.id);
  176. });
  177. $scope.selected = {
  178. items: []
  179. };
  180. $scope.gridOptions.totalItems = $scope.gridOptions.totalItems - selectedItem.length;
  181. $scope.gridApi.grid.selection.selectedCount = 0;
  182. });
  183. } else {
  184. SweetAlert.swal({
  185. title: "无法删除!",
  186. text: "【"+response.data[0].name+"】已经绑定了用户或耗材!",
  187. type: "error"
  188. });
  189. }
  190. })
  191. }
  192. }
  193. })
  194. }
  195. //获取公司服务种类
  196. $scope.company_service_type = [];
  197. $scope.getCompanyServiceTypes = function(){
  198. api_wechatfile.getDictionary({
  199. key: "company_service_type",
  200. type: "list"
  201. }).then(function (res) {
  202. $scope.company_service_type = res;
  203. $scope.refreshData('expand-right', $scope.fileData);
  204. $scope.timer = $interval(function () {
  205. $scope.refreshData('expand-right', $scope.fileData);
  206. }, $rootScope.refreshTime);
  207. })
  208. }
  209. $scope.getCompanyServiceTypes();
  210. $scope.selected = {
  211. items: []
  212. }
  213. $scope.editted = {
  214. items: []
  215. }
  216. $scope.gridOptions.onRegisterApi = function (gridApi) {
  217. $scope.gridApi = gridApi;
  218. gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
  219. var filtersData = $scope.memoryfilterData;
  220. filtersData.idx = newPage - 1;
  221. filtersData.sum = pageSize;
  222. $scope.fileData.idx = newPage - 1;
  223. $scope.fileData.sum = pageSize;
  224. defaultFilterData = filtersData;
  225. $scope.refreshData('expand-right', $scope.fileData);
  226. });
  227. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  228. var j = 0;
  229. for (var i = 0; i <= scope.grid.appScope.selected.items.length; i++) {
  230. if (scope.grid.appScope.selected.items[i] == scope.entity) {
  231. j++;
  232. break;
  233. }
  234. }
  235. if (j == 1) {
  236. scope.grid.appScope.selected.items.splice(i, 1);
  237. } else {
  238. scope.grid.appScope.selected.items.push(scope.entity)
  239. }
  240. });
  241. gridApi.core.on.filterChanged($scope, function () {
  242. var grid = this.grid;
  243. var filtersData = $scope.memoryfilterData;
  244. angular.forEach(grid.columns, function (item) {
  245. if (item.enableFiltering) {
  246. if (angular.isDefined(item.filters[0].term) && item.filters[0].term != '') {
  247. if (angular.isUndefined(filtersData['company'])) {
  248. filtersData['company'] = {};
  249. filtersData['company']['flag'] = -1;
  250. filtersData['company'][item.field] = item.filters[0].term;
  251. } else {
  252. filtersData.company.flag = -1;
  253. filtersData.company[item.field] = item.filters[0].term;
  254. }
  255. }
  256. }
  257. });
  258. $scope.memoryfilterData = filtersData;
  259. $scope.refreshData('expand-right', $scope.fileData);
  260. });
  261. };
  262. var defaultFilterData = {
  263. "idx": 0,
  264. "sum": 10
  265. };
  266. $scope.memoryfilterData = {
  267. "idx": 0,
  268. "sum": 10
  269. }
  270. $scope.ldloading = {};
  271. $scope.fileData = {
  272. "idx": 0,
  273. "sum": 10,
  274. "company": {}
  275. }
  276. $scope.treeItem = "";
  277. $scope.onFilterCallback = function (item) {
  278. $scope.treeItem = item
  279. }
  280. // 搜索
  281. $scope.searchData = function () {
  282. if ($scope.treeItem) {
  283. $scope.fileData.company.groupdata = $scope.treeItem
  284. }
  285. if($scope.fileData.company.name){
  286. $scope.fileData.company.selectType= "pinyin_qs"
  287. }
  288. $scope.refreshData('expand-right', $scope.fileData);
  289. }
  290. // 清空
  291. $scope.clean = function () {
  292. delete $scope.fileData.company.account;
  293. delete $scope.fileData.company.name;
  294. delete $scope.fileData.company.groupdata;
  295. $scope.treeItem = "";
  296. $scope.refreshData('expand-right', $scope.fileData);
  297. }
  298. //刷新
  299. $scope.refresh = function (style, filterData) {
  300. $scope.selected = {
  301. items: []
  302. };
  303. if ($scope.gridApi) {
  304. $scope.gridApi.grid.selection.selectedCount = 0;
  305. }
  306. $scope.refreshData('expand-right', $scope.fileData);
  307. }
  308. //获取列表数据
  309. $scope.refreshData = function (style, filterData) {
  310. console.log(filterData)
  311. $scope.ldloading[style.replace('-', '_')] = true;
  312. if (angular.isUndefined(filterData)) {
  313. filterData = defaultFilterData;
  314. }
  315. if (angular.isDefined($scope.searchTypes)) {
  316. filterData['searchType'] = $scope.searchTypes;
  317. }
  318. $scope.myData = [];
  319. filterData['flag'] = -1;
  320. console.log("filterData=" + JSON.stringify(filterData))
  321. api_user_data.fetchDataList('company', filterData).then(function (data) {
  322. var myData = Restangular.stripRestangular(data);
  323. $scope.gridOptions.totalItems = myData.totalNum;
  324. //数据转换start
  325. myData.list.forEach(function(v){
  326. if(v.serviceTypeIds){
  327. var sArr = v.serviceTypeIds.split(',');
  328. var sNameArr = [];
  329. $scope.company_service_type.forEach(function(v1){
  330. sArr.forEach(function(v2){
  331. if(v1.id == v2){
  332. sNameArr.push(v1.name);
  333. }
  334. })
  335. })
  336. v.serviceTypeNames = sNameArr.join(',');//公司服务种类名称
  337. }
  338. })
  339. console.log(myData.list);
  340. //数据转换end
  341. $scope.myData = myData.list;
  342. for (var i = 0; i < $scope.myData.length; i++) {
  343. $scope.myData[i]['item'] = i + 1 + filterData.idx * filterData.sum
  344. }
  345. $scope.ldloading[style.replace('-', '_')] = false;
  346. }, function () {
  347. $scope.ldloading[style.replace('-', '_')] = false;
  348. });
  349. };
  350. $scope.$on('$destroy', function () {
  351. $interval.cancel($scope.timer)
  352. });
  353. }]);