123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- import { Component, OnInit, ViewChild } from "@angular/core";
- import { ActivatedRoute } 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 { NzMessageService } from "ng-zorro-antd";
- import { format } from "date-fns";
- @Component({
- selector: "app-timing-message-sending",
- templateUrl: "./timing-message-sending.component.html",
- styleUrls: ["./timing-message-sending.component.less"],
- })
- export class TimingMessageSendingComponent implements OnInit {
- @ViewChild("osComponentRef1", {
- read: OverlayScrollbarsComponent,
- static: false,
- })
- osComponentRef1: OverlayScrollbarsComponent;
- constructor(
- private message: NzMessageService,
- private fb: FormBuilder,
- private mainService: MainService,
- private route: ActivatedRoute,
- private tool: ToolService
- ) {}
- userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
- menu: any = JSON.parse(localStorage.getItem("menu")) || []; //菜单
- hosId;
- createUser = "";
- users = []; // 用户列表
- listOfData: any[] = []; //表格数据
- pageIndex: number = 1; //表格当前页码
- pageSize: number = 10; //表格每页展示条数
- listLength: number = 10; //表格总数据量
- tableHeight: number; //表格动态高
- modal: boolean = false; //新增/编辑模态框
- validateForm: FormGroup; //新增/编辑表单
- dataContent: any; //当前操作列
- oneOption: any; //适用日期类型
- btnLoading: boolean = false; //提交按钮loading状态
- promptContent: string; //操作提示框提示信息
- ifSuccess: boolean; //操作成功/失败
- promptInfo: string; //操作结果提示信息
- promptModalShow: boolean; //操作提示框是否展示
- demoValue: number = 0;
- ngOnInit() {
- this.hosId = this.tool.getCurrentHospital().id;
- this.getList();
- this.initCoopBtns();
- this.initForm();
- }
- changeForm(flag) {
- if (flag) {
- this.changeInp("no", "form");
- }
- }
- // 边输边搜节流阀
- isLoading = false;
- changeInp(dept, type) {
- if (!dept) {
- return;
- }
- if (dept === "no") {
- dept = "";
- }
- this.isLoading = true;
- this.searchUsers(dept, type);
- }
- // 搜索用户
- snum = 0;
- searchUsers(dept, type) {
- let data = {
- user: {
- name: dept,
- hospital: { id: this.hosId },
- },
- idx: 0,
- sum: 20,
- };
- this.snum++;
- this.mainService
- .getFetchDataList("data", "user", data)
- .subscribe((data) => {
- this.snum--;
- if (data.status == 200) {
- if (type === "form") {
- if (this.snum === 0) {
- this.isLoading = false;
- }
- this.users = data.list;
- }
- }
- });
- }
- // 初始化权限按钮
- coopBtns: any = {
- edit: false, //编辑
- isStartUp: false, //是否启用
- };
- initCoopBtns() {
- // 二级菜单
- let secondMenus = [];
- this.menu.forEach((e) => {
- e.childrens.forEach((el) => {
- secondMenus.push(el);
- });
- });
- let link = this.route.parent.snapshot.routeConfig.path;
- let btns = [];
- secondMenus.forEach((e) => {
- if (e.link == link) {
- btns = e.childrens || [];
- }
- });
- btns.forEach((e) => {
- this.coopBtns[e.link] = true;
- });
- }
- // 表格数据
- loading1 = false;
- getList() {
- let postData = {
- idx: this.pageIndex - 1,
- sum: this.pageSize,
- messageJob: {
- hospital: this.hosId,
- },
- };
- this.loading1 = true;
- this.mainService
- .getFetchDataList("simple/data", "messageJob", postData)
- .subscribe((data) => {
- this.loading1 = false;
- if (data.status == 200) {
- this.listOfData = data.list;
- this.listOfData.forEach((item) => {
- if (item.timeStep == "week") {
- let weeks = [
- "周一",
- "周二",
- "周三",
- "周四",
- "周五",
- "周六",
- "周日",
- ];
- item.weekName = weeks[item.extra1 - 1];
- }
- item.usersName = item.users.map((value) => value.name).join();
- });
- this.listLength = data.totalNum;
- }
- });
- }
- //关闭编辑弹框
- hideAddModal() {
- this.modal = false;
- this.initForm();
- }
- // 初始化form表单
- initForm() {
- this.validateForm = this.fb.group({
- title: [null, [Validators.required]], //标题
- timeStep: ["day", [Validators.required]], //重复策略
- executeTime: [null, [Validators.required]], //定时发送时间
- active: [false, [Validators.required]], //是否启用
- userIds: [null, [Validators.required]], //接收人
- });
- }
- //修改重复策略
- months = [...Array(32).keys()].slice(1);
- timeStepChange(e) {
- switch (e) {
- case "day":
- this.validateForm.removeControl("doWeek");
- this.validateForm.removeControl("doMonth");
- this.validateForm.removeControl("doYear");
- break;
- case "week":
- this.validateForm.addControl(
- "doWeek",
- new FormControl(null, Validators.required)
- );
- this.validateForm.removeControl("doMonth");
- this.validateForm.removeControl("doYear");
- break;
- case "month":
- this.validateForm.addControl(
- "doMonth",
- new FormControl(null, Validators.required)
- );
- this.validateForm.removeControl("doWeek");
- this.validateForm.removeControl("doYear");
- break;
- case "year":
- this.validateForm.addControl(
- "doYear",
- new FormControl(null, Validators.required)
- );
- this.validateForm.removeControl("doWeek");
- this.validateForm.removeControl("doMonth");
- break;
- }
- }
- // 表单提交
- submitForm(): void {
- this.btnLoading = true;
- for (const i in this.validateForm.controls) {
- this.validateForm.controls[i].markAsDirty();
- this.validateForm.controls[i].updateValueAndValidity();
- }
- if (this.validateForm.invalid) {
- this.btnLoading = false;
- return;
- }
- let postData: any = {
- title: this.validateForm.value.title,
- executeTime: new Date(this.validateForm.value.executeTime).getTime(),
- userIds: this.validateForm.value.userIds.join(),
- active: this.validateForm.value.active,
- content: this.dataContent.content,
- key: this.dataContent.key,
- id: this.dataContent.id,
- timeStep: this.validateForm.value.timeStep,
- };
- if (this.validateForm.value.timeStep == "day") {
- delete postData.extra1;
- } else if (this.validateForm.value.timeStep == "week") {
- postData.extra1 = this.validateForm.value.doWeek;
- } else if (this.validateForm.value.timeStep == "month") {
- postData.extra1 = this.validateForm.value.doMonth;
- } else if (this.validateForm.value.timeStep == "year") {
- delete postData.extra1;
- postData.executeTime = new Date(
- format(this.validateForm.value.doYear, "yyyy-MM-dd") +
- " " +
- format(new Date(this.validateForm.value.executeTime), "HH:mm:ss")
- ).getTime();
- }
- this.mainService
- .simplePost("updData", "messageJob", postData)
- .subscribe((data) => {
- this.btnLoading = false;
- this.hideAddModal();
- this.initForm();
- if (data.status == 200) {
- this.listLength++;
- this.showPromptModal("修改", true, "");
- } else {
- this.showPromptModal("修改", false, data.msg);
- }
- });
- }
- // 编辑
- maskFlag: any = false;
- edit(data) {
- this.dataContent = data;
- this.validateForm.controls.executeTime.setValue(new Date(data.executeTime)); //定时发送时间
- this.validateForm.controls.title.setValue(data.title); //标题
- this.validateForm.controls.active.setValue(data.active); //是否启用
- this.timeStepChange(data.timeStep);
- this.validateForm.controls.timeStep.setValue(data.timeStep); //重复策略
- if (data.timeStep == "year") {
- this.validateForm.controls.doYear.setValue(
- format(data.executeTime, "yyyy-MM-dd HH:mm:ss")
- );
- } else if (data.timeStep == "month") {
- this.validateForm.controls.doMonth.setValue(data.extra1);
- } else if (data.timeStep == "week") {
- this.validateForm.controls.doWeek.setValue(data.extra1);
- }
- // --------接收人---
- this.maskFlag = this.message.loading("正在加载中..", {
- nzDuration: 0,
- }).messageId;
- this.mainService
- .getFetchDataList("data", "user", {
- idx: 0,
- sum: 20,
- user: {
- hosId: this.hosId,
- },
- })
- .subscribe((result) => {
- this.message.remove(this.maskFlag);
- this.maskFlag = false;
- this.modal = true;
- if (result.status == 200) {
- let add = data.users.filter(
- (item) => !result.list.some((ele) => ele.id == item.id)
- );
- this.users = add.concat(result.list);
- this.validateForm.controls.userIds.setValue(data.userIds.split(",")); //接收人
- }
- });
- // --------/接收人---
- }
- // 展示信息提示框(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; //删除模态框
- tipsMsg1: string; //提示框信息
- tipsMsg2: string; //操作后信息
- confirmDelType: string; //确认的类型(启用/停用,删除)
- confirmDelIsSwitch: boolean; //启用/停用
- showDelModal(
- dataContent,
- tipsMsg1: string,
- tipsMsg2: string,
- type: string,
- isSwitch?: boolean
- ) {
- this.confirmDelIsSwitch = isSwitch;
- this.confirmDelType = type;
- this.delModal = true;
- this.dataContent = dataContent;
- this.tipsMsg1 = tipsMsg1;
- this.tipsMsg2 = tipsMsg2;
- }
- // 隐藏
- hideDelModal() {
- this.delModal = false;
- }
- // 确认
- confirmDel() {
- this.btnLoading = true;
- if (this.confirmDelType === "switch") {
- //启用/停用
- let postData = {
- id: this.dataContent.id,
- title: this.dataContent.title,
- executeTime: this.dataContent.executeTime,
- userIds: this.dataContent.userIds,
- active: this.dataContent.active ? false : true,
- content: this.dataContent.content,
- key: this.dataContent.key,
- };
- this.mainService
- .simplePost("updData", "messageJob", postData)
- .subscribe((data) => {
- this.btnLoading = false;
- this.delModal = false;
- if (data.status == 200) {
- this.showPromptModal(this.tipsMsg2, true, "");
- } else {
- this.showPromptModal(this.tipsMsg2, false, data.msg);
- }
- });
- }
- }
- }
|