tab-custom.component.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } 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 { forkJoin, Subject } from "rxjs";
  8. import { debounceTime } from "rxjs/operators";
  9. import { NzMessageService } from "ng-zorro-antd";
  10. import { isThisISOWeek } from 'date-fns';
  11. @Component({
  12. selector: "app-tab-custom",
  13. templateUrl: "./tab-custom.component.html",
  14. styleUrls: ["./tab-custom.component.less"],
  15. })
  16. export class TabCustomComponent implements OnInit {
  17. @ViewChild("osComponentRef1", {
  18. read: OverlayScrollbarsComponent,
  19. static: false,
  20. })
  21. osComponentRef1: OverlayScrollbarsComponent;
  22. constructor(
  23. private message: NzMessageService,
  24. private fb: FormBuilder,
  25. private route: ActivatedRoute,
  26. private router: Router,
  27. private mainService: MainService,
  28. private tool: ToolService
  29. ) {}
  30. listOfData: any[] = []; //表格数据
  31. modal: boolean = false; //新增/编辑模态框
  32. add: boolean; //true:新增;false:编辑
  33. validateForm: FormGroup; //新增/编辑表单
  34. coopId: number; //表格中执行操作的id
  35. department: any; //所属科室
  36. num; //工号
  37. name; //姓名
  38. userType: any; //用户类型
  39. hosId: any; //院区(搜索)
  40. userGroup; //所属组
  41. userGroup1; //所属组(搜索)
  42. userTypes: Array<any>; //所有用户类型
  43. alldepart: any = []; //所有所属科室
  44. alldepart1: any = []; //所有所属科室(搜索)
  45. hospitals1: any = []; //院区列表(搜索)
  46. otherTasktypeList: Array<any>; //所有其他临床服务任务类型
  47. allUserRole: Array<any>; //所有角色
  48. pageIndex: number = 1; //页码
  49. listLength: number = 10; //总条数
  50. pageSize: number = 10; //每页条数
  51. promptContent: string; //操作提示框提示信息
  52. ifSuccess: boolean; //操作成功/失败
  53. promptInfo: string; //操作结果提示信息
  54. promptModalShow: boolean; //操作提示框是否展示
  55. btnLoading: boolean = false; //提交按钮loading状态
  56. wxRequired = false; //新增或编辑用户的时候,微信号是否必填
  57. changeInpSubject = new Subject(); //防抖
  58. ngOnInit() {
  59. //防抖
  60. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  61. this.getOtherTasktype(v[0]);
  62. });
  63. this.coopBtns = this.tool.initCoopBtns(this.route);
  64. this.initForm();
  65. this.hosId = this.tool.getCurrentHospital().id;
  66. this.getList();
  67. }
  68. // 初始化增删改按钮
  69. coopBtns: any = {};
  70. // 搜索
  71. search() {
  72. this.pageIndex = 1;
  73. this.getList();
  74. }
  75. // 表格数据
  76. loading1 = false;
  77. getList() {
  78. let data = {
  79. idx: this.pageIndex - 1,
  80. sum: this.pageSize,
  81. tabPermission: {
  82. hosId: this.hosId,
  83. },
  84. };
  85. this.loading1 = true;
  86. this.mainService
  87. .getFetchDataList("simple/data", "tabPermission", data)
  88. .subscribe((data) => {
  89. this.loading1 = false;
  90. this.listOfData = data.list;
  91. this.listLength = data.totalNum;
  92. });
  93. }
  94. // 获取任务类型列表-其他临床服务
  95. getOtherTasktype(keywords = '') {
  96. let hid = this.tool.getCurrentHospital().id;
  97. let postData = {
  98. taskType: {
  99. hosIds: hid,
  100. taskName: keywords,
  101. simpleQuery: true,
  102. associationType: {
  103. key: 'association_types',
  104. value: 'other',
  105. }
  106. },
  107. idx: 0,
  108. sum: 10,
  109. };
  110. this.isLoading = true;
  111. this.mainService.getFetchDataList("configuration", "taskType", postData).subscribe((res) => {
  112. this.isLoading = false;
  113. this.otherTasktypeList = res.list || [];
  114. });
  115. }
  116. // 新增弹框
  117. showModal() {
  118. this.add = true;
  119. this.modal = true;
  120. this.initForm();
  121. }
  122. hideModal() {
  123. this.modal = false;
  124. this.initForm();
  125. }
  126. // 初始化新增form表单
  127. initForm() {
  128. if (this.add) {
  129. this.otherTasktypeList = [];
  130. }
  131. this.validateForm = this.fb.group({
  132. title: ['', [Validators.required]],
  133. orders: [0, [Validators.required]],
  134. taskTypeList: [null],
  135. });
  136. }
  137. // 表单提交
  138. submitForm(): void {
  139. for (const i in this.validateForm.controls) {
  140. this.validateForm.controls[i].markAsDirty({ onlySelf: true });
  141. this.validateForm.controls[i].updateValueAndValidity();
  142. }
  143. if (this.validateForm.invalid) return;
  144. this.btnLoading = true;
  145. let data = {
  146. tabPermission: {
  147. title: this.validateForm.value.title,
  148. orders: this.validateForm.value.orders,
  149. hosId: this.hosId,
  150. deleteFlag: 0,
  151. // taskTypeList: this.validateForm.value.taskTypeList
  152. },
  153. };
  154. if (!this.add) {
  155. data.tabPermission["id"] = this.coopId;
  156. }
  157. console.log(data);
  158. return;
  159. this.mainService
  160. .coopData("addData", "tabPermission", data)
  161. .subscribe((data) => {
  162. this.btnLoading = false;
  163. this.hideModal();
  164. this.initForm();
  165. if (data.status == 200) {
  166. this.showPromptModal(this.add ? "新增" : "编辑", true, "");
  167. } else {
  168. this.showPromptModal(this.add ? "新增" : "编辑", false, data.msg);
  169. }
  170. });
  171. }
  172. // 编辑
  173. maskFlag: any = false;
  174. edit(data) {
  175. this.validateForm.controls.title.setValue(data.title);
  176. this.validateForm.controls.orders.setValue(data.orders);
  177. this.modal = true;
  178. this.add = false;
  179. this.coopId = data.id;
  180. }
  181. // 删除
  182. delModal: boolean = false; //删除模态框
  183. del(data) {
  184. this.coopId = data.id;
  185. this.delModal = true;
  186. }
  187. // 确认删除
  188. confirmDel() {
  189. return;
  190. this.btnLoading = true;
  191. this.mainService
  192. .rmvDataAndWeChatNum([this.coopId], true)
  193. .subscribe((data) => {
  194. this.btnLoading = false;
  195. this.hideDelModal();
  196. if (data["status"] == 200) {
  197. if (
  198. this.listOfData.length == 1 &&
  199. this.pageIndex == Math.ceil(this.listLength / this.pageSize)
  200. ) {
  201. this.listLength--;
  202. this.pageIndex = Math.ceil(this.listLength / this.pageSize);
  203. }
  204. this.showPromptModal("删除", true, "");
  205. } else {
  206. this.showPromptModal("删除", false, data["msg"]);
  207. }
  208. });
  209. }
  210. // 关闭删除模态框
  211. hideDelModal() {
  212. this.delModal = false;
  213. }
  214. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  215. showPromptModal(con, success, promptInfo?) {
  216. this.promptModalShow = false;
  217. this.promptContent = con;
  218. this.ifSuccess = success;
  219. this.promptInfo = promptInfo;
  220. setTimeout(() => {
  221. this.promptModalShow = true;
  222. }, 100);
  223. this.getList();
  224. }
  225. // 边输边搜节流阀
  226. isLoading = false;
  227. changeInp(e) {
  228. this.changeInpSubject.next([e]);
  229. }
  230. // 打开任务类型
  231. openOtherTasktype(e){
  232. if(e){
  233. this.getOtherTasktype();
  234. }
  235. }
  236. }