123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- import { Component, OnInit, ViewChild } from "@angular/core";
- import { ActivatedRoute, Router } from "@angular/router";
- import {
- FormBuilder,
- Validators,
- FormGroup,
- FormControl,
- } from "@angular/forms";
- import { MainService } from "../../services/main.service";
- import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
- import { ToolService } from "../../services/tool.service";
- import { format } from "date-fns";
- import { NzMessageService } from "ng-zorro-antd";
- @Component({
- selector: "app-office-management",
- templateUrl: "./office-management.component.html",
- styleUrls: ["./office-management.component.less"],
- })
- export class OfficeManagementComponent implements OnInit {
- @ViewChild("osComponentRef1", {
- read: OverlayScrollbarsComponent,
- static: false,
- })
- osComponentRef1: OverlayScrollbarsComponent;
- constructor(
- private message: NzMessageService,
- private fb: FormBuilder,
- private route: ActivatedRoute,
- private router: Router,
- private mainService: MainService,
- private tool: ToolService
- ) {}
- ngOnInit() {
- this.coopBtns = this.tool.initCoopBtns(this.route);
- this.initForm();
- this.getAllHospital();
- this.getType();
- }
- listOfData: any[] = []; //表格数据
- promptContent: string; //操作提示框提示信息
- ifSuccess: boolean; //操作成功/失败
- promptInfo: string; //操作结果提示信息
- promptModalShow: boolean; //操作提示框是否展示
- modal: boolean = false; //新增/编辑模态框
- add: boolean; //true:新增;false:编辑
- validateForm: FormGroup; //新增/编辑表单
- coopId: number; //表格中执行操作的id
- hospital; //所属院区
- name; //名称
- num; //编码
- deptalias; //别名
- type; //类型
- pageIndex: number = 1; //页码
- listLength: number = 10; //总条数
- pageSize: number = 10; //每页条数
- btnLoading: boolean = false; //确认按钮loading状态
- printLoading: boolean = false; //批量打印按钮loading状态
- deptPhones: any = []; //新添加的科室电话列表
- isAddDeptsPhone = true; //添加新的科室电话是否禁用
- deptsPhoneId = 1; //科室电话自增id
- // 初始化增删改按钮
- coopBtns: any = {};
- // 新添加科室号码
- addDeptPhone(e: MouseEvent) {
- e.preventDefault();
- this.deptPhones.push({ id: ++this.deptsPhoneId, phone: "" });
- this.deptsPhoneChange();
- }
- // 删除新添加科室号码
- removeDeptPhone(index: number, e: MouseEvent) {
- e.preventDefault();
- this.deptPhones.splice(index, 1);
- this.deptsPhoneChange();
- }
- //监听科室电话输入事件
- deptsPhoneChange(e?, phone?) {
- if (e !== undefined && phone !== undefined) {
- phone.phone = e;
- }
- // -------------判断添加按钮是否禁用 start
- this.isAddDeptsPhone = !this.validateForm.value.officeNum;
- if (!this.isAddDeptsPhone) {
- //如果没禁用
- this.isAddDeptsPhone = this.deptPhones.some((item) => item.phone === "");
- }
- // -------------判断添加按钮是否禁用 end
- }
- // 搜索
- search() {
- this.pageIndex = 1;
- this.getList();
- }
- // 重置
- reset() {
- this.pageIndex = 1;
- this.hospital = this.tool.getCurrentHospital().id + "";
- this.type = null;
- this.name = "";
- this.num = "";
- this.deptalias = "";
- this.getList();
- }
- // 表格数据
- loading1 = false;
- getList() {
- var that = this;
- let data = {
- idx: that.pageIndex - 1,
- sum: that.pageSize,
- department: {
- hospital: { id: that.hospital || "" },
- dept: that.name || "",
- pcode: that.num || "",
- type: { id: that.type || "" },
- deptalias: that.deptalias || "",
- },
- };
- that.mapOfCheckedId = {};
- that.checkedDepIds = [];
- that.isAllDisplayDataChecked = false;
- this.loading1 = true;
- that.mainService
- .getFetchDataList("data", "department", data)
- .subscribe((data) => {
- this.loading1 = false;
- that.listOfData = data.list;
- that.listLength = data.totalNum;
- });
- }
- // 获取所有院区
- getAllHospital() {
- this.hospital = this.tool.getCurrentHospital().id + "";
- this.getList();
- }
- // 切换院区选项
- buildings: any = []; //楼栋
- maskFlag: any = false;
- changeHosp(obj?) {
- let hospitalId;
- if (obj) {
- hospitalId = obj.hospital.id;
- }
- let hid;
- if (hospitalId || hospitalId == 0) {
- hid = hospitalId - 0;
- } else {
- hid = this.hospital - 0;
- }
- let data = {
- hosId: hid,
- };
- this.maskFlag = this.message.loading("正在加载中..", {
- nzDuration: 0,
- }).messageId;
- this.mainService.getBuildingOrFloor("building", data).subscribe((data) => {
- this.buildings = data.data;
- this.floors = [];
- // ---------
- if (obj) {
- //编辑
- let arr = this.buildings.map((item) => item.id);
- if (obj.building.id && arr.includes(obj.building.id)) {
- //有楼栋
- this.changeBuilding(obj.building.id, obj);
- this.validateForm.controls.building.setValue(obj.building.id + "");
- } else {
- //无楼栋
- this.floors = [];
- this.message.remove(this.maskFlag);
- this.maskFlag = false;
- this.modal = true;
- this.validateForm.controls.building.setValue(null);
- this.validateForm.controls.officeAddress.setValue(null);
- }
- } else {
- //新增
- this.message.remove(this.maskFlag);
- this.maskFlag = false;
- this.modal = true;
- }
- // ---------
- });
- }
- // 切换楼栋信息
- floors: Array<any> = []; //楼层
- floorLoading: boolean = false;
- changeBuilding(buildingId?, obj?) {
- var that = this;
- that.floors = [];
- var bid;
- if (buildingId || buildingId == 0) {
- bid = buildingId - 0;
- } else if (!that.add && that.validateForm.value.building) {
- bid = that.validateForm.value.building - 0;
- } else {
- return;
- }
- let data = {
- buildingId: bid,
- };
- this.floorLoading = true;
- that.mainService.getBuildingOrFloor("floor", data).subscribe((data) => {
- this.floorLoading = false;
- this.message.remove(this.maskFlag);
- this.maskFlag = false;
- this.modal = true;
- that.floors = data.data;
- if (obj) {
- let floorId = obj.floor.id;
- let arr = that.floors.map((item) => item["id"]);
- if (floorId && arr.includes(floorId)) {
- this.validateForm.controls.floor.setValue(floorId + "");
- } else {
- this.validateForm.controls.floor.setValue(null);
- this.validateForm.controls.officeAddress.setValue(null);
- }
- }
- });
- }
- // 获取科室类型
- types: Array<any> = [];
- getType() {
- var that = this;
- that.mainService.getDictionary("list", "dept_type").subscribe((data) => {
- console.log(data);
- that.types = data;
- });
- }
- // 新增弹框
- showModal() {
- this.initForm();
- this.changeHosp();
- this.add = true;
- this.isAddDeptsPhone = true;
- this.deptPhones = [];
- }
- hideModal() {
- this.modal = false;
- this.initForm();
- }
- // 初始化新增form表单
- initForm() {
- this.endTime1Hourdis = () => [];
- this.endTime1Mindis = () => [];
- this.endTime2Hourdis = () => [];
- this.endTime2Mindis = () => [];
- this.startTime1Hourdis = () => [];
- this.startTime1Mindis = () => [];
- this.startTime2Hourdis = () => [];
- this.startTime2Mindis = () => [];
- this.validateForm = this.fb.group({
- officeName: [null, [Validators.required]],
- deptalias: [null],
- officeNo: [null, [Validators.required]],
- officeNum: [null, [Validators.required]],
- building: [null, [Validators.required]],
- floor: [null, [Validators.required]],
- officeAddress: [null, [Validators.required]],
- officeType: [null, [Validators.required]],
- startTime1: [null],
- endTime1: [null],
- startTime2: [null],
- endTime2: [null],
- });
- }
- // 科室位置必填
- buildValidator = (control: FormControl): { [s: string]: boolean } => {
- if (
- this.validateForm &&
- this.validateForm.value &&
- (!this.validateForm.value.building ||
- !this.validateForm.value.floor ||
- !this.validateForm.value.officeAddress)
- ) {
- return { required: true };
- }
- };
- /**
- * 生成一个从 start 到 end 的连续数组
- * @param start
- * @param end
- */
- generateArray(start, end) {
- return Array.from(new Array(end).keys()).slice(start);
- }
- //服务时间选择
- // 禁用的小时
- startTime1Hourdis() {
- return [];
- }
- endTime1Hourdis() {
- return [];
- }
- startTime2Hourdis() {
- return [];
- }
- endTime2Hourdis() {
- return [];
- }
- // 禁用的分钟
- startTime1Mindis() {
- return [];
- }
- endTime1Mindis() {
- return [];
- }
- startTime2Mindis() {
- return [];
- }
- endTime2Mindis() {
- return [];
- }
- timeChange(e: boolean, type: string, num: number) {
- if (!e && this.validateForm.value[type + num]) {
- let hour = new Date(this.validateForm.value[type + num]).getHours();
- let minute = new Date(this.validateForm.value[type + num]).getMinutes();
- if (type == "startTime" && num === 1) {
- this.endTime1Hourdis = () => this.generateArray(0, hour);
- this.endTime1Mindis = () => this.generateArray(0, minute + 1);
- } else if (type == "startTime" && num === 2) {
- this.endTime2Hourdis = () => this.generateArray(0, hour);
- this.endTime2Mindis = () => this.generateArray(0, minute + 1);
- } else if (type == "endTime" && num === 1) {
- this.startTime1Hourdis = () => this.generateArray(hour + 1, 24);
- this.startTime1Mindis = () => this.generateArray(minute, 60);
- } else if (type == "endTime" && num === 2) {
- this.startTime2Hourdis = () => this.generateArray(hour + 1, 24);
- this.startTime2Mindis = () => this.generateArray(minute, 60);
- }
- }
- }
- // 表单提交
- submitForm(): void {
- var that = this;
- for (const i in that.validateForm.controls) {
- that.validateForm.controls[i].markAsDirty();
- that.validateForm.controls[i].updateValueAndValidity();
- }
- console.log(that.validateForm);
- if (that.validateForm.invalid) return;
- let deptsPhone = this.deptPhones.map((item) => item.phone).join();
- let data = {
- department: {
- dept: that.validateForm.value.officeName,
- deptalias: that.validateForm.value.deptalias,
- hospital: { id: that.hospital },
- pcode: that.validateForm.value.officeNo,
- manyPhone: deptsPhone
- ? that.validateForm.value.officeNum + "," + deptsPhone
- : that.validateForm.value.officeNum,
- building: { id: that.validateForm.value.building - 0 },
- floor: { id: that.validateForm.value.floor - 0 },
- address: that.validateForm.value.officeAddress,
- type: { id: that.validateForm.value.officeType },
- },
- };
- if (
- this.validateForm.value.startTime1 ||
- this.validateForm.value.endTime1
- ) {
- if (
- this.validateForm.value.startTime1 &&
- this.validateForm.value.endTime1
- ) {
- data.department["startTime1"] = format(
- this.validateForm.value.startTime1,
- "yyyy-MM-dd HH:mm:ss"
- );
- data.department["endTime1"] = format(
- this.validateForm.value.endTime1,
- "yyyy-MM-dd HH:mm:ss"
- );
- } else {
- return;
- }
- }
- if (
- this.validateForm.value.startTime2 ||
- this.validateForm.value.endTime2
- ) {
- if (
- this.validateForm.value.startTime2 &&
- this.validateForm.value.endTime2
- ) {
- data.department["startTime2"] = format(
- this.validateForm.value.startTime2,
- "yyyy-MM-dd HH:mm:ss"
- );
- data.department["endTime2"] = format(
- this.validateForm.value.endTime2,
- "yyyy-MM-dd HH:mm:ss"
- );
- } else {
- return;
- }
- }
- if (!that.add) {
- data.department["id"] = that.coopId;
- }
- that.btnLoading = true;
- that.mainService
- .coopData(that.add ? "addData" : "updData", "department", data)
- .subscribe((data) => {
- that.btnLoading = false;
- that.hideModal();
- that.initForm();
- if (data.status == 200) {
- that.showPromptModal(that.add ? "新增" : "编辑", true, "");
- } else {
- that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
- }
- });
- }
- // 编辑
- edit(e, data) {
- e.stopPropagation();
- this.add = false;
- this.coopId = data.id;
- this.isAddDeptsPhone = false;
- this.deptPhones = [];
- let phones = data.manyPhone ? data.manyPhone.split(",") : [];
- if (phones.length === 0) {
- this.validateForm.controls.officeNum.setValue("");
- this.deptPhones = [];
- } else if (phones.length === 1) {
- this.validateForm.controls.officeNum.setValue(phones[0]);
- this.deptPhones = [];
- } else {
- this.validateForm.controls.officeNum.setValue(phones[0]);
- this.deptPhones = phones.slice(1).map((item) => {
- return {
- id: ++this.deptsPhoneId,
- phone: item,
- };
- });
- }
- if (data.startTime1 && data.endTime1) {
- this.validateForm.controls.startTime1.setValue(new Date(data.startTime1));
- this.validateForm.controls.endTime1.setValue(new Date(data.endTime1));
- }
- if (data.startTime2 && data.endTime2) {
- this.validateForm.controls.startTime2.setValue(new Date(data.startTime2));
- this.validateForm.controls.endTime2.setValue(new Date(data.endTime2));
- }
- this.validateForm.controls.officeAddress.setValue(data.address);
- this.validateForm.controls.officeName.setValue(data.dept);
- this.validateForm.controls.deptalias.setValue(data.deptalias);
- this.validateForm.controls.officeNo.setValue(data.pcode);
- this.validateForm.controls.officeType.setValue(data.type.id + "");
- this.changeHosp(data);
- this.validateForm.controls.officeAddress.setValue(data.address);
- }
- // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
- showPromptModal(con, success, promptInfo?) {
- this.promptModalShow = false;
- this.promptContent = con;
- this.ifSuccess = success;
- this.promptInfo = promptInfo;
- setTimeout(() => {
- this.promptModalShow = true;
- }, 100);
- this.getList();
- }
- delModal: boolean = false; //删除模态框
- coopIds: any;
- coopFlag: any = false;
- /**
- *
- * @param e 事件对象
- * @param flag true是批量删除,false是单个删除
- * @param id
- */
- showDelModal(e, flag, id) {
- e.stopPropagation();
- this.delModal = true;
- this.coopFlag = flag;
- if (flag) {
- this.coopIds = id;
- } else {
- this.coopId = id;
- }
- }
- hideDelModal() {
- this.delModal = false;
- }
- // 确认删除
- confirmDel() {
- var that = this;
- that.btnLoading = true;
- that.mainService
- .coopData(
- "rmvData",
- "department",
- this.coopFlag ? this.coopIds : [that.coopId]
- )
- .subscribe((data) => {
- that.btnLoading = false;
- that.delModal = false;
- if (data.status == 200 && !data.data[0].msg) {
- if (
- that.listOfData.length == 1 &&
- that.pageIndex == Math.ceil(that.listLength / that.pageSize)
- ) {
- that.listLength--;
- that.pageIndex = Math.ceil(that.listLength / that.pageSize);
- }
- that.showPromptModal("删除", true, "");
- } else {
- that.showPromptModal("删除", false, data.data[0].msg);
- }
- });
- }
- // 查看
- detail(e, id) {
- e.stopPropagation();
- this.router.navigateByUrl("/main/officeManagement/officeDetail/" + id);
- }
- // 选中表格中科室
- mapOfCheckedId: { [key: string]: boolean } = {};
- checkedDepIds = []; //已选中科室id
- refreshStatus(): void {
- this.isAllDisplayDataChecked = this.listOfData.every(
- (item) => this.mapOfCheckedId[item.id]
- );
- let arr = [];
- for (var k in this.mapOfCheckedId) {
- if (this.mapOfCheckedId[k]) {
- arr.push(Number(k));
- }
- }
- this.checkedDepIds = arr;
- console.log(this.checkedDepIds);
- }
- //表格整行选中
- selectedListData(id) {
- this.mapOfCheckedId[id] = !this.mapOfCheckedId[id];
- this.refreshStatus();
- }
- // 全选
- isAllDisplayDataChecked = false; //当前页是否全选
- checkAll(value: boolean): void {
- this.listOfData.forEach((item) => (this.mapOfCheckedId[item.id] = value));
- this.refreshStatus();
- }
- // 打印
- codes = []; //二维码
- print(e, batch, id?) {
- e.stopPropagation();
- let that = this;
- that.printLoading = true;
- that.mainService
- .postCustomCode("dept", "deptCodes", batch ? that.checkedDepIds : [id])
- .subscribe((data) => {
- that.codes = data.data;
- that.printLoading = false;
- setTimeout(() => {
- const printContent = document.getElementById("report");
- const WindowPrt = window.open("", "", "width=700,height=900");
- WindowPrt.document.write(printContent.innerHTML);
- WindowPrt.document.close();
- WindowPrt.focus();
- WindowPrt.print();
- WindowPrt.close();
- }, 100);
- });
- }
- }
|