office-management.component.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import {
  4. FormBuilder,
  5. Validators,
  6. FormGroup,
  7. FormControl,
  8. } from "@angular/forms";
  9. import { MainService } from "../../services/main.service";
  10. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  11. import { ToolService } from "../../services/tool.service";
  12. import { format } from "date-fns";
  13. import { NzMessageService } from "ng-zorro-antd";
  14. @Component({
  15. selector: "app-office-management",
  16. templateUrl: "./office-management.component.html",
  17. styleUrls: ["./office-management.component.less"],
  18. })
  19. export class OfficeManagementComponent implements OnInit {
  20. @ViewChild("osComponentRef1", {
  21. read: OverlayScrollbarsComponent,
  22. static: false,
  23. })
  24. osComponentRef1: OverlayScrollbarsComponent;
  25. constructor(
  26. private message: NzMessageService,
  27. private fb: FormBuilder,
  28. private route: ActivatedRoute,
  29. private router: Router,
  30. private mainService: MainService,
  31. private tool: ToolService
  32. ) {}
  33. ngOnInit() {
  34. this.coopBtns = this.tool.initCoopBtns(this.route);
  35. this.initForm();
  36. this.getAllHospital();
  37. this.getType();
  38. }
  39. listOfData: any[] = []; //表格数据
  40. promptContent: string; //操作提示框提示信息
  41. ifSuccess: boolean; //操作成功/失败
  42. promptInfo: string; //操作结果提示信息
  43. promptModalShow: boolean; //操作提示框是否展示
  44. modal: boolean = false; //新增/编辑模态框
  45. add: boolean; //true:新增;false:编辑
  46. validateForm: FormGroup; //新增/编辑表单
  47. coopId: number; //表格中执行操作的id
  48. hospital; //所属院区
  49. name; //名称
  50. num; //编码
  51. deptalias; //别名
  52. type; //类型
  53. pageIndex: number = 1; //页码
  54. listLength: number = 10; //总条数
  55. pageSize: number = 10; //每页条数
  56. btnLoading: boolean = false; //确认按钮loading状态
  57. printLoading: boolean = false; //批量打印按钮loading状态
  58. deptPhones: any = []; //新添加的科室电话列表
  59. isAddDeptsPhone = true; //添加新的科室电话是否禁用
  60. deptsPhoneId = 1; //科室电话自增id
  61. // 初始化增删改按钮
  62. coopBtns: any = {};
  63. // 新添加科室号码
  64. addDeptPhone(e: MouseEvent) {
  65. e.preventDefault();
  66. this.deptPhones.push({ id: ++this.deptsPhoneId, phone: "" });
  67. this.deptsPhoneChange();
  68. }
  69. // 删除新添加科室号码
  70. removeDeptPhone(index: number, e: MouseEvent) {
  71. e.preventDefault();
  72. this.deptPhones.splice(index, 1);
  73. this.deptsPhoneChange();
  74. }
  75. //监听科室电话输入事件
  76. deptsPhoneChange(e?, phone?) {
  77. if (e !== undefined && phone !== undefined) {
  78. phone.phone = e;
  79. }
  80. // -------------判断添加按钮是否禁用 start
  81. this.isAddDeptsPhone = !this.validateForm.value.officeNum;
  82. if (!this.isAddDeptsPhone) {
  83. //如果没禁用
  84. this.isAddDeptsPhone = this.deptPhones.some((item) => item.phone === "");
  85. }
  86. // -------------判断添加按钮是否禁用 end
  87. }
  88. // 搜索
  89. search() {
  90. this.pageIndex = 1;
  91. this.getList();
  92. }
  93. // 重置
  94. reset() {
  95. this.pageIndex = 1;
  96. this.hospital = this.tool.getCurrentHospital().id + "";
  97. this.type = null;
  98. this.name = "";
  99. this.num = "";
  100. this.deptalias = "";
  101. this.getList();
  102. }
  103. // 表格数据
  104. loading1 = false;
  105. getList() {
  106. var that = this;
  107. let data = {
  108. idx: that.pageIndex - 1,
  109. sum: that.pageSize,
  110. department: {
  111. hospital: { id: that.hospital || "" },
  112. dept: that.name || "",
  113. pcode: that.num || "",
  114. type: { id: that.type || "" },
  115. deptalias: that.deptalias || "",
  116. },
  117. };
  118. that.mapOfCheckedId = {};
  119. that.checkedDepIds = [];
  120. that.isAllDisplayDataChecked = false;
  121. this.loading1 = true;
  122. that.mainService
  123. .getFetchDataList("data", "department", data)
  124. .subscribe((data) => {
  125. this.loading1 = false;
  126. that.listOfData = data.list;
  127. that.listLength = data.totalNum;
  128. });
  129. }
  130. // 获取所有院区
  131. getAllHospital() {
  132. this.hospital = this.tool.getCurrentHospital().id + "";
  133. this.getList();
  134. }
  135. // 切换院区选项
  136. buildings: any = []; //楼栋
  137. maskFlag: any = false;
  138. changeHosp(obj?) {
  139. let hospitalId;
  140. if (obj) {
  141. hospitalId = obj.hospital.id;
  142. }
  143. let hid;
  144. if (hospitalId || hospitalId == 0) {
  145. hid = hospitalId - 0;
  146. } else {
  147. hid = this.hospital - 0;
  148. }
  149. let data = {
  150. hosId: hid,
  151. };
  152. this.maskFlag = this.message.loading("正在加载中..", {
  153. nzDuration: 0,
  154. }).messageId;
  155. this.mainService.getBuildingOrFloor("building", data).subscribe((data) => {
  156. this.buildings = data.data;
  157. this.floors = [];
  158. // ---------
  159. if (obj) {
  160. //编辑
  161. let arr = this.buildings.map((item) => item.id);
  162. if (obj.building.id && arr.includes(obj.building.id)) {
  163. //有楼栋
  164. this.changeBuilding(obj.building.id, obj);
  165. this.validateForm.controls.building.setValue(obj.building.id + "");
  166. } else {
  167. //无楼栋
  168. this.floors = [];
  169. this.message.remove(this.maskFlag);
  170. this.maskFlag = false;
  171. this.modal = true;
  172. this.validateForm.controls.building.setValue(null);
  173. this.validateForm.controls.officeAddress.setValue(null);
  174. }
  175. } else {
  176. //新增
  177. this.message.remove(this.maskFlag);
  178. this.maskFlag = false;
  179. this.modal = true;
  180. }
  181. // ---------
  182. });
  183. }
  184. // 切换楼栋信息
  185. floors: Array<any> = []; //楼层
  186. floorLoading: boolean = false;
  187. changeBuilding(buildingId?, obj?) {
  188. var that = this;
  189. that.floors = [];
  190. var bid;
  191. if (buildingId || buildingId == 0) {
  192. bid = buildingId - 0;
  193. } else if (!that.add && that.validateForm.value.building) {
  194. bid = that.validateForm.value.building - 0;
  195. } else {
  196. return;
  197. }
  198. let data = {
  199. buildingId: bid,
  200. };
  201. this.floorLoading = true;
  202. that.mainService.getBuildingOrFloor("floor", data).subscribe((data) => {
  203. this.floorLoading = false;
  204. this.message.remove(this.maskFlag);
  205. this.maskFlag = false;
  206. this.modal = true;
  207. that.floors = data.data;
  208. if (obj) {
  209. let floorId = obj.floor.id;
  210. let arr = that.floors.map((item) => item["id"]);
  211. if (floorId && arr.includes(floorId)) {
  212. this.validateForm.controls.floor.setValue(floorId + "");
  213. } else {
  214. this.validateForm.controls.floor.setValue(null);
  215. this.validateForm.controls.officeAddress.setValue(null);
  216. }
  217. }
  218. });
  219. }
  220. // 获取科室类型
  221. types: Array<any> = [];
  222. getType() {
  223. var that = this;
  224. that.mainService.getDictionary("list", "dept_type").subscribe((data) => {
  225. console.log(data);
  226. that.types = data;
  227. });
  228. }
  229. // 新增弹框
  230. showModal() {
  231. this.initForm();
  232. this.changeHosp();
  233. this.add = true;
  234. this.isAddDeptsPhone = true;
  235. this.deptPhones = [];
  236. }
  237. hideModal() {
  238. this.modal = false;
  239. this.initForm();
  240. }
  241. // 初始化新增form表单
  242. initForm() {
  243. this.endTime1Hourdis = () => [];
  244. this.endTime1Mindis = () => [];
  245. this.endTime2Hourdis = () => [];
  246. this.endTime2Mindis = () => [];
  247. this.startTime1Hourdis = () => [];
  248. this.startTime1Mindis = () => [];
  249. this.startTime2Hourdis = () => [];
  250. this.startTime2Mindis = () => [];
  251. this.validateForm = this.fb.group({
  252. officeName: [null, [Validators.required]],
  253. deptalias: [null],
  254. officeNo: [null, [Validators.required]],
  255. officeNum: [null, [Validators.required]],
  256. building: [null, [Validators.required]],
  257. floor: [null, [Validators.required]],
  258. officeAddress: [null, [Validators.required]],
  259. officeType: [null, [Validators.required]],
  260. startTime1: [null],
  261. endTime1: [null],
  262. startTime2: [null],
  263. endTime2: [null],
  264. });
  265. }
  266. // 科室位置必填
  267. buildValidator = (control: FormControl): { [s: string]: boolean } => {
  268. if (
  269. this.validateForm &&
  270. this.validateForm.value &&
  271. (!this.validateForm.value.building ||
  272. !this.validateForm.value.floor ||
  273. !this.validateForm.value.officeAddress)
  274. ) {
  275. return { required: true };
  276. }
  277. };
  278. /**
  279. * 生成一个从 start 到 end 的连续数组
  280. * @param start
  281. * @param end
  282. */
  283. generateArray(start, end) {
  284. return Array.from(new Array(end).keys()).slice(start);
  285. }
  286. //服务时间选择
  287. // 禁用的小时
  288. startTime1Hourdis() {
  289. return [];
  290. }
  291. endTime1Hourdis() {
  292. return [];
  293. }
  294. startTime2Hourdis() {
  295. return [];
  296. }
  297. endTime2Hourdis() {
  298. return [];
  299. }
  300. // 禁用的分钟
  301. startTime1Mindis() {
  302. return [];
  303. }
  304. endTime1Mindis() {
  305. return [];
  306. }
  307. startTime2Mindis() {
  308. return [];
  309. }
  310. endTime2Mindis() {
  311. return [];
  312. }
  313. timeChange(e: boolean, type: string, num: number) {
  314. if (!e && this.validateForm.value[type + num]) {
  315. let hour = new Date(this.validateForm.value[type + num]).getHours();
  316. let minute = new Date(this.validateForm.value[type + num]).getMinutes();
  317. if (type == "startTime" && num === 1) {
  318. this.endTime1Hourdis = () => this.generateArray(0, hour);
  319. this.endTime1Mindis = () => this.generateArray(0, minute + 1);
  320. } else if (type == "startTime" && num === 2) {
  321. this.endTime2Hourdis = () => this.generateArray(0, hour);
  322. this.endTime2Mindis = () => this.generateArray(0, minute + 1);
  323. } else if (type == "endTime" && num === 1) {
  324. this.startTime1Hourdis = () => this.generateArray(hour + 1, 24);
  325. this.startTime1Mindis = () => this.generateArray(minute, 60);
  326. } else if (type == "endTime" && num === 2) {
  327. this.startTime2Hourdis = () => this.generateArray(hour + 1, 24);
  328. this.startTime2Mindis = () => this.generateArray(minute, 60);
  329. }
  330. }
  331. }
  332. // 表单提交
  333. submitForm(): void {
  334. var that = this;
  335. for (const i in that.validateForm.controls) {
  336. that.validateForm.controls[i].markAsDirty();
  337. that.validateForm.controls[i].updateValueAndValidity();
  338. }
  339. console.log(that.validateForm);
  340. if (that.validateForm.invalid) return;
  341. let deptsPhone = this.deptPhones.map((item) => item.phone).join();
  342. let data = {
  343. department: {
  344. dept: that.validateForm.value.officeName,
  345. deptalias: that.validateForm.value.deptalias,
  346. hospital: { id: that.hospital },
  347. pcode: that.validateForm.value.officeNo,
  348. manyPhone: deptsPhone
  349. ? that.validateForm.value.officeNum + "," + deptsPhone
  350. : that.validateForm.value.officeNum,
  351. building: { id: that.validateForm.value.building - 0 },
  352. floor: { id: that.validateForm.value.floor - 0 },
  353. address: that.validateForm.value.officeAddress,
  354. type: { id: that.validateForm.value.officeType },
  355. },
  356. };
  357. if (
  358. this.validateForm.value.startTime1 ||
  359. this.validateForm.value.endTime1
  360. ) {
  361. if (
  362. this.validateForm.value.startTime1 &&
  363. this.validateForm.value.endTime1
  364. ) {
  365. data.department["startTime1"] = format(
  366. this.validateForm.value.startTime1,
  367. "yyyy-MM-dd HH:mm:ss"
  368. );
  369. data.department["endTime1"] = format(
  370. this.validateForm.value.endTime1,
  371. "yyyy-MM-dd HH:mm:ss"
  372. );
  373. } else {
  374. return;
  375. }
  376. }
  377. if (
  378. this.validateForm.value.startTime2 ||
  379. this.validateForm.value.endTime2
  380. ) {
  381. if (
  382. this.validateForm.value.startTime2 &&
  383. this.validateForm.value.endTime2
  384. ) {
  385. data.department["startTime2"] = format(
  386. this.validateForm.value.startTime2,
  387. "yyyy-MM-dd HH:mm:ss"
  388. );
  389. data.department["endTime2"] = format(
  390. this.validateForm.value.endTime2,
  391. "yyyy-MM-dd HH:mm:ss"
  392. );
  393. } else {
  394. return;
  395. }
  396. }
  397. if (!that.add) {
  398. data.department["id"] = that.coopId;
  399. }
  400. that.btnLoading = true;
  401. that.mainService
  402. .coopData(that.add ? "addData" : "updData", "department", data)
  403. .subscribe((data) => {
  404. that.btnLoading = false;
  405. that.hideModal();
  406. that.initForm();
  407. if (data.status == 200) {
  408. that.showPromptModal(that.add ? "新增" : "编辑", true, "");
  409. } else {
  410. that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
  411. }
  412. });
  413. }
  414. // 编辑
  415. edit(e, data) {
  416. e.stopPropagation();
  417. this.add = false;
  418. this.coopId = data.id;
  419. this.isAddDeptsPhone = false;
  420. this.deptPhones = [];
  421. let phones = data.manyPhone ? data.manyPhone.split(",") : [];
  422. if (phones.length === 0) {
  423. this.validateForm.controls.officeNum.setValue("");
  424. this.deptPhones = [];
  425. } else if (phones.length === 1) {
  426. this.validateForm.controls.officeNum.setValue(phones[0]);
  427. this.deptPhones = [];
  428. } else {
  429. this.validateForm.controls.officeNum.setValue(phones[0]);
  430. this.deptPhones = phones.slice(1).map((item) => {
  431. return {
  432. id: ++this.deptsPhoneId,
  433. phone: item,
  434. };
  435. });
  436. }
  437. if (data.startTime1 && data.endTime1) {
  438. this.validateForm.controls.startTime1.setValue(new Date(data.startTime1));
  439. this.validateForm.controls.endTime1.setValue(new Date(data.endTime1));
  440. }
  441. if (data.startTime2 && data.endTime2) {
  442. this.validateForm.controls.startTime2.setValue(new Date(data.startTime2));
  443. this.validateForm.controls.endTime2.setValue(new Date(data.endTime2));
  444. }
  445. this.validateForm.controls.officeAddress.setValue(data.address);
  446. this.validateForm.controls.officeName.setValue(data.dept);
  447. this.validateForm.controls.deptalias.setValue(data.deptalias);
  448. this.validateForm.controls.officeNo.setValue(data.pcode);
  449. this.validateForm.controls.officeType.setValue(data.type.id + "");
  450. this.changeHosp(data);
  451. this.validateForm.controls.officeAddress.setValue(data.address);
  452. }
  453. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  454. showPromptModal(con, success, promptInfo?) {
  455. this.promptModalShow = false;
  456. this.promptContent = con;
  457. this.ifSuccess = success;
  458. this.promptInfo = promptInfo;
  459. setTimeout(() => {
  460. this.promptModalShow = true;
  461. }, 100);
  462. this.getList();
  463. }
  464. delModal: boolean = false; //删除模态框
  465. coopIds: any;
  466. coopFlag: any = false;
  467. /**
  468. *
  469. * @param e 事件对象
  470. * @param flag true是批量删除,false是单个删除
  471. * @param id
  472. */
  473. showDelModal(e, flag, id) {
  474. e.stopPropagation();
  475. this.delModal = true;
  476. this.coopFlag = flag;
  477. if (flag) {
  478. this.coopIds = id;
  479. } else {
  480. this.coopId = id;
  481. }
  482. }
  483. hideDelModal() {
  484. this.delModal = false;
  485. }
  486. // 确认删除
  487. confirmDel() {
  488. var that = this;
  489. that.btnLoading = true;
  490. that.mainService
  491. .coopData(
  492. "rmvData",
  493. "department",
  494. this.coopFlag ? this.coopIds : [that.coopId]
  495. )
  496. .subscribe((data) => {
  497. that.btnLoading = false;
  498. that.delModal = false;
  499. if (data.status == 200 && !data.data[0].msg) {
  500. if (
  501. that.listOfData.length == 1 &&
  502. that.pageIndex == Math.ceil(that.listLength / that.pageSize)
  503. ) {
  504. that.listLength--;
  505. that.pageIndex = Math.ceil(that.listLength / that.pageSize);
  506. }
  507. that.showPromptModal("删除", true, "");
  508. } else {
  509. that.showPromptModal("删除", false, data.data[0].msg);
  510. }
  511. });
  512. }
  513. // 查看
  514. detail(e, id) {
  515. e.stopPropagation();
  516. this.router.navigateByUrl("/main/officeManagement/officeDetail/" + id);
  517. }
  518. // 选中表格中科室
  519. mapOfCheckedId: { [key: string]: boolean } = {};
  520. checkedDepIds = []; //已选中科室id
  521. refreshStatus(): void {
  522. this.isAllDisplayDataChecked = this.listOfData.every(
  523. (item) => this.mapOfCheckedId[item.id]
  524. );
  525. let arr = [];
  526. for (var k in this.mapOfCheckedId) {
  527. if (this.mapOfCheckedId[k]) {
  528. arr.push(Number(k));
  529. }
  530. }
  531. this.checkedDepIds = arr;
  532. console.log(this.checkedDepIds);
  533. }
  534. //表格整行选中
  535. selectedListData(id) {
  536. this.mapOfCheckedId[id] = !this.mapOfCheckedId[id];
  537. this.refreshStatus();
  538. }
  539. // 全选
  540. isAllDisplayDataChecked = false; //当前页是否全选
  541. checkAll(value: boolean): void {
  542. this.listOfData.forEach((item) => (this.mapOfCheckedId[item.id] = value));
  543. this.refreshStatus();
  544. }
  545. // 打印
  546. codes = []; //二维码
  547. print(e, batch, id?) {
  548. e.stopPropagation();
  549. let that = this;
  550. that.printLoading = true;
  551. that.mainService
  552. .postCustomCode("dept", "deptCodes", batch ? that.checkedDepIds : [id])
  553. .subscribe((data) => {
  554. that.codes = data.data;
  555. that.printLoading = false;
  556. setTimeout(() => {
  557. const printContent = document.getElementById("report");
  558. const WindowPrt = window.open("", "", "width=700,height=900");
  559. WindowPrt.document.write(printContent.innerHTML);
  560. WindowPrt.document.close();
  561. WindowPrt.focus();
  562. WindowPrt.print();
  563. WindowPrt.close();
  564. }, 100);
  565. });
  566. }
  567. }