configuration-inspect.component.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import { Component, OnInit, ViewChild, Input } from "@angular/core";
  2. import { ActivatedRoute } from "@angular/router";
  3. import { MainService } from "../../../services/main.service";
  4. import { Validators, FormGroup, FormBuilder, FormControl } from '@angular/forms';
  5. import { ToolService } from 'src/app/services/tool.service';
  6. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  7. import { NzMessageService } from 'ng-zorro-antd';
  8. import { v4 as uuidv4, validate as uuidValidate } from 'uuid';
  9. import { addDays, startOfMinute, endOfMinute, set, getYear, getMonth, getDate, format } from 'date-fns';
  10. @Component({
  11. selector: "app-configuration-inspect",
  12. templateUrl: "./configuration-inspect.component.html",
  13. styleUrls: ["./configuration-inspect.component.less"],
  14. })
  15. export class ConfigurationInspectComponent implements OnInit {
  16. constructor(
  17. private route: ActivatedRoute,
  18. private mainService: MainService,
  19. private fb: FormBuilder,
  20. private tool: ToolService,
  21. private message: NzMessageService,
  22. ) {}
  23. @ViewChild("osComponentRef1", {
  24. read: OverlayScrollbarsComponent,
  25. static: false,
  26. })
  27. osComponentRef1: OverlayScrollbarsComponent;
  28. @ViewChild("osComponentRef2", {
  29. read: OverlayScrollbarsComponent,
  30. static: false,
  31. })
  32. osComponentRef2: OverlayScrollbarsComponent;
  33. ngOnInit() {
  34. this.activeDictionaryKey = this.dictionaryKeyList[0];
  35. this.getDictionaryList();
  36. this.initDictionaryForm();
  37. }
  38. // 数据字典key列表
  39. dictionaryKeyList:any[] = [
  40. { id: 1, name: '注意事项', key: "inspect_notes"},
  41. { id: 2, name: '批量建单配置', key: "", postData: {
  42. ibActiveStartTime1: undefined,
  43. ibActiveEndTime1: undefined,
  44. ibActiveStartTime2: undefined,
  45. ibActiveEndTime2: undefined,
  46. ibDefaultStartTime: undefined,
  47. ibDefaultEndTime: undefined,
  48. ibDefaultDayStart: [{ label:'+1天', value: 0 }],
  49. ibDefaultDayEnd: [{ label:'+1天', value: 0 }],
  50. ib2ActiveStartTime1: undefined,
  51. ib2ActiveEndTime1: undefined,
  52. ib2ActiveStartTime2: undefined,
  53. ib2ActiveEndTime2: undefined,
  54. ib2DefaultStartTime: undefined,
  55. ib2DefaultEndTime: undefined,
  56. ib2DefaultDayStart: [{ label:'+1天', value: 0 }],
  57. ib2DefaultDayEnd: [{ label:'+1天', value: 0 }],
  58. }},
  59. { id: 3, name: '检查项目', key: ""},
  60. ]
  61. // 点击数据字典key
  62. activeDictionaryKey:any;
  63. clickDictionaryKey(item){
  64. this.activeDictionaryKey = item;
  65. if(this.activeDictionaryKey.id == 1){
  66. this.getDictionaryList();
  67. this.initDictionaryForm();
  68. }
  69. }
  70. btnLoading: boolean = false; //提交按钮loading状态
  71. // ------------------------------
  72. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  73. promptContent: string; //操作提示框提示信息
  74. ifSuccess: boolean; //操作成功/失败
  75. promptInfo: string; //操作结果提示信息
  76. promptModalShow: boolean; //操作提示框是否展示
  77. showPromptModal(con, success, promptInfo?) {
  78. this.promptModalShow = false;
  79. this.promptContent = con;
  80. this.ifSuccess = success;
  81. this.promptInfo = promptInfo;
  82. setTimeout(() => {
  83. this.promptModalShow = true;
  84. }, 100);
  85. this.getDictionaryList();
  86. }
  87. coopData: any = {}; //当前操作列
  88. delModal: boolean = false; //删除模态框
  89. tipsMsg1: string; //提示框信息
  90. tipsMsg2: string; //操作后信息
  91. confirmDelType: string; //确认的类型(启用/停用,删除)
  92. showDelModal(
  93. data,
  94. tipsMsg1: string,
  95. tipsMsg2: string,
  96. type: string,
  97. ) {
  98. this.confirmDelType = type;
  99. this.delModal = true;
  100. this.coopData = data;
  101. this.tipsMsg1 = tipsMsg1;
  102. this.tipsMsg2 = tipsMsg2;
  103. }
  104. // 隐藏删除框
  105. hideDelModal() {
  106. this.delModal = false;
  107. }
  108. // 确认删除
  109. confirmDel() {
  110. this.btnLoading = true;
  111. if (this.confirmDelType === "delDictionary") {
  112. //删除-数据字典
  113. this.mainService
  114. .simplePost("rmvData", "dictionary", [this.coopData.id])
  115. .subscribe((data) => {
  116. this.btnLoading = false;
  117. this.delModal = false;
  118. if (data.status == 200) {
  119. this.mainService.clearDictionary();
  120. this.showPromptModal(this.tipsMsg2, true, "");
  121. } else {
  122. this.showPromptModal(this.tipsMsg2, false, data.msg);
  123. }
  124. });
  125. }
  126. }
  127. // 初始化数据字典新增form表单
  128. validateDictionaryForm: FormGroup; //新增/编辑表单
  129. dictionaryList: any = [];
  130. initDictionaryForm() {
  131. this.validateDictionaryForm = this.fb.group({
  132. // name: [null, [Validators.required]],//键
  133. // value: [null, [Validators.required]],//值
  134. // orders: [null, [Validators.required]],//排序号
  135. });
  136. console.log(this.validateDictionaryForm.controls)
  137. }
  138. // 获取数据字典数据
  139. maskFlag: any = false;
  140. getDictionaryList() {
  141. let postData = {
  142. idx: 0,
  143. sum: 9999,
  144. dictionary: {
  145. key: this.activeDictionaryKey.key,
  146. }
  147. }
  148. this.maskFlag = this.message.loading("正在加载中..", {
  149. nzDuration: 0,
  150. }).messageId;
  151. this.mainService.getFetchDataList('simple/data','dictionary',postData).subscribe(data => {
  152. this.message.remove(this.maskFlag);
  153. this.maskFlag = false;
  154. let list = data.list || [];
  155. if(list.length){
  156. this.dictionaryList = list.map(v => {
  157. return {
  158. id: v.id,
  159. name: v.name || null,
  160. value: v.value || null,
  161. orders: v.orders || null,
  162. system: v.system || false,
  163. }
  164. });
  165. }else{
  166. this.dictionaryList = [
  167. {
  168. id: uuidv4(),
  169. name: null,
  170. value: null,
  171. orders: null,
  172. system: false,
  173. }
  174. ];
  175. }
  176. console.log(this.dictionaryList);
  177. // 动态添加表单
  178. this.dictionaryList.forEach((obj, i) => {
  179. for (const key in obj) {
  180. if(key !== 'id' && key !== 'system'){
  181. if(this.activeDictionaryKey.key === 'incident_status' || this.activeDictionaryKey.key === 'incident_degree'){
  182. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl({value: obj[key], disabled: true}, [Validators.required]))
  183. }else{
  184. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl({value: obj[key], disabled: key === 'value' ? obj.system : false}, [Validators.required]))
  185. }
  186. }
  187. }
  188. })
  189. console.log(this.validateDictionaryForm.controls)
  190. })
  191. }
  192. // 添加数据字典
  193. addField(i:number): void{
  194. let obj = {
  195. id: uuidv4(),
  196. name: null,
  197. value: null,
  198. orders: null,
  199. system: false,
  200. };
  201. // 动态添加表单
  202. for (const key in obj) {
  203. console.log(key + '_' + obj.id)
  204. if(key !== 'id' && key !== 'system'){
  205. this.validateDictionaryForm.addControl(key + '_' + obj.id, new FormControl(null, [Validators.required]))
  206. }
  207. }
  208. this.dictionaryList.splice(i + 1, 0, obj);
  209. }
  210. // 删除
  211. removeField(obj, i:number): void {
  212. if(uuidValidate(obj.id)){
  213. this.dictionaryList.splice(i, 1);
  214. this.dictionaryList = [...this.dictionaryList];
  215. // 动态删除表单
  216. for (const key in obj) {
  217. this.validateDictionaryForm.removeControl(key + '_' + obj.id);
  218. }
  219. }else{
  220. this.showDelModal(obj,'您确认要删除吗?','删除','delDictionary')
  221. }
  222. }
  223. // 保存数据字典
  224. saveDictionary(): void {
  225. console.log(this.coopData)
  226. for (const i in this.validateDictionaryForm.controls) {
  227. this.validateDictionaryForm.controls[i].markAsDirty();
  228. this.validateDictionaryForm.controls[i].updateValueAndValidity();
  229. }
  230. if (this.validateDictionaryForm.invalid) {
  231. return;
  232. }
  233. console.log(this.validateDictionaryForm.value);
  234. let postData:any = {};
  235. //增加
  236. postData = [];
  237. let rawValueObj = this.validateDictionaryForm.getRawValue();
  238. for (let i = 0; i < this.dictionaryList.length; i++) {
  239. postData.push({
  240. id: uuidValidate(this.dictionaryList[i].id) ? undefined : this.dictionaryList[i].id,
  241. name: rawValueObj['name_' + this.dictionaryList[i].id],
  242. value: rawValueObj['value_' + this.dictionaryList[i].id],
  243. orders: rawValueObj['orders_' + this.dictionaryList[i].id],
  244. system: uuidValidate(this.dictionaryList[i].id) ? false : this.dictionaryList[i].system,
  245. key: this.activeDictionaryKey.key,
  246. })
  247. }
  248. console.log(postData);
  249. this.btnLoading = true;
  250. this.mainService
  251. .simplePost("addListData", "dictionary", postData)
  252. .subscribe((result) => {
  253. this.btnLoading = false;
  254. if (result.status == 200) {
  255. this.mainService.clearDictionary();
  256. this.showPromptModal('保存', true, '');
  257. } else {
  258. this.showPromptModal('保存', false, result.msg || '');
  259. }
  260. });
  261. }
  262. }