build-quick-confirm.component.ts 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import { Component, OnInit, Output, Input, ViewChild, ElementRef } from '@angular/core';
  2. import { EventEmitter } from '@angular/core';
  3. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  4. import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
  5. import { MainService } from 'src/app/services/main.service';
  6. import { ToolService } from 'src/app/services/tool.service';
  7. import { Subject } from 'rxjs';
  8. import { debounceTime } from 'rxjs/operators';
  9. @Component({
  10. selector: 'app-build-quick-confirm',
  11. templateUrl: './build-quick-confirm.component.html',
  12. styleUrls: ['./build-quick-confirm.component.less']
  13. })
  14. export class BuildQuickConfirmComponent implements OnInit {
  15. @ViewChild("osComponentRef1", {
  16. read: OverlayScrollbarsComponent,
  17. static: false,
  18. })
  19. osComponentRef1: OverlayScrollbarsComponent;
  20. @ViewChild("remarksEle", { static: false }) remarksEle: ElementRef;
  21. @Output() cancelModal = new EventEmitter();
  22. @Output() confirmModal = new EventEmitter();
  23. @Input() buildQuickConfirmData: any = {};//数据
  24. @Input() loading5: boolean = false;//loading
  25. hosLoading: boolean = false;//确定按钮的loading
  26. configurationCenterMenus: any[] = [];//配置中心菜单
  27. searchAccountSubject = new Subject(); //查工号防抖
  28. constructor(
  29. private mainService: MainService,
  30. private fb: FormBuilder,
  31. public tool: ToolService,
  32. ) { }
  33. ngOnInit() {
  34. this.getPagePermissionConfigById();
  35. //防抖
  36. this.getAccountList();
  37. this.searchAccountSubject.pipe(debounceTime(500)).subscribe((v:any) => {
  38. this.getAccountList(v);
  39. });
  40. }
  41. activeTabId:any;
  42. clickTab(data){
  43. this.activeTabId = data.id;
  44. this.newShortcutOrder(data, data.associationType.value);
  45. }
  46. // 建单条件
  47. workOrderRemark = ""; //备注
  48. customRemarks = []; //备注快速输入
  49. shortcutMsg; //一键发起信息
  50. buildMsg: any = {}; //一键发起返回信息
  51. buildType: string = ""; //快捷建单类型
  52. historyCustomRemarks = []; //历史快捷输入
  53. workOrderRemarkTips = ""; //备注提示
  54. nLoading = false;
  55. isEndFixedType: boolean = false;
  56. isStartFixedType: boolean = false;
  57. msgId:any;
  58. newShortcutOrder(data, type) {
  59. this.workOrderRemark = "";
  60. this.customRemarks = [];
  61. this.historyCustomRemarks = [];
  62. console.log(data, type);
  63. this.buildType = type;
  64. this.shortcutMsg = data;
  65. this.initForm();
  66. this.buildMsg = {};
  67. this.msgId = data.id;
  68. let postData:any = {
  69. taskTypeId: data.id,
  70. };
  71. if(data.associationType.value === 'specimen'){
  72. postData.deptId = this.tool.getCurrentUserDept().id;
  73. }
  74. this.nLoading = true;
  75. this.mainService
  76. .postCustom("nurse", "workOrder/buildTrip", postData)
  77. .subscribe((result) => {
  78. this.buildMsg = result;
  79. if(result.end){
  80. if(result.end.end.departmentStrategy==202 ||
  81. result.end.end.departmentStrategy==204 ||
  82. result.end.end.departmentStrategy==205){
  83. this.isEndFixedType = true
  84. }else{
  85. this.isEndFixedType = false
  86. }
  87. }
  88. if(result.start){
  89. if(result.start.start.departmentStrategy==202 ||
  90. result.start.start.departmentStrategy==204 ||
  91. result.start.start.departmentStrategy==205){
  92. this.isStartFixedType = true
  93. }else{
  94. this.isStartFixedType = false
  95. }
  96. }
  97. if (result.remarksSwitch == 1) {
  98. if (result.customRemarks === null || result.customRemarks === "") {
  99. this.customRemarks = [];
  100. } else {
  101. this.customRemarks = result.customRemarks.split("$");
  102. }
  103. this.workOrderRemarkTips =
  104. result.remarksPrompts || "请填写工单备注,不超过100个字符";
  105. let user = JSON.parse(localStorage.getItem("user"));
  106. this.mainService
  107. .postCustom("nurse", "workOrder/recentRemarks", {
  108. deptId: user.user.dept.id,
  109. taskTypeId: data.id,
  110. })
  111. .subscribe((result1) => {
  112. this.nLoading = false;
  113. if (result1.state == 200) {
  114. this.historyCustomRemarks = result1.data;
  115. }
  116. });
  117. } else {
  118. this.nLoading = false;
  119. }
  120. });
  121. }
  122. // 初始化form表单
  123. shortcutForm: FormGroup; //一键发起建单表单
  124. initForm() {
  125. // 初始化一键发起建单表单
  126. this.shortcutForm = this.fb.group({
  127. targetOffice: [null, [this.targetOfficeShortCutValidator]],
  128. originOffice: [null, [this.originOfficeShortCutValidator]],
  129. });
  130. }
  131. // 起点科室校验
  132. originOfficeShortCutValidator = (control: FormControl): { [s: string]: boolean } => {
  133. if (this.shortcutForm && this.shortcutForm.value && !control.value && (this.buildMsg.status == 100013 || this.buildMsg.status == 100015)) {
  134. return { required: true };
  135. }
  136. };
  137. // 目标科室校验
  138. targetOfficeShortCutValidator = (control: FormControl): { [s: string]: boolean } => {
  139. if (this.shortcutForm && this.shortcutForm.value && !control.value && (this.buildMsg.status == 100014 || this.buildMsg.status == 100015)) {
  140. return { required: true };
  141. }
  142. };
  143. // 添加备注
  144. addRemarks(item) {
  145. this.remarksEle.nativeElement.focus();
  146. this.workOrderRemark += item;
  147. }
  148. // 目标科室输入搜索
  149. searchDept(type, msg, e) {
  150. this.getDeptList(type, msg, e);
  151. }
  152. // 获取科室
  153. isLoading:boolean = false;
  154. getDeptList(type, msg, key?): void {
  155. // 返回值的status是201 则是默认发起科室
  156. // 返回值的status是202 则是固定科室范围
  157. // 返回值的status是203 则是固定科室
  158. // 返回值的status是204 则是自主填写
  159. // 返回值的status是205 则是固定科室类型
  160. if (
  161. (type == "start" && msg.start.start.departmentStrategy == 202) ||
  162. (type == "target" && msg.end.end.departmentStrategy == 202)
  163. ) {
  164. let data = [];
  165. let postData = {
  166. taskTypeId: this.msgId
  167. };
  168. if(type == "start"){
  169. this.mainService
  170. .postCustom("nurse", "workOrder/buildTrip", postData)
  171. .subscribe((result) => {
  172. let arr = result.start.start.list;
  173. if(key!=''){
  174. data = arr.filter(i=>i.dept.indexOf(key) !=-1)
  175. msg.start.start.list = data
  176. }else{
  177. msg.start.start.list = arr
  178. }
  179. });
  180. }else{
  181. this.mainService
  182. .postCustom("nurse", "workOrder/buildTrip", postData)
  183. .subscribe((result) => {
  184. let arr = result.end.end.list;
  185. if(key!=''){
  186. data = arr.filter(i=>i.dept.indexOf(key) !=-1)
  187. msg.end.end.list = data
  188. }else{
  189. msg.end.end.list = arr
  190. }
  191. });
  192. }
  193. return; //固定科室范围禁用搜索
  194. }
  195. let postData: any = {
  196. idx: 0,
  197. sum: 20,
  198. department: {
  199. searchType: 1,
  200. cascadeHosId: this.tool.getCurrentHospital().id
  201. },
  202. };
  203. if (key) {
  204. postData.department["keyWord"] = key;
  205. }
  206. if (type == "start" && msg.start.start.departmentStrategy == 205) {
  207. postData.department["type"] = { id: msg.start.start.startTypeId };
  208. } else if (type == "target" && msg.end.end.departmentStrategy == 205) {
  209. postData.department["type"] = { id: msg.end.end.endTypeId };
  210. }
  211. if (type == "start") {
  212. postData.department["ids"] = msg.start.deptIds || "";
  213. } else if (type == "target") {
  214. postData.department["ids"] = msg.end.deptIds || "";
  215. }
  216. postData.department.nurseSign = 1;
  217. this.isLoading = true;
  218. this.mainService
  219. .getFetchDataList("data", "department", postData)
  220. .subscribe((data) => {
  221. this.isLoading = false;
  222. if (type == "target") {
  223. msg.end.end.list = data.list;
  224. } else if (type == "start") {
  225. msg.start.start.list = data.list;
  226. }
  227. });
  228. }
  229. // 工号输入搜索
  230. searchAccount(e) {
  231. this.searchAccountSubject.next(e);
  232. }
  233. // 根据工号获取用户
  234. account = null;
  235. accountList = [];
  236. getAccountList(key = ''): void {
  237. let postData = {
  238. idx: 0,
  239. sum: 10,
  240. user: {
  241. account: key,
  242. hospital: {
  243. id: this.tool.getCurrentHospital().id
  244. }
  245. }
  246. };
  247. this.isLoading = true;
  248. this.mainService
  249. .getFetchDataList("data", "user", postData)
  250. .subscribe((data) => {
  251. this.isLoading = false;
  252. this.accountList = data.list || [];
  253. });
  254. }
  255. // 修改工号
  256. userAccount = null;
  257. changeAccount(e){
  258. this.userAccount =this.accountList.find(v => v.id == e);
  259. }
  260. // 根据ID获取快捷配置
  261. pagePermissionConfig: any = {};
  262. getPagePermissionConfigById() {
  263. let data = {
  264. idx: 0,
  265. sum: 99999,
  266. pagePermissionConfig: {
  267. id: this.buildQuickConfirmData.id,
  268. taskTypeDeptId: this.tool.getCurrentUserDept().id,
  269. },
  270. };
  271. this.mainService
  272. .getFetchDataList("simple/data", "pagePermissionConfig", data)
  273. .subscribe((data) => {
  274. let pagePermissionConfigList = data.list || [];
  275. if(pagePermissionConfigList.length){
  276. this.pagePermissionConfig = pagePermissionConfigList[0];
  277. // 默认选中第一项
  278. this.pagePermissionConfig.taskTypeList = this.pagePermissionConfig.taskTypeList || [];
  279. if(this.pagePermissionConfig.taskTypeList.length > 0){
  280. this.clickTab(this.pagePermissionConfig.taskTypeList[0]);
  281. }
  282. }else{
  283. this.pagePermissionConfig = {};
  284. }
  285. });
  286. }
  287. // 取消
  288. cancel() {
  289. this.cancelModal.emit(false)
  290. }
  291. // 确认
  292. confirm() {
  293. let taskType = this.pagePermissionConfig.taskTypeList.find(item => item.id == this.activeTabId);
  294. this.confirmModal.emit({taskType, shortcutForm: this.shortcutForm, buildMsg: this.buildMsg, workOrderRemark: this.workOrderRemark, userAccount: this.userAccount})
  295. }
  296. }