123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import { Component, OnInit } from "@angular/core";
- import { ActivatedRoute } from "@angular/router";
- import { NzMessageService } from "ng-zorro-antd";
- import { MainService } from "src/app/services/main.service";
- import { ToolService } from "src/app/services/tool.service";
- @Component({
- selector: "app-inspection-distance",
- templateUrl: "./inspection-distance.component.html",
- styleUrls: ["./inspection-distance.component.less"],
- })
- export class InspectionDistanceComponent implements OnInit {
- coopBtns: any = {};
- id: number = 0; //id
- hosId; //当前院区id
- buildings = []; //所有楼栋距离组合
- loading2: boolean = false; //获取所有楼栋配置的loading
- loading3: boolean = false; //保存所有楼栋配置的loading
- loading4: boolean = false; //删除楼栋配置的loading
- delModal: boolean = false; //删除的模态框
- delObj; //要删除的元素
- constructor(
- private route: ActivatedRoute,
- private mainService: MainService,
- private tool: ToolService,
- private message: NzMessageService
- ) {}
- ngOnInit() {
- this.hosId = this.tool.getCurrentHospital().id;
- this.coopBtns = this.tool.initCoopBtns(this.route);
- this.getBuildingConfig(this.hosId);
- }
- //获取楼栋距离配置
- getBuildingConfig(hosId) {
- let postData = { idx: 0, sum: 9999, workOrderInspectScore: { hosId } };
- this.loading2 = true;
- this.mainService
- .getFetchDataList("simple/data", "workOrderInspectScore", postData)
- .subscribe((result) => {
- this.loading2 = false;
- if (result.status == 200) {
- this.buildings = result.list.map((item) => {
- return {
- id: item.id,
- inspectMode: item.inspectMode,
- increaseScore: item.increaseScore,
- border: "none",
- };
- });
- } else {
- this.message.error("请求数据失败");
- }
- });
- }
- //新增
- addBuilding() {
- this.buildings.push({
- id: --this.id,
- inspectMode: '',
- buildingStart: null,
- buildingEnd: null,
- increaseScore: 0,
- border: "none",
- });
- }
- // 删除
- delete(obj) {
- this.delModal = true;
- this.delObj = obj;
- }
- //隐藏删除模态框
- hideDelModal() {
- this.delModal = false;
- }
- // 确定删除
- confirmDel() {
- this.loading4 = true;
- this.mainService.delBuildings([this.delObj.id]).subscribe((result) => {
- this.loading4 = false;
- if (result["status"] == 200) {
- this.message.success("删除成功");
- this.buildings = this.buildings.filter(
- (item) => item.id !== this.delObj.id
- );
- } else {
- this.message.error("删除失败");
- }
- this.hideDelModal();
- });
- }
- //保存
- save() {
- this.buildings = this.buildings.filter(
- (item) => item.inspectMode && (item.increaseScore || item.increaseScore === 0)
- );
- let postData = this.buildings.map((item) => {
- return {
- id: item.id,
- inspectMode: item.inspectMode,
- increaseScore: item.increaseScore,
- hosId: this.hosId,
- };
- });
- postData.forEach((item) => {
- if (item.id < 0) {
- delete item.id;
- }
- });
- this.loading3 = true;
- this.mainService.saveInspections(postData).subscribe((result) => {
- this.loading3 = false;
- if (result["status"] == 200) {
- this.message.success("保存成功");
- this.getBuildingConfig(this.hosId);
- } else {
- this.message.error("保存失败");
- result["data"].forEach((item) => {
- let i = this.buildings.findIndex((v) => v.id === item.id);
- this.buildings[i].border = "red";
- });
- }
- });
- }
- //trackBy
- trackById(index, item) {
- return item.id;
- }
- }
|