drug-search.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. import { Component, OnInit } from "@angular/core";
  2. import { Subject } from "rxjs";
  3. import { debounceTime } from "rxjs/operators";
  4. import { MainService } from "src/app/services/main.service";
  5. import { ToolService } from "src/app/services/tool.service";
  6. import { format, startOfDay, endOfDay } from 'date-fns';
  7. import { ActivatedRoute, Router } from "@angular/router";
  8. import { FormBuilder, Validators, FormGroup, FormControl } from "@angular/forms";
  9. @Component({
  10. selector: "app-drug-search",
  11. templateUrl: "./drug-search.component.html",
  12. styleUrls: ["./drug-search.component.less"],
  13. })
  14. export class DrugSearchComponent implements OnInit {
  15. constructor(
  16. private fb: FormBuilder,
  17. private mainService: MainService,
  18. private tool: ToolService,
  19. private router: Router,
  20. private route: ActivatedRoute
  21. ) {}
  22. currentUserAccount: any = JSON.parse(localStorage.getItem("user")).user.account; //当前登录人账号
  23. searchCriteria = {
  24. //搜索条件
  25. packid: "", //请领单号
  26. launch: null, //发药科室
  27. target: null, //发药科室
  28. drugsState: null,
  29. receiverName: null,
  30. drugsBagType: null,
  31. dateRange:[],
  32. };
  33. deptList = []; // 院区下的配送人员列表(搜索框)
  34. hosId;
  35. listOfData: any[] = []; //表格数据
  36. pageIndex: number = 1; //表格当前页码
  37. pageSize: number = 10; //表格每页展示条数
  38. listLength: number = 10; //表格总数据量
  39. changeSearchSubject = new Subject();
  40. changeInpSubject = new Subject();
  41. changeUserInpSubject = new Subject();
  42. coopBtns:any;
  43. validateForm: FormGroup; //新增/编辑表单
  44. ngOnInit() {
  45. this.coopBtns = this.tool.initCoopBtns(this.route);
  46. this.changeSearchSubject.pipe(debounceTime(500)).subscribe((v) => {
  47. this.getDept(v);
  48. });
  49. this.changeInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  50. this.searchDept(v[0], v[1]);
  51. });
  52. this.changeUserInpSubject.pipe(debounceTime(500)).subscribe((v) => {
  53. this.searchUser(v);
  54. });
  55. this.getHospital();
  56. this.getDrugsList();
  57. this.getDept('');
  58. this.searchUser('');
  59. this.searchTypes();
  60. }
  61. // 查看流程信息弹窗
  62. logPromptModalShow = false; //弹窗开关
  63. drugsBagId = ""; //查看记录携带id
  64. showLogs(data) {
  65. this.drugsBagId = data.id;
  66. this.logPromptModalShow = true;
  67. }
  68. // 关闭流程信息弹窗
  69. closeModelLog(e) {
  70. this.logPromptModalShow = JSON.parse(e).show;
  71. }
  72. // 清空药品
  73. delModal: boolean = false; //删除模态框
  74. tipsMsg1: string; //提示框信息
  75. showDelModal(
  76. tipsMsg1: string
  77. ) {
  78. this.delModal = true;
  79. this.tipsMsg1 = tipsMsg1;
  80. }
  81. // 隐藏删除框
  82. hideDelModal() {
  83. this.delModal = false;
  84. }
  85. // 确认
  86. btnLoading: boolean = false; //提交按钮loading状态
  87. confirmDel() {
  88. this.btnLoading = true;
  89. this.mainService
  90. .coopDataM("drugsBag/emptyData", {"hosId":1,"isEmpty":'ok'})
  91. .subscribe((data) => {
  92. this.btnLoading = false;
  93. this.delModal = false;
  94. if (data.status == 200) {
  95. this.showPromptModal("药品清空", true, "");
  96. } else {
  97. this.showPromptModal("药品清空", false, "");
  98. }
  99. });
  100. }
  101. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  102. promptContent: string; //操作提示框提示信息
  103. ifSuccess: boolean; //操作成功/失败
  104. promptInfo: string; //操作结果提示信息
  105. promptModalShow: boolean; //操作提示框是否展示
  106. showPromptModal(con, success, promptInfo?) {
  107. this.promptModalShow = false;
  108. this.promptContent = con;
  109. this.ifSuccess = success;
  110. this.promptInfo = promptInfo;
  111. setTimeout(() => {
  112. this.promptModalShow = true;
  113. }, 100);
  114. this.getList(0);
  115. }
  116. // 搜索类型
  117. isLoading1 = false;
  118. types = []; // 类型列表(搜索框)
  119. searchTypes() {
  120. this.isLoading1 = true;
  121. this.mainService.getDictionary("list", "drug_state").subscribe((res) => {
  122. this.isLoading1 = false;
  123. this.types = res;
  124. });
  125. }
  126. // 打开搜索框
  127. changeSearch1(flag) {
  128. if (flag) {
  129. this.searchTypes();
  130. }
  131. }
  132. // 获取药品类型
  133. drugsList:any = [];
  134. getDrugsList(){
  135. this.mainService.getDictionary("list", "drugs_bag_type").subscribe((res) => {
  136. this.drugsList = res;
  137. });
  138. }
  139. //获取用户
  140. userSearch:any = [];
  141. searchUser(keyword) {
  142. let data = {
  143. user: {
  144. // usertype: { id: 106 },
  145. name: keyword,
  146. hospital: {
  147. id: this.hosId,
  148. },
  149. },
  150. idx: 0,
  151. sum: 10,
  152. };
  153. this.mainService
  154. .getFetchDataList("data", "user", data)
  155. .subscribe((data) => {
  156. if (data.status == 200) {
  157. this.isLoading = false;
  158. this.userSearch = data.list;
  159. }
  160. });
  161. }
  162. // 搜索用户
  163. changeUserInp(e){
  164. this.isLoading = true;
  165. this.changeUserInpSubject.next(e);
  166. }
  167. // 日期选择
  168. startDate: string; //发起时间开始
  169. endDate: string; //发起时间结束
  170. changeDate(result?): void {
  171. if (result.length==0) {
  172. this.startDate = this.endDate = null;
  173. return;
  174. }
  175. this.startDate = format(result[0], 'yyyy-MM-dd HH:mm:ss');
  176. this.endDate = format(result[1], 'yyyy-MM-dd HH:mm:ss');
  177. this.searchCriteria.dateRange = [this.startDate,this.endDate]
  178. }
  179. onCalendarChangeDate(dateArr){
  180. console.log(dateArr)
  181. if(dateArr.length == 2){
  182. let dateStart = new Date(dateArr[0]);
  183. let dateEnd = new Date(dateArr[1]);
  184. dateStart.setHours(0,0,0);
  185. dateEnd.setHours(23,59,59);
  186. this.searchCriteria.dateRange = [dateStart,dateEnd];
  187. }
  188. }
  189. // 重置
  190. reset() {
  191. this.searchCriteria = {
  192. //搜索条件
  193. packid: "",
  194. launch: null,
  195. target: null,
  196. drugsState: null,
  197. receiverName: null,
  198. drugsBagType: null,
  199. dateRange:[]
  200. };
  201. this.startDate = null;
  202. this.endDate = null;
  203. this.getList(1);
  204. }
  205. // 获取所有院区
  206. getHospital() {
  207. this.hosId = this.tool.getCurrentHospital().id;
  208. this.getList(1);
  209. }
  210. // 查看标本历史记录
  211. historyPromptModalShow = false; //标本历史记录弹窗开关
  212. scode = ""; //查看历史记录携带
  213. viewSpecimenHistory(data) {
  214. this.scode = data.scode;
  215. this.historyPromptModalShow = true;
  216. }
  217. // 关闭标本历史记录弹窗
  218. closeModelHistory(e) {
  219. this.historyPromptModalShow = JSON.parse(e).show;
  220. }
  221. // 打开搜索框
  222. changeSearch(flag) {
  223. if (flag) {
  224. this.changeInp("no");
  225. }
  226. }
  227. // 边输边搜节流阀
  228. isLoading = false;
  229. changeInp(dept) {
  230. if (!dept) {
  231. return;
  232. }
  233. if (dept === "no") {
  234. dept = "";
  235. }
  236. this.isLoading = true;
  237. this.changeSearchSubject.next(dept);
  238. }
  239. // 搜索科室
  240. deptList1:any = [];
  241. deptList2:any = [];
  242. searchDept(dept, type) {
  243. let postData = {
  244. department: {
  245. hospital: { id: this.hosId },
  246. dept,
  247. },
  248. idx: 0,
  249. sum: 10,
  250. };
  251. this.mainService
  252. .getFetchDataList("data", "department", postData)
  253. .subscribe((result) => {
  254. if (result.status == 200) {
  255. this.isLoading = false;
  256. if(type == 1){
  257. this.deptList1 = result.list;
  258. }else{
  259. this.deptList2 = result.list;
  260. }
  261. }
  262. });
  263. }
  264. getDept(dept){
  265. let postData = {
  266. department: {
  267. hospital: { id: this.hosId },
  268. dept,
  269. },
  270. idx: 0,
  271. sum: 10,
  272. };
  273. this.mainService
  274. .getFetchDataList("data", "department", postData)
  275. .subscribe((result) => {
  276. if (result.status == 200) {
  277. this.isLoading = false;
  278. this.deptList = result.list;
  279. this.deptList1 = result.list;
  280. this.deptList2 = result.list;
  281. }
  282. });
  283. }
  284. // 查看
  285. detail(e, data) {
  286. if(!data.workOrderDTO){
  287. return
  288. }
  289. e.stopPropagation();
  290. this.router.navigateByUrl("/main/drugSearch/orderDetail/" + data.workOrderDTO.id);
  291. }
  292. // 新增弹框
  293. modal:boolean = false;
  294. add:boolean = false;
  295. addMoadl() {
  296. this.getDept('');
  297. this.add = true;
  298. this.modal = true;
  299. this.itemData = null;
  300. this.initForm();
  301. }
  302. hideModal() {
  303. this.getDept('');
  304. this.modal = false;
  305. this.initForm();
  306. }
  307. // 搜索科室
  308. changeDept(dept, type){
  309. this.isLoading = true;
  310. this.changeInpSubject.next([dept, type]);
  311. }
  312. // 初始化新增form表单
  313. initForm() {
  314. this.validateForm = this.fb.group({
  315. packid:[null, [Validators.required]],
  316. batchNo: [null, []],
  317. launch: [null, [Validators.required]],
  318. target: [null, [Validators.required]],
  319. creatTime: [null, [Validators.required]],
  320. drugsState: [null, [Validators.required]],
  321. drugsBagType: [null, []],
  322. });
  323. }
  324. // // 选择开始时间
  325. onStartChange(result: Date): void {
  326. console.log('Selected Time: ', result);
  327. let startTime = format(result, 'yyyy-MM-dd HH:mm:ss');
  328. this.validateForm.controls.creatTime.setValue(startTime);
  329. }
  330. // 表单提交
  331. submitForm(): void {
  332. var that = this;
  333. for (const i in that.validateForm.controls) {
  334. that.validateForm.controls[i].markAsDirty();
  335. that.validateForm.controls[i].updateValueAndValidity();
  336. }
  337. if (that.validateForm.invalid) return;
  338. let data = {
  339. drugsBag:{
  340. ...this.itemData,
  341. packid: this.validateForm.value.packid,
  342. batchNo: this.validateForm.value.batchNo || undefined,
  343. drugsState: {
  344. id: this.validateForm.value.drugsState
  345. },
  346. drugsBagType: {
  347. id: this.validateForm.value.drugsBagType
  348. },
  349. launch: {
  350. id:this.validateForm.value.launch
  351. },
  352. target: {
  353. id:this.validateForm.value.target
  354. },
  355. creatTime: this.validateForm.value.creatTime,
  356. id:0,
  357. }
  358. };
  359. if (!that.add) {
  360. data.drugsBag.id = that.coopId;
  361. }else{
  362. delete data.drugsBag.id
  363. }
  364. if(this.validateForm.value.drugsBagType){
  365. data.drugsBag.drugsBagType.id = this.validateForm.value.drugsBagType
  366. }else{
  367. delete data.drugsBag.drugsBagType
  368. }
  369. that.btnLoading = true;
  370. that.mainService
  371. .dataPost(this.add ? "addData":"updData", "drugsBag", data)
  372. .subscribe((data) => {
  373. that.btnLoading = false;
  374. if (data.status == 200) {
  375. that.hideModal();
  376. that.showPromptModal(that.add ? "新增" : "编辑", true, "");
  377. } else {
  378. that.showPromptModal(that.add ? "新增" : "编辑", false, data.msg);
  379. }
  380. });
  381. }
  382. // 编辑
  383. itemData:any;
  384. coopId:any;
  385. edit(data) {
  386. this.add = false
  387. this.initForm();
  388. this.itemData = data;
  389. this.coopId = data.id;
  390. this.validateForm.controls.packid.setValue(data.packid || '');
  391. this.validateForm.controls.batchNo.setValue(data.batchNo || '');
  392. this.validateForm.controls.launch.setValue(data.launch.id);
  393. this.validateForm.controls.target.setValue(data.target.id)
  394. this.validateForm.controls.drugsState.setValue(data.drugsState.id)
  395. this.validateForm.controls.drugsBagType.setValue(data.drugsBagType && data.drugsBagType.id)
  396. this.validateForm.controls.creatTime.setValue(data.creatTime);
  397. let item = this.deptList1.find(i=>i.id == data.launch.id)
  398. if(!item){
  399. this.deptList1.push({
  400. dept: data.launch.dept,
  401. id: data.launch.id,
  402. })
  403. }
  404. let item2 = this.deptList2.find(i=>i.id == data.target.id)
  405. if(!item2){
  406. this.deptList2.push({
  407. dept: data.target.dept,
  408. id: data.target.id,
  409. })
  410. }
  411. this.modal = true
  412. }
  413. // 消息发送
  414. sendModal:boolean = false;
  415. sendMsg(data){
  416. this.itemData = data;
  417. this.sendModal = true
  418. }
  419. // 取消删除弹框
  420. cancelSend(){
  421. this.hideSendModal();
  422. }
  423. hideSendModal(){
  424. this.sendModal = false
  425. }
  426. // 确认发送
  427. confirmSend() {
  428. let that = this;
  429. let query = {
  430. drugsBag:{
  431. ...this.itemData,
  432. operationType:'sendMsg'
  433. }
  434. }
  435. that.btnLoading = true;
  436. that.mainService
  437. .dataPost("updData", "drugsBag", query)
  438. .subscribe((data) => {
  439. that.btnLoading = false;
  440. this.hideSendModal();
  441. if (data.status == 200) {
  442. that.showPromptModal("发送", true, "");
  443. } else {
  444. that.showPromptModal("发送", false, data.msg);
  445. }
  446. });
  447. }
  448. // 表格数据
  449. loading1 = false;
  450. getList(type) {
  451. if (type == 1) {
  452. this.pageIndex = 1;
  453. }
  454. let postData: any = {
  455. idx: this.pageIndex - 1,
  456. sum: this.pageSize,
  457. drugsBag: {
  458. hosId: this.hosId,
  459. drugsState: this.searchCriteria.drugsState ? { id: this.searchCriteria.drugsState } : undefined,
  460. startTime: this.startDate || undefined,
  461. endTime: this.endDate || undefined,
  462. drugsBagType:{
  463. id:null
  464. },
  465. deliveryUser:{
  466. id:null
  467. }
  468. },
  469. };
  470. if (this.searchCriteria.target) {
  471. postData.drugsBag.target = { id: this.searchCriteria.target };
  472. }
  473. if (this.searchCriteria.launch) {
  474. postData.drugsBag.launch = { id: this.searchCriteria.launch };
  475. }
  476. if (this.searchCriteria.packid) {
  477. postData.drugsBag.packid = this.searchCriteria.packid;
  478. }
  479. if (this.searchCriteria.receiverName) {
  480. postData.drugsBag.deliveryUser.id = this.searchCriteria.receiverName;
  481. }else{
  482. delete postData.drugsBag.deliveryUser
  483. }
  484. if (this.searchCriteria.drugsBagType) {
  485. postData.drugsBag.drugsBagType.id = this.searchCriteria.drugsBagType;
  486. }else{
  487. delete postData.drugsBag.drugsBagType
  488. }
  489. this.loading1 = true;
  490. this.mainService
  491. .getFetchDataList("drugsBag", "drugsBag", postData)
  492. .subscribe((data) => {
  493. this.loading1 = false;
  494. if (data["status"] == 200) {
  495. this.listOfData = data["list"];
  496. this.listLength = data["totalNum"];
  497. }
  498. });
  499. }
  500. }