attachment.component.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
  2. import { CommonCompModule } from '../../../../services/common.modules';
  3. import { NzSelectModule } from 'ng-zorro-antd/select';
  4. import { ReactiveFormsModule } from '@angular/forms';
  5. import { NzRadioModule } from 'ng-zorro-antd/radio';
  6. import { NzMessageService } from 'ng-zorro-antd/message';
  7. import { NzGridModule } from 'ng-zorro-antd/grid';
  8. import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
  9. import { NzTableModule } from 'ng-zorro-antd/table';
  10. import { NzUploadChangeParam } from 'ng-zorro-antd/upload';
  11. import { NzUploadModule } from 'ng-zorro-antd/upload';
  12. import { NzModalService } from 'ng-zorro-antd/modal';
  13. import Parse from 'parse';
  14. import {
  15. FormControl,
  16. FormGroup,
  17. NonNullableFormBuilder,
  18. Validators,
  19. ValidatorFn,
  20. AbstractControl,
  21. } from '@angular/forms';
  22. interface opinionType {
  23. name: string;
  24. unit: string;
  25. birth: Date | any;
  26. nationality: string;
  27. reviewFile: string | object;
  28. }
  29. import { textbookServer } from '../../../../services/textbook';
  30. @Component({
  31. selector: 'app-attachment',
  32. imports: [
  33. CommonCompModule,
  34. ReactiveFormsModule,
  35. NzSelectModule,
  36. NzRadioModule,
  37. NzGridModule,
  38. NzCheckboxModule,
  39. NzTableModule,
  40. NzUploadModule,
  41. ],
  42. standalone: true,
  43. templateUrl: './attachment.component.html',
  44. styleUrls: ['./attachment.component.scss'],
  45. })
  46. export class AttachmentComponent implements OnInit {
  47. @Input('eduTextbook') eduTextbook: any;
  48. @Input('maxWidth') maxWidth: number = 0;
  49. @Output() state: EventEmitter<any> = new EventEmitter<any>();
  50. @Output() save: EventEmitter<any> = new EventEmitter<any>();
  51. //填写诚信承诺是否正确
  52. confirmationValidator: ValidatorFn = (
  53. control: AbstractControl
  54. ): { [s: string]: boolean } => {
  55. if (
  56. control.value !=
  57. '本人自愿参加此次申报,已认真填写并检查以上材料,保证内容真实'
  58. ) {
  59. return { required: true };
  60. }
  61. return {};
  62. };
  63. validateForm: FormGroup<{
  64. textbookTypes: FormControl<Array<string> | any>; //教材电子版
  65. textbookFiles: FormControl<Array<string> | any>; //上传教材文件
  66. links: FormControl<string>; //教材数字内容链接地址、账号
  67. selfResults: FormControl<object | any>; //图书编校质量自查结果记录表
  68. expertOpinion: FormControl<object | any>; //专家审核意见表
  69. evidence: FormControl<object | any>; //教材使用情况证明材料
  70. moreMaterial: FormControl<Array<any> | any>; //其他材料
  71. unitMaterial: FormControl<object | any>; //申报单位承诺意见材料
  72. accept: FormControl<string>; //填写诚信承诺
  73. }> = this.fb.group({
  74. textbookTypes: ['', [Validators.required]],
  75. textbookFiles: [
  76. [
  77. {
  78. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  79. },
  80. ],
  81. [Validators.required]
  82. ],
  83. links: ['', [Validators.required]],
  84. selfResults: [
  85. {
  86. name: '自查表.pdf',
  87. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  88. },
  89. [Validators.required]
  90. ],
  91. expertOpinion: [
  92. {
  93. name: '自查表.pdf',
  94. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  95. },
  96. [Validators.required]
  97. ],
  98. evidence: [
  99. {
  100. name: '材料.pdf',
  101. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  102. },
  103. [Validators.required]
  104. ],
  105. moreMaterial: [
  106. [
  107. {
  108. name: '材料1.pdf',
  109. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  110. },
  111. {
  112. name: '材料2.pdf',
  113. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  114. },
  115. ],
  116. ],
  117. unitMaterial: [
  118. {
  119. name: '承诺意见表.pdf',
  120. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  121. },
  122. [Validators.required]
  123. ],
  124. accept: ['', [Validators.required, this.confirmationValidator]],
  125. });
  126. checkOptionsOne = [
  127. { label: '纸质教材', value: '纸质教材', checked: true },
  128. { label: '电子教材 / 资源', value: '电子教材 / 资源', checked: true },
  129. ];
  130. //所有作者政治审查意见
  131. opinions: Array<opinionType> = [
  132. {
  133. name: '', //作者
  134. unit: '', //单位
  135. birth: '', //出生年月
  136. nationality: '', //国籍
  137. reviewFile: {
  138. name: '自查表.pdf',
  139. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  140. }, //作者政治审查表/作者签名
  141. },
  142. ];
  143. //所有作者签名
  144. authorSign: Array<opinionType> = [
  145. {
  146. name: '', //作者
  147. unit: '', //单位
  148. birth: '', //出生年月
  149. nationality: '', //国籍
  150. reviewFile: {
  151. name: '审查表.pdf',
  152. url: 'https://www.jyvtc.edu.cn/yssj/resource/cms/2022/01/2022010610314324023.pdf',
  153. }, //作者政治审查表/作者签名
  154. },
  155. ];
  156. constructor(
  157. public tbookSer: textbookServer,
  158. private fb: NonNullableFormBuilder,
  159. private msg: NzMessageService,
  160. private modal: NzModalService
  161. ) {}
  162. ngOnInit() {
  163. if (this.eduTextbook.id) {
  164. this.validateForm = this.fb.group({
  165. textbookTypes: [
  166. this.eduTextbook.get('textbookTypes'),
  167. [Validators.required]
  168. ],
  169. textbookFiles: [
  170. this.eduTextbook.get('textbookFiles') ||
  171. this.validateForm.value.textbookFiles,
  172. [Validators.required]
  173. ],
  174. links: [
  175. this.eduTextbook.get('links')?.join('\n') || '',
  176. [Validators.required]
  177. ],
  178. selfResults: [
  179. this.eduTextbook.get('selfResults') ||
  180. this.validateForm.value.selfResults,
  181. [Validators.required]
  182. ],
  183. expertOpinion: [
  184. this.eduTextbook.get('expertOpinion') ||
  185. this.validateForm.value.expertOpinion,
  186. [Validators.required]
  187. ],
  188. evidence: [
  189. this.eduTextbook.get('evidence') || this.validateForm.value.evidence,
  190. [Validators.required]
  191. ],
  192. moreMaterial: [''],
  193. unitMaterial: [
  194. this.eduTextbook.get('unitMaterial') ||
  195. this.validateForm.value.unitMaterial,
  196. [Validators.required]
  197. ],
  198. accept: [
  199. this.eduTextbook.get('accept') || '',
  200. [Validators.required, this.confirmationValidator]
  201. ],
  202. });
  203. this.opinions = this.eduTextbook.get('opinions') || this.opinions
  204. this.authorSign = this.eduTextbook.get('authorSign') || this.authorSign
  205. }
  206. }
  207. async submitForm(event?: string): Promise<void> {
  208. if (event == 'pre') {
  209. this.state.emit({ type: 'pre' });
  210. return;
  211. }
  212. console.log(this.validateForm.value);
  213. let opinionsVrifly = !this.opinions.some((item) =>
  214. Object.values(item).some((val) => val == '' || val == undefined)
  215. );
  216. let authorSignVrifly = !this.authorSign.some((item) =>
  217. Object.values(item).some((val) => val == '' || val == undefined)
  218. );
  219. let params: any = this.validateForm.value;
  220. if (this.validateForm.valid) {
  221. console.log(this.validateForm.value);
  222. if (event == 'complete') {
  223. if (!opinionsVrifly) {
  224. this.msg.warning('所有作者政治审查意见填写不完整');
  225. return;
  226. }
  227. if (!authorSignVrifly) {
  228. this.msg.warning('上传所有作者签名填写不完整');
  229. return;
  230. }
  231. await this.saveEduTextbook(params, true);
  232. let textBookJson = this.eduTextbook.toJSON()
  233. let ignoreFiled = ['typeNumber','importantProjectOther','createdAt','updatedAt'] //非必填字段
  234. console.log(textBookJson);
  235. let isVrifly = Object.keys(textBookJson).some((item:string)=>{
  236. if(!ignoreFiled.includes(item) && (textBookJson[item] === '' || textBookJson[item] === undefined || textBookJson[item] === null)){
  237. console.warn('字段未填写:'+item);
  238. return true
  239. }
  240. return
  241. })
  242. if(isVrifly){
  243. this.msg.warning('存在未填项')
  244. return
  245. }
  246. this.state.emit({ type: 'complete', textBook: this.eduTextbook });
  247. this.eduTextbook.set('complete', true)
  248. this.eduTextbook.set('status', '102')
  249. await this.eduTextbook.save()
  250. this.msg.success('已填写完成')
  251. }
  252. } else {
  253. if (event == 'save') {
  254. await this.saveEduTextbook(params, this.validateForm.valid && opinionsVrifly && authorSignVrifly);
  255. this.modal.success({
  256. nzTitle: '保存成功',
  257. nzContent: '<p>已保存并且至空间</p>',
  258. nzOnOk: () => console.log('Info OK'),
  259. });
  260. return;
  261. }
  262. Object.values(this.validateForm.controls).forEach((control) => {
  263. if (control.invalid) {
  264. control.markAsDirty();
  265. control.updateValueAndValidity({ onlySelf: true });
  266. }
  267. });
  268. this.msg.warning('请填写完整信息');
  269. }
  270. await this.saveEduTextbook(params, this.validateForm.valid && opinionsVrifly && authorSignVrifly);
  271. if (event == 'save') {
  272. this.modal.success({
  273. nzTitle: '您已填写完成',
  274. nzContent: '<p>已保存并且至空间</p>',
  275. nzOnOk: () => console.log('Info OK'),
  276. });
  277. }
  278. }
  279. changeCode() {}
  280. getCode(e: any) {}
  281. //添加作者信息
  282. onPush(type: string, idx: number) {
  283. switch (type) {
  284. case 'opinions':
  285. this.opinions.splice(idx + 1, 0, {
  286. name: '', //作者
  287. unit: '', //单位
  288. birth: '', //出生年月
  289. nationality: '', //国籍
  290. reviewFile: '', //作者政治审查表/作者签名
  291. });
  292. break;
  293. case 'authorSign':
  294. this.authorSign.splice(idx + 1, 0, {
  295. name: '', //作者
  296. unit: '', //单位
  297. birth: '', //出生年月
  298. nationality: '', //国籍
  299. reviewFile: '', //作者政治审查表/作者签名
  300. });
  301. break;
  302. }
  303. }
  304. //删除作者信息
  305. onDel(type: string, idx: number) {
  306. switch (type) {
  307. case 'opinions':
  308. if (this.opinions.length <= 1) {
  309. this.opinions = [
  310. {
  311. name: '', //作者
  312. unit: '', //单位
  313. birth: '', //出生年月
  314. nationality: '', //国籍
  315. reviewFile: '', //作者政治审查表/作者签名
  316. },
  317. ];
  318. return;
  319. }
  320. this.opinions.splice(idx, 1);
  321. break;
  322. case 'authorSign':
  323. if (this.authorSign.length <= 1) {
  324. this.authorSign = [
  325. {
  326. name: '', //作者
  327. unit: '', //单位
  328. birth: '', //出生年月
  329. nationality: '', //国籍
  330. reviewFile: '', //作者政治审查表/作者签名
  331. },
  332. ];
  333. return;
  334. }
  335. this.authorSign.splice(idx, 1);
  336. break;
  337. }
  338. }
  339. handleChange(info: NzUploadChangeParam): void {
  340. if (info.file.status !== 'uploading') {
  341. console.log(info.file, info.fileList);
  342. }
  343. if (info.file.status === 'done') {
  344. this.msg.success(`${info.file.name} file uploaded successfully`);
  345. } else if (info.file.status === 'error') {
  346. this.msg.error(`${info.file.name} file upload failed.`);
  347. }
  348. }
  349. async saveEduTextbook(params: any, isComplete: boolean) {
  350. console.log(params);
  351. if (!this.eduTextbook) {
  352. this.msg.error('请先创建教材');
  353. return;
  354. }
  355. //如果填写未完整,仅保存,状态修改待完善101
  356. if (this.eduTextbook.get('status') == '102' && !isComplete) {
  357. this.eduTextbook?.set('status', '101');
  358. } else if (!this.eduTextbook.get('status')) {
  359. this.eduTextbook?.set('status', '101');
  360. }
  361. this.eduTextbook?.set('user', Parse.User.current()?.toPointer());
  362. this.eduTextbook?.set('company', {
  363. __type: 'Pointer',
  364. className: 'Company',
  365. objectId: this.tbookSer.company,
  366. });
  367. params.textbookTypes &&
  368. this.eduTextbook?.set('textbookTypes', params.textbookTypes);
  369. params.textbookFiles &&
  370. this.eduTextbook?.set('textbookFiles', params.textbookFiles);
  371. let links = params.links.split(/[(\r\n)\r\n]+/);
  372. links && this.eduTextbook?.set('links', links);
  373. params.selfResults &&
  374. this.eduTextbook?.set('selfResults', params.selfResults);
  375. params.unitMaterial &&
  376. this.eduTextbook?.set('unitMaterial', params.unitMaterial);
  377. params.expertOpinion &&
  378. this.eduTextbook?.set('expertOpinion', params.expertOpinion);
  379. params.evidence && this.eduTextbook?.set('evidence', params.evidence);
  380. params.moreMaterial &&
  381. this.eduTextbook?.set('moreMaterial', params.moreMaterial);
  382. params.accept && this.eduTextbook?.set('accept', params.accept);
  383. this.opinions && this.eduTextbook?.set('opinions', this.opinions);
  384. this.authorSign && this.eduTextbook?.set('authorSign', this.authorSign);
  385. await this.eduTextbook?.save();
  386. return;
  387. }
  388. }