configuration-specimen-auto-build-order.component.ts 11 KB

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