responsibilityDeptCtrl.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. "use strict";
  2. /**
  3. * controller for User Profile Example
  4. */
  5. app.controller("responsibilityDeptlistCtrl", [
  6. "$rootScope",
  7. "$scope",
  8. "$state",
  9. "$timeout",
  10. "$interval",
  11. "$modal",
  12. "SweetAlert",
  13. "i18nService",
  14. "uiGridConstants",
  15. "uiGridGroupingConstants",
  16. "Restangular",
  17. "api_user_data",
  18. function (
  19. $rootScope,
  20. $scope,
  21. $state,
  22. $timeout,
  23. $interval,
  24. $modal,
  25. SweetAlert,
  26. i18nService,
  27. uiGridConstants,
  28. uiGridGroupingConstants,
  29. Restangular,
  30. api_user_data
  31. ) {
  32. $scope.langs = i18nService.getAllLangs();
  33. $scope.lang = "zh-cn";
  34. i18nService.setCurrentLang($scope.lang);
  35. var loginUser = $rootScope.user;
  36. $scope.xinzeng = false;
  37. $scope.shanchu = false;
  38. $scope.bianji = false;
  39. for (var i = 0; i < loginUser.menu.length; i++) {
  40. if (loginUser.menu[i].link == "responsibilityDept_add") {
  41. $scope.xinzeng = true;
  42. }
  43. if (loginUser.menu[i].link == "responsibilityDept_del") {
  44. $scope.shanchu = true;
  45. }
  46. if (loginUser.menu[i].link == "responsibilityDept_edit") {
  47. $scope.bianji = true;
  48. }
  49. }
  50. $scope.gridOptions = {};
  51. $scope.gridOptions.data = "myData";
  52. $scope.gridOptions.enableColumnResizing = true;
  53. $scope.gridOptions.enableFiltering = true;
  54. $scope.gridOptions.enableGridMenu = true;
  55. $scope.gridOptions.enableRowSelection = true;
  56. $scope.gridOptions.showGridFooter = true;
  57. $scope.gridOptions.showColumnFooter = false;
  58. $scope.gridOptions.fastWatch = true;
  59. $scope.gridOptions.useExternalFiltering = true;
  60. $scope.gridOptions.useExternalPagination = true;
  61. $scope.gridOptions.paginationPageSizes = [10, 20, 50, 100];
  62. $scope.gridOptions.paginationPageSize = 10;
  63. $scope.gridOptions.multiSelect = false;
  64. $scope.gridOptions.rowTemplate =
  65. '<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>';
  66. $scope.gridOptions.rowIdentity = function (row) {
  67. return row.id;
  68. };
  69. $scope.gridOptions.getRowIdentity = function (row) {
  70. return row.id;
  71. };
  72. $scope.gridOptions.columnDefs = [
  73. {
  74. name: "item",
  75. displayName: "序号",
  76. width: 50,
  77. enableFiltering: false,
  78. },
  79. {
  80. name: "branchName",
  81. displayName: "院区",
  82. width: "20%",
  83. enableFiltering: false,
  84. },
  85. {
  86. name: "parent.dept",
  87. displayName: "父级科室",
  88. width: "20%",
  89. enableFiltering: false,
  90. },
  91. {
  92. name: "dept",
  93. displayName: "责任科室",
  94. width: "20%",
  95. enableFiltering: false,
  96. },
  97. {
  98. name: "phone",
  99. displayName: "科室电话",
  100. width: "20%",
  101. enableFiltering: false,
  102. },
  103. {
  104. name: "操作",
  105. cellTemplate:
  106. '<div><div class="cl-effect-1 ui-grid-cell-contents pull-left" >' +
  107. // '<a ng-click="grid.appScope.saveData(row.entity)" tooltip="编辑" tooltip-placement="right">' +
  108. // '<i class="fa fa-pencil-square-o"></i></a>'+
  109. '<a ng-click="grid.appScope.saveData(row.entity)" ng-show="grid.appScope.bianji" class="bianjifont">编辑</a>' +
  110. "</div></div>",
  111. enableFiltering: false,
  112. },
  113. ];
  114. $scope.transferDept = function (data) {
  115. if (data) {
  116. return data;
  117. } else {
  118. return "无";
  119. }
  120. };
  121. $scope.saveData = function (selectdata) {
  122. console.log(selectdata);
  123. var modalInstance = $modal.open({
  124. templateUrl: "assets/views/system/tpl/responsibilityDeptchange.html",
  125. controller: function ($scope, scope, $modalInstance, api_user_data) {
  126. $scope.summaryOrderList = [
  127. {id: 1, name: '是', value: 1},
  128. {id: 2, name: '否', value: 0}
  129. ]
  130. $scope.deptdata = {
  131. uuid:selectdata.uuid,
  132. id: selectdata.id,
  133. dept: selectdata.dept,
  134. phone: selectdata.phone,
  135. branch: { id: selectdata.branch, hosName: selectdata.branchName },
  136. parent:selectdata.parent,
  137. addSummary: $scope.summaryOrderList.find(v => v.value == selectdata.addSummary) || $scope.summaryOrderList.find(v => v.value == 0),
  138. supportZero: $scope.summaryOrderList.find(v => v.value == selectdata.supportZero) || $scope.summaryOrderList.find(v => v.value == 0),
  139. };
  140. $scope.branchList = [];
  141. $scope.title = "责任科室修改";
  142. $scope.parentList = [];
  143. $scope.changeBranch = function(keyword=''){
  144. api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10,"dutyDepartment":{dept: keyword, selectType: "pinyin_qs"} })
  145. .then(function (data) {
  146. $scope.parentList = Restangular.stripRestangular(data).list.filter(v=>v.id != selectdata.id);
  147. });
  148. }
  149. api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10 })
  150. .then(function (data) {
  151. $scope.parentList = Restangular.stripRestangular(data).list.filter(v=>v.id != selectdata.id);
  152. });
  153. api_user_data
  154. .fetchDataList("branch", { idx: 0, sum: 100 })
  155. .then(function (data) {
  156. $scope.branchList = Restangular.stripRestangular(data).list;
  157. });
  158. $scope.cancel = function () {
  159. $modalInstance.dismiss("cancel");
  160. };
  161. // 保存
  162. $scope.savercode = function (deptdata) {
  163. if (
  164. deptdata &&
  165. deptdata.dept &&
  166. deptdata.phone &&
  167. deptdata.branch &&
  168. deptdata.addSummary &&
  169. deptdata.supportZero
  170. ) {
  171. var fildata = {
  172. dutyDepartment: {
  173. uuid:deptdata.uuid,
  174. id: deptdata.id,
  175. deleteFlag: 0,
  176. phone: deptdata.phone,
  177. dept: deptdata.dept,
  178. branch: deptdata.branch.id,
  179. parent:deptdata.parent,
  180. addSummary: deptdata.addSummary.value,
  181. supportZero: deptdata.supportZero.value,
  182. },
  183. };
  184. api_user_data
  185. .updData("dutyDepartment", fildata)
  186. .then(function (response) {
  187. if (response) {
  188. if (response.status == 200) {
  189. SweetAlert.swal(
  190. {
  191. title: "修改成功!",
  192. type: "success",
  193. },
  194. function () {
  195. scope.refreshData("expand-right", scope.fileData);
  196. }
  197. );
  198. } else if (response.status == 500) {
  199. SweetAlert.swal(
  200. {
  201. title: "修改失败!",
  202. text: "该科室已存在",
  203. type: "error",
  204. },
  205. function () {
  206. scope.refreshData("expand-right", scope.fileData);
  207. }
  208. );
  209. } else {
  210. SweetAlert.swal(
  211. {
  212. title: "修改失败!",
  213. type: "error",
  214. },
  215. function () {
  216. scope.refreshData("expand-right", scope.fileData);
  217. }
  218. );
  219. }
  220. $modalInstance.close();
  221. } else {
  222. SweetAlert.swal(
  223. {
  224. title: "修改失败!",
  225. type: "error",
  226. },
  227. function () {
  228. scope.refreshData("expand-right", scope.fileData);
  229. }
  230. );
  231. }
  232. });
  233. } else {
  234. SweetAlert.swal(
  235. {
  236. title: "修改失败!",
  237. text: "请填写必填项!",
  238. type: "error",
  239. confirmButtonColor: "#DD6B55",
  240. },
  241. function () {}
  242. );
  243. }
  244. };
  245. },
  246. resolve: {
  247. scope: function () {
  248. return $scope;
  249. },
  250. },
  251. });
  252. };
  253. $scope.addData = function () {
  254. var modalInstance = $modal.open({
  255. templateUrl: "assets/views/system/tpl/responsibilityDeptchange.html",
  256. controller: function ($scope, $modalInstance, api_user_data) {
  257. $scope.summaryOrderList = [
  258. {id: 1, name: '是', value: 1},
  259. {id: 2, name: '否', value: 0}
  260. ]
  261. $scope.deptdata = {
  262. dept: "",
  263. phone: "",
  264. branch: "",
  265. parent:'',
  266. addSummary: $scope.summaryOrderList.find(v => v.value == 0),
  267. supportZero: $scope.summaryOrderList.find(v => v.value == 0),
  268. };
  269. $scope.title = "责任科室新增";
  270. $scope.parentList = [];
  271. $scope.changeBranch = function(keyword=''){
  272. api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10,"dutyDepartment":{dept: keyword, selectType: "pinyin_qs"} })
  273. .then(function (data) {
  274. $scope.parentList = Restangular.stripRestangular(data).list;
  275. });
  276. }
  277. api_user_data
  278. .fetchDataList("branch", { idx: 0, sum: 100 })
  279. .then(function (data) {
  280. $scope.branchList = Restangular.stripRestangular(data).list;
  281. });
  282. $scope.cancel = function () {
  283. $modalInstance.dismiss("cancel");
  284. };
  285. // 保存
  286. $scope.savercode = function (deptdata) {
  287. if (
  288. deptdata &&
  289. deptdata.dept &&
  290. deptdata.phone &&
  291. deptdata.branch &&
  292. deptdata.addSummary &&
  293. deptdata.supportZero
  294. ) {
  295. $modalInstance.close(deptdata);
  296. } else {
  297. SweetAlert.swal(
  298. {
  299. title: "新增失败!",
  300. text: "请填写必填项!",
  301. type: "error",
  302. confirmButtonColor: "#DD6B55",
  303. },
  304. function () {}
  305. );
  306. }
  307. };
  308. },
  309. });
  310. modalInstance.result.then(function (selectedItem) {
  311. if (selectedItem.dept && selectedItem.phone && selectedItem.branch && selectedItem.addSummary && selectedItem.supportZero) {
  312. var fildata = {
  313. dutyDepartment: {
  314. phone: selectedItem.phone,
  315. dept: selectedItem.dept,
  316. branch: selectedItem.branch.id,
  317. parent:selectedItem.parent?selectedItem.parent:undefined,
  318. addSummary: selectedItem.addSummary.value,
  319. supportZero: selectedItem.supportZero.value,
  320. },
  321. };
  322. api_user_data
  323. .addData("dutyDepartment", fildata)
  324. .then(function (response) {
  325. if (response) {
  326. if (response.status == 200) {
  327. SweetAlert.swal(
  328. {
  329. title: "新增成功!",
  330. type: "success",
  331. },
  332. function () {
  333. $scope.refreshData("expand-right", $scope.fileData);
  334. }
  335. );
  336. } else {
  337. SweetAlert.swal({
  338. title: "新增失败!",
  339. text: response.msg,
  340. type: "error",
  341. });
  342. }
  343. }
  344. });
  345. } else {
  346. SweetAlert.swal(
  347. {
  348. title: "新增失败!",
  349. text: "请填写必填项!",
  350. type: "error",
  351. confirmButtonColor: "#DD6B55",
  352. },
  353. function () {}
  354. );
  355. }
  356. });
  357. };
  358. $scope.removeData = function () {
  359. var modalInstance = $modal.open({
  360. // templateUrl: 'assets/views/delete.html',
  361. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  362. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  363. var rmvList = [];
  364. $scope.title = "科室删除";
  365. $scope.connect = "确定要删除此科室?";
  366. rmvList.push(scope.selected.items);
  367. $scope.ok = function () {
  368. $modalInstance.close(rmvList);
  369. // }
  370. };
  371. $scope.cancel = function () {
  372. $modalInstance.dismiss("cancel");
  373. };
  374. },
  375. size: "sm",
  376. resolve: {
  377. scope: function () {
  378. return $scope;
  379. },
  380. },
  381. });
  382. modalInstance.result.then(function (selectedItem) {
  383. if (selectedItem) {
  384. if (selectedItem.length > 0) {
  385. console.log(selectedItem);
  386. if (selectedItem[0].children && selectedItem[0].children.length > 0) {
  387. SweetAlert.swal({
  388. title: "该科室存在子类科室",
  389. text: "请先删除该科室子类科室!",
  390. type: "error",
  391. });
  392. } else {
  393. api_user_data
  394. .rmvData("dutyDepartment", [selectedItem[0].id])
  395. .then(function (response) {
  396. if (response.status == 200) {
  397. SweetAlert.swal(
  398. {
  399. title: "删除成功!",
  400. type: "success",
  401. confirmButtonColor: "#007AFF",
  402. },
  403. function () {
  404. $scope.myData = _.reject($scope.myData, function (o) {
  405. return _.includes(selectedItem, o.id);
  406. });
  407. $scope.selected = {
  408. items: [],
  409. };
  410. $scope.gridOptions.totalItems =
  411. $scope.gridOptions.totalItems - selectedItem.length;
  412. $scope.gridApi.grid.selection.selectedCount = 0;
  413. $scope.refreshData("expand-right", $scope.fileData);
  414. }
  415. );
  416. } else {
  417. SweetAlert.swal({
  418. title: "操作异常!",
  419. text: "系统异常,请稍后重试,或者联系管理员!",
  420. type: "error",
  421. });
  422. }
  423. });
  424. }
  425. }
  426. }
  427. });
  428. };
  429. $scope.selected = {
  430. items: [],
  431. };
  432. $scope.editted = {
  433. items: [],
  434. };
  435. $scope.gridOptions.onRegisterApi = function (gridApi) {
  436. $scope.gridApi = gridApi;
  437. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  438. // // console.log(rowEntity);
  439. // });
  440. gridApi.pagination.on.paginationChanged(
  441. $scope,
  442. function (newPage, pageSize) {
  443. var filtersData = $scope.memoryfilterData;
  444. filtersData.idx = newPage - 1;
  445. filtersData.sum = pageSize;
  446. $scope.fileData.idx = newPage - 1;
  447. $scope.fileData.sum = pageSize;
  448. defaultFilterData = filtersData;
  449. $scope.refreshData("expand-right", $scope.fileData);
  450. }
  451. );
  452. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  453. scope.grid.appScope.selected.items = scope.entity;
  454. });
  455. };
  456. var defaultFilterData = {
  457. idx: 0,
  458. sum: 10,
  459. };
  460. $scope.memoryfilterData = {
  461. idx: 0,
  462. sum: 10,
  463. };
  464. $scope.fileData = {
  465. idx: 0,
  466. sum: 10,
  467. dutyDepartment: {},
  468. };
  469. $scope.ldloading = {};
  470. $scope.refreshData = function (style, filterData) {
  471. $scope.selected.items = {};
  472. $scope.ldloading[style.replace("-", "_")] = true;
  473. if (angular.isUndefined(filterData)) {
  474. filterData = defaultFilterData;
  475. }
  476. $scope.myData = [];
  477. $scope.selected = { items: [] };
  478. if ($scope.gridApi) {
  479. $scope.gridApi.grid.selection.selectedCount = 0;
  480. }
  481. filterData = angular.copy(filterData);
  482. if(filterData.dutyDepartment.branch){
  483. filterData.dutyDepartment.branch = filterData.dutyDepartment.branch.id;
  484. }
  485. api_user_data.fetchDataList("dutyDepartment", filterData).then(
  486. function (data) {
  487. var myData = Restangular.stripRestangular(data);
  488. $scope.gridOptions.totalItems = myData.totalNum;
  489. $scope.myData = myData.list;
  490. for (var i = 0; i < $scope.myData.length; i++) {
  491. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  492. }
  493. $scope.ldloading[style.replace("-", "_")] = false;
  494. },
  495. function () {
  496. $scope.ldloading[style.replace("-", "_")] = false;
  497. }
  498. );
  499. };
  500. $scope.refreshData2 = function (style, filterData) {
  501. $scope.selected.items = {};
  502. $scope.ldloading[style.replace("-", "_")] = true;
  503. if (angular.isUndefined(filterData)) {
  504. filterData = defaultFilterData;
  505. }
  506. // $scope.myData = [];
  507. $scope.selected = { items: [] };
  508. if ($scope.gridApi) {
  509. $scope.gridApi.grid.selection.selectedCount = 0;
  510. }
  511. filterData = angular.copy(filterData);
  512. if(filterData.dutyDepartment.branch){
  513. filterData.dutyDepartment.branch = filterData.dutyDepartment.branch.id;
  514. }
  515. api_user_data.fetchDataList("dutyDepartment", filterData).then(
  516. function (data) {
  517. var myData = Restangular.stripRestangular(data);
  518. $scope.gridOptions.totalItems = myData.totalNum;
  519. $scope.myData = myData.list;
  520. for (var i = 0; i < $scope.myData.length; i++) {
  521. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  522. }
  523. $scope.ldloading[style.replace("-", "_")] = false;
  524. },
  525. function () {
  526. $scope.ldloading[style.replace("-", "_")] = false;
  527. }
  528. );
  529. };
  530. // 搜索
  531. $scope.searchData = function () {
  532. $scope.refreshData("expand-right", $scope.fileData);
  533. };
  534. // 清空
  535. $scope.clean = function () {
  536. delete $scope.fileData.dutyDepartment.dept;
  537. delete $scope.fileData.dutyDepartment.phone;
  538. delete $scope.fileData.dutyDepartment.branch;
  539. $scope.refreshData("expand-right", $scope.fileData);
  540. };
  541. // 获取院区下拉
  542. $scope.model = {};
  543. $scope.branchData = [];
  544. $scope.getDeptData = function () {
  545. var data = {
  546. idx: 0,
  547. sum: 1000,
  548. };
  549. api_user_data.fetchDataList("branch", data).then(function (res) {
  550. $scope.branchData = res.list;
  551. });
  552. };
  553. $scope.getDeptData();
  554. $scope.refreshData("expand-right", $scope.fileData);
  555. $scope.timer = $interval(function () {
  556. $scope.refreshData2("expand-right", $scope.fileData);
  557. }, $rootScope.refreshTime);
  558. $scope.$on("$destroy", function () {
  559. $interval.cancel($scope.timer);
  560. });
  561. },
  562. ]);