configuration-inspect-inspects.component.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. import { Component, OnInit, Input } from "@angular/core";
  2. import { Subject } from 'rxjs';
  3. import { debounceTime } from 'rxjs/operators';
  4. import { Validators, FormGroup, FormBuilder } from '@angular/forms';
  5. import { ToolService } from 'src/app/services/tool.service';
  6. import { NzMessageService } from 'ng-zorro-antd';
  7. import { MainService } from 'src/app/services/main.service';
  8. @Component({
  9. selector: "app-configuration-inspect-inspects",
  10. templateUrl: "./configuration-inspect-inspects.component.html",
  11. styleUrls: ["./configuration-inspect-inspects.component.less"],
  12. })
  13. export class ConfigurationInspectInspectsComponent implements OnInit {
  14. constructor(
  15. private mainService: MainService,
  16. private fb: FormBuilder,
  17. private tool: ToolService,
  18. private message: NzMessageService,
  19. ) {}
  20. coopData: any = {}; //当前操作列
  21. hosId: any = this.tool.getCurrentHospital().id;
  22. searchTimerSubject = new Subject();
  23. ngOnInit() {
  24. this.searchTimerSubject.pipe(debounceTime(500)).subscribe((v) => {
  25. let fun = v[0];
  26. fun.call(this, v[1]);
  27. });
  28. setTimeout(() => {
  29. this.tableWechatHeight = document.querySelector('#wechatTable').clientHeight - document.querySelector('#wechatTable .list-template__top').clientHeight - 8 - document.querySelector('#wechatTable .thead').clientHeight;
  30. }, 0)
  31. this.getTypes();
  32. this.getList();
  33. }
  34. // 新增弹框
  35. modelName = ""; //模态框名称
  36. modalWechat: boolean = false; //新增/编辑模态框
  37. add: boolean; //true:新增;false:编辑
  38. addWechatModal() {
  39. this.modelName = "新增";
  40. this.add = true; //新增
  41. this.modalWechat = true;
  42. this.initWechatForm();
  43. }
  44. //关闭新增/编辑弹框
  45. hideWechatModal() {
  46. this.modalWechat = false;
  47. }
  48. // 编辑
  49. editWechat(data) {
  50. console.log(data);
  51. this.modelName = "编辑";
  52. this.add = false;
  53. this.modalWechat = true;
  54. this.initWechatForm();
  55. this.coopData = data;
  56. this.validateForm.controls.orders.setValue(data.orders);
  57. this.validateForm.controls.name.setValue(data.name);
  58. this.validateForm.controls.extra6.setValue(data.extra6);
  59. this.validateForm.controls.extra4.setValue(data.extra4DTO ? data.extra4DTO.id : null);
  60. this.validateForm.controls.extra5.setValue(data.extra5DTO ? data.extra5DTO.id : null);
  61. this.validateForm.controls.extra7.setValue(data.deptList ? data.deptList.map(v => v.id) : []);
  62. data.extra4DTO && (this.deptList = [data.extra4DTO]);
  63. data.deptList && (this.deptsList = data.deptList);
  64. }
  65. // 新增/编辑表单提交
  66. btnLoading: boolean = false; //提交按钮loading状态
  67. submitWechatForm(): void {
  68. for (const i in this.validateForm.controls) {
  69. this.validateForm.controls[i].markAsDirty();
  70. this.validateForm.controls[i].updateValueAndValidity();
  71. }
  72. if (this.validateForm.invalid) {
  73. return;
  74. }
  75. console.log(this.validateForm.value);
  76. this.btnLoading = true;
  77. let postData:any = {};
  78. let arr = this.dataList.filter(
  79. (item) => item.name == this.validateForm.value.name && item.id != this.coopData.id
  80. );
  81. //有重复名称
  82. if (arr.length > 0) {
  83. this.btnLoading = false;
  84. this.showPromptModal(
  85. this.add ? "新增" : "编辑",
  86. false,
  87. `存在重复的检查项目名称【${this.validateForm.value.name}】请修改后再保存!`
  88. );
  89. return;
  90. }
  91. if (this.add) {
  92. //增加
  93. let n = 0;
  94. if (this.dataList.length > 0) {
  95. let sortArr = this.dataList.map((item) => Number(item.value));
  96. n = Math.max.apply(null, sortArr);
  97. } else {
  98. n = 0;
  99. }
  100. postData = {
  101. // dictionary: {
  102. key: "inspect_check_type",
  103. value: n + 1,
  104. desc: "检查项目",
  105. orders: this.validateForm.value.orders,
  106. name: this.validateForm.value.name,
  107. extra6: this.validateForm.value.extra6,
  108. extra4: this.validateForm.value.extra4,
  109. extra5: this.validateForm.value.extra5,
  110. extra7: this.validateForm.value.extra7.toString(),
  111. extra8: '1',
  112. // }
  113. };
  114. } else {
  115. //编辑
  116. postData = {
  117. // dictionary: {
  118. ...this.coopData,
  119. ...{
  120. orders: this.validateForm.value.orders,
  121. name: this.validateForm.value.name,
  122. extra6: this.validateForm.value.extra6,
  123. extra4: this.validateForm.value.extra4,
  124. extra5: this.validateForm.value.extra5,
  125. extra7: this.validateForm.value.extra7.toString(),
  126. }
  127. // }
  128. };
  129. }
  130. this.mainService
  131. .simplePost("addData", "dictionary", postData)
  132. .subscribe((result) => {
  133. this.btnLoading = false;
  134. this.hideWechatModal();
  135. let msg = "";
  136. if (this.add) {
  137. msg = "新增";
  138. } else {
  139. msg = "修改";
  140. }
  141. if (result.status == 200) {
  142. this.showPromptModal(msg, true, '');
  143. } else {
  144. this.showPromptModal(msg, false, result.msg);
  145. }
  146. });
  147. }
  148. // 初始化新增form表单
  149. validateForm: FormGroup; //新增/编辑表单
  150. initWechatForm() {
  151. this.validateForm = this.fb.group({
  152. orders: [null, [Validators.required]],
  153. name: [null, [Validators.required]],
  154. extra6: [null, [Validators.required]],
  155. extra4: [null, [Validators.required]],
  156. extra5: [null, [Validators.required]],
  157. extra7: [[]],
  158. });
  159. }
  160. // 重置
  161. queryData: any = {}
  162. reset(){
  163. this.queryData = {};
  164. this.getList();
  165. }
  166. // 获取列表
  167. loading1:boolean = false;
  168. dataList: any[] = []; //表格数据
  169. tableWechatHeight:number = 0;
  170. getList() {
  171. let data = {
  172. idx: 0,
  173. sum: 9999,
  174. dictionary: {
  175. key: "inspect_check_type",
  176. name: this.queryData.name || undefined,
  177. extra4: this.queryData.extra4 || undefined,
  178. extra5: this.queryData.extra5 || undefined,
  179. extra8: this.queryData.extra8 || undefined,
  180. },
  181. };
  182. this.loading1 = true;
  183. this.mainService
  184. .getFetchDataList("simple/data", "dictionary", data)
  185. .subscribe((data) => {
  186. this.loading1 = false;
  187. if (data.status == 200) {
  188. this.dataList = data.list || [];
  189. }else{
  190. this.message.error(data.msg || "请求数据失败");
  191. }
  192. });
  193. }
  194. // 防抖
  195. isLoading = false;
  196. isSelecting:boolean = false; // 是否在选中状态
  197. searchTimer(fun, e) {
  198. if (this.isSelecting) {
  199. this.isSelecting = false; // 重置标志
  200. return; // 跳过处理
  201. }
  202. this.isLoading = true;
  203. this.searchTimerSubject.next([fun, e]);
  204. }
  205. // 设置标志
  206. setIsSelecting(flag){
  207. this.isSelecting = flag; // 设置标志
  208. }
  209. openChangeDept(flag){
  210. flag && this.setIsSelecting(false);
  211. flag && this.getDeptList();
  212. }
  213. // 科室搜索
  214. changeDeptInp(e) {
  215. this.searchTimer(this.getDeptList, e);
  216. }
  217. // 获取默认检查科室
  218. deptList: any = [];
  219. getDeptList(e = undefined) {
  220. let postData = {
  221. idx: 0,
  222. sum: 20,
  223. department: {
  224. searchType: 1,// 简单查询
  225. cascadeHosId: this.hosId,
  226. dept: e,
  227. }
  228. };
  229. this.isLoading = true;
  230. this.mainService
  231. .getFetchDataList("simple/data", "department", postData)
  232. .subscribe((data) => {
  233. this.isLoading = false;
  234. this.deptList = data.list || [];
  235. });
  236. }
  237. openChangeDepts(flag){
  238. flag && this.setIsSelecting(false);
  239. flag && this.getDeptsList();
  240. }
  241. // 科室搜索
  242. changeDeptsInp(e) {
  243. this.searchTimer(this.getDeptsList, e);
  244. }
  245. // 获取检查科室
  246. deptsList: any = [];
  247. getDeptsList(e = undefined) {
  248. let postData = {
  249. idx: 0,
  250. sum: 20,
  251. department: {
  252. searchType: 1,// 简单查询
  253. cascadeHosId: this.hosId,
  254. dept: e,
  255. }
  256. };
  257. this.isLoading = true;
  258. this.mainService
  259. .getFetchDataList("simple/data", "department", postData)
  260. .subscribe((data) => {
  261. this.isLoading = false;
  262. this.deptsList = data.list || [];
  263. });
  264. }
  265. // 获取检查类型
  266. typeList: any = [];
  267. getTypes() {
  268. this.mainService.getDictionary('list', 'inspect_check_item').subscribe((data) => {
  269. this.isLoading = false;
  270. this.typeList = data || [];
  271. });
  272. }
  273. delModal: boolean = false; //删除模态框
  274. tipsMsg1: string; //提示框信息
  275. tipsMsg2: string; //操作后信息
  276. confirmDelType: string; //确认的类型(启用/停用,删除)
  277. showDelModal(
  278. data,
  279. tipsMsg1: string,
  280. tipsMsg2: string,
  281. type: string,
  282. ) {
  283. this.confirmDelType = type;
  284. this.delModal = true;
  285. this.coopData = data;
  286. this.tipsMsg1 = tipsMsg1;
  287. this.tipsMsg2 = tipsMsg2;
  288. }
  289. // 隐藏删除框
  290. hideDelModal() {
  291. this.delModal = false;
  292. }
  293. // 确认删除
  294. confirmDel() {
  295. this.btnLoading = true;
  296. if (this.confirmDelType === "del") {
  297. //删除
  298. this.mainService
  299. .simplePost("rmvData", "dictionary", [this.coopData.id])
  300. .subscribe((data) => {
  301. this.btnLoading = false;
  302. this.delModal = false;
  303. if (data.status == 200) {
  304. this.showPromptModal(this.tipsMsg2, true, "");
  305. } else {
  306. this.showPromptModal(this.tipsMsg2, false, data.msg);
  307. }
  308. });
  309. }
  310. }
  311. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  312. promptContent: string; //操作提示框提示信息
  313. ifSuccess: boolean; //操作成功/失败
  314. promptInfo: string; //操作结果提示信息
  315. promptModalShow: boolean; //操作提示框是否展示
  316. showPromptModal(con, success, promptInfo?) {
  317. this.promptModalShow = false;
  318. this.promptContent = con;
  319. this.ifSuccess = success;
  320. this.promptInfo = promptInfo;
  321. setTimeout(() => {
  322. this.promptModalShow = true;
  323. }, 100);
  324. this.getList();
  325. }
  326. }