clinical-users-management.component.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. gradeId: [null],
  266. usertype: [this.userType + '', [Validators.required]],
  267. dept: [null, [Validators.required]],
  268. deptPhone: [null, [Validators.required]],
  269. gender: [null, [Validators.required]],
  270. userGroup: [null],
  271. role: [null, [Validators.required]],
  272. weixin: [null],
  273. });
  274. }
  275. // 选择用户类型
  276. usertypeChange() {
  277. // if (this.validateForm.value.usertype == 106) {
  278. // //配送人员
  279. // this.wxRequired = true;
  280. // this.validateForm.get("weixin")!.setValidators(Validators.required);
  281. // this.validateForm.get("weixin")!.markAsDirty();
  282. // } else {
  283. // this.wxRequired = false;
  284. // this.validateForm.get("weixin")!.clearValidators();
  285. // this.validateForm.get("weixin")!.markAsPristine();
  286. // }
  287. this.wxRequired = false;
  288. this.validateForm.get("weixin")!.clearValidators();
  289. this.validateForm.get("weixin")!.markAsPristine();
  290. this.validateForm.get("weixin")!.updateValueAndValidity();
  291. }
  292. // 表单提交
  293. submitForm(): void {
  294. var that = this;
  295. for (const i in that.validateForm.controls) {
  296. that.validateForm.controls[i].markAsDirty({ onlySelf: true });
  297. that.validateForm.controls[i].updateValueAndValidity();
  298. }
  299. if (that.validateForm.invalid) return;
  300. that.btnLoading = true;
  301. let groups = [],
  302. roles = [];
  303. if (that.validateForm.value.userGroup) {
  304. that.validateForm.value.userGroup.forEach((element) => {
  305. groups.push({ id: element });
  306. });
  307. }
  308. that.validateForm.value.role.forEach((element) => {
  309. roles.push({ id: element });
  310. });
  311. let data = {
  312. user: {
  313. name: that.validateForm.value.name,
  314. account: that.validateForm.value.account,
  315. gradeId: that.validateForm.value.gradeId,
  316. gender: { id: that.validateForm.value.gender, key: "user_gender" },
  317. usertype: { id: that.validateForm.value.usertype },
  318. dept: { id: that.validateForm.value.dept },
  319. group: groups,
  320. role: roles,
  321. phone: that.validateForm.value.deptPhone,
  322. hospital: { id: that.add ? that.tool.getCurrentHospital().id : that.hosId },
  323. weixin: that.validateForm.value.weixin,
  324. engineer: this.userTypes.find(v => v.id == that.validateForm.value.usertype).value == 4 ? 1 : 0,
  325. },
  326. };
  327. if (!that.validateForm.value.userGroup) {
  328. delete data.user.group;
  329. } else if (that.validateForm.value.userGroup.length === 0) {
  330. delete data.user.group;
  331. }
  332. if (!that.add) {
  333. data.user["id"] = that.coopId;
  334. }
  335. that.mainService
  336. .coopData(that.add ? "addData" : "updData", "user", data)
  337. .subscribe((data) => {
  338. that.btnLoading = false;
  339. that.hideModal();
  340. that.initForm();
  341. if (data.status == 200) {
  342. that.showPromptModal(that.add ? "新增" : "编辑", true, "");
  343. } else {
  344. that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
  345. }
  346. });
  347. }
  348. // 编辑
  349. maskFlag: any = false;
  350. edit(data) {
  351. // ----------------
  352. var hid = data.hospital.id;
  353. let departmentData = {
  354. department: {
  355. hospital: { id: hid },
  356. },
  357. idx: 0,
  358. sum: 20,
  359. };
  360. let groupData = {
  361. group2: {
  362. hospitals: hid,
  363. type:1
  364. },
  365. idx: 0,
  366. sum: 9999,
  367. };
  368. this.maskFlag = this.message.loading("正在加载中..", {
  369. nzDuration: 0,
  370. }).messageId;
  371. this.mainService
  372. .getFetchDataList("data", "group2", groupData)
  373. .subscribe((item1) => {
  374. this.allUserGroup = item1.list;
  375. this.mainService
  376. .getFetchDataList("data", "department", departmentData)
  377. .subscribe((item2) => {
  378. this.message.remove(this.maskFlag);
  379. this.maskFlag = false;
  380. this.modal = true;
  381. this.alldepart = item2.list;
  382. if (data.dept) {
  383. let has = item2.list.some((d) => d.id == data.dept.id);
  384. if (!has) {
  385. this.alldepart = [data.dept, ...item2.list];
  386. }
  387. }
  388. this.isLoading = false;
  389. // ------------------------
  390. this.add = false;
  391. this.coopId = data.id;
  392. let groups = [],
  393. roles = [];
  394. if (data.group) {
  395. data.group.forEach((element) => {
  396. groups.push(element["id"] + "");
  397. });
  398. }
  399. if (data.role) {
  400. data.role.forEach((element) => {
  401. roles.push(element["id"] + "");
  402. });
  403. }
  404. this.validateForm.controls.name.setValue(data.name);
  405. this.validateForm.controls.account.setValue(data.account);
  406. this.validateForm.controls.gradeId.setValue(data.gradeId);
  407. this.validateForm.controls.usertype.setValue(data.usertype.id + "");
  408. if (data.dept) {
  409. this.validateForm.controls.dept.setValue(data.dept.id);
  410. }
  411. this.validateForm.controls.deptPhone.setValue(data.phone);
  412. this.validateForm.controls.gender.setValue(data.gender.id + "");
  413. this.validateForm.controls.userGroup.setValue(
  414. groups.length ? groups : null
  415. );
  416. this.validateForm.controls.role.setValue(
  417. roles.length ? roles : null
  418. );
  419. this.validateForm.controls.gender.setValue(data.gender.id + "");
  420. this.validateForm.controls.weixin.setValue(data.weixin);
  421. this.usertypeChange();
  422. });
  423. });
  424. // ----------------
  425. }
  426. // 删除
  427. delModal: boolean = false; //删除模态框
  428. del(data) {
  429. let that = this;
  430. that.coopId = data.id;
  431. that.delModal = true;
  432. }
  433. // 确认删除(删除企业微信用户)
  434. confirmDel() {
  435. let that = this;
  436. that.btnLoading = true;
  437. that.mainService
  438. .rmvDataAndWeChatNum([that.coopId], true)
  439. .subscribe((data) => {
  440. that.btnLoading = false;
  441. that.hideDelModal();
  442. if (data["status"] == 200) {
  443. if (
  444. that.listOfData.length == 1 &&
  445. that.pageIndex == Math.ceil(that.listLength / that.pageSize)
  446. ) {
  447. that.listLength--;
  448. that.pageIndex = Math.ceil(that.listLength / that.pageSize) || 1;
  449. }
  450. that.showPromptModal("删除", true, "");
  451. } else {
  452. that.showPromptModal("删除", false, data["msg"]);
  453. }
  454. });
  455. }
  456. // 确认删除(不删除企业用户)
  457. cancenlLoading = false;
  458. cancelDel() {
  459. let that = this;
  460. that.cancenlLoading = true;
  461. that.mainService
  462. .rmvDataAndWeChatNum([that.coopId], false)
  463. .subscribe((data) => {
  464. that.cancenlLoading = false;
  465. that.hideDelModal();
  466. if (data["status"] == 200) {
  467. if (
  468. that.listOfData.length == 1 &&
  469. that.pageIndex == Math.ceil(that.listLength / that.pageSize)
  470. ) {
  471. that.listLength--;
  472. that.pageIndex = Math.ceil(that.listLength / that.pageSize) || 1;
  473. }
  474. that.showPromptModal("删除", true, "");
  475. } else {
  476. that.showPromptModal("删除", false, data["msg"]);
  477. }
  478. });
  479. }
  480. // 关闭删除模态框
  481. hideDelModal() {
  482. this.delModal = false;
  483. }
  484. // ==================重置密码start====================
  485. // 重置密码
  486. resetModal: boolean = false; //删除模态框
  487. resetPwd(data) {
  488. this.coopId = data.id;
  489. this.resetModal = true;
  490. }
  491. // 确认重置密码
  492. confirmReset() {
  493. this.btnLoading = true;
  494. this.mainService
  495. .resetpwd(this.coopId)
  496. .subscribe((data) => {
  497. this.btnLoading = false;
  498. this.hideResetModal();
  499. if (data["status"] == 200) {
  500. this.showPromptModal("重置密码", true, "");
  501. } else {
  502. this.showPromptModal("重置密码", false, data["msg"]);
  503. }
  504. });
  505. }
  506. // 取消
  507. cancelReset() {
  508. this.resetModal = false;
  509. }
  510. // 关闭删除模态框
  511. hideResetModal() {
  512. this.resetModal = false;
  513. }
  514. // ==================重置密码end====================
  515. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  516. showPromptModal(con, success, promptInfo?) {
  517. this.promptModalShow = false;
  518. this.promptContent = con;
  519. this.ifSuccess = success;
  520. this.promptInfo = promptInfo;
  521. setTimeout(() => {
  522. this.promptModalShow = true;
  523. }, 100);
  524. this.getList();
  525. }
  526. // 查看
  527. detail(id) {
  528. this.router.navigateByUrl("/main/clinicalUsersManagement/userDetail/" + id);
  529. }
  530. // 边输边搜节流阀
  531. isLoading = false;
  532. changeInp(hosId, type, e) {
  533. if (!hosId) {
  534. if (type == "search") {
  535. this.alldepart1 = [];
  536. } else if (type == "add") {
  537. this.alldepart = [];
  538. }
  539. return;
  540. }
  541. this.isLoading = true;
  542. this.changeInpSubject.next([hosId, type, e]);
  543. }
  544. // 边输边搜节流阀
  545. changeInpHospital(hosId, type, e) {
  546. if (!hosId) {
  547. if (type == "search") {
  548. this.hospitals1 = [];
  549. } else if (type == "add") {}
  550. return;
  551. }
  552. this.isLoading = true;
  553. this.changeInpHospitalSubject.next([hosId, type, e]);
  554. }
  555. // 获取所有科室
  556. snum = 0;
  557. getDeparts(hosId, type, dept) {
  558. var that = this;
  559. let data = {
  560. department: {
  561. dept,
  562. hospital: {
  563. id: type == "search" ? hosId : this.tool.getCurrentHospital().id,
  564. },
  565. },
  566. idx: 0,
  567. sum: 20,
  568. };
  569. this.snum++;
  570. that.mainService
  571. .getFetchDataList("data", "department", data)
  572. .subscribe((data) => {
  573. this.snum--;
  574. if (type == "search") {
  575. that.alldepart1 = data.list;
  576. } else if (type == "add") {
  577. that.alldepart = data.list;
  578. }
  579. if (this.snum === 0) {
  580. that.isLoading = false;
  581. }
  582. });
  583. }
  584. // 获取院区
  585. hnum = 0;
  586. getHospitals(hosId, type, keword) {
  587. this.hnum++;
  588. this.mainService
  589. .apiPostAll("topLevelParentHosList", {})
  590. .subscribe((data:any) => {
  591. this.hnum--;
  592. if (type == "search") {
  593. this.hospitals1 = data.list;
  594. } else if (type == "add") {}
  595. if (this.hnum === 0) {
  596. this.isLoading = false;
  597. }
  598. });
  599. }
  600. }