limit-initiation-time.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import { ToolService } from "../../services/tool.service";
  5. import { LimitInitiationTimeService } from './limit-initiation-time.service';
  6. import { Subject } from 'rxjs';
  7. import { debounceTime } from 'rxjs/operators';
  8. import { format, startOfMinute, endOfMinute } from 'date-fns';
  9. import { NzMessageService } from 'ng-zorro-antd/message';
  10. @Component({
  11. selector: "app-limit-initiation-time",
  12. templateUrl: "./limit-initiation-time.component.html",
  13. styleUrls: ["./limit-initiation-time.component.less"],
  14. })
  15. export class LimitInitiationTimeComponent implements OnInit {
  16. constructor(
  17. private fb: FormBuilder,
  18. private limitInitiationTimeService: LimitInitiationTimeService,
  19. private route: ActivatedRoute,
  20. private tool: ToolService,
  21. private message: NzMessageService,
  22. ) {}
  23. userInfo: any = JSON.parse(localStorage.getItem("user")) || {}; //登录用户信息
  24. listOfData: any[] = []; //表格数据
  25. pageIndex: number = 1; //表格当前页码
  26. pageSize: number = 10; //表格每页展示条数
  27. listLength: number = 10; //表格总数据量
  28. tableHeight: number; //表格动态高
  29. modal: boolean = false; //新增/编辑模态框
  30. add: boolean; //true:新增;false:编辑
  31. validateForm: FormGroup; //新增/编辑表单
  32. coopId: any; //当前操作列
  33. currentHospital; //当前院区
  34. btnLoading: boolean = false; //提交按钮loading状态
  35. promptContent: string; //操作提示框提示信息
  36. ifSuccess: boolean; //操作成功/失败
  37. promptInfo: string; //操作结果提示信息
  38. promptModalShow: boolean; //操作提示框是否展示
  39. modelName = ""; //模态框名称
  40. changeInpSubject = new Subject(); //防抖
  41. ngOnInit() {
  42. //防抖
  43. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  44. if(v[1] === 'taskType'){
  45. this.getTaskTypeList(true, v[0]);
  46. }else if(v[1] === 'building'){
  47. this.getBuildingList(true, v[0]);
  48. }else if(v[1] === 'department'){
  49. this.getDepartmentList(true, v[0]);
  50. }
  51. });
  52. this.currentHospital = this.tool.getCurrentHospital();
  53. this.coopBtns = this.tool.initCoopBtns(this.route);
  54. this.initForm();
  55. this.getList(1);
  56. }
  57. // 初始化增删改按钮
  58. coopBtns: any = {};
  59. // 表格数据
  60. loading1 = false;
  61. getList(type) {
  62. if (type == 1) {
  63. this.pageIndex = 1;
  64. }
  65. let data = {
  66. idx: this.pageIndex - 1,
  67. sum: this.pageSize,
  68. workTimeRule: {
  69. hosId: this.currentHospital.id,
  70. },
  71. };
  72. this.loading1 = true;
  73. this.limitInitiationTimeService
  74. .getFetchDataList(data)
  75. .subscribe((data) => {
  76. this.loading1 = false;
  77. if (data.status == 200) {
  78. this.listOfData = data.list;
  79. this.listLength = data.totalNum;
  80. }
  81. });
  82. }
  83. //打开查询任务类型下拉框
  84. isLoading:boolean = false;
  85. taskTypeList:any[] = [];
  86. getTaskTypeList(flag, keyWord = '') {
  87. if (flag) {
  88. let postData = {
  89. idx: 0,
  90. sum: 9999,
  91. taskType: {
  92. simpleQuery: true,
  93. taskName: keyWord,
  94. hosId: {
  95. id: this.currentHospital.id,
  96. },
  97. }
  98. };
  99. this.isLoading = true;
  100. this.limitInitiationTimeService
  101. .getTaskTypes(postData)
  102. .subscribe((data) => {
  103. this.isLoading = false;
  104. if (data.status == 200) {
  105. this.taskTypeList = data.list;
  106. }
  107. });
  108. }
  109. }
  110. //打开查询楼栋下拉框
  111. buildingList:any[] = [];
  112. getBuildingList(flag, keyWord = '') {
  113. if (flag) {
  114. let postData = {
  115. idx: 0,
  116. sum: 9999,
  117. building: {
  118. simpleQuery: true,
  119. buildingName: keyWord,
  120. cascadeHosId: this.currentHospital.id,
  121. }
  122. };
  123. this.isLoading = true;
  124. this.limitInitiationTimeService
  125. .getBuildings(postData)
  126. .subscribe((data) => {
  127. this.isLoading = false;
  128. if (data.status == 200) {
  129. this.buildingList = data.list;
  130. }
  131. });
  132. }
  133. }
  134. //打开查询科室下拉框
  135. departmentList:any[] = [];
  136. getDepartmentList(flag, keyWord = '') {
  137. if (flag) {
  138. let postData = {
  139. idx: 0,
  140. sum: 9999,
  141. department: {
  142. searchType: 1,// 简单查询
  143. dept: keyWord,
  144. cascadeHosId: this.currentHospital.id,
  145. }
  146. };
  147. this.isLoading = true;
  148. this.limitInitiationTimeService
  149. .getDepartments(postData)
  150. .subscribe((data) => {
  151. this.isLoading = false;
  152. if (data.status == 200) {
  153. this.departmentList = data.list;
  154. }
  155. });
  156. }
  157. }
  158. //搜索
  159. changeInp(e, type) {
  160. this.isLoading = true;
  161. this.changeInpSubject.next([e, type]);
  162. }
  163. // 新增弹框
  164. addModal() {
  165. this.modelName = "新增";
  166. this.add = true; //新增
  167. this.modal = true;
  168. this.initForm();
  169. }
  170. //关闭新增/编辑弹框
  171. hideAddModal() {
  172. this.modal = false;
  173. this.initForm();
  174. }
  175. //服务时间选择
  176. // 禁用的小时
  177. startTimeHourdis() {
  178. return [];
  179. }
  180. endTimeHourdis() {
  181. return [];
  182. }
  183. // 禁用的分钟
  184. startTimeMindis() {
  185. return [];
  186. }
  187. endTimeMindis() {
  188. return [];
  189. }
  190. timeChange(e: boolean, type: string) {
  191. if (!e && this.validateForm.value[type]) {
  192. let hour = new Date(this.validateForm.value[type]).getHours();
  193. // let minute = new Date(this.validateForm.value[type]).getMinutes();
  194. if (type == "startTime") {
  195. this.endTimeHourdis = () => this.generateArray(0, hour);
  196. // this.endTimeMindis = () => this.generateArray(0, minute + 1);
  197. } else if (type == "endTime") {
  198. this.startTimeHourdis = () => this.generateArray(hour + 1, 24);
  199. // this.startTimeMindis = () => this.generateArray(minute, 60);
  200. }
  201. }
  202. }
  203. /**
  204. * 生成一个从 start 到 end 的连续数组
  205. * @param start
  206. * @param end
  207. */
  208. generateArray(start, end) {
  209. return Array.from(new Array(end).keys()).slice(start);
  210. }
  211. // 初始化新增form表单
  212. initForm() {
  213. this.endTimeHourdis = () => [];
  214. this.endTimeMindis = () => [];
  215. this.startTimeHourdis = () => [];
  216. this.startTimeMindis = () => [];
  217. this.validateForm = this.fb.group({
  218. taskType: [null, [Validators.required]],
  219. limitAllDept: [1, [Validators.required]],
  220. buildingIds: [[]],
  221. deptIds: [[]],
  222. limitType: [1, [Validators.required]],
  223. startTime: [null],
  224. endTime: [null],
  225. remark: ['', [Validators.required]],
  226. });
  227. }
  228. // 修改是否限制所有科室
  229. changeLimitAllDept(e){
  230. this.validateForm.controls.buildingIds.setValue([]);
  231. this.validateForm.controls.deptIds.setValue([]);
  232. }
  233. // 新增/编辑表单提交
  234. submitForm(): void {
  235. for (const i in this.validateForm.controls) {
  236. this.validateForm.controls[i].markAsDirty();
  237. this.validateForm.controls[i].updateValueAndValidity();
  238. }
  239. if (this.validateForm.invalid) {
  240. return;
  241. }
  242. if(this.validateForm.value.limitAllDept == 0 && !this.validateForm.value.buildingIds.length && !this.validateForm.value.deptIds.length){
  243. this.message.info('请设置楼栋或科室!');
  244. return;
  245. }
  246. if((/^\s+/.test(this.validateForm.value.remark) || /\s+$/.test(this.validateForm.value.remark)) && !this.validateForm.value.remark.trim()){
  247. this.message.info('请设置提示备注!');
  248. return;
  249. }
  250. if(this.validateForm.value.startTime.getTime() >= this.validateForm.value.endTime.getTime()){
  251. this.message.info('开始时间不能大于结束时间!');
  252. return;
  253. }
  254. this.btnLoading = true;
  255. let data = {};
  256. if (this.add) {
  257. //增加
  258. data = {
  259. taskType: this.validateForm.value.taskType,
  260. limitAllDept: this.validateForm.value.limitAllDept,
  261. buildingIds: this.validateForm.value.buildingIds.length ? this.validateForm.value.buildingIds.toString() : null,
  262. deptIds: this.validateForm.value.deptIds.length ? this.validateForm.value.deptIds.toString() : null,
  263. limitType: this.validateForm.value.limitType,
  264. startTime: format(startOfMinute(this.validateForm.value.startTime), "yyyy-MM-dd HH:mm:ss"),
  265. endTime: format(endOfMinute(this.validateForm.value.endTime), "yyyy-MM-dd HH:mm:ss"),
  266. remark: this.validateForm.value.remark.trim(),
  267. hosId: this.currentHospital.id,
  268. };
  269. } else {
  270. //编辑
  271. data = {
  272. ...this.coopId,
  273. taskType: this.validateForm.value.taskType,
  274. limitAllDept: this.validateForm.value.limitAllDept,
  275. buildingIds: this.validateForm.value.buildingIds.length ? this.validateForm.value.buildingIds.toString() : null,
  276. deptIds: this.validateForm.value.deptIds.length ? this.validateForm.value.deptIds.toString() : null,
  277. limitType: this.validateForm.value.limitType,
  278. startTime: format(startOfMinute(this.validateForm.value.startTime), "yyyy-MM-dd HH:mm:ss"),
  279. endTime: format(endOfMinute(this.validateForm.value.endTime), "yyyy-MM-dd HH:mm:ss"),
  280. remark: this.validateForm.value.remark.trim(),
  281. hosId: this.currentHospital.id,
  282. };
  283. }
  284. this.limitInitiationTimeService
  285. .simplePost("addData", "workTimeRule", data)
  286. .subscribe((result) => {
  287. this.btnLoading = false;
  288. this.hideAddModal();
  289. this.initForm();
  290. if (result.status == 200) {
  291. if (this.add) {
  292. this.showPromptModal("新增", true, "");
  293. this.listLength++;
  294. }else{
  295. this.showPromptModal("编辑", true, "");
  296. }
  297. } else {
  298. this.showPromptModal(this.add ? '新增' : '修改', false, result.msg);
  299. }
  300. });
  301. }
  302. // 编辑
  303. edit(data) {
  304. console.log(data);
  305. this.modelName = "编辑";
  306. this.add = false;
  307. this.modal = true;
  308. this.coopId = data;
  309. this.taskTypeList = data.taskTypeDTO ? [data.taskTypeDTO] : [];
  310. this.validateForm.controls.taskType.setValue(data.taskType); //任务类型
  311. this.validateForm.controls.limitAllDept.setValue(data.limitAllDept); //是否限制所有科室
  312. this.buildingList = data.buildingList || [];
  313. this.validateForm.controls.buildingIds.setValue(this.buildingList.map(v => v.id)); //楼栋
  314. this.departmentList = data.deptList || [];
  315. this.validateForm.controls.deptIds.setValue( this.departmentList.map(v => v.id)); //科室
  316. this.validateForm.controls.limitType.setValue(data.limitType); //限制方式
  317. if (data.startTime && data.endTime) {
  318. this.validateForm.controls.startTime.setValue(new Date(data.startTime));
  319. this.validateForm.controls.endTime.setValue(new Date(data.endTime));
  320. }
  321. this.validateForm.controls.remark.setValue(data.remark); //提示备注
  322. }
  323. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  324. showPromptModal(con, success, promptInfo?) {
  325. this.promptModalShow = false;
  326. this.promptContent = con;
  327. this.ifSuccess = success;
  328. this.promptInfo = promptInfo;
  329. setTimeout(() => {
  330. this.promptModalShow = true;
  331. }, 100);
  332. this.getList(0);
  333. }
  334. delModal: boolean = false; //删除模态框
  335. tipsMsg1: string; //提示框信息
  336. tipsMsg2: string; //操作后信息
  337. confirmDelType: string; //确认的类型(启用/停用,删除)
  338. showDelModal(
  339. data,
  340. tipsMsg1: string,
  341. tipsMsg2: string,
  342. type: string,
  343. ) {
  344. this.confirmDelType = type;
  345. this.delModal = true;
  346. this.coopId = data;
  347. this.tipsMsg1 = tipsMsg1;
  348. this.tipsMsg2 = tipsMsg2;
  349. }
  350. // 隐藏删除框
  351. hideDelModal() {
  352. this.delModal = false;
  353. }
  354. // 确认删除
  355. confirmDel() {
  356. this.btnLoading = true;
  357. if (this.confirmDelType === "del") {
  358. //删除
  359. this.limitInitiationTimeService
  360. .simplePost("rmvData", "workTimeRule", [this.coopId.id])
  361. .subscribe((data) => {
  362. this.btnLoading = false;
  363. this.delModal = false;
  364. if (data.status == 200) {
  365. if (
  366. this.listOfData.length == 1 &&
  367. this.pageIndex == Math.ceil(this.listLength / this.pageSize)
  368. ) {
  369. this.listLength--;
  370. if (this.listLength === 0) {
  371. this.pageIndex = 1;
  372. } else {
  373. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  374. }
  375. }
  376. this.showPromptModal(this.tipsMsg2, true, "");
  377. } else {
  378. this.showPromptModal(this.tipsMsg2, false, data.msg);
  379. }
  380. });
  381. }
  382. }
  383. }