attachment.component.ts 16 KB

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