building-floor.component.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { FormBuilder, Validators, FormGroup } from "@angular/forms";
  4. import { MainService } from "../../services/main.service";
  5. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  6. import { ToolService } from "../../services/tool.service";
  7. import { GenerateFloorComponent } from "src/app/share/generate-floor/generate-floor.component";
  8. import { NzMessageService } from "ng-zorro-antd";
  9. import host from "../../../assets/js/http";
  10. import { HttpRequest, HttpResponse, HttpClient } from '@angular/common/http';
  11. import { filter } from 'rxjs/operators';
  12. @Component({
  13. selector: "app-building-floor",
  14. templateUrl: "./building-floor.component.html",
  15. styleUrls: ["./building-floor.component.less"],
  16. })
  17. export class BuildingFloorComponent implements OnInit {
  18. tableHeight;
  19. validateForm: FormGroup;
  20. validateFloorForm: FormGroup;
  21. allFloorList: any[] = []; //当前选中的楼栋包含的所有楼层
  22. mapOfCheckedId: { [key: string]: boolean } = {};
  23. checkedBuilding: any = {}; //选中楼栋
  24. buildingList: Array<any> = []; //楼栋信息
  25. hosId: any; //当前选择的院区id
  26. promptContent: string; //操作提示框提示信息
  27. ifSuccess: boolean; //操作成功/失败
  28. promptInfo: string; //操作结果提示信息
  29. promptModalShow: boolean; //是否展示提示框
  30. btnLoading: boolean = false; //确认按钮loading状态
  31. coopBtns: any = {}; // 初始化增删改按钮
  32. buildingsLoading = false; //获取楼栋列表的loading
  33. floorsLoading = false; //获取楼层列表的loading
  34. positionY = 0; //记录Y轴滚动距离
  35. selectedFloor = []; //选中的楼层
  36. coopModal: boolean = false; //楼栋模态框是否展示
  37. add: boolean = true; //楼栋新增的标识,true:新增;false:编辑
  38. floorModal: boolean = false; //楼层模态框是否展示
  39. addFloor: boolean = true; //楼层,true:新增;false:编辑
  40. floorDataEdit; //正在编辑的楼层
  41. delModal: boolean = false; //删除楼栋,模态框是否显示
  42. delFloorModal: boolean = false; //删除楼层,模态框是否显示
  43. isDelSingle: boolean = false; //是否单个删除楼层
  44. generateModal: boolean = false; //生成楼层的模态框
  45. isAllDisplayDataChecked = false; //当前页是否全选
  46. maskFlag: any = false;
  47. constructor(
  48. private fb: FormBuilder,
  49. private route: ActivatedRoute,
  50. private mainService: MainService,
  51. private message: NzMessageService,
  52. private tool: ToolService,
  53. private http: HttpClient,
  54. ) {}
  55. @ViewChild("osComponentRef1", {
  56. read: OverlayScrollbarsComponent,
  57. static: false,
  58. })
  59. osComponentRef1: OverlayScrollbarsComponent;
  60. @ViewChild(GenerateFloorComponent, { static: false })
  61. generate1: GenerateFloorComponent;
  62. ngOnInit() {
  63. this.coopBtns = this.tool.initCoopBtns(this.route);
  64. this.hosId = this.tool.getCurrentHospital().id;
  65. this.getBuildingList();
  66. this.tableHeight = document.body.clientHeight - 312;
  67. }
  68. // 模板导出
  69. excelExport(){
  70. this.maskFlag = this.message.loading("下载模板中..", {
  71. nzDuration: 0,
  72. }).messageId;
  73. this.mainService.exportExcel("building", {}).subscribe(
  74. (data) => {
  75. this.message.remove(this.maskFlag);
  76. this.maskFlag = false;
  77. this.message.success('下载模板成功');
  78. var file = new Blob([data], {
  79. type: "application/vnd.ms-excel",
  80. });
  81. //trick to download store a file having its URL
  82. var fileURL = URL.createObjectURL(file);
  83. var a = document.createElement("a");
  84. a.href = fileURL;
  85. a.target = "_blank";
  86. a.download = "楼栋楼层导入模板.xls";
  87. document.body.appendChild(a);
  88. a.click();
  89. },
  90. (err) => {
  91. this.message.remove(this.maskFlag);
  92. this.maskFlag = false;
  93. this.message.error('下载模板失败');
  94. }
  95. );
  96. }
  97. // 导入---start
  98. // model-取消
  99. isShow = false;
  100. hideExcelImport() {
  101. this.isShow = false;
  102. }
  103. // 触发
  104. excelImport() {
  105. this.isShow = true;
  106. }
  107. submitExcelImport({fileList}){
  108. this.isShow = false;
  109. const formData = new FormData();
  110. fileList.forEach((file: any) => {
  111. formData.append('file', file);
  112. });
  113. this.maskFlag = this.message.loading("正在导入中..", {
  114. nzDuration: 0,
  115. }).messageId;
  116. const req = new HttpRequest('Post', host.host + '/user/data/importExcel/building', formData, {
  117. reportProgress: true
  118. });
  119. this.http
  120. .request(req)
  121. .pipe(filter(e => e instanceof HttpResponse))
  122. .subscribe(
  123. (res:any) => {
  124. if(res.body.status == 200){
  125. this.message.remove(this.maskFlag);
  126. this.maskFlag = false;
  127. this.message.success('导入成功');
  128. this.getBuildingList();
  129. }else{
  130. this.message.remove(this.maskFlag);
  131. this.maskFlag = false;
  132. this.showPromptModal("导入", false, res.body.msg);
  133. }
  134. },
  135. () => {
  136. this.message.remove(this.maskFlag);
  137. this.maskFlag = false;
  138. this.message.error('导入失败');
  139. },
  140. );
  141. }
  142. // 导入---end
  143. // 楼栋列表
  144. getBuildingList() {
  145. let postData = {
  146. idx: 0,
  147. sum: 9999,
  148. building: { hosId: this.hosId },
  149. };
  150. this.buildingsLoading = true;
  151. this.mainService
  152. .getFetchDataList("simple/data", "building", postData)
  153. .subscribe((result) => {
  154. this.buildingsLoading = false;
  155. if (result.status == 200) {
  156. this.buildingList = result.list;
  157. if (Object.keys(this.checkedBuilding).length) {
  158. result.list.forEach((item) => {
  159. if (item.id == this.checkedBuilding.id) {
  160. this.checkBuilding(item);
  161. }
  162. });
  163. } else {
  164. this.checkBuilding(result.list[0]);
  165. }
  166. }
  167. });
  168. }
  169. // 获取选中楼栋下楼层列表
  170. getAllFloor() {
  171. // 初始化的时候搜索一次,然后前端过滤
  172. let postData = {
  173. idx: 0,
  174. sum: 9999,
  175. floor: { hosId: this.hosId, buildId: this.checkedBuilding.id },
  176. };
  177. this.floorsLoading = true;
  178. this.mainService
  179. .getFetchDataList("simple/data", "floor", postData)
  180. .subscribe((result) => {
  181. this.floorsLoading = false;
  182. if (result.status == 200) {
  183. this.allFloorList = result.list;
  184. this.refreshStatus();
  185. }
  186. });
  187. }
  188. // 选中楼栋
  189. checkBuilding(data) {
  190. this.positionY = this.osComponentRef1.osInstance().scroll().position.y; //内容滚动的距离
  191. this.checkedBuilding = data ? data : {};
  192. this.mapOfCheckedId = {};
  193. this.getAllFloor();
  194. }
  195. selectedUser(data) {
  196. this.mapOfCheckedId[data.id] = !this.mapOfCheckedId[data.id];
  197. this.refreshStatus();
  198. }
  199. // 选中列表中楼层
  200. refreshStatus(): void {
  201. let arr = [];
  202. if (this.allFloorList.length) {
  203. this.isAllDisplayDataChecked = this.allFloorList.every(
  204. (item) => this.mapOfCheckedId[item.id]
  205. );
  206. } else {
  207. this.isAllDisplayDataChecked = false;
  208. }
  209. for (var m in this.mapOfCheckedId) {
  210. if (this.mapOfCheckedId[m]) {
  211. arr.push({ id: m });
  212. }
  213. }
  214. this.selectedFloor = arr;
  215. }
  216. // 新增/编辑楼栋模态框
  217. showCoopModal(type) {
  218. if (type == "edit" && !this.checkedBuilding.id) {
  219. this.message.create("warning", "请选择需要编辑的楼栋!");
  220. return;
  221. }
  222. this.coopModal = true;
  223. this.add = type == "add";
  224. if (type == "edit") {
  225. this.initForm();
  226. this.validateForm.controls.buildingName.setValue(
  227. this.checkedBuilding["buildingName"]
  228. );
  229. } else {
  230. this.initForm();
  231. }
  232. }
  233. // 新增/编辑楼层模态框
  234. showFloorModal(e, type, data?) {
  235. this.floorModal = true;
  236. this.addFloor = type == "add";
  237. if (type == "edit") {
  238. this.initFormFloor();
  239. this.floorDataEdit = data;
  240. this.validateFloorForm.controls.buildId.setValue(data.buildId);
  241. this.validateFloorForm.controls.floorName.setValue(data.floorName);
  242. } else {
  243. this.initFormFloor();
  244. }
  245. e.stopPropagation();
  246. }
  247. // 隐藏楼栋模态框
  248. hideCoopModal() {
  249. this.coopModal = false;
  250. }
  251. // 隐藏楼层模态框
  252. hideFloorModal() {
  253. this.floorModal = false;
  254. }
  255. // 初始化新增form表单
  256. initForm() {
  257. this.validateForm = this.fb.group({
  258. buildingName: [null, [Validators.required]],
  259. });
  260. }
  261. // 初始化新增form表单floor
  262. initFormFloor() {
  263. this.validateFloorForm = this.fb.group({
  264. buildId: [this.checkedBuilding.id, [Validators.required]],
  265. floorName: [null, [Validators.required]],
  266. });
  267. }
  268. // 新增/编辑楼栋提交
  269. submitForm(): void {
  270. for (const i in this.validateForm.controls) {
  271. this.validateForm.controls[i].markAsDirty();
  272. this.validateForm.controls[i].updateValueAndValidity();
  273. }
  274. if (this.validateForm.invalid) return;
  275. this.btnLoading = true;
  276. let postData;
  277. let arr = this.buildingList.filter(
  278. (item) => item.buildingName == this.validateForm.value.buildingName
  279. );
  280. //有重复名称
  281. if (arr.length > 0) {
  282. this.btnLoading = false;
  283. this.showPromptModal(
  284. "新增",
  285. false,
  286. `存在重复的楼栋名称【${this.validateForm.value.buildingName}】请修改后再保存!`
  287. );
  288. return;
  289. }
  290. if (this.add) {
  291. postData = {
  292. buildingName: this.validateForm.value.buildingName,
  293. deleted: false,
  294. hosId: this.hosId,
  295. };
  296. } else {
  297. postData = {
  298. buildingName: this.validateForm.value.buildingName,
  299. deleted: false,
  300. hosId: this.hosId,
  301. id: this.checkedBuilding.id,
  302. };
  303. }
  304. this.mainService
  305. .simplePost("addData", "building", postData)
  306. .subscribe((result) => {
  307. this.hideCoopModal();
  308. this.btnLoading = false;
  309. if (result["status"] == 200) {
  310. this.showPromptModal(this.add ? "新增" : "编辑", true, "");
  311. } else {
  312. this.showPromptModal(
  313. this.add ? "新增" : "编辑",
  314. false,
  315. result["msg"]
  316. );
  317. }
  318. });
  319. }
  320. // 新增/编辑楼层提交
  321. submitFormFloor(): void {
  322. for (const i in this.validateFloorForm.controls) {
  323. this.validateFloorForm.controls[i].markAsDirty();
  324. this.validateFloorForm.controls[i].updateValueAndValidity();
  325. }
  326. if (this.validateFloorForm.invalid) return;
  327. this.btnLoading = true;
  328. let postData;
  329. let arr = this.allFloorList.filter(
  330. (item) => item.floorName == this.validateFloorForm.value.floorName
  331. );
  332. //有重复名称
  333. if (arr.length > 0) {
  334. this.btnLoading = false;
  335. this.showPromptModal(
  336. "新增",
  337. false,
  338. `同一个楼栋存在重复的楼层名称【${this.validateFloorForm.value.floorName}】请修改后再保存!`
  339. );
  340. return;
  341. }
  342. if (this.addFloor) {
  343. postData = {
  344. buildId: this.validateFloorForm.value.buildId,
  345. floorName: this.validateFloorForm.value.floorName,
  346. deleted: false,
  347. hosId: this.hosId,
  348. };
  349. } else {
  350. postData = {
  351. buildId: this.validateFloorForm.value.buildId,
  352. floorName: this.validateFloorForm.value.floorName,
  353. deleted: false,
  354. hosId: this.hosId,
  355. id: this.floorDataEdit.id,
  356. };
  357. }
  358. this.addFloorHandler(postData, false);
  359. }
  360. //新增楼层
  361. addFloorHandler(postData, flag) {
  362. this.mainService
  363. .simplePost(flag ? "addListData" : "addData", "floor", postData)
  364. .subscribe((result) => {
  365. this.hideFloorModal();
  366. this.generate1 && (this.generate1.delModal = false);
  367. this.hideGenerateModal();
  368. this.btnLoading = false;
  369. if (result["status"] == 200) {
  370. this.showPromptModal(this.addFloor ? "新增" : "编辑", true, "");
  371. } else {
  372. this.showPromptModal(
  373. this.addFloor ? "新增" : "编辑",
  374. false,
  375. result["msg"]
  376. );
  377. }
  378. });
  379. }
  380. //删除楼栋
  381. showDelModal() {
  382. if (!this.checkedBuilding.id) {
  383. this.message.create("warning", "请选择需要删除的楼栋!");
  384. return;
  385. }
  386. this.delModal = true;
  387. }
  388. hideDelModal() {
  389. this.delModal = false;
  390. }
  391. // 确认删除
  392. confirmDel() {
  393. this.btnLoading = true;
  394. let postData = [this.checkedBuilding["id"]];
  395. this.mainService.delBuildingList(postData).subscribe((result) => {
  396. this.hideDelModal();
  397. this.btnLoading = false;
  398. if (result["status"] == 200 && !result["data"][0].msg) {
  399. this.showPromptModal("删除", true, "");
  400. this.checkedBuilding = {};
  401. } else {
  402. this.showPromptModal("删除", false, result["data"][0].msg);
  403. }
  404. });
  405. }
  406. /**
  407. * 删除楼层
  408. * @param e 事件对象
  409. * @param data 有值就是单个删除,无值就是批量删除
  410. */
  411. showDelFloorModal(e, data?) {
  412. if (data) {
  413. this.isDelSingle = true;
  414. this.floorDataEdit = data;
  415. } else {
  416. this.isDelSingle = false;
  417. }
  418. this.delFloorModal = true;
  419. e.stopPropagation();
  420. }
  421. hideDelFloorModal() {
  422. this.delFloorModal = false;
  423. }
  424. // 确认删除
  425. confirmFloorDel() {
  426. this.btnLoading = true;
  427. let selectedFloor = this.selectedFloor.map((item) => item.id);
  428. let postData = this.isDelSingle ? [this.floorDataEdit.id] : selectedFloor;
  429. this.mainService.delFloorList(postData).subscribe((result) => {
  430. this.hideDelFloorModal();
  431. this.btnLoading = false;
  432. if (result["status"] == 200 && !result["data"][0].msg) {
  433. this.showPromptModal("删除", true, "");
  434. } else {
  435. this.showPromptModal("删除", false, result["data"][0].msg);
  436. }
  437. });
  438. }
  439. // 全选
  440. checkAll(value: boolean): void {
  441. console.log(this.allFloorList);
  442. this.allFloorList.forEach((item) => {
  443. this.mapOfCheckedId[item.id] = value;
  444. });
  445. this.refreshStatus();
  446. }
  447. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  448. showPromptModal(con, success, promptInfo) {
  449. this.promptModalShow = false;
  450. this.promptContent = con;
  451. this.ifSuccess = success;
  452. this.promptInfo = promptInfo;
  453. this.osComponentRef1.osInstance().scroll({ x: 0, y: this.positionY });
  454. if (success) {
  455. setTimeout(() => {
  456. this.promptModalShow = true;
  457. this.getBuildingList();
  458. }, 100);
  459. } else {
  460. setTimeout(() => {
  461. this.promptModalShow = true;
  462. }, 100);
  463. }
  464. }
  465. // 生成楼层
  466. generate() {
  467. this.generateModal = true;
  468. }
  469. // 隐藏楼层模态框
  470. hideGenerateModal() {
  471. this.generateModal = false;
  472. }
  473. // 确认生成
  474. confirmGenerate(e) {
  475. console.log(e);
  476. let arr = []; //生成的楼层
  477. for (let i = e[1]; i <= e[2]; i++) {
  478. arr.push({
  479. buildId: e[0].id,
  480. floorName: i + "",
  481. deleted: false,
  482. hosId: this.hosId,
  483. });
  484. }
  485. // 去重
  486. this.allFloorList.forEach((item1) => {
  487. arr = arr.filter(
  488. (item2) =>
  489. !(
  490. item1.buildId == item2.buildId && item1.floorName == item2.floorName
  491. )
  492. );
  493. });
  494. this.btnLoading = true;
  495. this.addFloorHandler(arr, true);
  496. }
  497. }