123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- import { Component, OnInit, ViewChild } from "@angular/core";
- import { ActivatedRoute, Router } from "@angular/router";
- import {
- FormBuilder,
- Validators,
- FormGroup,
- FormControl,
- } from "@angular/forms";
- import { MainService } from "../../services/main.service";
- import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
- import { ToolService } from "../../services/tool.service";
- import { NzMessageService, UploadFile, UploadXHRArgs } from "ng-zorro-antd";
- import { Observable, Observer, Subject } from "rxjs";
- import { debounceTime, filter } from "rxjs/operators";
- import { HttpEventType, HttpEvent, HttpRequest, HttpResponse, HttpClient } from '@angular/common/http';
- @Component({
- selector: "app-repository-manage-add",
- templateUrl: "./repository-manage-add.component.html",
- styleUrls: ["./repository-manage-add.component.less"],
- })
- export class RepositoryManageAddComponent implements OnInit {
- @ViewChild("osComponentRef1", {
- read: OverlayScrollbarsComponent,
- static: false,
- })
- osComponentRef1: OverlayScrollbarsComponent;
- constructor(
- private message: NzMessageService,
- private fb: FormBuilder,
- private route: ActivatedRoute,
- private router: Router,
- private mainService: MainService,
- private tool: ToolService,
- private http: HttpClient,
- ) {}
- ngOnInit() {
- this.searchParentDeptSubject.pipe(debounceTime(500)).subscribe((e) => {
- this.isDeptLoading = true;
- this.getProduct(e[0]);
- });
- this.detailId = this.route.snapshot.params.id;
- if(this.detailId==0){
- this.add = true
- }else{
- this.add = false
- }
- this.hosId = this.tool.getCurrentHospital().id;
- this.coopBtns = this.tool.initCoopBtns(this.route);
- this.initForm();
- this.getAllHospital();
- }
- classItem:null;
- detailId:null; //列表数据
- deptId:null; //选中的科室id
- listOfData: any[] = []; //表格数据
- promptContent: string; //操作提示框提示信息
- ifSuccess: boolean; //操作成功/失败
- promptInfo: string; //操作结果提示信息
- promptModalShow: boolean; //操作提示框是否展示
- modal: boolean = false; //新增/编辑模态框
- add: boolean; //true:新增;false:编辑
- validateForm: FormGroup; //新增/编辑表单
- coopId: number; //表格中执行操作的id
- department: number; //所属科室
- drug: number; //药品名称
- hosId: number;
- rowId:number; //清单id
- dateRange;//时间
- batchNumber; //批次号
- num; //编码
- deptalias; //别名
- type; //类型
- deptHandoverType; //类型
- pageIndex: number = 1; //页码
- listLength: number = 10; //总条数
- pageSize: number = 10; //每页条数
- btnLoading1: boolean = false; //确认按钮loading状态
- btnLoading2: boolean = false; //确认按钮loading状态
- printLoading: boolean = false; //批量打印按钮loading状态
- deptPhones: any = []; //新添加的科室电话列表
- isAddDeptsPhone = true; //添加新的科室电话是否禁用
- deptsPhoneId = 1; //科室电话自增id
- allParentdepart: any = []; //所有的父级科室列表
- hospitals1: any = []; //科室列表
- buildingList: any = []; //楼栋列表
- deptList: any = []; //楼栋科室
- malfunctionData: any = []; //故障现象数据
- productData: any = []; //产品数据
- typeDic:any = []; //知识库状态字典
- fileData:any[] = []; //附件数据
- building:''; //楼栋
- deptIndex:number; //选中index
- searchParentDeptSubject = new Subject();
- // 初始化增删改按钮
- coopBtns: any = {};
- deptName:null;
- //搜索父级科室
- isDeptLoading = false;
- isSpinning = false;
- delGrantModal = false;
- showInsp = false;
- changeInp(e, type) {
- this.searchParentDeptSubject.next([e, type]);
- }
- // 表格数据
- loading1 = false;
- getList() {
- var that = this;
- let data = {
- idx: 0,
- sum: 9999,
- drugsConfigure: {
- hosId: this.hosId,
- deptId :this.deptId?this.deptId:null,
- batchId: this.detailId
- }
- };
- this.loading1 = true;
- that.mainService
- .getFetchDataList("data", "drugsConfigure", data)
- .subscribe((data) => {
- this.loading1 = false;
- that.listOfData = data.list;
- });
- }
-
- // 发药科室列表
- getDispensingDept(e,type){
- var that = this;
- let data = {
- idx: 0,
- sum: 9999,
- drugsConfigure: {
- hosId: this.hosId,
- deptId :e,
- batchId:''
- }
- };
- if(type=='dept'){
- data.drugsConfigure.batchId = this.detailId
- }else{
- delete data.drugsConfigure.batchId
- }
- let deptData = this.hospitals1.find(i=>i.id==e)
- that.mainService
- .getFetchDataList("data", "drugsConfigure", data)
- .subscribe((res) => {
- if(res.list.length==0){
- this.message.error(`您选择的科室“ ${deptData.dept}”时间段内没有消耗药品无法添加发药单。`)
- }else{
- this.getDeptData(e,'all','load')
- }
- });
- }
-
- // 科室点击
- deptClick(e,item,index){
- e.stopPropagation();
- this.deptId = item.applyDeptDTO.id
- this.deptName = item.applyDeptDTO.dept
- this.deptIndex = index
- this.getList()
- }
-
- // 科室删除
- deptDel(e,item,index){
- e.stopPropagation();
- this.delModal = true;
- this.coopId = item.applyDept;
- }
-
- hideDelModal() {
- this.delModal = false;
- }
-
- // 选择楼栋
- buildingChange(e){
- this.deptId = null
- this.deptName = null
- this.deptIndex = null
- this.listOfData=[]
- this.showInsp = true
- this.getDeptData(e,'','')
- }
-
- // 根据楼栋查询科室
- getDeptData(e,type,initial){
- var that = this;
- let data = {
- idx: 0,
- sum: 99999,
- drugsList: {
- hosId: this.hosId,
- buildingId:e,
- batch:{
- id:this.detailId
- }
- },
- };
- if(type=='all'){
- delete data.drugsList.buildingId
- }else{
- data.drugsList.buildingId = e
- }
- if(this.showInsp){
- this.isSpinning = true
- }
- that.mainService
- .getFetchDataList("data", "drugsList", data)
- .subscribe((res) => {
- this.isSpinning = false
- that.deptList = res.list;
- if(initial=='load'){
- if(res.list.length>0){
- this.deptId = res.list[0].applyDeptDTO.id
- this.deptName = res.list[0].applyDeptDTO.dept
- this.deptIndex = 0
- }
- this.getList()
- }
- });
- }
-
- // 选择科室
- addDeptId=''
- deptChange(e){
- this.addDeptId = e
-
- }
- // 添加科室
- addDept(){
- if(this.addDeptId){
- this.showInsp = true
- this.getDispensingDept(this.addDeptId,'dept')
- }else{
- this.message.error('请先选择发药科室')
- }
- }
-
- // 获取产品
- getProduct(name){
- let postData = {
- assetProduct: {
- hosId: this.hosId,
- name:name
- },
- idx: 0,
- sum: 20,
- };
- this.mainService
- .getFetchDataList("data", "assetProduct", postData)
- .subscribe((result) => {
- this.isDeptLoading = false
- this.productData = result.list;
- });
- }
-
- // 获取所有科室
- getDeparts() {
- let data = {
- batchId:this.detailId
- };
- this.mainService
- .getConsumeDept(data)
- .subscribe((res) => {
- this.hospitals1 = res.data
- });
- }
-
- // 获取所有院区
- getAllHospital() {
- this.getPolling()
- this.getProduct('')
- this.getMalfunction()
- this.getDicData()
- }
-
- // 获取故障现象数据
- getMalfunction(){
- let postData = {
- building: {
- cascadeHosId: this.hosId,
- },
- idx: 0,
- sum: 20,
- };
- this.mainService
- .getFetchDataList("data", "building", postData)
- .subscribe((result) => {
- this.malfunctionData = result.data
- });
- }
-
- // 获取巡检列表
- pollingData = [];
- getPolling(){
- let data = {
- idx: 0,
- sum: 9999,
- inspection: {
- hosId: this.hosId
- },
- };
- this.mainService
- .getFetchDataList("simple/data", "inspectionForm", data)
- .subscribe((data) => {
- if (data.status == 200) {
- this.pollingData = data.list.filter(i=>i.status.name=='已发布');
- }
- });
- }
-
- // 获取知识分类字典
- dicData = [];
- getDicData(){
- this.mainService.getDictionary("list", "solution_type").subscribe((res) => {
- this.dicData = res
- });
- this.mainService.getDictionary("list", "solution_status").subscribe((res) => {
- this.typeDic = res
- });
- }
-
- // 选择知识库分类
- radioChnage(e){
- let item = this.dicData.find(i=>i.id == this.validateForm.value.knowledgeClass)
- this.classItem = item.value
- }
-
-
-
- hideGrantModal(){
- this.delGrantModal = false;
- }
-
- // 增加/减少
- rowData = null;
- itemClick(e, data, type){
- e.stopPropagation();
- this.rowId = data.id
- this.rowData = data
- if(type=='add'){
- this.add = true
- }else{
- this.add = false
- }
- this.modal = true
- this.initForm();
- }
-
- // 富文本内容
- editOrData=null;
- changeContent(data){
- this.editOrData = data
- }
-
- // 表单提交
- submitForm(type): void {
- var that = this;
- for (const i in that.validateForm.controls) {
- that.validateForm.controls[i].markAsDirty();
- that.validateForm.controls[i].updateValueAndValidity();
- }
- if (that.validateForm.invalid) return;
- let data = {
- ...this.validateForm.value,
- content:this.editOrData,
- id:'',
- hosId:this.hosId,
- inspectionForm:{
- id:this.validateForm.value.polling
- },
- type:{
- id:this.validateForm.value.knowledgeClass
- },
- buttonType:type==1?'confirm':'ts'
- };
- if(this.add){
- delete data.id
- }else{
- data.id = this.detailId
- }
- if(type==1){
- that.btnLoading1 = true;
- }else{
- that.btnLoading2 = true;
- }
-
- that.mainService
- .simplePost("addData", "solution", data)
- .subscribe((res) => {
- if(type==1){
- that.btnLoading1 = false;
- }else{
- that.btnLoading2 = false;
- }
- if(this.fileData.length>0){
- this.uploadFile(res.data.id)
- if (res.status == 200) {
- that.showPromptModal(that.add ? "增加" : "减少", true, "");
- } else {
- that.showPromptModal(that.add ? "增加" : "减少", false, res.msg);
- }
- that.hideModal();
- }else{
- if (res.status == 200) {
- that.showPromptModal(that.add ? "增加" : "减少", true, "");
- } else {
- that.showPromptModal(that.add ? "增加" : "减少", false, res.msg);
- }
- that.hideModal();
- }
- });
- }
-
- // 上传图片
- uploadFile(id){
- console.log(555,this.fileData)
- let url = `/service/common/common/uploadAttachment/solution/${id}/${id}`
-
- for(let i of this.fileData){
- console.log(54545,i)
- const formData = new FormData();
- formData.append('file', i.originFileObj);
- formData.append('filename', i.originFileObj.name);
- const req = new HttpRequest('POST', url, formData, {
- reportProgress: true,
- withCredentials: true
- });
- this.http.request(req).subscribe((res) => {
-
- });
- }
- }
-
- // 新增弹框
- showModal() {
- this.add = true;
- this.isAddDeptsPhone = true;
- this.deptPhones = [];
- }
- // 返回
- back(){
- this.router.navigateByUrl(`/main/repositoryManage`);
- }
-
- hideModal() {
- this.initForm();
- this.modal = false;
- }
- // 初始化新增form表单
- initForm() {
- this.validateForm = this.fb.group({
- title: [null, [Validators.required]],
- code: [null, []],
- version: [null, []],
- content: [null, []],
- assetProductId: [null,[]],
- repairVisible: [null, [Validators.required]],
- knowledgeClass: [null, [Validators.required]],
- polling: [null, [Validators.required]],
-
- });
- }
-
- avatarLoading = false;
- avatarUrl: string;
- avatarUrl1: string;
- beforeUpload = (file: File) => {
- return new Observable((observer: Observer<boolean>) => {
- let type = file.name.split('.')
- console.log(888,type[1])
- const isPic = (type[1] === 'xlsx' || type[1] === 'pdf' ||
- type[1] === 'xls' || type[1] === 'ppt' || type[1] === 'txt');
- if (!isPic) {
- this.message.error('只能上传PDF、word、ppt、excel、txt等文件类型格式!');
- observer.complete();
- return;
- }
- const isLt4M = file.size / 1024 / 1024 < 10;
- if (!isLt4M) {
- this.message.error('图片大小不能大于10MB!');
- observer.complete();
- return;
- }
- observer.next(isPic && isLt4M);
- observer.complete();
- });
- };
-
- // 附件上传
- handleChange(info: { file: UploadFile }): void {
- // console.log(999,this.fileData)
- }
-
- private getBase64(img: File, callback: (img: string) => void): void {
- const reader = new FileReader();
- reader.addEventListener('load', () => callback(reader.result!.toString()));
- reader.readAsDataURL(img);
- }
-
- // 删除附件
- removeFile = (file: File) => {
-
- // let index = this.fileData.findIndex(i=>i.uid==e.uid)
- // this.fileData.splice(index, 1)
- }
-
- // 自定义上传
- customReq = (item: UploadXHRArgs) => {
- // this.fileData.push(item.file)
- // console.log(2222,this.fileData);
- // Create a FormData here to store files and other parameters.
- const formData = new FormData();
- // tslint:disable-next-line:no-any
- formData.append('file', item.file as any);
- formData.append('filename', item.file.name);
- const req = new HttpRequest('POST', item.action!, formData, {
- reportProgress: true,
- withCredentials: true
- });
- // Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
- return this.http.request(req).subscribe(
- // tslint:disable-next-line no-any
- (event: HttpEvent<any>) => {
- if (event.type === HttpEventType.UploadProgress) {
- if (event.total! > 0) {
- // tslint:disable-next-line:no-any
- (event as any).percent = (event.loaded / event.total!) * 100;
- }
- item.onProgress!(event, item.file!);
- } else if (event instanceof HttpResponse) {
- item.onSuccess!(event.body, item.file!, event);
- }
- },
- err => {
- item.onError!(err, item.file!);
- }
- );
- };
-
- closeModel(){
- this.back()
- }
-
- // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
- showPromptModal(con, success, promptInfo?) {
- this.promptModalShow = false;
- this.promptContent = con;
- this.ifSuccess = success;
- this.promptInfo = promptInfo;
- setTimeout(() => {
- this.promptModalShow = true;
- }, 100);
- }
- delModal: boolean = false; //删除模态框
- coopIds: any;
- coopFlag: any = false;
- }
|