timing-message-sending.component.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute } 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 { NzMessageService } from "ng-zorro-antd";
  13. import { format } from "date-fns";
  14. @Component({
  15. selector: "app-timing-message-sending",
  16. templateUrl: "./timing-message-sending.component.html",
  17. styleUrls: ["./timing-message-sending.component.less"],
  18. })
  19. export class TimingMessageSendingComponent 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 mainService: MainService,
  29. private route: ActivatedRoute,
  30. private tool: ToolService
  31. ) {}
  32. userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
  33. menu: any = JSON.parse(localStorage.getItem("menu")) || []; //菜单
  34. hosId;
  35. createUser = "";
  36. users = []; // 用户列表
  37. listOfData: any[] = []; //表格数据
  38. pageIndex: number = 1; //表格当前页码
  39. pageSize: number = 10; //表格每页展示条数
  40. listLength: number = 10; //表格总数据量
  41. tableHeight: number; //表格动态高
  42. modal: boolean = false; //新增/编辑模态框
  43. validateForm: FormGroup; //新增/编辑表单
  44. dataContent: any; //当前操作列
  45. oneOption: any; //适用日期类型
  46. btnLoading: boolean = false; //提交按钮loading状态
  47. promptContent: string; //操作提示框提示信息
  48. ifSuccess: boolean; //操作成功/失败
  49. promptInfo: string; //操作结果提示信息
  50. promptModalShow: boolean; //操作提示框是否展示
  51. demoValue: number = 0;
  52. ngOnInit() {
  53. this.hosId = this.tool.getCurrentHospital().id;
  54. this.getList();
  55. this.initCoopBtns();
  56. this.initForm();
  57. }
  58. changeForm(flag) {
  59. if (flag) {
  60. this.changeInp("no", "form");
  61. }
  62. }
  63. // 边输边搜节流阀
  64. isLoading = false;
  65. changeInp(dept, type) {
  66. if (!dept) {
  67. return;
  68. }
  69. if (dept === "no") {
  70. dept = "";
  71. }
  72. this.isLoading = true;
  73. this.searchUsers(dept, type);
  74. }
  75. // 搜索用户
  76. snum = 0;
  77. searchUsers(dept, type) {
  78. let data = {
  79. user: {
  80. name: dept,
  81. hospital: { id: this.hosId },
  82. },
  83. idx: 0,
  84. sum: 20,
  85. };
  86. this.snum++;
  87. this.mainService
  88. .getFetchDataList("data", "user", data)
  89. .subscribe((data) => {
  90. this.snum--;
  91. if (data.status == 200) {
  92. if (type === "form") {
  93. if (this.snum === 0) {
  94. this.isLoading = false;
  95. }
  96. this.users = data.list;
  97. }
  98. }
  99. });
  100. }
  101. // 初始化权限按钮
  102. coopBtns: any = {
  103. edit: false, //编辑
  104. isStartUp: false, //是否启用
  105. };
  106. initCoopBtns() {
  107. // 二级菜单
  108. let secondMenus = [];
  109. this.menu.forEach((e) => {
  110. e.childrens.forEach((el) => {
  111. secondMenus.push(el);
  112. });
  113. });
  114. let link = this.route.parent.snapshot.routeConfig.path;
  115. let btns = [];
  116. secondMenus.forEach((e) => {
  117. if (e.link == link) {
  118. btns = e.childrens || [];
  119. }
  120. });
  121. btns.forEach((e) => {
  122. this.coopBtns[e.link] = true;
  123. });
  124. }
  125. // 表格数据
  126. loading1 = false;
  127. getList() {
  128. let postData = {
  129. idx: this.pageIndex - 1,
  130. sum: this.pageSize,
  131. messageJob: {
  132. hospital: this.hosId,
  133. },
  134. };
  135. this.loading1 = true;
  136. this.mainService
  137. .getFetchDataList("simple/data", "messageJob", postData)
  138. .subscribe((data) => {
  139. this.loading1 = false;
  140. if (data.status == 200) {
  141. this.listOfData = data.list;
  142. this.listOfData.forEach((item) => {
  143. if (item.timeStep == "week") {
  144. let weeks = [
  145. "周一",
  146. "周二",
  147. "周三",
  148. "周四",
  149. "周五",
  150. "周六",
  151. "周日",
  152. ];
  153. item.weekName = weeks[item.extra1 - 1];
  154. }
  155. item.usersName = item.users.map((value) => value.name).join();
  156. });
  157. this.listLength = data.totalNum;
  158. }
  159. });
  160. }
  161. //关闭编辑弹框
  162. hideAddModal() {
  163. this.modal = false;
  164. this.initForm();
  165. }
  166. // 初始化form表单
  167. initForm() {
  168. this.validateForm = this.fb.group({
  169. title: [null, [Validators.required]], //标题
  170. timeStep: ["day", [Validators.required]], //重复策略
  171. executeTime: [null, [Validators.required]], //定时发送时间
  172. active: [false, [Validators.required]], //是否启用
  173. userIds: [null, [Validators.required]], //接收人
  174. });
  175. }
  176. //修改重复策略
  177. months = [...Array(32).keys()].slice(1);
  178. timeStepChange(e) {
  179. switch (e) {
  180. case "day":
  181. this.validateForm.removeControl("doWeek");
  182. this.validateForm.removeControl("doMonth");
  183. this.validateForm.removeControl("doYear");
  184. break;
  185. case "week":
  186. this.validateForm.addControl(
  187. "doWeek",
  188. new FormControl(null, Validators.required)
  189. );
  190. this.validateForm.removeControl("doMonth");
  191. this.validateForm.removeControl("doYear");
  192. break;
  193. case "month":
  194. this.validateForm.addControl(
  195. "doMonth",
  196. new FormControl(null, Validators.required)
  197. );
  198. this.validateForm.removeControl("doWeek");
  199. this.validateForm.removeControl("doYear");
  200. break;
  201. case "year":
  202. this.validateForm.addControl(
  203. "doYear",
  204. new FormControl(null, Validators.required)
  205. );
  206. this.validateForm.removeControl("doWeek");
  207. this.validateForm.removeControl("doMonth");
  208. break;
  209. }
  210. }
  211. // 表单提交
  212. submitForm(): void {
  213. this.btnLoading = true;
  214. for (const i in this.validateForm.controls) {
  215. this.validateForm.controls[i].markAsDirty();
  216. this.validateForm.controls[i].updateValueAndValidity();
  217. }
  218. if (this.validateForm.invalid) {
  219. this.btnLoading = false;
  220. return;
  221. }
  222. let postData: any = {
  223. title: this.validateForm.value.title,
  224. executeTime: new Date(this.validateForm.value.executeTime).getTime(),
  225. userIds: this.validateForm.value.userIds.join(),
  226. active: this.validateForm.value.active,
  227. content: this.dataContent.content,
  228. key: this.dataContent.key,
  229. id: this.dataContent.id,
  230. timeStep: this.validateForm.value.timeStep,
  231. };
  232. if (this.validateForm.value.timeStep == "day") {
  233. delete postData.extra1;
  234. } else if (this.validateForm.value.timeStep == "week") {
  235. postData.extra1 = this.validateForm.value.doWeek;
  236. } else if (this.validateForm.value.timeStep == "month") {
  237. postData.extra1 = this.validateForm.value.doMonth;
  238. } else if (this.validateForm.value.timeStep == "year") {
  239. delete postData.extra1;
  240. postData.executeTime = new Date(
  241. format(this.validateForm.value.doYear, "yyyy-MM-dd") +
  242. " " +
  243. format(new Date(this.validateForm.value.executeTime), "HH:mm:ss")
  244. ).getTime();
  245. }
  246. this.mainService
  247. .simplePost("updData", "messageJob", postData)
  248. .subscribe((data) => {
  249. this.btnLoading = false;
  250. this.hideAddModal();
  251. this.initForm();
  252. if (data.status == 200) {
  253. this.listLength++;
  254. this.showPromptModal("修改", true, "");
  255. } else {
  256. this.showPromptModal("修改", false, data.msg);
  257. }
  258. });
  259. }
  260. // 编辑
  261. maskFlag: any = false;
  262. edit(data) {
  263. this.dataContent = data;
  264. this.validateForm.controls.executeTime.setValue(new Date(data.executeTime)); //定时发送时间
  265. this.validateForm.controls.title.setValue(data.title); //标题
  266. this.validateForm.controls.active.setValue(data.active); //是否启用
  267. this.timeStepChange(data.timeStep);
  268. this.validateForm.controls.timeStep.setValue(data.timeStep); //重复策略
  269. if (data.timeStep == "year") {
  270. this.validateForm.controls.doYear.setValue(
  271. format(data.executeTime, "yyyy-MM-dd HH:mm:ss")
  272. );
  273. } else if (data.timeStep == "month") {
  274. this.validateForm.controls.doMonth.setValue(data.extra1);
  275. } else if (data.timeStep == "week") {
  276. this.validateForm.controls.doWeek.setValue(data.extra1);
  277. }
  278. // --------接收人---
  279. this.maskFlag = this.message.loading("正在加载中..", {
  280. nzDuration: 0,
  281. }).messageId;
  282. this.mainService
  283. .getFetchDataList("data", "user", {
  284. idx: 0,
  285. sum: 20,
  286. user: {
  287. hosId: this.hosId,
  288. },
  289. })
  290. .subscribe((result) => {
  291. this.message.remove(this.maskFlag);
  292. this.maskFlag = false;
  293. this.modal = true;
  294. if (result.status == 200) {
  295. let add = data.users.filter(
  296. (item) => !result.list.some((ele) => ele.id == item.id)
  297. );
  298. this.users = add.concat(result.list);
  299. this.validateForm.controls.userIds.setValue(data.userIds.split(",")); //接收人
  300. }
  301. });
  302. // --------/接收人---
  303. }
  304. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  305. showPromptModal(con, success, promptInfo?) {
  306. this.promptModalShow = false;
  307. this.promptContent = con;
  308. this.ifSuccess = success;
  309. this.promptInfo = promptInfo;
  310. setTimeout(() => {
  311. this.promptModalShow = true;
  312. }, 100);
  313. this.getList();
  314. }
  315. // 是否启用
  316. delModal: boolean = false; //删除模态框
  317. tipsMsg1: string; //提示框信息
  318. tipsMsg2: string; //操作后信息
  319. confirmDelType: string; //确认的类型(启用/停用,删除)
  320. confirmDelIsSwitch: boolean; //启用/停用
  321. showDelModal(
  322. dataContent,
  323. tipsMsg1: string,
  324. tipsMsg2: string,
  325. type: string,
  326. isSwitch?: boolean
  327. ) {
  328. this.confirmDelIsSwitch = isSwitch;
  329. this.confirmDelType = type;
  330. this.delModal = true;
  331. this.dataContent = dataContent;
  332. this.tipsMsg1 = tipsMsg1;
  333. this.tipsMsg2 = tipsMsg2;
  334. }
  335. // 隐藏
  336. hideDelModal() {
  337. this.delModal = false;
  338. }
  339. // 确认
  340. confirmDel() {
  341. this.btnLoading = true;
  342. if (this.confirmDelType === "switch") {
  343. //启用/停用
  344. let postData = {
  345. id: this.dataContent.id,
  346. title: this.dataContent.title,
  347. executeTime: this.dataContent.executeTime,
  348. userIds: this.dataContent.userIds,
  349. active: this.dataContent.active ? false : true,
  350. content: this.dataContent.content,
  351. key: this.dataContent.key,
  352. };
  353. this.mainService
  354. .simplePost("updData", "messageJob", postData)
  355. .subscribe((data) => {
  356. this.btnLoading = false;
  357. this.delModal = false;
  358. if (data.status == 200) {
  359. this.showPromptModal(this.tipsMsg2, true, "");
  360. } else {
  361. this.showPromptModal(this.tipsMsg2, false, data.msg);
  362. }
  363. });
  364. }
  365. }
  366. }