classes-management.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { ActivatedRoute } from '@angular/router';
  3. import { FormBuilder, Validators, FormGroup, FormControl } from '@angular/forms';
  4. import { MainService } from "../../services/main.service"
  5. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  6. import { ToolService } from '../../services/tool.service';
  7. import { NzMessageService } from 'ng-zorro-antd';
  8. @Component({
  9. selector: 'app-classes-management',
  10. templateUrl: './classes-management.component.html',
  11. styleUrls: ['./classes-management.component.less']
  12. })
  13. export class ClassesManagementComponent implements OnInit {
  14. @ViewChild('osComponentRef1', { read: OverlayScrollbarsComponent, static: false })
  15. osComponentRef1: OverlayScrollbarsComponent;
  16. constructor(
  17. private fb: FormBuilder,
  18. private mainService: MainService,
  19. private route: ActivatedRoute,
  20. private tool: ToolService,
  21. private msg: NzMessageService
  22. ) { }
  23. userInfo: any = JSON.parse(localStorage.getItem('user')) || {};//登录用户信息
  24. hospital: any = null;//院区搜索框
  25. listOfData: any[] = [];//表格数据
  26. pageIndex: number = 1;//表格当前页码
  27. pageSize: number = 10;//表格每页展示条数
  28. listLength: number = 10;//表格总数据量
  29. modal: boolean = false;//新增/编辑模态框
  30. add: boolean;//true:新增;false:编辑
  31. validateForm: FormGroup;//新增/编辑表单
  32. coopId: number;//当前操作列id
  33. oneOption: any;//适用日期类型
  34. btnLoading: boolean = false;//提交按钮loading状态
  35. promptContent: string;//操作提示框提示信息
  36. ifSuccess: boolean;//操作成功/失败
  37. promptInfo: string;//操作结果提示信息
  38. promptModalShow: boolean;//操作提示框是否展示
  39. demoValue: number = 0;
  40. ngOnInit() {
  41. this.coopBtns = this.tool.initCoopBtns(this.route);
  42. this.getAllHospital()
  43. this.initForm();
  44. }
  45. // 初始化增删改按钮
  46. coopBtns: any = {};
  47. // 修改适用日期类型
  48. logDateType(value: object[]): void {
  49. console.log(value);
  50. }
  51. // 获取当前院区
  52. getAllHospital() {
  53. this.hospital = this.tool.getCurrentHospital().id + "";
  54. this.getList();
  55. }
  56. // 表格数据
  57. loading1 = false;
  58. getList(num?: number) {
  59. if (num !== undefined) {
  60. this.pageIndex = num;
  61. }
  62. var data = {
  63. idx: this.pageIndex - 1,
  64. sum: this.pageSize,
  65. scheduleClass: { hospital: { id: this.hospital || '' } }
  66. }
  67. this.loading1 = true;
  68. this.mainService.getFetchDataList('configuration', 'scheduleClass', data).subscribe(data => {
  69. this.loading1 = false;
  70. this.listOfData = data.list;
  71. this.listLength = data.totalNum;
  72. })
  73. }
  74. // 新增/编辑弹框
  75. addModal() {
  76. this.add = true;
  77. this.modal = true;
  78. this.initForm();
  79. }
  80. hideAddModal() {
  81. this.modal = false;
  82. this.initForm();
  83. }
  84. // 初始化新增form表单
  85. initForm() {
  86. this.oneOption = [
  87. { label: '工作日', value: '工作日', checked: false },
  88. { label: '节假日', value: '节假日', checked: false },
  89. ]
  90. this.validateForm = this.fb.group({
  91. classesName: [null, [Validators.required]],
  92. description: [null, [Validators.required]],
  93. datesType: [null, [this.dateValidator]],
  94. // 时间段1
  95. timerF1: [null, [Validators.required]],
  96. timerT1: [null, [Validators.required]],
  97. // 时间段2
  98. timerF2: [null, []],
  99. timerT2: [null, []],
  100. // 时间段3
  101. timerF3: [null, []],
  102. timerT3: [null, []],
  103. });
  104. }
  105. //创建自定义校验规则dateValidator,用于复选框组校验时调用。
  106. selectedDate: any = [];
  107. dateValidator = (control: FormControl): { [s: string]: boolean } => {
  108. this.selectedDate = [];
  109. for (const i in control.value) {
  110. if (control.value[i].checked) {
  111. this.selectedDate.push(control.value[i]);
  112. }
  113. }
  114. if (this.selectedDate.length == 0) {
  115. return { required: true };
  116. }
  117. };
  118. // 时间段选择器校验
  119. timer1Validator = (): { [s: string]: boolean } => {
  120. let that = this;
  121. if (that.validateForm && that.validateForm.value) {
  122. if ((!that.validateForm.value.timerMF1 && that.validateForm.value.timerMF1 != 0) || (!that.validateForm.value.timerSF1 && that.validateForm.value.timerSF1 != 0) || (!that.validateForm.value.timerMT1 && that.validateForm.value.timerMT1 != 0) || (!that.validateForm.value.timerST1 && that.validateForm.value.timerST1 != 0)) {
  123. return { required: true };
  124. }
  125. }
  126. };
  127. timer1Validator1 = (): { [s: string]: boolean } => {
  128. let that = this;
  129. if (that.validateForm && that.validateForm.value) {
  130. if (!that.validateForm.value.timer1 || !that.validateForm.value.timer1) {
  131. return { required: true };
  132. }
  133. }
  134. };
  135. // 新增表单提交
  136. submitForm(): void {
  137. var that = this;
  138. for (const i in that.validateForm.controls) {
  139. that.validateForm.controls[i].markAsDirty();
  140. that.validateForm.controls[i].updateValueAndValidity();
  141. }
  142. if (that.selectedDate) {
  143. var arr = [];
  144. this.validateForm.value.datesType.forEach(e => {
  145. if (e.checked) {
  146. arr.push(e.label)
  147. }
  148. });
  149. if (arr.length == 2) {
  150. that.validateForm.value.datesType = 3
  151. } else {
  152. if (arr[0] == '工作日') {
  153. that.validateForm.value.datesType = 1
  154. } else {
  155. that.validateForm.value.datesType = 2
  156. }
  157. }
  158. }
  159. console.log(that.validateForm)
  160. if (that.validateForm.invalid) return;
  161. let times: any = [];
  162. times = [
  163. {
  164. startTime: "2019-08-28 " + that.validateForm.value.timerF1.getHours() + ":" + that.validateForm.value.timerF1.getMinutes() + ":34",
  165. endTime: "2019-08-28 " + that.validateForm.value.timerT1.getHours() + ":" + that.validateForm.value.timerT1.getMinutes() + ":37"
  166. }
  167. ]
  168. let data = {
  169. scheduleClass:
  170. {
  171. name: that.validateForm.value.classesName,
  172. describe: that.validateForm.value.description,
  173. scheduleClassTimes: times,
  174. type: that.validateForm.value.datesType,
  175. hospital: { id: this.hospital },
  176. deleteFlag: 0
  177. }
  178. }
  179. if (that.validateForm.value.timerF2 && that.validateForm.value.timerT2) {
  180. data.scheduleClass.scheduleClassTimes.push({
  181. startTime: "2019-08-28 " + that.validateForm.value.timerF2.getHours() + ":" + that.validateForm.value.timerF2.getMinutes() + ":34",
  182. endTime: "2019-08-28 " + that.validateForm.value.timerT2.getHours() + ":" + that.validateForm.value.timerT2.getMinutes() + ":37"
  183. })
  184. }
  185. if (that.validateForm.value.timerF3 && that.validateForm.value.timerT3) {
  186. data.scheduleClass.scheduleClassTimes.push({
  187. startTime: "2019-08-28 " + that.validateForm.value.timerF3.getHours() + ":" + that.validateForm.value.timerF3.getMinutes() + ":34",
  188. endTime: "2019-08-28 " + that.validateForm.value.timerT3.getHours() + ":" + that.validateForm.value.timerT3.getMinutes() + ":37"
  189. })
  190. }
  191. console.log(data)
  192. // return;
  193. if (!that.add) {
  194. // 编辑
  195. data.scheduleClass['id'] = that.coopId;
  196. data.scheduleClass.scheduleClassTimes[0]['id'] = that.coopDatas.scheduleClassTimes[0].id;
  197. // 删除班次
  198. if (!data.scheduleClass.scheduleClassTimes[1] && that.coopDatas.scheduleClassTimes[1]) {
  199. data.scheduleClass.scheduleClassTimes.push({});
  200. // data.scheduleClass.scheduleClassTimes[1]['id'] = that.coopDatas.scheduleClassTimes[1].id;
  201. }
  202. if (!data.scheduleClass.scheduleClassTimes[2] && that.coopDatas.scheduleClassTimes[2]) {
  203. data.scheduleClass.scheduleClassTimes.push({});
  204. // data.scheduleClass.scheduleClassTimes[2]['id'] = that.coopDatas.scheduleClassTimes[2].id;
  205. }
  206. if (that.coopDatas.scheduleClassTimes[1]) {
  207. data.scheduleClass.scheduleClassTimes[1]['id'] = that.coopDatas.scheduleClassTimes[1].id;
  208. }
  209. if (that.coopDatas.scheduleClassTimes[2]) {
  210. data.scheduleClass.scheduleClassTimes[2]['id'] = that.coopDatas.scheduleClassTimes[2].id;
  211. }
  212. }
  213. console.log(data)
  214. that.btnLoading = true;
  215. that.mainService.coopTypeConfig((that.add ? 'addData' : 'updData'), 'scheduleClass', data).subscribe(data => {
  216. that.btnLoading = false;
  217. that.hideAddModal();
  218. that.initForm();
  219. if (data.status == 200) {
  220. that.listLength++;
  221. that.showPromptModal((that.add ? '新增' : '编辑'), true, '');
  222. } else {
  223. that.showPromptModal((that.add ? '新增' : '编辑'), false, data.msg);
  224. }
  225. })
  226. }
  227. // 编辑
  228. coopDatas;
  229. edit(data) {
  230. console.log(data);
  231. this.coopDatas = data;
  232. this.add = false;
  233. this.modal = true;
  234. this.coopId = data.id;
  235. this.validateForm.controls.classesName.setValue(data.name);
  236. this.validateForm.controls.description.setValue(data.describe);
  237. if (data.type == 1) {
  238. this.oneOption[0]['checked'] = true;
  239. } else if (data.type == 2) {
  240. this.oneOption[1]['checked'] = true;
  241. } else {
  242. this.oneOption[0]['checked'] = true;
  243. this.oneOption[1]['checked'] = true;
  244. }
  245. let timeF1 = new Date(2018, 11, 12, data.scheduleClassTimes[0].startTime.substring(11, 13), data.scheduleClassTimes[0].startTime.substring(14, 16));
  246. let timeT1 = new Date(2018, 11, 12, data.scheduleClassTimes[0].endTime.substring(11, 13), data.scheduleClassTimes[0].endTime.substring(14, 16));
  247. this.validateForm.controls.timerF1.setValue(timeF1)
  248. this.validateForm.controls.timerT1.setValue(timeT1)
  249. if (data.scheduleClassTimes[1]) {
  250. let timeF2 = new Date(2018, 11, 12, data.scheduleClassTimes[1].startTime.substring(11, 13), data.scheduleClassTimes[1].startTime.substring(14, 16));
  251. let timeT2 = new Date(2018, 11, 12, data.scheduleClassTimes[1].endTime.substring(11, 13), data.scheduleClassTimes[1].endTime.substring(14, 16));
  252. this.validateForm.controls.timerF2.setValue(timeF2)
  253. this.validateForm.controls.timerT2.setValue(timeT2)
  254. }
  255. if (data.scheduleClassTimes[2]) {
  256. let timeF3 = new Date(2018, 11, 12, data.scheduleClassTimes[2].startTime.substring(11, 13), data.scheduleClassTimes[2].startTime.substring(14, 16));
  257. let timeT3 = new Date(2018, 11, 12, data.scheduleClassTimes[2].endTime.substring(11, 13), data.scheduleClassTimes[2].endTime.substring(14, 16));
  258. this.validateForm.controls.timerF3.setValue(timeF3)
  259. this.validateForm.controls.timerT3.setValue(timeT3)
  260. }
  261. }
  262. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  263. showPromptModal(con, success, promptInfo?) {
  264. this.promptModalShow = false;
  265. this.promptContent = con;
  266. this.ifSuccess = success;
  267. this.promptInfo = promptInfo;
  268. setTimeout(() => {
  269. this.promptModalShow = true;
  270. }, 100);
  271. this.getList();
  272. }
  273. // 删除班次
  274. delModal: boolean = false;//删除模态框
  275. showDelModal(id) {
  276. this.delModal = true;
  277. this.coopId = id;
  278. }
  279. // 隐藏删除框
  280. hideDelModal() {
  281. this.delModal = false;
  282. }
  283. // 确认删除
  284. confirmDel() {
  285. this.delModal = false;
  286. this.btnLoading = true;
  287. this.mainService.coopData('rmvData', 'scheduleClass', [this.coopId]).subscribe(data => {
  288. this.btnLoading = false;
  289. if (data.status == 200) {
  290. if (this.listOfData.length == 1 && this.pageIndex == Math.ceil(this.listLength / this.pageSize)) {
  291. this.listLength--;
  292. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  293. }
  294. this.showPromptModal('删除', true, '');
  295. } else {
  296. this.showPromptModal('删除', false, data.msg);
  297. }
  298. })
  299. }
  300. // 刷新缓存
  301. refreshLoading = false;
  302. refreshTaskType() {
  303. this.refreshLoading = true;
  304. this.mainService.refreshTaskType().subscribe(result => {
  305. this.refreshLoading = false;
  306. if (result.state == 200) {
  307. this.msg.create('success', '刷新缓存成功!');
  308. } else {
  309. this.msg.create('error', result.msg);
  310. }
  311. })
  312. }
  313. }