group-management.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import { NzMessageService } from "ng-zorro-antd/message";
  5. import { MainService } from "../../services/main.service";
  6. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  7. import { ToolService } from "../../services/tool.service";
  8. import { Subject } from "rxjs";
  9. import { debounceTime } from "rxjs/operators";
  10. @Component({
  11. selector: "app-group-management",
  12. templateUrl: "./group-management.component.html",
  13. styleUrls: ["./group-management.component.less"],
  14. })
  15. export class GroupManagementComponent implements OnInit {
  16. tableHeight;
  17. constructor(
  18. private fb: FormBuilder,
  19. private route: ActivatedRoute,
  20. private mainService: MainService,
  21. private msg: NzMessageService,
  22. private tool: ToolService
  23. ) {}
  24. @ViewChild("osComponentRef1", {
  25. read: OverlayScrollbarsComponent,
  26. static: false,
  27. })
  28. osComponentRef1: OverlayScrollbarsComponent;
  29. ngOnInit() {
  30. this.changeInpSubject
  31. .pipe(debounceTime(500))
  32. .subscribe((keyword: string) => {
  33. this.getUserList(keyword);
  34. });
  35. this.coopBtns = this.tool.initCoopBtns(this.route);
  36. this.initForm();
  37. this.getHospitalList();
  38. this.getGroupList();
  39. this.getScheduleList();
  40. this.tableHeight = document.body.clientHeight - 267;
  41. }
  42. isAllDisplayDataChecked = false;
  43. isIndeterminate = false;
  44. listOfDisplayData: any[] = [];
  45. allUserList: any[] = []; //所有用户
  46. groupUserList: any[] = []; //所选组内用户
  47. mapOfCheckedId: { [key: string]: boolean } = {};
  48. checkedGroup: any = {}; //选中分组
  49. groupList: Array<any> = []; //分组信息
  50. hospitalList: Array<any> = []; //院区列表
  51. hosId: any; //当前选择的院区id
  52. scheduleList: Array<any> = []; //班次列表
  53. userList: Array<any> = []; //用户列表
  54. searchName: string = ""; //用户信息搜索输入框
  55. promptContent: string; //操作提示框提示信息
  56. ifSuccess: boolean; //操作成功/失败
  57. promptInfo: string; //操作结果提示信息
  58. promptModalShow: boolean; //是否展示提示框
  59. btnLoading: boolean = false; //确认按钮loading状态
  60. saveLoading: boolean = false; //批量打印按钮loading状态
  61. changeInpSubject = new Subject();
  62. // 初始化增删改按钮
  63. coopBtns: any = {};
  64. // 边输边搜节流阀
  65. isLoading = false;
  66. changeInp(keyword: string = "") {
  67. this.isLoading = true;
  68. this.changeInpSubject.next(keyword);
  69. }
  70. // 打开搜索框
  71. changeSearch(flag) {
  72. if (flag && !this.editLoading) {
  73. this.changeInp();
  74. }
  75. }
  76. // 分组列表
  77. loading1 = false;
  78. getGroupList() {
  79. let that = this;
  80. let arr = [];
  81. this.hospitalList.forEach((item) => {
  82. arr.push(item["id"]);
  83. });
  84. let data = {
  85. idx: 0,
  86. sum: 999,
  87. group2: {
  88. hospitals: arr.join(),
  89. },
  90. };
  91. this.loading1 = true;
  92. that.mainService
  93. .getFetchDataList("data", "group2", data)
  94. .subscribe((data1) => {
  95. this.loading1 = false;
  96. that.groupList = data1.list;
  97. console.log(this.checkedGroup);
  98. if (Object.keys(this.checkedGroup).length) {
  99. console.log(this.checkedGroup);
  100. data1.list.forEach((item) => {
  101. if (item.id == this.checkedGroup.id) {
  102. this.checkGroup(item);
  103. }
  104. });
  105. } else {
  106. this.checkGroup(data1.list[0]);
  107. }
  108. });
  109. }
  110. // 获取选中院区下用户列表
  111. loading2 = false;
  112. onlyFlag = true;
  113. allUsers = [];
  114. getAllUser() {
  115. // 初始化的时候搜索一次,然后前端过滤
  116. if (this.onlyFlag) {
  117. let data = {
  118. idx: 0,
  119. sum: 999,
  120. user: {
  121. name: this.searchName,
  122. usertype: { id: 106 },
  123. hospital: { id: this.hosId },
  124. },
  125. };
  126. this.timeNum++;
  127. this.loading2 = true;
  128. this.mainService
  129. .getFetchDataList("data", "user", data)
  130. .subscribe((result) => {
  131. this.timeNum--;
  132. if (this.timeNum === 0) {
  133. this.loading2 = false;
  134. this.onlyFlag = false;
  135. }
  136. this.allUserList = result.list;
  137. this.allUsers = JSON.parse(JSON.stringify(result.list));
  138. this.refreshStatus(true);
  139. });
  140. } else {
  141. this.allUserList = this.allUsers.filter((item) => {
  142. return (
  143. item.pinYin.includes(this.searchName) ||
  144. item.name.includes(this.searchName) ||
  145. item.inputCode.includes(this.searchName)
  146. );
  147. });
  148. this.refreshStatus(true);
  149. }
  150. }
  151. // 输入用户信息搜索节流阀
  152. time: any;
  153. timeNum = 0;
  154. searchInp(e) {
  155. let that = this;
  156. that.getAllUser();
  157. }
  158. // 院区列表
  159. getHospitalList() {
  160. this.hosId = this.tool.getCurrentHospital().id;
  161. this.hospitalList = [this.tool.getCurrentHospital()];
  162. }
  163. // 班次列表
  164. getScheduleList() {
  165. const data = {
  166. idx: 0,
  167. scheduleClass: { hospital: { id: this.hosId } },
  168. sum: 999,
  169. };
  170. this.mainService
  171. .getFetchDataList("configuration", "scheduleClass", data)
  172. .subscribe((data) => {
  173. this.scheduleList = data.list;
  174. });
  175. }
  176. // 用户列表
  177. getUserList(keyword: string = "") {
  178. const data = {
  179. idx: 0,
  180. user: {
  181. hospital: { id: this.hosId },
  182. name: keyword,
  183. simpleQuery: true,
  184. },
  185. sum: 5,
  186. };
  187. this.mainService
  188. .getFetchDataList("data", "user", data)
  189. .subscribe((result) => {
  190. this.isLoading = false;
  191. if (result.status == 200) {
  192. this.userList = result.list;
  193. }
  194. });
  195. }
  196. // 选中分组
  197. positionY = 0; //记录其他建单Y轴滚动距离
  198. checkGroup(data) {
  199. this.positionY = this.osComponentRef1.osInstance().scroll().position.y; //内容滚动的距离
  200. this.searchName = "";
  201. this.checkedGroup = data ? data : {};
  202. this.mapOfCheckedId = {};
  203. this.groupUserList = this.checkedGroup["users"]
  204. ? this.checkedGroup["users"]
  205. : [];
  206. this.getAllUser();
  207. }
  208. selectedUser(data) {
  209. console.log(data)
  210. if(this.checkedGroup.type == 2){
  211. return;
  212. }
  213. this.mapOfCheckedId[data.id] = !this.mapOfCheckedId[data.id];
  214. this.refreshStatus();
  215. }
  216. // 选中列表中当前分组用户
  217. usersArr = [];
  218. refreshStatus(first?): void {
  219. let i, j;
  220. // 切换分组信息时初始化表格內checkbox选中情况
  221. if (first) {
  222. for (j = 0; j < this.groupUserList.length; j++) {
  223. for (i = 0; i < this.allUserList.length; i++) {
  224. if (this.allUserList[i]["id"] == this.groupUserList[j]["id"]) {
  225. this.mapOfCheckedId[this.allUserList[i]["id"]] = true;
  226. break;
  227. }
  228. }
  229. }
  230. }
  231. let arr = [];
  232. for (var m in this.mapOfCheckedId) {
  233. if (this.mapOfCheckedId[m]) {
  234. arr.push({ id: m });
  235. }
  236. }
  237. this.usersArr = arr;
  238. }
  239. // 保存
  240. save() {
  241. let that = this;
  242. that.saveLoading = true;
  243. let postData = {
  244. group2: {
  245. id: that.checkedGroup["id"],
  246. users: that.usersArr,
  247. },
  248. };
  249. that.mainService
  250. .coopData("updData", "group2", postData)
  251. .subscribe((data) => {
  252. that.saveLoading = false;
  253. if (data.status == 200) {
  254. that.showPromptModal("保存", true, "");
  255. } else {
  256. that.showPromptModal("保存", false, data.msg);
  257. }
  258. });
  259. }
  260. // 新增/编辑模态框
  261. coopModal: boolean = false; //模态框是否展示
  262. add: boolean = true; //true:新增;false:编辑
  263. editLoading = false;//分组组长选择框loading
  264. isDisabledGroupType = false;//分组类型是否禁用
  265. showCoopModal(type) {
  266. if (type == "edit" && !this.checkedGroup["groupName"]) {
  267. this.msg.create("warning", "请选择需要编辑的分组!");
  268. return;
  269. }
  270. this.coopModal = true;
  271. this.add = type == "add";
  272. if (type == "edit") {
  273. this.isDisabledGroupType = true;
  274. this.validateForm.controls.groupLeader.setValue(null);//先清空组长
  275. this.validateForm.controls.classes.setValue(
  276. this.checkedGroup["scheduleClass"].id + ""
  277. );
  278. this.validateForm.controls.groupName.setValue(
  279. this.checkedGroup["groupName"]
  280. );
  281. this.validateForm.controls.groupType.setValue(
  282. this.checkedGroup["type"].toString()
  283. );
  284. if (this.checkedGroup["manager"]) {
  285. this.editLoading = true;
  286. this.mainService
  287. .getFetchData("data", "user", this.checkedGroup["manager"])
  288. .subscribe((result) => {
  289. this.editLoading = false;
  290. if (result.status == 200) {
  291. if (result.data) {
  292. this.userList.unshift(result.data);
  293. }
  294. this.validateForm.controls.groupLeader.setValue(
  295. this.checkedGroup["manager"].toString()
  296. );
  297. }
  298. });
  299. } else {
  300. this.validateForm.controls.groupLeader.setValue(null);
  301. }
  302. } else {
  303. this.isDisabledGroupType = false;
  304. this.validateForm.controls.classes.setValue(null);
  305. this.validateForm.controls.groupName.setValue(null);
  306. this.validateForm.controls.groupLeader.setValue(null);
  307. this.validateForm.controls.groupType.setValue(null);
  308. }
  309. }
  310. // 隐藏分组信息模态框
  311. hideCoopModal() {
  312. this.coopModal = false;
  313. }
  314. // 初始化新增form表单
  315. initForm() {
  316. this.validateForm = this.fb.group({
  317. classes: [null, [Validators.required]],
  318. groupName: [null, [Validators.required]],
  319. groupType: [null, [Validators.required]],
  320. groupLeader: [null, [Validators.required]],
  321. });
  322. }
  323. // 新增/编辑提交
  324. validateForm: FormGroup;
  325. submitForm(): void {
  326. let that = this;
  327. for (const i in that.validateForm.controls) {
  328. that.validateForm.controls[i].markAsDirty();
  329. that.validateForm.controls[i].updateValueAndValidity();
  330. }
  331. if (that.validateForm.invalid) return;
  332. that.btnLoading = true;
  333. let data = {
  334. group2: {
  335. groupName: that.validateForm.value.groupName,
  336. hospital: { id: that.hosId - 0 },
  337. scheduleClass: { id: that.validateForm.value.classes - 0 },
  338. manager: that.validateForm.value.groupLeader,
  339. type: that.validateForm.value.groupType,
  340. },
  341. };
  342. if (!that.add) {
  343. data.group2["id"] = that.checkedGroup["id"];
  344. }
  345. that.mainService
  346. .coopData(that.add ? "addData" : "updData", "group2", data)
  347. .subscribe((data) => {
  348. that.hideCoopModal();
  349. that.btnLoading = false;
  350. that.initForm();
  351. if (data.status == 200) {
  352. that.showPromptModal(that.add ? "新增" : "编辑", true, "");
  353. } else {
  354. that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
  355. }
  356. });
  357. }
  358. //删除modal
  359. delModal: boolean = false;
  360. showDelModal() {
  361. if (!this.checkedGroup["groupName"]) {
  362. this.msg.create("warning", "请选择需要删除的分组!");
  363. return;
  364. }
  365. this.delModal = true;
  366. }
  367. hideDelModal() {
  368. this.delModal = false;
  369. }
  370. // 确认删除
  371. confirmDel() {
  372. this.btnLoading = true;
  373. this.mainService
  374. .coopData("rmvData", "group2", [this.checkedGroup["id"]])
  375. .subscribe((data) => {
  376. this.hideDelModal();
  377. this.btnLoading = false;
  378. if (data.data && data.data[0]) {
  379. if (!data.data[0].msg) {
  380. this.showPromptModal("删除", true, "");
  381. this.checkedGroup = {};
  382. } else {
  383. this.showPromptModal("删除", false, data.data[0].msg);
  384. }
  385. } else {
  386. this.showPromptModal("删除", false, "");
  387. }
  388. });
  389. }
  390. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  391. showPromptModal(con, success, promptInfo?) {
  392. this.promptModalShow = false;
  393. this.promptContent = con;
  394. this.ifSuccess = success;
  395. this.promptInfo = promptInfo;
  396. this.osComponentRef1.osInstance().scroll({ x: 0, y: this.positionY });
  397. setTimeout(() => {
  398. this.promptModalShow = true;
  399. this.getGroupList();
  400. }, 100);
  401. }
  402. }