data-dictionary.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. @Component({
  8. selector: "app-data-dictionary",
  9. templateUrl: "./data-dictionary.component.html",
  10. styleUrls: ["./data-dictionary.component.less"],
  11. })
  12. export class DataDictionaryComponent implements OnInit {
  13. tableHeight;
  14. validateForm: FormGroup;
  15. allDataList: any[] = []; //数据字典下的数据列表
  16. mapOfCheckedId: { [key: string]: boolean } = {};
  17. checkedDictionary: any = {}; //选中
  18. dictionaryList: Array<any> = []; //数据字典信息
  19. parentList: Array<any> = []; //父级数据字典信息
  20. hosId: any; //当前选择的院区id
  21. promptContent: string; //操作提示框提示信息
  22. ifSuccess: boolean; //操作成功/失败
  23. promptInfo: string; //操作结果提示信息
  24. promptModalShow: boolean; //是否展示提示框
  25. btnLoading: boolean = false; //确认按钮loading状态
  26. coopBtns: any = {}; // 初始化增删改按钮
  27. dictionaryLoading = false; //loading
  28. positionY = 0; //记录Y轴滚动距离
  29. selectedDictionary = []; //选中的
  30. add: boolean = true; //新增的标识,true:新增;false:编辑
  31. dictionaryModal: boolean = false; //模态框是否展示
  32. dataEdit; //正在编辑的
  33. delModal: boolean = false; //删除,模态框是否显示
  34. delDictionaryModal: boolean = false; //删除,模态框是否显示
  35. isDelSingle: boolean = false; //是否单个删除
  36. isAllDisplayDataChecked = false; //当前页是否全选
  37. constructor(
  38. private fb: FormBuilder,
  39. private route: ActivatedRoute,
  40. private mainService: MainService,
  41. private tool: ToolService
  42. ) {}
  43. @ViewChild("osComponentRef1", {
  44. read: OverlayScrollbarsComponent,
  45. static: true,
  46. })
  47. osComponentRef1: OverlayScrollbarsComponent;
  48. ngOnInit() {
  49. this.coopBtns = this.tool.initCoopBtns(this.route);
  50. this.hosId = this.tool.getCurrentHospital().id;
  51. this.getDictionaryList();
  52. this.tableHeight = document.body.clientHeight - 312;
  53. }
  54. // 数据字典列表
  55. getDictionaryList() {
  56. this.dictionaryList = [
  57. {
  58. id: -1,
  59. dictionaryName: '被服种类',
  60. key: 'clothes_type',
  61. type: 'dictionaryTree',
  62. },
  63. {
  64. id: -2,
  65. dictionaryName: '统计分类',
  66. key: 'statistics_date_type',
  67. type: 'dictionary',
  68. },
  69. {
  70. id: -3,
  71. dictionaryName: '大扫描提示',
  72. key: 'bigScan_special_msg',
  73. type: 'dictionary',
  74. },
  75. ];
  76. if (Object.keys(this.checkedDictionary).length) {
  77. this.dictionaryList.forEach((item) => {
  78. if (item.id == this.checkedDictionary.id) {
  79. this.checkDictionary(item);
  80. }
  81. });
  82. } else {
  83. this.checkDictionary(this.dictionaryList[0]);
  84. }
  85. }
  86. searchDto:any = {
  87. parent: null,
  88. }
  89. // 获取父级分类
  90. getParentList() {
  91. let postData = {
  92. idx: 0,
  93. sum: 9999,
  94. dictionaryTree: {
  95. hosId: this.hosId,
  96. level: 1,
  97. key: 'clothes_type',
  98. deleted: 0,
  99. },
  100. };
  101. this.mainService
  102. .getFetchDataList("simple/data", "dictionaryTree", postData)
  103. .subscribe((result) => {
  104. if(result.status == 200){
  105. this.parentList = result.list || [];
  106. }
  107. });
  108. }
  109. // 获取选中数据字典列表
  110. getAll() {
  111. this.dictionaryLoading = true;
  112. let postData = {};
  113. if(this.checkedDictionary.type === 'dictionary'){
  114. postData = {
  115. idx: 0,
  116. sum: 9999,
  117. dictionary: {
  118. key: this.checkedDictionary.key,
  119. deleted: 0,
  120. },
  121. }
  122. }else if(this.checkedDictionary.type === 'dictionaryTree'){
  123. postData = {
  124. idx: 0,
  125. sum: 9999,
  126. dictionaryTree: {
  127. hosId: this.hosId,
  128. level: 2,
  129. parent: this.searchDto.parent || undefined,
  130. key: this.checkedDictionary.key,
  131. deleted: 0,
  132. },
  133. }
  134. }
  135. this.mainService
  136. .getFetchDataList("simple/data", this.checkedDictionary.type, postData)
  137. .subscribe((result) => {
  138. this.dictionaryLoading = false;
  139. if (result.status == 200) {
  140. this.allDataList = result.list;
  141. this.refreshStatus();
  142. }
  143. });
  144. }
  145. // 选中数据字典
  146. checkDictionary(data) {
  147. this.positionY = this.osComponentRef1.osInstance() ? this.osComponentRef1.osInstance().scroll().position.y : 0; //内容滚动的距离
  148. this.checkedDictionary = data ? data : {};
  149. this.mapOfCheckedId = {};
  150. this.getAll();
  151. this.checkedDictionary.type === 'dictionaryTree' && this.getParentList();
  152. }
  153. selectedUser(data) {
  154. this.mapOfCheckedId[data.id] = !this.mapOfCheckedId[data.id];
  155. this.refreshStatus();
  156. }
  157. // 选中列表中
  158. refreshStatus(): void {
  159. let arr = [];
  160. if (this.allDataList.length) {
  161. this.isAllDisplayDataChecked = this.allDataList.every(
  162. (item) => this.mapOfCheckedId[item.id]
  163. );
  164. } else {
  165. this.isAllDisplayDataChecked = false;
  166. }
  167. for (var m in this.mapOfCheckedId) {
  168. if (this.mapOfCheckedId[m]) {
  169. arr.push({ id: m });
  170. }
  171. }
  172. this.selectedDictionary = arr;
  173. }
  174. // 新增/编辑模态框
  175. showModal(e, type, data?) {
  176. e.stopPropagation();
  177. this.dictionaryModal = true;
  178. this.add = type == "add";
  179. if (type == "edit") {
  180. this.initForm();
  181. this.dataEdit = data;
  182. if(this.checkedDictionary.type === 'dictionaryTree'){
  183. this.validateForm.controls.key.setValue(data.key);
  184. this.validateForm.controls.parent.setValue(data.parent);
  185. this.validateForm.controls.name.setValue(data.name);
  186. this.validateForm.controls.value.setValue(data.value);
  187. this.validateForm.controls.orders.setValue(data.orders);
  188. this.validateForm.controls.extra3.setValue(data.extra3);
  189. this.validateForm.controls.desc.setValue(data.desc);
  190. } else if(this.checkedDictionary.type === 'dictionary'){
  191. this.validateForm.controls.key.setValue(data.key);
  192. this.validateForm.controls.name.setValue(data.name);
  193. this.validateForm.controls.value.setValue(data.value);
  194. this.validateForm.controls.orders.setValue(data.orders);
  195. this.validateForm.controls.desc.setValue(data.desc);
  196. }
  197. } else {
  198. this.initForm();
  199. }
  200. }
  201. // 隐藏模态框
  202. hideModal() {
  203. this.dictionaryModal = false;
  204. }
  205. // 初始化新增form表单dictionary
  206. initForm() {
  207. if(this.checkedDictionary.type === 'dictionaryTree'){
  208. this.validateForm = this.fb.group({
  209. key: [this.checkedDictionary.key, [Validators.required]],
  210. parent: [null, [Validators.required]],
  211. name: [null, [Validators.required]],
  212. value: [null, [Validators.required]],
  213. orders: [0, [Validators.required]],
  214. extra3: [0, [Validators.required]],
  215. desc: [null, [Validators.required]],
  216. });
  217. } else if(this.checkedDictionary.type === 'dictionary'){
  218. this.validateForm = this.fb.group({
  219. key: [this.checkedDictionary.key, [Validators.required]],
  220. name: [null, [Validators.required]],
  221. value: [null, [Validators.required]],
  222. orders: [0, [Validators.required]],
  223. desc: [null, [Validators.required]],
  224. });
  225. }
  226. }
  227. // 数据字典修改name,value自动变化,且value禁止修改
  228. changeValue(e){
  229. if(this.checkedDictionary.type === 'dictionary'){
  230. this.validateForm.controls.value.setValue(e.target.value);
  231. }
  232. }
  233. // 新增/编辑提交
  234. submitForm(): void {
  235. for (const i in this.validateForm.controls) {
  236. this.validateForm.controls[i].markAsDirty();
  237. this.validateForm.controls[i].updateValueAndValidity();
  238. }
  239. if (this.validateForm.invalid) return;
  240. this.btnLoading = true;
  241. let postData;
  242. if(this.checkedDictionary.type === 'dictionaryTree'){
  243. if (this.add) {
  244. postData = {
  245. hosId: this.hosId,
  246. key: this.validateForm.value.key,
  247. parent: this.validateForm.value.parent,
  248. name: this.validateForm.value.name,
  249. value: this.validateForm.value.value,
  250. orders: this.validateForm.value.orders,
  251. extra3: this.validateForm.value.extra3,
  252. desc: this.validateForm.value.desc,
  253. level: 2,
  254. system: 0,
  255. };
  256. } else {
  257. postData = {
  258. hosId: this.hosId,
  259. key: this.validateForm.value.key,
  260. parent: this.validateForm.value.parent,
  261. name: this.validateForm.value.name,
  262. value: this.validateForm.value.value,
  263. orders: this.validateForm.value.orders,
  264. extra3: this.validateForm.value.extra3,
  265. desc: this.validateForm.value.desc,
  266. id: this.dataEdit.id,
  267. level: 2,
  268. system: 0,
  269. };
  270. }
  271. }else if(this.checkedDictionary.type === 'dictionary'){
  272. if (this.add) {
  273. postData = {
  274. key: this.validateForm.value.key,
  275. name: this.validateForm.value.name,
  276. value: this.validateForm.value.value,
  277. orders: this.validateForm.value.orders,
  278. desc: this.validateForm.value.desc,
  279. system: 0,
  280. };
  281. } else {
  282. postData = {
  283. key: this.validateForm.value.key,
  284. name: this.validateForm.value.name,
  285. value: this.validateForm.value.value,
  286. orders: this.validateForm.value.orders,
  287. desc: this.validateForm.value.desc,
  288. system: 0,
  289. id: this.dataEdit.id,
  290. };
  291. }
  292. }
  293. this.addHandler(postData);
  294. }
  295. //新增/编辑
  296. addHandler(postData) {
  297. this.mainService
  298. .simplePost("addData", this.checkedDictionary.type, postData)
  299. .subscribe((result) => {
  300. this.hideModal();
  301. this.btnLoading = false;
  302. if (result["status"] == 200) {
  303. if(this.checkedDictionary.type === 'dictionary'){
  304. this.mainService.clearDictionary();
  305. }
  306. this.showPromptModal(this.add ? "新增" : "编辑", true, "");
  307. } else {
  308. this.showPromptModal(
  309. this.add ? "新增" : "编辑",
  310. false,
  311. result["msg"]
  312. );
  313. }
  314. });
  315. }
  316. /**
  317. * 删除
  318. * @param e 事件对象
  319. * @param data 有值就是单个删除,无值就是批量删除
  320. */
  321. showDelDictionaryModal(e, data?) {
  322. if (data) {
  323. this.isDelSingle = true;
  324. this.dataEdit = data;
  325. } else {
  326. this.isDelSingle = false;
  327. }
  328. this.delDictionaryModal = true;
  329. e.stopPropagation();
  330. }
  331. hideDelDictionaryModal() {
  332. this.delDictionaryModal = false;
  333. }
  334. // 确认删除
  335. confirmDictionaryDel() {
  336. this.btnLoading = true;
  337. let selectedDictionary = this.selectedDictionary.map((item) => item.id);
  338. let postData = this.isDelSingle ? [this.dataEdit.id] : selectedDictionary;
  339. this.mainService.simplePost("rmvData", this.checkedDictionary.type, postData).subscribe((result) => {
  340. this.hideDelDictionaryModal();
  341. this.btnLoading = false;
  342. if (result.status == 200) {
  343. if(this.checkedDictionary.type === 'dictionary'){
  344. this.mainService.clearDictionary();
  345. }
  346. this.showPromptModal("删除", true, "");
  347. } else {
  348. this.showPromptModal("删除", false, result.msg);
  349. }
  350. });
  351. }
  352. // 全选
  353. checkAll(value: boolean): void {
  354. console.log(this.allDataList);
  355. this.allDataList.forEach((item) => {
  356. this.mapOfCheckedId[item.id] = value;
  357. });
  358. this.refreshStatus();
  359. }
  360. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  361. showPromptModal(con, success, promptInfo) {
  362. this.promptModalShow = false;
  363. this.promptContent = con;
  364. this.ifSuccess = success;
  365. this.promptInfo = promptInfo;
  366. this.osComponentRef1.osInstance().scroll({ x: 0, y: this.positionY });
  367. if (success) {
  368. setTimeout(() => {
  369. this.promptModalShow = true;
  370. this.getDictionaryList();
  371. }, 100);
  372. } else {
  373. setTimeout(() => {
  374. this.promptModalShow = true;
  375. }, 100);
  376. }
  377. }
  378. }