thirdPartyCompanyCtrl.js 14 KB

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