repository-manage-add.component.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute, Router } from "@angular/router";
  3. import {
  4. FormBuilder,
  5. Validators,
  6. FormGroup,
  7. FormControl,
  8. } from "@angular/forms";
  9. import { MainService } from "../../services/main.service";
  10. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  11. import { ToolService } from "../../services/tool.service";
  12. import { NzMessageService, UploadFile, UploadXHRArgs } from "ng-zorro-antd";
  13. import { Observable, Observer, Subject } from "rxjs";
  14. import { debounceTime, filter } from "rxjs/operators";
  15. import { HttpEventType, HttpEvent, HttpRequest, HttpResponse, HttpClient } from '@angular/common/http';
  16. @Component({
  17. selector: "app-repository-manage-add",
  18. templateUrl: "./repository-manage-add.component.html",
  19. styleUrls: ["./repository-manage-add.component.less"],
  20. })
  21. export class RepositoryManageAddComponent implements OnInit {
  22. @ViewChild("osComponentRef1", {
  23. read: OverlayScrollbarsComponent,
  24. static: false,
  25. })
  26. osComponentRef1: OverlayScrollbarsComponent;
  27. constructor(
  28. private message: NzMessageService,
  29. private fb: FormBuilder,
  30. private route: ActivatedRoute,
  31. private router: Router,
  32. private mainService: MainService,
  33. private tool: ToolService,
  34. private http: HttpClient,
  35. ) {}
  36. ngOnInit() {
  37. this.searchParentDeptSubject.pipe(debounceTime(500)).subscribe((e) => {
  38. this.isDeptLoading = true;
  39. this.getProduct(e[0]);
  40. });
  41. this.detailId = this.route.snapshot.params.id;
  42. if(this.detailId==0){
  43. this.add = true
  44. }else{
  45. this.add = false
  46. }
  47. this.hosId = this.tool.getCurrentHospital().id;
  48. this.coopBtns = this.tool.initCoopBtns(this.route);
  49. this.initForm();
  50. this.getAllHospital();
  51. }
  52. classItem:null;
  53. detailId:null; //列表数据
  54. deptId:null; //选中的科室id
  55. listOfData: any[] = []; //表格数据
  56. promptContent: string; //操作提示框提示信息
  57. ifSuccess: boolean; //操作成功/失败
  58. promptInfo: string; //操作结果提示信息
  59. promptModalShow: boolean; //操作提示框是否展示
  60. modal: boolean = false; //新增/编辑模态框
  61. add: boolean; //true:新增;false:编辑
  62. validateForm: FormGroup; //新增/编辑表单
  63. coopId: number; //表格中执行操作的id
  64. department: number; //所属科室
  65. drug: number; //药品名称
  66. hosId: number;
  67. rowId:number; //清单id
  68. dateRange;//时间
  69. batchNumber; //批次号
  70. num; //编码
  71. deptalias; //别名
  72. type; //类型
  73. deptHandoverType; //类型
  74. pageIndex: number = 1; //页码
  75. listLength: number = 10; //总条数
  76. pageSize: number = 10; //每页条数
  77. btnLoading1: boolean = false; //确认按钮loading状态
  78. btnLoading2: boolean = false; //确认按钮loading状态
  79. printLoading: boolean = false; //批量打印按钮loading状态
  80. deptPhones: any = []; //新添加的科室电话列表
  81. isAddDeptsPhone = true; //添加新的科室电话是否禁用
  82. deptsPhoneId = 1; //科室电话自增id
  83. allParentdepart: any = []; //所有的父级科室列表
  84. hospitals1: any = []; //科室列表
  85. buildingList: any = []; //楼栋列表
  86. deptList: any = []; //楼栋科室
  87. malfunctionData: any = []; //故障现象数据
  88. productData: any = []; //产品数据
  89. typeDic:any = []; //知识库状态字典
  90. fileData:any[] = []; //附件数据
  91. building:''; //楼栋
  92. deptIndex:number; //选中index
  93. searchParentDeptSubject = new Subject();
  94. // 初始化增删改按钮
  95. coopBtns: any = {};
  96. deptName:null;
  97. //搜索父级科室
  98. isDeptLoading = false;
  99. isSpinning = false;
  100. delGrantModal = false;
  101. showInsp = false;
  102. changeInp(e, type) {
  103. this.searchParentDeptSubject.next([e, type]);
  104. }
  105. // 表格数据
  106. loading1 = false;
  107. getList() {
  108. var that = this;
  109. let data = {
  110. idx: 0,
  111. sum: 9999,
  112. drugsConfigure: {
  113. hosId: this.hosId,
  114. deptId :this.deptId?this.deptId:null,
  115. batchId: this.detailId
  116. }
  117. };
  118. this.loading1 = true;
  119. that.mainService
  120. .getFetchDataList("data", "drugsConfigure", data)
  121. .subscribe((data) => {
  122. this.loading1 = false;
  123. that.listOfData = data.list;
  124. });
  125. }
  126. // 发药科室列表
  127. getDispensingDept(e,type){
  128. var that = this;
  129. let data = {
  130. idx: 0,
  131. sum: 9999,
  132. drugsConfigure: {
  133. hosId: this.hosId,
  134. deptId :e,
  135. batchId:''
  136. }
  137. };
  138. if(type=='dept'){
  139. data.drugsConfigure.batchId = this.detailId
  140. }else{
  141. delete data.drugsConfigure.batchId
  142. }
  143. let deptData = this.hospitals1.find(i=>i.id==e)
  144. that.mainService
  145. .getFetchDataList("data", "drugsConfigure", data)
  146. .subscribe((res) => {
  147. if(res.list.length==0){
  148. this.message.error(`您选择的科室“ ${deptData.dept}”时间段内没有消耗药品无法添加发药单。`)
  149. }else{
  150. this.getDeptData(e,'all','load')
  151. }
  152. });
  153. }
  154. // 科室点击
  155. deptClick(e,item,index){
  156. e.stopPropagation();
  157. this.deptId = item.applyDeptDTO.id
  158. this.deptName = item.applyDeptDTO.dept
  159. this.deptIndex = index
  160. this.getList()
  161. }
  162. // 科室删除
  163. deptDel(e,item,index){
  164. e.stopPropagation();
  165. this.delModal = true;
  166. this.coopId = item.applyDept;
  167. }
  168. hideDelModal() {
  169. this.delModal = false;
  170. }
  171. // 选择楼栋
  172. buildingChange(e){
  173. this.deptId = null
  174. this.deptName = null
  175. this.deptIndex = null
  176. this.listOfData=[]
  177. this.showInsp = true
  178. this.getDeptData(e,'','')
  179. }
  180. // 根据楼栋查询科室
  181. getDeptData(e,type,initial){
  182. var that = this;
  183. let data = {
  184. idx: 0,
  185. sum: 99999,
  186. drugsList: {
  187. hosId: this.hosId,
  188. buildingId:e,
  189. batch:{
  190. id:this.detailId
  191. }
  192. },
  193. };
  194. if(type=='all'){
  195. delete data.drugsList.buildingId
  196. }else{
  197. data.drugsList.buildingId = e
  198. }
  199. if(this.showInsp){
  200. this.isSpinning = true
  201. }
  202. that.mainService
  203. .getFetchDataList("data", "drugsList", data)
  204. .subscribe((res) => {
  205. this.isSpinning = false
  206. that.deptList = res.list;
  207. if(initial=='load'){
  208. if(res.list.length>0){
  209. this.deptId = res.list[0].applyDeptDTO.id
  210. this.deptName = res.list[0].applyDeptDTO.dept
  211. this.deptIndex = 0
  212. }
  213. this.getList()
  214. }
  215. });
  216. }
  217. // 选择科室
  218. addDeptId=''
  219. deptChange(e){
  220. this.addDeptId = e
  221. }
  222. // 添加科室
  223. addDept(){
  224. if(this.addDeptId){
  225. this.showInsp = true
  226. this.getDispensingDept(this.addDeptId,'dept')
  227. }else{
  228. this.message.error('请先选择发药科室')
  229. }
  230. }
  231. // 获取产品
  232. getProduct(name){
  233. let postData = {
  234. assetProduct: {
  235. hosId: this.hosId,
  236. name:name
  237. },
  238. idx: 0,
  239. sum: 20,
  240. };
  241. this.mainService
  242. .getFetchDataList("data", "assetProduct", postData)
  243. .subscribe((result) => {
  244. this.isDeptLoading = false
  245. this.productData = result.list;
  246. });
  247. }
  248. // 获取所有科室
  249. getDeparts() {
  250. let data = {
  251. batchId:this.detailId
  252. };
  253. this.mainService
  254. .getConsumeDept(data)
  255. .subscribe((res) => {
  256. this.hospitals1 = res.data
  257. });
  258. }
  259. // 获取所有院区
  260. getAllHospital() {
  261. this.getPolling()
  262. this.getProduct('')
  263. this.getMalfunction()
  264. this.getDicData()
  265. }
  266. // 获取故障现象数据
  267. getMalfunction(){
  268. let postData = {
  269. building: {
  270. cascadeHosId: this.hosId,
  271. },
  272. idx: 0,
  273. sum: 20,
  274. };
  275. this.mainService
  276. .getFetchDataList("data", "building", postData)
  277. .subscribe((result) => {
  278. this.malfunctionData = result.data
  279. });
  280. }
  281. // 获取巡检列表
  282. pollingData = [];
  283. getPolling(){
  284. let data = {
  285. idx: 0,
  286. sum: 9999,
  287. inspection: {
  288. hosId: this.hosId
  289. },
  290. };
  291. this.mainService
  292. .getFetchDataList("simple/data", "inspectionForm", data)
  293. .subscribe((data) => {
  294. if (data.status == 200) {
  295. this.pollingData = data.list.filter(i=>i.status.name=='已发布');
  296. }
  297. });
  298. }
  299. // 获取知识分类字典
  300. dicData = [];
  301. getDicData(){
  302. this.mainService.getDictionary("list", "solution_type").subscribe((res) => {
  303. this.dicData = res
  304. });
  305. this.mainService.getDictionary("list", "solution_status").subscribe((res) => {
  306. this.typeDic = res
  307. });
  308. }
  309. // 选择知识库分类
  310. radioChnage(e){
  311. let item = this.dicData.find(i=>i.id == this.validateForm.value.knowledgeClass)
  312. this.classItem = item.value
  313. }
  314. hideGrantModal(){
  315. this.delGrantModal = false;
  316. }
  317. // 增加/减少
  318. rowData = null;
  319. itemClick(e, data, type){
  320. e.stopPropagation();
  321. this.rowId = data.id
  322. this.rowData = data
  323. if(type=='add'){
  324. this.add = true
  325. }else{
  326. this.add = false
  327. }
  328. this.modal = true
  329. this.initForm();
  330. }
  331. // 富文本内容
  332. editOrData=null;
  333. changeContent(data){
  334. this.editOrData = data
  335. }
  336. // 表单提交
  337. submitForm(type): void {
  338. var that = this;
  339. for (const i in that.validateForm.controls) {
  340. that.validateForm.controls[i].markAsDirty();
  341. that.validateForm.controls[i].updateValueAndValidity();
  342. }
  343. if (that.validateForm.invalid) return;
  344. let data = {
  345. ...this.validateForm.value,
  346. content:this.editOrData,
  347. id:'',
  348. hosId:this.hosId,
  349. inspectionForm:{
  350. id:this.validateForm.value.polling
  351. },
  352. type:{
  353. id:this.validateForm.value.knowledgeClass
  354. },
  355. buttonType:type==1?'confirm':'ts'
  356. };
  357. if(this.add){
  358. delete data.id
  359. }else{
  360. data.id = this.detailId
  361. }
  362. if(type==1){
  363. that.btnLoading1 = true;
  364. }else{
  365. that.btnLoading2 = true;
  366. }
  367. that.mainService
  368. .simplePost("addData", "solution", data)
  369. .subscribe((res) => {
  370. if(type==1){
  371. that.btnLoading1 = false;
  372. }else{
  373. that.btnLoading2 = false;
  374. }
  375. if(this.fileData.length>0){
  376. this.uploadFile(res.data.id)
  377. if (res.status == 200) {
  378. that.showPromptModal(that.add ? "增加" : "减少", true, "");
  379. } else {
  380. that.showPromptModal(that.add ? "增加" : "减少", false, res.msg);
  381. }
  382. that.hideModal();
  383. }else{
  384. if (res.status == 200) {
  385. that.showPromptModal(that.add ? "增加" : "减少", true, "");
  386. } else {
  387. that.showPromptModal(that.add ? "增加" : "减少", false, res.msg);
  388. }
  389. that.hideModal();
  390. }
  391. });
  392. }
  393. // 上传图片
  394. uploadFile(id){
  395. console.log(555,this.fileData)
  396. let url = `/service/common/common/uploadAttachment/solution/${id}/${id}`
  397. for(let i of this.fileData){
  398. console.log(54545,i)
  399. const formData = new FormData();
  400. formData.append('file', i.originFileObj);
  401. formData.append('filename', i.originFileObj.name);
  402. const req = new HttpRequest('POST', url, formData, {
  403. reportProgress: true,
  404. withCredentials: true
  405. });
  406. this.http.request(req).subscribe((res) => {
  407. });
  408. }
  409. }
  410. // 新增弹框
  411. showModal() {
  412. this.add = true;
  413. this.isAddDeptsPhone = true;
  414. this.deptPhones = [];
  415. }
  416. // 返回
  417. back(){
  418. this.router.navigateByUrl(`/main/repositoryManage`);
  419. }
  420. hideModal() {
  421. this.initForm();
  422. this.modal = false;
  423. }
  424. // 初始化新增form表单
  425. initForm() {
  426. this.validateForm = this.fb.group({
  427. title: [null, [Validators.required]],
  428. code: [null, []],
  429. version: [null, []],
  430. content: [null, []],
  431. assetProductId: [null,[]],
  432. repairVisible: [null, [Validators.required]],
  433. knowledgeClass: [null, [Validators.required]],
  434. polling: [null, [Validators.required]],
  435. });
  436. }
  437. avatarLoading = false;
  438. avatarUrl: string;
  439. avatarUrl1: string;
  440. beforeUpload = (file: File) => {
  441. return new Observable((observer: Observer<boolean>) => {
  442. let type = file.name.split('.')
  443. console.log(888,type[1])
  444. const isPic = (type[1] === 'xlsx' || type[1] === 'pdf' ||
  445. type[1] === 'xls' || type[1] === 'ppt' || type[1] === 'txt');
  446. if (!isPic) {
  447. this.message.error('只能上传PDF、word、ppt、excel、txt等文件类型格式!');
  448. observer.complete();
  449. return;
  450. }
  451. const isLt4M = file.size / 1024 / 1024 < 10;
  452. if (!isLt4M) {
  453. this.message.error('图片大小不能大于10MB!');
  454. observer.complete();
  455. return;
  456. }
  457. observer.next(isPic && isLt4M);
  458. observer.complete();
  459. });
  460. };
  461. // 附件上传
  462. handleChange(info: { file: UploadFile }): void {
  463. // console.log(999,this.fileData)
  464. }
  465. private getBase64(img: File, callback: (img: string) => void): void {
  466. const reader = new FileReader();
  467. reader.addEventListener('load', () => callback(reader.result!.toString()));
  468. reader.readAsDataURL(img);
  469. }
  470. // 删除附件
  471. removeFile = (file: File) => {
  472. // let index = this.fileData.findIndex(i=>i.uid==e.uid)
  473. // this.fileData.splice(index, 1)
  474. }
  475. // 自定义上传
  476. customReq = (item: UploadXHRArgs) => {
  477. // this.fileData.push(item.file)
  478. // console.log(2222,this.fileData);
  479. // Create a FormData here to store files and other parameters.
  480. const formData = new FormData();
  481. // tslint:disable-next-line:no-any
  482. formData.append('file', item.file as any);
  483. formData.append('filename', item.file.name);
  484. const req = new HttpRequest('POST', item.action!, formData, {
  485. reportProgress: true,
  486. withCredentials: true
  487. });
  488. // Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
  489. return this.http.request(req).subscribe(
  490. // tslint:disable-next-line no-any
  491. (event: HttpEvent<any>) => {
  492. if (event.type === HttpEventType.UploadProgress) {
  493. if (event.total! > 0) {
  494. // tslint:disable-next-line:no-any
  495. (event as any).percent = (event.loaded / event.total!) * 100;
  496. }
  497. item.onProgress!(event, item.file!);
  498. } else if (event instanceof HttpResponse) {
  499. item.onSuccess!(event.body, item.file!, event);
  500. }
  501. },
  502. err => {
  503. item.onError!(err, item.file!);
  504. }
  505. );
  506. };
  507. closeModel(){
  508. this.back()
  509. }
  510. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  511. showPromptModal(con, success, promptInfo?) {
  512. this.promptModalShow = false;
  513. this.promptContent = con;
  514. this.ifSuccess = success;
  515. this.promptInfo = promptInfo;
  516. setTimeout(() => {
  517. this.promptModalShow = true;
  518. }, 100);
  519. }
  520. delModal: boolean = false; //删除模态框
  521. coopIds: any;
  522. coopFlag: any = false;
  523. }