123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
- import { CommonCompModule } from '../../../../services/common.modules';
- import { NzSelectModule } from 'ng-zorro-antd/select';
- import { ReactiveFormsModule } from '@angular/forms';
- import { NzRadioModule } from 'ng-zorro-antd/radio';
- import { NzMessageService } from 'ng-zorro-antd/message';
- import { NzGridModule } from 'ng-zorro-antd/grid';
- import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
- import { NzTableModule } from 'ng-zorro-antd/table';
- import { NzModalService } from 'ng-zorro-antd/modal';
- import Parse from 'parse';
- import {
- FormControl,
- FormGroup,
- NonNullableFormBuilder,
- Validators,
- } from '@angular/forms';
- import { textbookServer } from '../../../../services/textbook';
- import { CreatedService } from '../../../../services/created.service';
- import { ContentComponent } from '../create/content/content.component';
- import { NzCollapseModule } from 'ng-zorro-antd/collapse';
- import { ViewChildren, QueryList } from '@angular/core';
- interface course {
- date: Date | any;
- wordage: number | any;
- num: number | any;
- sumNum: number | any;
- accolade: string;
- }
- @Component({
- selector: 'app-textbook-content',
- imports: [
- NzCollapseModule,
- CommonCompModule,
- ReactiveFormsModule,
- NzSelectModule,
- NzRadioModule,
- NzGridModule,
- NzCheckboxModule,
- NzTableModule,
- ContentComponent,
- ],
- standalone: true,
- templateUrl: './textbook-content.component.html',
- styleUrls: ['./textbook-content.component.scss'],
- })
- export class TextbookContentComponent implements OnInit {
- @Input('eduTextbook') eduTextbook: any;
- @Input('maxWidth') maxWidth: number = 0;
- @Output() state: EventEmitter<any> = new EventEmitter<any>();
- @Output() save: EventEmitter<any> = new EventEmitter<any>();
- validateForm: FormGroup<{
- innovateExplain: FormControl<string>; //申报教材特色及创新
- influence: FormControl<string>; //申报教材应用情况及社会影响力
- }> = this.fb.group({
- innovateExplain: ['', [Validators.required]],
- influence: ['', [Validators.required]],
- });
- //申报教材建设历程
- courses: Array<course> = [
- {
- date: '', //出版时间
- wordage: '', //字数
- num: '', //重印次数
- sumNum: '', //本版总印数
- accolade: '', //获奖励情况
- },
- ];
- constructor(
- public tbookSer: textbookServer,
- private fb: NonNullableFormBuilder,
- private modal: NzModalService,
- private msg: NzMessageService,
- private creatSev: CreatedService
- ) {}
- loading = false;
- /**扩展表记录 */
- eduTextbookVolumeList: Array<any> = [];
- /**获取扩展表记录 */
- async getEduTextbookVolumeList() {
- if (this.typeNumber && this.typeNumber > 12) {
- this.typeNumber = 12;
- }
- console.log(this.type, this.typeNumber);
- let query = new Parse.Query('EduTextbookVolume');
- query.equalTo('eduTextbook', this.eduTextbook?.id);
- query.select('objectId');
- query.ascending('createdAt'); //小到大
- query.notEqualTo('isDeleted', true);
- if (this.type == '全册') {
- query.limit(this.typeNumber);
- } else {
- query.limit(1);
- }
- let list = await query.find();
- console.log(list);
- if (this.type == '全册') {
- this.eduTextbookVolumeList = new Array(this.typeNumber).fill({
- objectId: '',
- });
- for (let i in list) {
- this.eduTextbookVolumeList[i] = list[i];
- }
- } else {
- this.eduTextbookVolumeList[0] = list[0];
- console.log(this.eduTextbookVolumeList);
- this.eduTextbookVolumeId = list[0]?.id;
- }
- }
- /** 册数*/
- typeNumber: any;
- /** 申报类型*/
- type: any;
- /** 单册时该册id*/
- eduTextbookVolumeId: any;
- ngAfterViewInit(): void {
- this.typeNumber = this.eduTextbook?.get('typeNumber');
- this.type = this.eduTextbook?.get('type');
- this.getEduTextbookVolumeList();
- this.creatSev.getEduTextbookVolumeList(this.eduTextbook.id);
- }
- ngOnInit() {
- if (this.eduTextbook.id) {
- this.creatSev.type = this.eduTextbook.get('type');
- this.creatSev.typeNumber = this.eduTextbook.get('typeNumber');
- this.validateForm = this.fb.group({
- innovateExplain: [
- this.eduTextbook.get('innovateExplain'),
- [Validators.required],
- ],
- influence: [this.eduTextbook.get('influence'), [Validators.required]],
- });
- console.log(this.validateForm.value);
- this.courses = this.eduTextbook.get('courses') || this.courses;
- }
- }
- async submitForm(event?: string): Promise<void> {
- let params: any = this.validateForm.value;
- console.log(params);
- if (event == 'pre') {
- this.state.emit({ type: 'pre' });
- return
- }
- console.log(this.validateForm.value);
- // let coursesVrifly = !this.courses.some(item=>Object.values(item).some(val=> val == '' || val == undefined))
- let coursesVrifly = true
- if (this.validateForm.valid) {
- let params: any = this.validateForm.value;
- if (event == 'next') {
- if(!coursesVrifly){
- this.msg.warning('申报教材建设历程填写不完整')
- return
- }
- await this.saveEduTextbook(params, true);
- this.state.emit({ type: 'next', textBook: this.eduTextbook });
- }
- } else {
- if (event == 'save') {
- let params: any = this.validateForm.value;
- await this.saveEduTextbook(params, (this.validateForm.valid && coursesVrifly));
- this.modal.success({
- nzTitle: '保存成功',
- nzContent: '<p>已保存并且至空间</p>',
- nzOnOk: () => console.log('Info OK'),
- });
- return;
- }
- if (event == 'next') {
- let params: any = this.validateForm.value;
- await this.saveEduTextbook(params, false);
- this.state.emit({ type: 'next', textBook: this.eduTextbook });
- }
- // Object.values(this.validateForm.controls).forEach((control) => {
- // if (control.invalid) {
- // control.markAsDirty();
- // control.updateValueAndValidity({ onlySelf: true });
- // }
- // });
- // this.msg.warning('请填写完整信息');
- return;
- }
- // let coursesVrifly = !this.courses.some(item=>Object.values(item).some(val=> val == '' || val == undefined))
- if (event == 'save') {
- await this.saveEduTextbook(params, this.validateForm.valid);
- this.modal.success({
- nzTitle: '保存成功',
- nzContent: '<p>已保存并且至空间</p>',
- nzOnOk: () => console.log('Info OK'),
- });
- return;
- }
- if (event == 'next') {
- await this.saveEduTextbook(params, this.validateForm.valid);
- this.state.emit({ type: 'next', textBook: this.eduTextbook });
- return;
- }
- // if (this.validateForm.valid) {
- // let params: any = this.validateForm.value;
- // if (event == 'next') {
- // // if(!coursesVrifly){
- // // this.msg.warning('申报教材建设历程填写不完整')
- // // return
- // // }
- // await this.saveEduTextbook(params, true);
- // this.state.emit({ type: 'next', textBook: this.eduTextbook });
- // }
- // } else {
- // if (event == 'save') {
- // let params: any = this.validateForm.value;
- // await this.saveEduTextbook(params, this.validateForm.valid);
- // this.modal.success({
- // nzTitle: '保存成功',
- // nzContent: '<p>已保存并且至空间</p>',
- // nzOnOk: () => console.log('Info OK'),
- // });
- // return;
- // }
- // if (event == 'next') {
- // let params: any = this.validateForm.value;
- // await this.saveEduTextbook(params, false);
- // this.state.emit({ type: 'next', textBook: this.eduTextbook });
- // }
- // // Object.values(this.validateForm.controls).forEach((control) => {
- // // if (control.invalid) {
- // // control.markAsDirty();
- // // control.updateValueAndValidity({ onlySelf: true });
- // // }
- // // });
- // // this.msg.warning('请填写完整信息');
- // }
- // if (event == 'save') {
- // let params = this.validateForm.value;
- // await this.saveEduTextbook(params, this.validateForm.valid);
- // this.modal.success({
- // nzTitle: '保存成功',
- // nzContent: '<p>已保存并且至空间</p>',
- // nzOnOk: () => console.log('Info OK'),
- // });
- // }
- }
- changeCode() {}
- getCode(e: any) {}
- //添加作者信息
- onPush(idx: number) {
- this.courses.splice(idx + 1, 0, {
- date: '',
- wordage: '',
- num: '',
- sumNum: '',
- accolade: '',
- });
- }
- //删除作者信息
- onDel(idx: number) {
- if (this.courses?.length == 1) return;
- this.courses.splice(idx, 1);
- }
- @ViewChildren(ContentComponent) children: QueryList<ContentComponent> | any;
- /**上传分册数据 */
- async saveEduTextbookVolume() {
- let arr = []; //存储返回的数组id
- let isVrifly = true; //默认都通过,若一项填写未完成,则不通过
- return Promise.all(
- this.children.map(async (comp: any) => {
- let req = await comp.submitForm();
- // console.log(req)
- if (!req) {
- isVrifly = false;
- }
- return isVrifly;
- })
- ).then((data) => {
- console.log(isVrifly);
- return isVrifly;
- });
- }
- saveLoading: boolean = false;
- async saveEduTextbook(params: any, isComplete: boolean) {
- console.log(params);
- if (!this.eduTextbook) {
- this.msg.error('请先创建教材');
- return;
- }
- if (this.saveLoading) return;
- this.saveLoading = true;
- try {
- //如果填写未完整,仅保存,状态修改待完善101
- let complete = await this.saveEduTextbookVolume();
- isComplete = isComplete && complete;
- if (this.eduTextbook.get('status') == '102' && !isComplete) {
- this.eduTextbook?.set('status', '101');
- this.eduTextbook.set('complete', false);
- } else if (!this.eduTextbook.get('status')) {
- this.eduTextbook?.set('status', '101');
- }
- this.eduTextbook?.set('user', Parse.User.current()?.toPointer());
- this.eduTextbook?.set('company', {
- __type: 'Pointer',
- className: 'Company',
- objectId: this.tbookSer.company,
- });
- params.innovateExplain &&
- this.eduTextbook?.set('innovateExplain', params.innovateExplain);
- params.influence && this.eduTextbook?.set('influence', params.influence);
- // this.eduTextbook?.set('courses', this.courses);
- await this.eduTextbook?.save();
- this.saveLoading = false;
- if (!isComplete) {
- this.msg.warning('保存成功,但存在未填写完成项');
- }
- return;
- } catch (err) {
- console.warn('保存错误:', err);
- this.saveLoading = false;
- this.msg.error('保存出错');
- }
- }
- }
|