clinical-users-management.component.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import { MainService } from "../../services/main.service";
  5. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  6. import { ToolService } from "../../services/tool.service";
  7. import { forkJoin, Subject } from "rxjs";
  8. import { debounceTime } from "rxjs/operators";
  9. import { NzMessageService } from "ng-zorro-antd";
  10. @Component({
  11. selector: "app-clinical-users-management",
  12. templateUrl: "./clinical-users-management.component.html",
  13. styleUrls: ["./clinical-users-management.component.less"],
  14. })
  15. export class ClinicalUsersManagementComponent implements OnInit {
  16. @ViewChild("osComponentRef1", {
  17. read: OverlayScrollbarsComponent,
  18. static: false,
  19. })
  20. osComponentRef1: OverlayScrollbarsComponent;
  21. constructor(
  22. private message: NzMessageService,
  23. private fb: FormBuilder,
  24. private route: ActivatedRoute,
  25. private router: Router,
  26. private mainService: MainService,
  27. private tool: ToolService
  28. ) {}
  29. listOfData: any[] = []; //表格数据
  30. modal: boolean = false; //新增/编辑模态框
  31. add: boolean; //true:新增;false:编辑
  32. validateForm: FormGroup; //新增/编辑表单
  33. coopId: number; //表格中执行操作的id
  34. department: any; //所属科室
  35. num; //工号
  36. name; //姓名
  37. userType: any; //用户类型
  38. hosId: any; //院区(搜索)
  39. userGroup; //所属组
  40. userGroup1; //所属组(搜索)
  41. userTypes: Array<any>; //所有用户类型
  42. alldepart: any = []; //所有所属科室
  43. alldepart1: any = []; //所有所属科室(搜索)
  44. hospitals1: any = []; //院区列表(搜索)
  45. allUserGroup: Array<any>; //所有用户组
  46. allUserGroup1: Array<any>; //用户组(搜索)
  47. allUserRole: Array<any>; //所有角色
  48. pageIndex: number = 1; //页码
  49. listLength: number = 10; //总条数
  50. pageSize: number = 10; //每页条数
  51. promptContent: string; //操作提示框提示信息
  52. ifSuccess: boolean; //操作成功/失败
  53. promptInfo: string; //操作结果提示信息
  54. promptModalShow: boolean; //操作提示框是否展示
  55. btnLoading: boolean = false; //提交按钮loading状态
  56. wxRequired = false; //新增或编辑用户的时候,微信号是否必填
  57. changeInpSubject = new Subject(); //防抖
  58. changeInpHospitalSubject = new Subject(); //防抖
  59. ngOnInit() {
  60. //防抖
  61. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  62. this.getDeparts(v[0], v[1], v[2]);
  63. });
  64. //防抖
  65. this.changeInpHospitalSubject.pipe(debounceTime(500)).subscribe((v) => {
  66. this.getHospitals(v[0], v[1], v[2]);
  67. });
  68. this.coopBtns = this.tool.initCoopBtns(this.route);
  69. this.initForm();
  70. this.getUserTypes();
  71. this.getAllRole();
  72. this.getGender();
  73. }
  74. // 初始化增删改按钮
  75. coopBtns: any = {};
  76. // 搜索
  77. search() {
  78. this.pageIndex = 1;
  79. this.getList();
  80. }
  81. // 重置
  82. isShowSelectHospital = true;
  83. reset() {
  84. this.isShowSelectHospital = false;
  85. setTimeout(()=>{
  86. this.isShowSelectHospital = true;
  87. },0)
  88. this.pageIndex = 1;
  89. this.hosId = this.tool.getCurrentHospital().id;
  90. this.name = "";
  91. this.num = "";
  92. let userType = this.userTypes.find(v => v.value == 1);
  93. this.userType = userType ? userType.id: null;
  94. this.department = null;
  95. this.userGroup1 = null;
  96. this.changeHosp1(this.hosId);
  97. this.getList();
  98. }
  99. // 表格数据
  100. loading1 = false;
  101. getList() {
  102. let data = {
  103. idx: this.pageIndex - 1,
  104. sum: this.pageSize,
  105. user: {
  106. name: this.name || "",
  107. dept: { id: this.department || "" },
  108. usertype: { id: this.userType || "" },
  109. account: this.num || "",
  110. groupdata: { id: this.userGroup1 || "" },
  111. hospital: { id: this.hosId || "" },
  112. },
  113. };
  114. if (!data.user.dept || !data.user.dept.id) {
  115. delete data.user.dept;
  116. }
  117. if (!data.user.usertype || !data.user.usertype.id) {
  118. delete data.user.usertype;
  119. }
  120. if (!data.user.groupdata || !data.user.groupdata.id) {
  121. delete data.user.groupdata;
  122. }
  123. if (!data.user.hospital || !data.user.hospital.id) {
  124. delete data.user.hospital;
  125. }
  126. this.loading1 = true;
  127. this.mainService
  128. .getFetchDataList("data", "user", data)
  129. .subscribe((data) => {
  130. this.loading1 = false;
  131. this.listOfData = data.list;
  132. this.listLength = data.totalNum;
  133. });
  134. }
  135. // 获取所有用户类型
  136. getUserTypes() {
  137. this.mainService.getDictionary("list", "usertype").subscribe((data) => {
  138. this.userTypes = data || [];
  139. let userType = this.userTypes.find(v => v.value == 1);
  140. this.userType = userType ? userType.id: null;
  141. this.getAllHospital();
  142. });
  143. }
  144. // 获取相应的院区
  145. getAllHospital() {
  146. this.loading1 = true;
  147. let topLevelParentHosList$ = this.mainService.apiPostAll("topLevelParentHosList", {});
  148. // let topLevelParentHos$ = this.mainService.apiPostAll("topLevelParentHos", {hosId: this.tool.getCurrentHospital().id});
  149. forkJoin(topLevelParentHosList$).subscribe((dataArray:any[]) => {
  150. let [data1] = dataArray;
  151. this.hospitals1 = data1.topLevelParentHosList || [];
  152. // this.hosId = data2.topHospital ? data2.topHospital.id : null;
  153. this.hosId = this.tool.getCurrentHospital().id;
  154. this.changeHosp1(this.hosId);
  155. this.getList();
  156. }, err => {
  157. this.loading1 = false;
  158. })
  159. }
  160. // 角色列表
  161. getAllRole() {
  162. var that = this;
  163. let data = {
  164. idx: 0,
  165. sum: 1000,
  166. };
  167. that.mainService
  168. .getFetchDataList("data", "role", data)
  169. .subscribe((data) => {
  170. that.allUserRole = data.list;
  171. });
  172. }
  173. // 切换院区选项获取对应科室列表
  174. changeHosp() {
  175. let hid = this.tool.getCurrentHospital().id;
  176. let data = {
  177. department: {
  178. hospital: { id: hid },
  179. },
  180. idx: 0,
  181. sum: 20,
  182. };
  183. let groupData = {
  184. group2: {
  185. hospitals: hid,
  186. type:1
  187. },
  188. idx: 0,
  189. sum: 9999,
  190. };
  191. this.maskFlag = this.message.loading("正在加载中..", {
  192. nzDuration: 0,
  193. }).messageId;
  194. let department$ = this.mainService.getFetchDataList(
  195. "data",
  196. "department",
  197. data
  198. );
  199. let group$ = this.mainService.getFetchDataList("data", "group2", groupData);
  200. forkJoin(department$, group$).subscribe((res) => {
  201. this.message.remove(this.maskFlag);
  202. this.maskFlag = false;
  203. this.modal = true;
  204. this.alldepart = res[0]["list"];
  205. this.allUserGroup = res[1]["list"];
  206. });
  207. }
  208. // 切换院区选项获取对应科室列表(搜索)seimin
  209. changeHosp1(id) {
  210. this.department = null;
  211. this.userGroup1 = null;
  212. let departmentData = {
  213. department: {
  214. hospital: { id },
  215. },
  216. idx: 0,
  217. sum: 20,
  218. };
  219. let groupData = {
  220. group2: {
  221. hospitals: id,
  222. type:1
  223. },
  224. idx: 0,
  225. sum: 9999,
  226. };
  227. this.mainService
  228. .getFetchDataList("data", "department", departmentData)
  229. .subscribe((data) => {
  230. this.alldepart1 = data.list;
  231. });
  232. this.mainService
  233. .getFetchDataList("data", "group2", groupData)
  234. .subscribe((data) => {
  235. this.allUserGroup1 = data.list;
  236. });
  237. }
  238. // 获取性别
  239. genders: Array<any> = [];
  240. getGender() {
  241. var that = this;
  242. that.mainService.getDictionary("list", "user_gender").subscribe((data) => {
  243. that.genders = data;
  244. });
  245. }
  246. // 新增弹框
  247. showModal() {
  248. this.add = true;
  249. this.initForm();
  250. this.changeHosp();
  251. }
  252. hideModal() {
  253. this.modal = false;
  254. this.initForm();
  255. }
  256. // 初始化新增form表单
  257. initForm() {
  258. if (this.add) {
  259. this.alldepart = [];
  260. this.allUserGroup = [];
  261. }
  262. this.validateForm = this.fb.group({
  263. name: [null, [Validators.required]],
  264. account: [null, [Validators.required]],
  265. usertype: [this.userType + '', [Validators.required]],
  266. dept: [null, [Validators.required]],
  267. deptPhone: [null, [Validators.required]],
  268. gender: [null, [Validators.required]],
  269. userGroup: [null],
  270. role: [null, [Validators.required]],
  271. weixin: [null],
  272. });
  273. }
  274. // 选择用户类型
  275. usertypeChange() {
  276. // if (this.validateForm.value.usertype == 106) {
  277. // //配送人员
  278. // this.wxRequired = true;
  279. // this.validateForm.get("weixin")!.setValidators(Validators.required);
  280. // this.validateForm.get("weixin")!.markAsDirty();
  281. // } else {
  282. // this.wxRequired = false;
  283. // this.validateForm.get("weixin")!.clearValidators();
  284. // this.validateForm.get("weixin")!.markAsPristine();
  285. // }
  286. this.wxRequired = false;
  287. this.validateForm.get("weixin")!.clearValidators();
  288. this.validateForm.get("weixin")!.markAsPristine();
  289. this.validateForm.get("weixin")!.updateValueAndValidity();
  290. }
  291. // 表单提交
  292. submitForm(): void {
  293. var that = this;
  294. for (const i in that.validateForm.controls) {
  295. that.validateForm.controls[i].markAsDirty({ onlySelf: true });
  296. that.validateForm.controls[i].updateValueAndValidity();
  297. }
  298. if (that.validateForm.invalid) return;
  299. that.btnLoading = true;
  300. let groups = [],
  301. roles = [];
  302. if (that.validateForm.value.userGroup) {
  303. that.validateForm.value.userGroup.forEach((element) => {
  304. groups.push({ id: element });
  305. });
  306. }
  307. that.validateForm.value.role.forEach((element) => {
  308. roles.push({ id: element });
  309. });
  310. let data = {
  311. user: {
  312. name: that.validateForm.value.name,
  313. account: that.validateForm.value.account,
  314. gender: { id: that.validateForm.value.gender, key: "user_gender" },
  315. usertype: { id: that.validateForm.value.usertype },
  316. dept: { id: that.validateForm.value.dept },
  317. group: groups,
  318. role: roles,
  319. phone: that.validateForm.value.deptPhone,
  320. hospital: { id: that.add ? that.tool.getCurrentHospital().id : that.hosId },
  321. weixin: that.validateForm.value.weixin,
  322. },
  323. };
  324. if (!that.validateForm.value.userGroup) {
  325. delete data.user.group;
  326. } else if (that.validateForm.value.userGroup.length === 0) {
  327. delete data.user.group;
  328. }
  329. if (!that.add) {
  330. data.user["id"] = that.coopId;
  331. }
  332. that.mainService
  333. .coopData(that.add ? "addData" : "updData", "user", data)
  334. .subscribe((data) => {
  335. that.btnLoading = false;
  336. that.hideModal();
  337. that.initForm();
  338. if (data.status == 200) {
  339. that.showPromptModal(that.add ? "新增" : "编辑", true, "");
  340. } else {
  341. that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
  342. }
  343. });
  344. }
  345. // 编辑
  346. maskFlag: any = false;
  347. edit(data) {
  348. // ----------------
  349. var hid = data.hospital.id;
  350. let departmentData = {
  351. department: {
  352. hospital: { id: hid },
  353. },
  354. idx: 0,
  355. sum: 20,
  356. };
  357. let groupData = {
  358. group2: {
  359. hospitals: hid,
  360. type:1
  361. },
  362. idx: 0,
  363. sum: 9999,
  364. };
  365. this.maskFlag = this.message.loading("正在加载中..", {
  366. nzDuration: 0,
  367. }).messageId;
  368. this.mainService
  369. .getFetchDataList("data", "group2", groupData)
  370. .subscribe((item1) => {
  371. this.allUserGroup = item1.list;
  372. this.mainService
  373. .getFetchDataList("data", "department", departmentData)
  374. .subscribe((item2) => {
  375. this.message.remove(this.maskFlag);
  376. this.maskFlag = false;
  377. this.modal = true;
  378. this.alldepart = item2.list;
  379. if (data.dept) {
  380. let has = item2.list.some((d) => d.id == data.dept.id);
  381. if (!has) {
  382. this.alldepart = [data.dept, ...item2.list];
  383. }
  384. }
  385. this.isLoading = false;
  386. // ------------------------
  387. this.add = false;
  388. this.coopId = data.id;
  389. let groups = [],
  390. roles = [];
  391. if (data.group) {
  392. data.group.forEach((element) => {
  393. groups.push(element["id"] + "");
  394. });
  395. }
  396. if (data.role) {
  397. data.role.forEach((element) => {
  398. roles.push(element["id"] + "");
  399. });
  400. }
  401. this.validateForm.controls.name.setValue(data.name);
  402. this.validateForm.controls.account.setValue(data.account);
  403. this.validateForm.controls.usertype.setValue(data.usertype.id + "");
  404. if (data.dept) {
  405. this.validateForm.controls.dept.setValue(data.dept.id);
  406. }
  407. this.validateForm.controls.deptPhone.setValue(data.phone);
  408. this.validateForm.controls.gender.setValue(data.gender.id + "");
  409. this.validateForm.controls.userGroup.setValue(
  410. groups.length ? groups : null
  411. );
  412. this.validateForm.controls.role.setValue(
  413. roles.length ? roles : null
  414. );
  415. this.validateForm.controls.gender.setValue(data.gender.id + "");
  416. this.validateForm.controls.weixin.setValue(data.weixin);
  417. this.usertypeChange();
  418. });
  419. });
  420. // ----------------
  421. }
  422. // 删除
  423. delModal: boolean = false; //删除模态框
  424. del(data) {
  425. let that = this;
  426. that.coopId = data.id;
  427. that.delModal = true;
  428. }
  429. // 确认删除(删除企业微信用户)
  430. confirmDel() {
  431. let that = this;
  432. that.btnLoading = true;
  433. that.mainService
  434. .rmvDataAndWeChatNum([that.coopId], true)
  435. .subscribe((data) => {
  436. that.btnLoading = false;
  437. that.hideDelModal();
  438. if (data["status"] == 200) {
  439. if (
  440. that.listOfData.length == 1 &&
  441. that.pageIndex == Math.ceil(that.listLength / that.pageSize)
  442. ) {
  443. that.listLength--;
  444. that.pageIndex = Math.ceil(that.listLength / that.pageSize);
  445. }
  446. that.showPromptModal("删除", true, "");
  447. } else {
  448. that.showPromptModal("删除", false, data["msg"]);
  449. }
  450. });
  451. }
  452. // 确认删除(不删除企业用户)
  453. cancenlLoading = false;
  454. cancelDel() {
  455. let that = this;
  456. that.cancenlLoading = true;
  457. that.mainService
  458. .rmvDataAndWeChatNum([that.coopId], false)
  459. .subscribe((data) => {
  460. that.cancenlLoading = false;
  461. that.hideDelModal();
  462. if (data["status"] == 200) {
  463. if (
  464. that.listOfData.length == 1 &&
  465. that.pageIndex == Math.ceil(that.listLength / that.pageSize)
  466. ) {
  467. that.listLength--;
  468. that.pageIndex = Math.ceil(that.listLength / that.pageSize);
  469. }
  470. that.showPromptModal("删除", true, "");
  471. } else {
  472. that.showPromptModal("删除", false, data["msg"]);
  473. }
  474. });
  475. }
  476. // 关闭删除模态框
  477. hideDelModal() {
  478. this.delModal = false;
  479. }
  480. // ==================重置密码start====================
  481. // 重置密码
  482. resetModal: boolean = false; //删除模态框
  483. resetPwd(data) {
  484. this.coopId = data.id;
  485. this.resetModal = true;
  486. }
  487. // 确认重置密码
  488. confirmReset() {
  489. this.btnLoading = true;
  490. this.mainService
  491. .resetpwd(this.coopId)
  492. .subscribe((data) => {
  493. this.btnLoading = false;
  494. this.hideResetModal();
  495. if (data["status"] == 200) {
  496. this.showPromptModal("重置密码", true, "");
  497. } else {
  498. this.showPromptModal("重置密码", false, data["msg"]);
  499. }
  500. });
  501. }
  502. // 取消
  503. cancelReset() {
  504. this.resetModal = false;
  505. }
  506. // 关闭删除模态框
  507. hideResetModal() {
  508. this.resetModal = false;
  509. }
  510. // ==================重置密码end====================
  511. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  512. showPromptModal(con, success, promptInfo?) {
  513. this.promptModalShow = false;
  514. this.promptContent = con;
  515. this.ifSuccess = success;
  516. this.promptInfo = promptInfo;
  517. setTimeout(() => {
  518. this.promptModalShow = true;
  519. }, 100);
  520. this.getList();
  521. }
  522. // 查看
  523. detail(id) {
  524. this.router.navigateByUrl("/main/usersManagement/userDetail/" + id);
  525. }
  526. // 边输边搜节流阀
  527. isLoading = false;
  528. changeInp(hosId, type, e) {
  529. if (!hosId) {
  530. if (type == "search") {
  531. this.alldepart1 = [];
  532. } else if (type == "add") {
  533. this.alldepart = [];
  534. }
  535. return;
  536. }
  537. this.isLoading = true;
  538. this.changeInpSubject.next([hosId, type, e]);
  539. }
  540. // 边输边搜节流阀
  541. changeInpHospital(hosId, type, e) {
  542. if (!hosId) {
  543. if (type == "search") {
  544. this.hospitals1 = [];
  545. } else if (type == "add") {}
  546. return;
  547. }
  548. this.isLoading = true;
  549. this.changeInpHospitalSubject.next([hosId, type, e]);
  550. }
  551. // 获取所有科室
  552. snum = 0;
  553. getDeparts(hosId, type, dept) {
  554. var that = this;
  555. let data = {
  556. department: {
  557. dept,
  558. hospital: {
  559. id: type == "search" ? hosId : this.tool.getCurrentHospital().id,
  560. },
  561. },
  562. idx: 0,
  563. sum: 20,
  564. };
  565. this.snum++;
  566. that.mainService
  567. .getFetchDataList("data", "department", data)
  568. .subscribe((data) => {
  569. this.snum--;
  570. if (type == "search") {
  571. that.alldepart1 = data.list;
  572. } else if (type == "add") {
  573. that.alldepart = data.list;
  574. }
  575. if (this.snum === 0) {
  576. that.isLoading = false;
  577. }
  578. });
  579. }
  580. // 获取院区
  581. hnum = 0;
  582. getHospitals(hosId, type, keword) {
  583. this.hnum++;
  584. this.mainService
  585. .apiPostAll("topLevelParentHosList", {})
  586. .subscribe((data:any) => {
  587. this.hnum--;
  588. if (type == "search") {
  589. this.hospitals1 = data.list;
  590. } else if (type == "add") {}
  591. if (this.hnum === 0) {
  592. this.isLoading = false;
  593. }
  594. });
  595. }
  596. }