questionnaire-management.component.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. import { Component, OnInit } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import setSeconds from "date-fns/setSeconds";
  5. import setMinutes from "date-fns/setMinutes";
  6. import setHours from "date-fns/setHours";
  7. import { MainService } from "../../services/main.service";
  8. import { DisabledTimeFn } from "ng-zorro-antd/date-picker/standard-types";
  9. import { ToolService } from "../../services/tool.service";
  10. @Component({
  11. selector: "app-questionnaire-management",
  12. templateUrl: "./questionnaire-management.component.html",
  13. styleUrls: ["./questionnaire-management.component.less"],
  14. })
  15. export class QuestionnaireManagementComponent implements OnInit {
  16. constructor(
  17. private fb: FormBuilder,
  18. private mainService: MainService,
  19. private route: ActivatedRoute,
  20. private router: Router,
  21. private tool: ToolService
  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. dateModal: boolean = false; //定时启用设置日期模态框
  31. add: boolean; //true:新增;false:编辑
  32. validateForm: FormGroup; //新增/编辑表单
  33. validateDateForm: FormGroup; //定时启动设置日期表单
  34. coopId: any; //当前操作列
  35. currentHospital; //当前院区
  36. timeDefaultValue = setHours(setMinutes(setSeconds(new Date(), 0), 0), 0);
  37. btnLoading: boolean = false; //提交按钮loading状态
  38. promptContent: string; //操作提示框提示信息
  39. ifSuccess: boolean; //操作成功/失败
  40. promptInfo: string; //操作结果提示信息
  41. promptModalShow: boolean; //操作提示框是否展示
  42. nextSchemeName = ""; //下一个开启的方案名称
  43. modelName = ""; //模态框名称
  44. ngOnInit() {
  45. this.currentHospital = this.tool.getCurrentHospital();
  46. this.coopBtns = this.tool.initCoopBtns(this.route);
  47. this.initForm();
  48. this.getList(1);
  49. this.getSurveyTarget();
  50. }
  51. // 初始化增删改按钮
  52. coopBtns: any = {};
  53. // 获取字典数据-调查目标
  54. surveyTargets: any[] = [];
  55. getSurveyTarget() {
  56. this.mainService
  57. .getDictionary("list", "survey_target")
  58. .subscribe((data) => {
  59. this.surveyTargets = data;
  60. });
  61. }
  62. // 表格数据
  63. loading1 = false;
  64. getList(type) {
  65. if (type == 1) {
  66. this.pageIndex = 1;
  67. }
  68. let data = {
  69. idx: this.pageIndex - 1,
  70. sum: this.pageSize,
  71. workScheme: {
  72. hosId: this.currentHospital.id,
  73. },
  74. };
  75. this.loading1 = true;
  76. this.mainService
  77. .getFetchDataList("configuration", "workScheme", data)
  78. .subscribe((data) => {
  79. this.loading1 = false;
  80. if (data.status == 200) {
  81. this.listOfData = data.list;
  82. this.listLength = data.totalNum;
  83. }
  84. });
  85. }
  86. // 新增弹框
  87. addModal() {
  88. this.modelName = "新增";
  89. this.add = true; //新增
  90. this.modal = true;
  91. this.copyModel = false;
  92. this.initForm();
  93. }
  94. //关闭新增/编辑弹框
  95. hideAddModal() {
  96. this.modal = false;
  97. this.initForm();
  98. }
  99. // 新增/编辑弹框
  100. timeFlag = ""; //open开启,close关闭
  101. addDateModal(data) {
  102. if (!data.timingStatus) {
  103. this.datePicker = "";
  104. }
  105. this.timeFlag = data.timingStatus ? "close" : "open";
  106. this.coopId = data;
  107. if (this.timeFlag == "close") {
  108. this.showDelModal(
  109. data,
  110. "是否确定关闭定时启用?确定后该方案将不会执行!",
  111. "关闭定时启用",
  112. "switchTime"
  113. );
  114. } else {
  115. this.dateModal = true;
  116. }
  117. this.initDateForm();
  118. }
  119. //关闭定时启用设置日期弹框
  120. hideDateModal() {
  121. this.dateModal = false;
  122. this.initDateForm();
  123. }
  124. // 初始化新增form表单
  125. initForm() {
  126. this.validateForm = this.fb.group({
  127. title: [null, [Validators.required]],
  128. surveyTarget: [null, [Validators.required]],
  129. surveyDescribe: [null, [Validators.required]],
  130. });
  131. }
  132. // 初始化新增form表单
  133. initDateForm() {
  134. this.validateDateForm = this.fb.group({
  135. datePickerTime: [null, [Validators.required]],
  136. });
  137. }
  138. // 新增/编辑表单提交
  139. btnLoading1 = false; //完成
  140. submitForm(noGoTo?): void {
  141. for (const i in this.validateForm.controls) {
  142. this.validateForm.controls[i].markAsDirty();
  143. this.validateForm.controls[i].updateValueAndValidity();
  144. }
  145. if (this.validateForm.invalid) {
  146. return;
  147. }
  148. if (noGoTo) {
  149. this.btnLoading1 = true;
  150. } else {
  151. this.btnLoading = true;
  152. }
  153. let data = {};
  154. if (this.add) {
  155. //增加
  156. data = {
  157. questionnaireManagement: {
  158. title: this.validateForm.value.title,
  159. surveyTarget: { id: parseInt(this.validateForm.value.surveyTarget) },
  160. surveyDescribe: this.validateForm.value.surveyDescribe,
  161. hosId: this.currentHospital.id,
  162. },
  163. };
  164. } else {
  165. //编辑
  166. data = {
  167. questionnaireManagement: {
  168. id: this.coopId.id,
  169. title: this.validateForm.value.title,
  170. surveyTarget: this.validateForm.value.surveyTarget,
  171. surveyDescribe: this.validateForm.value.surveyDescribe,
  172. hosId: this.currentHospital.id,
  173. },
  174. };
  175. }
  176. if (this.copyModel) {
  177. //复制
  178. data = {
  179. workScheme: {
  180. name: this.validateForm.value.title,
  181. workType: this.validateForm.value.surveyTarget,
  182. describe: this.validateForm.value.surveyDescribe,
  183. status: 0,
  184. copy: 1,
  185. copySchemeId: this.coopId.id,
  186. hosId: this.currentHospital.id,
  187. },
  188. };
  189. }
  190. this.mainService
  191. .apiPost("addData", "questionnaireManagement", data)
  192. .subscribe((result) => {
  193. if (noGoTo) {
  194. this.btnLoading1 = false;
  195. } else {
  196. this.btnLoading = false;
  197. }
  198. this.hideAddModal();
  199. this.initForm();
  200. if (result.status == 200) {
  201. if (this.copyModel) {
  202. //复制
  203. this.listLength++;
  204. this.showPromptModal("复制", true, "");
  205. if (!noGoTo) {
  206. this.router.navigateByUrl(
  207. `/main/quickCombination?id=${result.data.id}&name=${result.data.name}&type=${result.data.workType}`
  208. );
  209. }
  210. return;
  211. }
  212. if (!this.add) {
  213. //编辑
  214. this.showPromptModal("编辑", true, "");
  215. if (!noGoTo) {
  216. this.router.navigateByUrl(
  217. `/main/quickCombination?id=${result.data.id}&name=${result.data.name}&type=${result.data.workType}`
  218. );
  219. }
  220. return;
  221. }
  222. if (this.add) {
  223. this.listLength++;
  224. }
  225. return;
  226. this.router.navigateByUrl(
  227. `/main/quickCombination?id=${result.data.id}&name=${result.data.name}&type=${result.data.workType}`
  228. );
  229. } else {
  230. let msg = "";
  231. if (this.add) {
  232. msg = "新增";
  233. } else {
  234. msg = "修改";
  235. }
  236. if (this.copyModel) {
  237. msg = "复制";
  238. }
  239. this.showPromptModal(msg, false, result.msg);
  240. }
  241. });
  242. }
  243. // 时间选择范围
  244. disabledDateTime: DisabledTimeFn = () => {
  245. return {
  246. nzDisabledHours: () => [],
  247. nzDisabledMinutes: () => [],
  248. nzDisabledSeconds: () => this.range(1, 60),
  249. };
  250. };
  251. range(start: number, end: number): number[] {
  252. const result: number[] = [];
  253. for (let i = start; i < end; i++) {
  254. result.push(i);
  255. }
  256. return result;
  257. }
  258. // 选择日期表单提交
  259. submitDateForm(): void {
  260. this.btnLoading = true;
  261. for (const i in this.validateDateForm.controls) {
  262. this.validateDateForm.controls[i].markAsDirty();
  263. this.validateDateForm.controls[i].updateValueAndValidity();
  264. }
  265. if (this.validateDateForm.invalid) {
  266. this.btnLoading = false;
  267. return;
  268. }
  269. let data = {};
  270. let todayDate = new Date(this.validateDateForm.value.datePickerTime);
  271. let year = todayDate.getFullYear();
  272. let month = (todayDate.getMonth() + 1).toString().padStart(2, "0");
  273. let date = todayDate.getDate().toString().padStart(2, "0");
  274. let hour = todayDate.getHours().toString().padStart(2, "0");
  275. let minutes = todayDate.getMinutes().toString().padStart(2, "0");
  276. // 2020-07-28 16:45:00
  277. data = {
  278. workScheme: {
  279. id: this.coopId.id,
  280. timingStatus: 1,
  281. startTime: `${year}-${month}-${date} ${hour}:${minutes}:00`,
  282. hosId: this.currentHospital.id,
  283. },
  284. };
  285. this.mainService
  286. .coopTypeConfig("addData", "workScheme", data)
  287. .subscribe((data) => {
  288. this.btnLoading = false;
  289. this.hideDateModal();
  290. this.initDateForm();
  291. if (data.status == 200) {
  292. this.listLength++;
  293. this.showPromptModal("定时启用时间设置", true, "");
  294. } else {
  295. this.showPromptModal("定时启用时间设置", false, data.msg);
  296. }
  297. });
  298. }
  299. // 编辑
  300. edit(data) {
  301. console.log(data);
  302. this.modelName = "编辑";
  303. this.add = false;
  304. this.modal = true;
  305. this.coopId = data;
  306. this.copyModel = false;
  307. this.validateForm.controls.title.setValue(data.name); //名称
  308. this.validateForm.controls.surveyTarget.setValue(data.workType + ""); //类型
  309. this.validateForm.controls.surveyDescribe.setValue(data.describe); //描述
  310. }
  311. //复制
  312. copyModel = false; //复制
  313. copy(data) {
  314. this.modelName = "复制";
  315. this.copyModel = true;
  316. this.modal = true;
  317. this.coopId = data;
  318. this.validateForm.controls.title.setValue(data.name); //名称
  319. this.validateForm.controls.surveyTarget.setValue(data.workType + ""); //类型
  320. this.validateForm.controls.surveyDescribe.setValue(data.describe); //描述
  321. }
  322. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  323. // promptModalUrl = '';
  324. showPromptModal(con, success, promptInfo?) {
  325. this.promptModalShow = false;
  326. this.promptContent = con;
  327. this.ifSuccess = success;
  328. this.promptInfo = promptInfo;
  329. // this.promptModalUrl = url;
  330. setTimeout(() => {
  331. this.promptModalShow = true;
  332. }, 100);
  333. this.getList(0);
  334. }
  335. // 启用
  336. delModal: boolean = false; //删除模态框
  337. tipsMsg1: string; //提示框信息
  338. tipsMsg2: string; //操作后信息
  339. confirmDelType: string; //确认的类型(启用/停用,删除)
  340. confirmDelIsSwitch: boolean; //启用/停用
  341. showDelModal(
  342. data,
  343. tipsMsg1: string,
  344. tipsMsg2: string,
  345. type: string,
  346. isSwitch?: boolean
  347. ) {
  348. this.confirmDelIsSwitch = isSwitch;
  349. this.confirmDelType = type;
  350. this.delModal = true;
  351. this.coopId = data;
  352. this.tipsMsg1 = tipsMsg1;
  353. this.tipsMsg2 = tipsMsg2;
  354. }
  355. // 隐藏删除框
  356. hideDelModal() {
  357. this.delModal = false;
  358. }
  359. // 确认删除
  360. confirmDel() {
  361. this.btnLoading = true;
  362. if (this.confirmDelType === "del") {
  363. //删除
  364. this.mainService
  365. .coopTypeConfig("rmvData", "workScheme", [this.coopId.id])
  366. .subscribe((data) => {
  367. this.btnLoading = false;
  368. this.delModal = false;
  369. if (data.status == 200) {
  370. if (
  371. this.listOfData.length == 1 &&
  372. this.pageIndex == Math.ceil(this.listLength / this.pageSize)
  373. ) {
  374. this.listLength--;
  375. if (this.listLength === 0) {
  376. this.pageIndex = 1;
  377. } else {
  378. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  379. }
  380. }
  381. this.showPromptModal(this.tipsMsg2, true, "");
  382. } else {
  383. this.showPromptModal(this.tipsMsg2, false, data.msg);
  384. }
  385. });
  386. } else if (this.confirmDelType === "switch") {
  387. //启用
  388. let data = {
  389. workScheme: {
  390. id: this.coopId.id,
  391. hosId: this.currentHospital.id,
  392. status: 1,
  393. workType: this.coopId.workType,
  394. },
  395. };
  396. this.mainService
  397. .coopConfig("activeWorkScheme", data)
  398. .subscribe((result) => {
  399. this.btnLoading = false;
  400. this.delModal = false;
  401. if (result.status == 200) {
  402. this.showPromptModal(this.tipsMsg2, true, "");
  403. } else {
  404. this.showPromptModal(this.tipsMsg2, false, result.msg);
  405. }
  406. });
  407. } else if (this.confirmDelType === "switchTime") {
  408. //关闭定时启用
  409. let data = {
  410. workScheme: {
  411. id: this.coopId.id,
  412. hosId: this.currentHospital.id,
  413. timingStatus: 0,
  414. },
  415. };
  416. this.mainService
  417. .coopTypeConfig("addData", "workScheme", data)
  418. .subscribe((result) => {
  419. this.btnLoading = false;
  420. this.delModal = false;
  421. if (result.status == 200) {
  422. this.showPromptModal(this.tipsMsg2, true, "");
  423. } else {
  424. this.showPromptModal(this.tipsMsg2, false, result.msg);
  425. }
  426. });
  427. }
  428. }
  429. // 查看
  430. detail(id) {
  431. this.router.navigateByUrl(
  432. "/main/workAssignment/workAssignmentDetail/" + id
  433. );
  434. }
  435. //时间选择框相关
  436. defaultTimePickerOpenValue = new Date();
  437. // 更改日期
  438. datePicker;
  439. datePickerChange(e) {
  440. if (!e) {
  441. return;
  442. }
  443. let todayDate = new Date(e);
  444. let year = todayDate.getFullYear();
  445. let month = (todayDate.getMonth() + 1).toString().padStart(2, "0");
  446. let date = todayDate.getDate().toString().padStart(2, "0");
  447. let hour = todayDate.getHours().toString().padStart(2, "0");
  448. let minutes = todayDate.getMinutes().toString().padStart(2, "0");
  449. this.datePicker = `${year}-${month}-${date} ${hour}:${minutes}:00`;
  450. }
  451. }