responsibilityDeptCtrl.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. parentDeptConsumable: $scope.summaryOrderList.find(v => v.value == selectdata.parentDeptConsumable) || $scope.summaryOrderList.find(v => v.value == 0),
  140. };
  141. $scope.branchList = [];
  142. $scope.title = "责任科室修改";
  143. $scope.parentList = [];
  144. $scope.changeBranch = function(keyword=''){
  145. api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10,"dutyDepartment":{dept: keyword, selectType: "pinyin_qs"} })
  146. .then(function (data) {
  147. $scope.parentList = Restangular.stripRestangular(data).list.filter(v=>v.id != selectdata.id);
  148. });
  149. }
  150. api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10 })
  151. .then(function (data) {
  152. $scope.parentList = Restangular.stripRestangular(data).list.filter(v=>v.id != selectdata.id);
  153. });
  154. api_user_data
  155. .fetchDataList("branch", { idx: 0, sum: 100 })
  156. .then(function (data) {
  157. $scope.branchList = Restangular.stripRestangular(data).list;
  158. });
  159. $scope.cancel = function () {
  160. $modalInstance.dismiss("cancel");
  161. };
  162. // 保存
  163. $scope.savercode = function (deptdata) {
  164. if (
  165. deptdata &&
  166. deptdata.dept &&
  167. deptdata.phone &&
  168. deptdata.branch &&
  169. deptdata.addSummary &&
  170. deptdata.supportZero &&
  171. deptdata.parentDeptConsumable
  172. ) {
  173. var fildata = {
  174. dutyDepartment: {
  175. uuid:deptdata.uuid,
  176. id: deptdata.id,
  177. deleteFlag: 0,
  178. phone: deptdata.phone,
  179. dept: deptdata.dept,
  180. branch: deptdata.branch.id,
  181. parent:deptdata.parent,
  182. addSummary: deptdata.addSummary.value,
  183. supportZero: deptdata.supportZero.value,
  184. parentDeptConsumable: deptdata.parentDeptConsumable.value,
  185. },
  186. };
  187. api_user_data
  188. .updData("dutyDepartment", fildata)
  189. .then(function (response) {
  190. if (response) {
  191. if (response.status == 200) {
  192. SweetAlert.swal(
  193. {
  194. title: "修改成功!",
  195. type: "success",
  196. },
  197. function () {
  198. scope.refreshData("expand-right", scope.fileData);
  199. }
  200. );
  201. } else if (response.status == 500) {
  202. SweetAlert.swal(
  203. {
  204. title: "修改失败!",
  205. text: "该科室已存在",
  206. type: "error",
  207. },
  208. function () {
  209. scope.refreshData("expand-right", scope.fileData);
  210. }
  211. );
  212. } else {
  213. SweetAlert.swal(
  214. {
  215. title: "修改失败!",
  216. type: "error",
  217. },
  218. function () {
  219. scope.refreshData("expand-right", scope.fileData);
  220. }
  221. );
  222. }
  223. $modalInstance.close();
  224. } else {
  225. SweetAlert.swal(
  226. {
  227. title: "修改失败!",
  228. type: "error",
  229. },
  230. function () {
  231. scope.refreshData("expand-right", scope.fileData);
  232. }
  233. );
  234. }
  235. });
  236. } else {
  237. SweetAlert.swal(
  238. {
  239. title: "修改失败!",
  240. text: "请填写必填项!",
  241. type: "error",
  242. confirmButtonColor: "#DD6B55",
  243. },
  244. function () {}
  245. );
  246. }
  247. };
  248. },
  249. resolve: {
  250. scope: function () {
  251. return $scope;
  252. },
  253. },
  254. });
  255. };
  256. $scope.addData = function () {
  257. var modalInstance = $modal.open({
  258. templateUrl: "assets/views/system/tpl/responsibilityDeptchange.html",
  259. controller: function ($scope, $modalInstance, api_user_data) {
  260. $scope.summaryOrderList = [
  261. {id: 1, name: '是', value: 1},
  262. {id: 2, name: '否', value: 0}
  263. ]
  264. $scope.deptdata = {
  265. dept: "",
  266. phone: "",
  267. branch: "",
  268. parent:'',
  269. addSummary: $scope.summaryOrderList.find(v => v.value == 0),
  270. supportZero: $scope.summaryOrderList.find(v => v.value == 0),
  271. parentDeptConsumable: $scope.summaryOrderList.find(v => v.value == 0),
  272. };
  273. $scope.title = "责任科室新增";
  274. $scope.parentList = [];
  275. $scope.changeBranch = function(keyword=''){
  276. api_user_data.fetchDataList("dutyDepartment", { "idx":0,"sum":10,"dutyDepartment":{dept: keyword, selectType: "pinyin_qs"} })
  277. .then(function (data) {
  278. $scope.parentList = Restangular.stripRestangular(data).list;
  279. });
  280. }
  281. api_user_data
  282. .fetchDataList("branch", { idx: 0, sum: 100 })
  283. .then(function (data) {
  284. $scope.branchList = Restangular.stripRestangular(data).list;
  285. });
  286. $scope.cancel = function () {
  287. $modalInstance.dismiss("cancel");
  288. };
  289. // 保存
  290. $scope.savercode = function (deptdata) {
  291. if (
  292. deptdata &&
  293. deptdata.dept &&
  294. deptdata.phone &&
  295. deptdata.branch &&
  296. deptdata.addSummary &&
  297. deptdata.supportZero &&
  298. deptdata.parentDeptConsumable
  299. ) {
  300. $modalInstance.close(deptdata);
  301. } else {
  302. SweetAlert.swal(
  303. {
  304. title: "新增失败!",
  305. text: "请填写必填项!",
  306. type: "error",
  307. confirmButtonColor: "#DD6B55",
  308. },
  309. function () {}
  310. );
  311. }
  312. };
  313. },
  314. });
  315. modalInstance.result.then(function (selectedItem) {
  316. if (selectedItem.dept && selectedItem.phone && selectedItem.branch && selectedItem.addSummary && selectedItem.supportZero && selectedItem.parentDeptConsumable) {
  317. var fildata = {
  318. dutyDepartment: {
  319. phone: selectedItem.phone,
  320. dept: selectedItem.dept,
  321. branch: selectedItem.branch.id,
  322. parent:selectedItem.parent?selectedItem.parent:undefined,
  323. addSummary: selectedItem.addSummary.value,
  324. supportZero: selectedItem.supportZero.value,
  325. parentDeptConsumable: selectedItem.parentDeptConsumable.value,
  326. },
  327. };
  328. api_user_data
  329. .addData("dutyDepartment", fildata)
  330. .then(function (response) {
  331. if (response) {
  332. if (response.status == 200) {
  333. SweetAlert.swal(
  334. {
  335. title: "新增成功!",
  336. type: "success",
  337. },
  338. function () {
  339. $scope.refreshData("expand-right", $scope.fileData);
  340. }
  341. );
  342. } else {
  343. SweetAlert.swal({
  344. title: "新增失败!",
  345. text: response.msg,
  346. type: "error",
  347. });
  348. }
  349. }
  350. });
  351. } else {
  352. SweetAlert.swal(
  353. {
  354. title: "新增失败!",
  355. text: "请填写必填项!",
  356. type: "error",
  357. confirmButtonColor: "#DD6B55",
  358. },
  359. function () {}
  360. );
  361. }
  362. });
  363. };
  364. $scope.removeData = function () {
  365. var modalInstance = $modal.open({
  366. // templateUrl: 'assets/views/delete.html',
  367. templateUrl: "assets/views/incident/tpl/acceptTask.tpl.html",
  368. controller: function ($scope, scope, $modalInstance, api_bpm_data) {
  369. var rmvList = [];
  370. $scope.title = "科室删除";
  371. $scope.connect = "确定要删除此科室?";
  372. rmvList.push(scope.selected.items);
  373. $scope.ok = function () {
  374. $modalInstance.close(rmvList);
  375. // }
  376. };
  377. $scope.cancel = function () {
  378. $modalInstance.dismiss("cancel");
  379. };
  380. },
  381. size: "sm",
  382. resolve: {
  383. scope: function () {
  384. return $scope;
  385. },
  386. },
  387. });
  388. modalInstance.result.then(function (selectedItem) {
  389. if (selectedItem) {
  390. if (selectedItem.length > 0) {
  391. console.log(selectedItem);
  392. if (selectedItem[0].children && selectedItem[0].children.length > 0) {
  393. SweetAlert.swal({
  394. title: "该科室存在子类科室",
  395. text: "请先删除该科室子类科室!",
  396. type: "error",
  397. });
  398. } else {
  399. api_user_data
  400. .rmvData("dutyDepartment", [selectedItem[0].id])
  401. .then(function (response) {
  402. if (response.status == 200) {
  403. SweetAlert.swal(
  404. {
  405. title: "删除成功!",
  406. type: "success",
  407. confirmButtonColor: "#007AFF",
  408. },
  409. function () {
  410. $scope.myData = _.reject($scope.myData, function (o) {
  411. return _.includes(selectedItem, o.id);
  412. });
  413. $scope.selected = {
  414. items: [],
  415. };
  416. $scope.gridOptions.totalItems =
  417. $scope.gridOptions.totalItems - selectedItem.length;
  418. $scope.gridApi.grid.selection.selectedCount = 0;
  419. $scope.refreshData("expand-right", $scope.fileData);
  420. }
  421. );
  422. } else {
  423. SweetAlert.swal({
  424. title: "操作异常!",
  425. text: "系统异常,请稍后重试,或者联系管理员!",
  426. type: "error",
  427. });
  428. }
  429. });
  430. }
  431. }
  432. }
  433. });
  434. };
  435. $scope.selected = {
  436. items: [],
  437. };
  438. $scope.editted = {
  439. items: [],
  440. };
  441. $scope.gridOptions.onRegisterApi = function (gridApi) {
  442. $scope.gridApi = gridApi;
  443. // gridApi.edit.on.afterCellEdit($scope,function(rowEntity, colDef, newValue, oldValue){
  444. // // console.log(rowEntity);
  445. // });
  446. gridApi.pagination.on.paginationChanged(
  447. $scope,
  448. function (newPage, pageSize) {
  449. var filtersData = $scope.memoryfilterData;
  450. filtersData.idx = newPage - 1;
  451. filtersData.sum = pageSize;
  452. $scope.fileData.idx = newPage - 1;
  453. $scope.fileData.sum = pageSize;
  454. defaultFilterData = filtersData;
  455. $scope.refreshData("expand-right", $scope.fileData);
  456. }
  457. );
  458. gridApi.selection.on.rowSelectionChanged($scope, function (scope) {
  459. scope.grid.appScope.selected.items = scope.entity;
  460. });
  461. };
  462. var defaultFilterData = {
  463. idx: 0,
  464. sum: 10,
  465. };
  466. $scope.memoryfilterData = {
  467. idx: 0,
  468. sum: 10,
  469. };
  470. $scope.fileData = {
  471. idx: 0,
  472. sum: 10,
  473. dutyDepartment: {},
  474. };
  475. $scope.ldloading = {};
  476. $scope.refreshData = function (style, filterData) {
  477. $scope.selected.items = {};
  478. $scope.ldloading[style.replace("-", "_")] = true;
  479. if (angular.isUndefined(filterData)) {
  480. filterData = defaultFilterData;
  481. }
  482. $scope.myData = [];
  483. $scope.selected = { items: [] };
  484. if ($scope.gridApi) {
  485. $scope.gridApi.grid.selection.selectedCount = 0;
  486. }
  487. filterData = angular.copy(filterData);
  488. if(filterData.dutyDepartment.branch){
  489. filterData.dutyDepartment.branch = filterData.dutyDepartment.branch.id;
  490. }
  491. api_user_data.fetchDataList("dutyDepartment", filterData).then(
  492. function (data) {
  493. var myData = Restangular.stripRestangular(data);
  494. $scope.gridOptions.totalItems = myData.totalNum;
  495. $scope.myData = myData.list;
  496. for (var i = 0; i < $scope.myData.length; i++) {
  497. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  498. }
  499. $scope.ldloading[style.replace("-", "_")] = false;
  500. },
  501. function () {
  502. $scope.ldloading[style.replace("-", "_")] = false;
  503. }
  504. );
  505. };
  506. $scope.refreshData2 = function (style, filterData) {
  507. $scope.selected.items = {};
  508. $scope.ldloading[style.replace("-", "_")] = true;
  509. if (angular.isUndefined(filterData)) {
  510. filterData = defaultFilterData;
  511. }
  512. // $scope.myData = [];
  513. $scope.selected = { items: [] };
  514. if ($scope.gridApi) {
  515. $scope.gridApi.grid.selection.selectedCount = 0;
  516. }
  517. filterData = angular.copy(filterData);
  518. if(filterData.dutyDepartment.branch){
  519. filterData.dutyDepartment.branch = filterData.dutyDepartment.branch.id;
  520. }
  521. api_user_data.fetchDataList("dutyDepartment", filterData).then(
  522. function (data) {
  523. var myData = Restangular.stripRestangular(data);
  524. $scope.gridOptions.totalItems = myData.totalNum;
  525. $scope.myData = myData.list;
  526. for (var i = 0; i < $scope.myData.length; i++) {
  527. $scope.myData[i]["item"] = i + 1 + filterData.idx * filterData.sum;
  528. }
  529. $scope.ldloading[style.replace("-", "_")] = false;
  530. },
  531. function () {
  532. $scope.ldloading[style.replace("-", "_")] = false;
  533. }
  534. );
  535. };
  536. // 搜索
  537. $scope.searchData = function () {
  538. $scope.refreshData("expand-right", $scope.fileData);
  539. };
  540. // 清空
  541. $scope.clean = function () {
  542. delete $scope.fileData.dutyDepartment.dept;
  543. delete $scope.fileData.dutyDepartment.phone;
  544. delete $scope.fileData.dutyDepartment.branch;
  545. $scope.refreshData("expand-right", $scope.fileData);
  546. };
  547. // 获取院区下拉
  548. $scope.model = {};
  549. $scope.branchData = [];
  550. $scope.getDeptData = function () {
  551. var data = {
  552. idx: 0,
  553. sum: 1000,
  554. };
  555. api_user_data.fetchDataList("branch", data).then(function (res) {
  556. $scope.branchData = res.list;
  557. });
  558. };
  559. $scope.getDeptData();
  560. $scope.refreshData("expand-right", $scope.fileData);
  561. $scope.timer = $interval(function () {
  562. $scope.refreshData2("expand-right", $scope.fileData);
  563. }, $rootScope.refreshTime);
  564. $scope.$on("$destroy", function () {
  565. $interval.cancel($scope.timer);
  566. });
  567. },
  568. ]);