123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623 |
- import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
- import { languages } from '../../../../services/languages.map';
- 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 { NzUploadModule } from 'ng-zorro-antd/upload';
- import { NzTagModule } from 'ng-zorro-antd/tag';
- import { NzMessageService } from 'ng-zorro-antd/message';
- import { NzModalService } from 'ng-zorro-antd/modal';
- import { textbookServer } from '../../../../services/textbook';
- import Parse from 'parse';
- import {
- FormControl,
- FormGroup,
- NonNullableFormBuilder,
- Validators,
- } from '@angular/forms';
- import { CompUploadComponent } from '../../../../app/comp-upload/comp-upload.component';
- import { NzInputModule } from 'ng-zorro-antd/input';
- import * as major from '../../../../services/majors4.map';
- import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
- import { BasicComponent } from '../create/basic/basic.component';
- import { ChangeDetectorRef } from '@angular/core';
- import { ViewChild } from '@angular/core';
- import { MatAccordion, MatExpansionModule } from '@angular/material/expansion';
- import { MatDatepickerModule } from '@angular/material/datepicker';
- import { MatInputModule } from '@angular/material/input';
- import { MatFormFieldModule } from '@angular/material/form-field';
- import { MatIconModule } from '@angular/material/icon';
- import { MatButtonModule } from '@angular/material/button';
- import { provideNativeDateAdapter } from '@angular/material/core';
- import { ViewChildren, QueryList } from '@angular/core';
- import { CreatedService } from '../../../../services/created.service';
- import { NzCollapseModule } from 'ng-zorro-antd/collapse';
- @Component({
- selector: 'app-basic',
- imports: [
- CommonCompModule,
- ReactiveFormsModule,
- NzSelectModule,
- NzRadioModule,
- NzUploadModule,
- NzInputModule,
- NzTagModule,
- CompUploadComponent,
- NzCheckboxModule,
- BasicComponent,
- MatButtonModule,
- MatExpansionModule,
- MatIconModule,
- MatFormFieldModule,
- MatInputModule,
- MatDatepickerModule,
- NzCollapseModule,
- ],
- standalone: true,
- templateUrl: './basic-in.component.html',
- styleUrls: ['./basic-in.component.scss'],
- providers: [provideNativeDateAdapter()],
- })
- export class BasicInComponent implements OnInit {
- @Input('eduTextbook') eduTextbook: Parse.Object | any;
- @Input('editFrom') editFrom: any;
- @Output() state: EventEmitter<any> = new EventEmitter<any>();
- @Output() save: EventEmitter<any> = new EventEmitter<any>();
- @ViewChild(MatAccordion) accordion: MatAccordion | any;
- @ViewChildren(BasicComponent) children: QueryList<BasicComponent> | any;
- /**删除分册 */
- async deleteVolume(index: number, comp: BasicComponent) {
- console.log(comp);
- if (this.eduTextbookVolumeList.length <= 2) {
- this.msg.create('warning', '全册最少两册');
- return;
- }
- this.eduTextbookVolumeList.splice(index, 1);
- this.typeNumber = this.typeNumber - 1;
- return;
- // console.log(this.eduTextbookVolumeList)
- // console.log(this.eduTextbookVolumeList[index])
- // if (this.eduTextbookVolumeList[index]?.id) {
- // this.eduTextbookVolumeList[index]?.set('isDeleted', true)
- // await this.eduTextbookVolumeList[index]?.save()
- // delete this.eduTextbookVolumeList[index]
- // this.typeNumber = this.typeNumber - 1
- // } else {
- // delete this.eduTextbookVolumeList[index]
- // this.typeNumber = this.typeNumber - 1
- // }
- // console.log(this.eduTextbookVolumeList);
- }
- /**上传分册数据 */
- async saveEduTextbookVolume(eduTextbookId?: string): Promise<any> {
- // console.log(eduTextbookId);
- let arr: Array<any> = []; //存储返回的数组id
- let isVrifly = true; //默认都通过,若一项填写未完成,则不通过
- return Promise.all(
- this.children.map(async (comp: any) => {
- // console.log(comp);
- let etvId = await comp.submitForm(eduTextbookId);
- console.log('返回eduTextbookVolume:'+etvId);
- arr.push({
- __type: 'Pointer',
- className: 'EduTextbookVolume',
- objectId: etvId,
- });
- if (!comp.isComlpete) {
- isVrifly = false;
- }
- //加上子组件返回是否填写完成的方法
- return arr;
- })
- ).then((data) => {
- // console.log(data);
- return {
- list: arr,
- isVrifly,
- };
- });
- }
- eduTextbookId: string = '';
- saveLoading: boolean = false; //保存等待
- async saveEduTextbook(params: any, isComplete: boolean) {
- if (this.saveLoading) return;
- this.saveLoading = true;
- try {
- // this.changeImportantProject()
- // console.log(params);
- if (!this.eduTextbook) {
- let obj = Parse.Object.extend('EduTextbook');
- this.eduTextbook = new obj();
- }
- this.eduTextbook?.set('user', Parse.User.current()?.toPointer());
- this.eduTextbook?.set('company', {
- __type: 'Pointer',
- className: 'Company',
- objectId: this.tbookSer.company,
- });
- let majorPoniter = this.selectList.find(
- (item) => item.code == params.majorPoniter
- );
- this.eduTextbook?.set('title', params.title);
- this.eduTextbook?.set('majorPoniter', majorPoniter);
- this.eduTextbook?.set('approval', params.approval);
- this.eduTextbook?.set('type', params.type);
- this.eduTextbook?.set('approvedImgUrl', params.approvedImgUrl);
- // this.eduTextbook?.set('typeNumber', this.typeNumber);
- if (!this.eduTextbook?.get('code')) {
- let t =
- this.tbookSer.formatTime('YYYYmmdd', new Date()) +
- Math.random().toString().slice(-4);
- this.eduTextbook.set('code', t);
- }
- // this.eduTextbook?.set('ISBN', (params.ISBN || 0).toString());
- // this.eduTextbook?.set('author', params.author);
- // this.eduTextbook?.set('unit', params.unit);
- // this.eduTextbook?.set('lang', params.lang);
- // this.eduTextbook?.set('authors', params.authors);
- // this.eduTextbook?.set('editor', params.editor);
- // this.eduTextbook?.set('editionUnit', params.editionUnit);
- // this.eduTextbook?.set('editionFirst', params.editionFirst);
- // this.eduTextbook?.set('carrierShape', params.carrierShape);
- // this.eduTextbook?.set('editionDate', params.editionDate);
- // this.eduTextbook?.set('editionNumber', params.editionNumber);
- // this.eduTextbook?.set('printDate', params.printDate);
- // this.eduTextbook?.set('printNumber', params.printNumber);
- // this.eduTextbook?.set('printSum', params.printSum);
- // this.eduTextbook?.set('importantProject', this.importantProject);
- // this.eduTextbook?.set('importantProjectOther', params.importantProjectOther);
- // this.eduTextbook?.set('unitType', params.unitType)
- let res = await this.eduTextbook?.save();
- this.eduTextbookId = await res?.id;
- // console.log(res?.id);
- let eduTextbookVolumes = await this.saveEduTextbookVolume(
- this.eduTextbookId
- );
- console.log(eduTextbookVolumes?.isVrifly);
- console.log(eduTextbookVolumes.list);
- this.eduTextbook?.set('childrens', eduTextbookVolumes.list);
- this.eduTextbook?.set('typeNumber', eduTextbookVolumes.list.length);
-
- isComplete = isComplete && eduTextbookVolumes?.isVrifly;
- //如果填写未完整,仅保存,状态修改待完善101
- 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');
- }
- if(isComplete){
- this.eduTextbook.set('complete', true)
- }
- await this.eduTextbook?.save();
- this.saveLoading = false;
- if (!isComplete) {
- this.msg.warning('保存成功,但存在未填写完成项');
- }
- return;
- } catch (err) {
- console.warn('保存错误:', err);
- this.saveLoading = false;
- this.msg.error('保存出错');
- }
- }
- /**扩展表记录 */
- eduTextbookVolumeList: Array<any> = [];
- /**获取扩展表记录 */
- async getEduTextbookVolumeList() {
- if (this.typeNumber && this.typeNumber > 12) {
- this.typeNumber = 12;
- }
- console.log(this.validateForm?.value?.type, this.typeNumber);
- // let query = new Parse.Query('EduTextbookVolume')
- // query.equalTo('eduTextbook', this.eduTextbook?.id)
- // // query.equalTo()
- // query.select('objectId')
- // query.ascending('createdAt')//小到大
- // query.notEqualTo('isDeleted', true)
- // if (this.validateForm?.value?.type == '全册') {
- // query.limit(this.typeNumber)
- // } else {
- // query.limit(1)
- // }
- let query = new Parse.Query('EduTextbook');
- query.equalTo('objectId', this.eduTextbook?.id);
- query.select('childrens');
- let r = await query.first();
- let list: any = r?.get('childrens') || [];
- console.log(list);
- this.eduTextbookVolumeList = new Array(this.typeNumber).fill({
- objectId: '',
- });
- if (this.validateForm?.value?.type == '全册') {
- if(this.eduTextbookVolumeList.length < 2){
- for (let index = 0; index < 2 - this.eduTextbookVolumeList.length; index++) {
- this.eduTextbookVolumeList.push({objectId:''})
- }
- }
- list.forEach((item: any, index: number) => {
- this.eduTextbookVolumeList[index] = item;
- });
- } else {
- this.singleId = list[0]?.id;
- }
- }
- singleId: string = '';
- loading = false;
- async checkSingle() {
- this.loading = true;
- this.validateForm.get('type')?.setValue('单本');
- await this.getEduTextbookVolumeList();
- this.loading = false;
- }
- /**申报类型选择全册 */
- async checkAll() {
- this.validateForm.get('type')?.setValue('全册');
- this.accordion?.openAll();
- this.getEduTextbookVolumeList();
- }
- changeCode() {}
- getCode(e: any) {}
- /***教材获批截图 */
- approvedImgList: Array<any> = [
- {
- name: '获批截图',
- status: 'done',
- url: '',
- },
- ];
- /**
- * 书号自动补全函数
- * @param isbn 书号
- */
- // async autoCompleteByISBN() {
- // let isbn = this.validateForm.value?.ISBN;
- // let result = await Parse.Cloud.run("tbookISBN", {
- // isbn: isbn
- // })
- // if (!result?.isbn) {
- // this.msg.warning('未找到该书号的图书信息,请手动填写')
- // }
- // // 其他字段,需补充接口与数据库对应关系
- // this.validateForm.get("title")?.setValue(result?.book_name)
- // this.validateForm.get("author")?.setValue(result?.author_name)
- // this.validateForm.get("authors")?.setValue(result?.author)
- // this.validateForm.get("majorPoniter")?.setValue(result?.major)
- // this.validateForm.get("lang")?.setValue(languages.options?.[result?.languages]?.name)
- // this.validateForm.get("editionUnit")?.setValue(result?.publisher)
- // this.validateForm.get("editionDate")?.setValue(new Date(result?.publish_time))
- // this.validateForm.get("carrierShape")?.setValue(result?.publication_class)
- // console.log(result)
- // }
- /**出版时间及版次不可选择时间 */
- disabledEditionDate = (current: Date): boolean => {
- return current < new Date(2022, 11, 1);
- };
- /** 全册次数*/
- typeNumber: number = 2;
- // typeNumberChange() {
- // if (this.typeNumber < 2) {
- // this.msg.create('warning', '不得小于两册')
- // this.typeNumber = 2
- // } else {
- // }
- // this.getEduTextbookVolumeList()
- // // this.eduTextbookVolumeList = []
- // // // for (let i = 1; i++; i <= this.typeNumber) {
- // // // this.eduTextbookVolumeList.push(false)
- // // // }
- // // this.eduTextbookVolumeList=new Array(this.typeNumber-1).fill(false)
- // // console.log(this.eduTextbookVolumeList)
- // }
- validateForm: FormGroup<{
- title: FormControl<string>; //申报教材名称
- majorPoniter: FormControl<string>; //教材应用对象及所诉学科专业类
- approval: FormControl<string>; //是否为重点立项教材
- type: FormControl<string>; //申报类型
- approvedImgUrl: FormControl<string>; //重点立项教材获批截图
- // ISBN: FormControl<any>; //国际标准书号
- // author: FormControl<string>; //第一主编(作者)
- // unit: FormControl<string>; //第一主编(作者)单位
- // unitType: FormControl<string>//第一主编(作者)单位类型
- // lang: FormControl<string>; //教材主要语种类型
- // authors: FormControl<string>; //其他主编姓名
- // editor: FormControl<string>; //其他编者姓名
- // editionUnit: FormControl<string>; //出版单位
- // editionFirst: FormControl<Date>; //初版时间
- // carrierShape: FormControl<string>; //载体形式
- // editionDate: FormControl<Date>; //出版时间
- // editionNumber: FormControl<number>; //出版版次
- // printDate: FormControl<Date>; //最新印次时间
- // printNumber: FormControl<number>; //最新印次
- // printSum: FormControl<number>; //初版以来合计印数
- // importantProjectOther: FormControl<string>; //其他省部级及以上项目
- }> = this.fb.group({
- title: ['', [Validators.required]],
- majorPoniter: ['', [Validators.required]],
- approval: ['', [Validators.required]],
- type: ['', [Validators.required]],
- approvedImgUrl: [''],
- // ISBN: [null, [Validators.required]],
- // author: ['', [Validators.required]],
- // unit: ['', [Validators.required]],
- // lang: ['', [Validators.required]],
- // authors: [''],
- // editor: [''],
- // editionUnit: ['', [Validators.required]],
- // editionFirst: [new Date(), [Validators.required]],
- // carrierShape: ['', [Validators.required]],
- // editionDate: [new Date(), [Validators.required]],
- // editionNumber: [0, [Validators.required]],
- // printDate: [new Date(), [Validators.required]],
- // printNumber: [0, [Validators.required]],
- // printSum: [0, [Validators.required]],
- // importantProjectOther: [''],
- // unitType: ['', [Validators.required]],
- });
- /** 所属学科专业类显示数量*/
- nzOptionOverflowSize = 5;
- //教材应用对象及所诉学科专业类
- selectList = major.majors.options;
- //语言选择
- selectLang: Array<any> = languages.options;
- //可选单位类型
- unitSelects: Array<any> = [
- {
- name: '部属高校',
- code: '部属高校',
- },
- {
- name: '部省合建高校',
- code: '部省合建高校',
- },
- {
- name: '省部共建高校',
- code: '省部共建高校',
- },
- {
- name: '其他',
- code: '其他',
- },
- ];
- //载体形式
- carrierOptions: Array<any> = [
- {
- name: '纸质教材',
- code: 'Z001',
- },
- {
- name: '电子教材',
- code: 'Z002',
- },
- {
- name: '纸质教材附带电子资源',
- code: 'Z003',
- },
- ];
- /**可选的重点项目 */
- importantProjectList: Array<any> = [
- {
- label: '首届全国教材建设奖全国优秀教材(高等教育类)',
- value: '首届全国教材建设奖全国优秀教材(高等教育类)',
- checked: false,
- },
- {
- label: '“十二五”普通高等教育本科国家级规划教材',
- value: '“十二五”普通高等教育本科国家级规划教材',
- checked: false,
- },
- {
- label: '“十二五”以来省级优秀教材',
- value: '“十二五”以来省级优秀教材',
- checked: false,
- },
- {
- label: '“十二五”以来省级规划教材',
- value: '“十二五”以来省级规划教材',
- checked: false,
- },
- {
- label: '其他省部级及以上项目',
- value: '其他省部级及以上项目',
- checked: false,
- },
- ];
- /**选中的重点项目 */
- importantProject: Array<any> = [];
- /**多选框改变 */
- changeImportantProject() {
- let checkedList =
- this.importantProjectList.filter((item) => item.checked) || [];
- this.importantProject = checkedList.map((item) => item.value);
- console.log(this.importantProject);
- }
- /* 是否重点立项教材可选列表 */
- options: Array<any> = [
- {
- name: '经中央有关部门审定的教材',
- code: '经中央有关部门审定的教材',
- },
- {
- name: '首届全国教材建设奖优秀教材(高等教育类)教材',
- code: '首届全国教材建设奖优秀教材(高等教育类)教材',
- },
- {
- name: '“101计划”核心教材',
- code: '“101计划”核心教材',
- },
- {
- name: '“四新”重点建设教材(含战略性新兴领域教材)',
- code: '“四新”重点建设教材(含战略性新兴领域教材)',
- },
- {
- name: '否',
- code: '否',
- },
- ];
- constructor(
- public tbookSer: textbookServer,
- private fb: NonNullableFormBuilder,
- private modal: NzModalService,
- private msg: NzMessageService,
- private cdr: ChangeDetectorRef,
- private creatSev: CreatedService
- ) {}
- isShowChooseEU: boolean = true;
- ngOnInit() {
- // if (this.eduTextbook?.get('editionUnit')) {
- // this.isShowChooseEU = false
- // }
- // this.importantProject = this.eduTextbook?.get('importantProject') || []
- // if (this.importantProject?.length > 0) {
- // for (let i in this.importantProjectList) {
- // if (this.importantProject.indexOf(this.importantProjectList[i].value) != -1) {
- // this.importantProjectList[i].checked = true
- // }
- // }
- // }
- this.approvedImgList[0].url = this.eduTextbook?.get('approvedImgUrl');
- this.typeNumber = this.eduTextbook?.get('childrens').length || 2;
- if (this.typeNumber > 12) this.typeNumber = 12;
- // console.log(this.approvedImgList)
- // console.log(this.eduTextbook);
- this.validateForm = this.fb.group({
- title: [this.eduTextbook?.get('title') || '', [Validators.required]],
- majorPoniter: [
- this.eduTextbook?.get('majorPoniter')?.code || '',
- [Validators.required],
- ],
- approval: [
- this.eduTextbook?.get('approval') || '',
- [Validators.required],
- ],
- type: [this.eduTextbook?.get('type') || '单本', [Validators.required]],
- approvedImgUrl: [this.eduTextbook?.get('approvedImgUrl') || ''],
- // ISBN: [parseInt(this.eduTextbook?.get('ISBN') || '') || null, [Validators.required]],
- // author: [this.eduTextbook?.get('author') || '', [Validators.required]],
- // unit: [this.eduTextbook?.get('unit') || '', [Validators.required]],
- // lang: [this.eduTextbook?.get('lang') || '', [Validators.required]],
- // authors: [this.eduTextbook?.get('authors') || ''],
- // editor: [this.eduTextbook?.get('editor') || '',],
- // editionUnit: [this.eduTextbook?.get('editionUnit') || '', [Validators.required]],
- // editionFirst: [this.eduTextbook?.get('editionFirst') || new Date(), [Validators.required]],
- // carrierShape: [this.eduTextbook?.get('carrierShape') || '', [Validators.required]],
- // editionDate: [this.eduTextbook?.get('editionDate') || new Date(), [Validators.required]],
- // editionNumber: [this.eduTextbook?.get('editionNumber') || 0, [Validators.required]],
- // printDate: [this.eduTextbook?.get('printDate') || new Date(), [Validators.required]],
- // printNumber: [this.eduTextbook?.get('printNumber') || 0, [Validators.required]],
- // printSum: [this.eduTextbook?.get('printSum') || 0, [Validators.required]],
- // importantProjectOther: [this.eduTextbook?.get('importantProjectOther') || ''],
- // unitType: [this.eduTextbook?.get('unitType') || '', [Validators.required]],
- });
- }
- ngAfterViewInit() {
- this.eduTextbookId = this.eduTextbook?.id;
- this.accordion?.openAll();
- this.cdr.detectChanges();
- this.getEduTextbookVolumeList();
- }
- addVolume() {
- if (this.eduTextbookVolumeList.length >= 12) {
- this.msg.error('已超过最多册数');
- return;
- }
- this.eduTextbookVolumeList.push({ objectId: '' });
- this.typeNumber++;
- }
- upload(e: any, type: string) {
- console.log(e);
- let file = e[0];
- // if(type == 'copyrightImgUrl' || type == 'CIPImgUrl' ||type=='approvedImgUrl'){
- if (type == 'approvedImgUrl') {
- this.validateForm.value[type] = file?.url;
- }
- console.log(this.validateForm.value);
- }
- async submitForm(event?: string): Promise<void> {
- console.log(this.validateForm.value);
- console.log(this.validateForm.valid);
- if (event == 'next') {
- let params = this.validateForm.value;
- await this.saveEduTextbook(params, this.validateForm.valid);
- this.state.emit({ type: 'next', textBook: this.eduTextbook });
- }
- // if (this.validateForm.valid) {
- // let params = this.validateForm.value
- // if (event == 'next') {
- // await this.saveEduTextbook(params, this.validateForm.valid)
- // this.state.emit({ type: 'next', textBook: this.eduTextbook });
- // }
- // } else {
- // if (event == 'save') {
- // let params = this.validateForm.value
- // await this.saveEduTextbook(params, this.validateForm.valid)
- // // await this.getEduTextbookVolumeList()
- // this.modal.success({
- // nzTitle: '保存成功',
- // nzContent: '<p>已保存并且至空间</p>',
- // nzOnOk: () => console.log('Info OK')
- // });
- // return
- // }
- // if (event == 'next') {
- // let params = this.validateForm.value
- // await this.saveEduTextbook(params, this.validateForm.valid)
- // this.state.emit({ type: 'next', textBook: this.eduTextbook });
- // }
- // }
- if (event == 'save') {
- let params = this.validateForm.value;
- await this.saveEduTextbook(params, this.validateForm.valid);
- // await this.getEduTextbookVolumeList()
- this.modal.success({
- nzTitle: '保存成功',
- nzContent: '<p>已保存并且至空间</p>',
- nzOnOk: () => console.log('Info OK'),
- });
- }
- }
- selectedValue = null;
- listOfOption: Array<{ value: string; text: string }> = [];
- nzFilterOption = (): boolean => true;
- eduTimeout: any;
- /**出版单位列表 */
- eduList: Array<Parse.Object> = [];
- /**搜索出版单位 */
- async search(value: string) {
- clearTimeout(this.eduTimeout);
- this.eduTimeout = setTimeout(async () => {
- let query = new Parse.Query('Department');
- query.notEqualTo('isDeleted', true);
- query.equalTo('parent', '66865d66ad23a23355b12aa7');
- query.contains('name', value);
- query.limit(10);
- this.eduList = await query.find();
- }, 500);
- }
- openFile(url: any) {
- window.open(url);
- }
- }
|