basic-in.component.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
  2. import { languages } from '../../../../services/languages.map';
  3. import { CommonCompModule } from '../../../../services/common.modules';
  4. import { NzSelectModule } from 'ng-zorro-antd/select';
  5. import { ReactiveFormsModule } from '@angular/forms';
  6. import { NzRadioModule } from 'ng-zorro-antd/radio';
  7. import { NzUploadModule } from 'ng-zorro-antd/upload';
  8. import { NzTagModule } from 'ng-zorro-antd/tag';
  9. import { NzMessageService } from 'ng-zorro-antd/message';
  10. import { NzModalService } from 'ng-zorro-antd/modal';
  11. import { textbookServer } from '../../../../services/textbook'
  12. import Parse from 'parse';
  13. import {
  14. FormControl,
  15. FormGroup,
  16. NonNullableFormBuilder,
  17. Validators,
  18. } from '@angular/forms';
  19. import { CompUploadComponent } from '../../../../app/comp-upload/comp-upload.component';
  20. import { NzInputModule } from 'ng-zorro-antd/input';
  21. import * as major from '../../../../services/majors4.map'
  22. import { NzCheckboxModule } from 'ng-zorro-antd/checkbox';
  23. import { BasicComponent } from '../create/basic/basic.component';
  24. import { ChangeDetectorRef } from '@angular/core';
  25. import { ViewChild } from '@angular/core';
  26. import { MatAccordion, MatExpansionModule } from '@angular/material/expansion';
  27. import { MatDatepickerModule } from '@angular/material/datepicker';
  28. import { MatInputModule } from '@angular/material/input';
  29. import { MatFormFieldModule } from '@angular/material/form-field';
  30. import { MatIconModule } from '@angular/material/icon';
  31. import { MatButtonModule } from '@angular/material/button';
  32. import { provideNativeDateAdapter } from '@angular/material/core';
  33. @Component({
  34. selector: 'app-basic',
  35. imports: [
  36. CommonCompModule,
  37. ReactiveFormsModule,
  38. NzSelectModule,
  39. NzRadioModule,
  40. NzUploadModule,
  41. NzInputModule,
  42. NzTagModule,
  43. CompUploadComponent,
  44. NzCheckboxModule,
  45. BasicComponent,
  46. MatButtonModule,
  47. MatExpansionModule,
  48. MatIconModule,
  49. MatFormFieldModule,
  50. MatInputModule,
  51. MatDatepickerModule,
  52. ],
  53. standalone: true,
  54. templateUrl: './basic-in.component.html',
  55. styleUrls: ['./basic-in.component.scss'],
  56. providers: [provideNativeDateAdapter()],
  57. })
  58. export class BasicInComponent implements OnInit {
  59. @Input('eduTextbook') eduTextbook: Parse.Object | any;
  60. @Input('editFrom') editFrom: any;
  61. @Output() state: EventEmitter<any> = new EventEmitter<any>();
  62. @Output() save: EventEmitter<any> = new EventEmitter<any>();
  63. @ViewChild(MatAccordion) accordion: MatAccordion | any;
  64. ngAfterViewInit() {
  65. this.accordion?.openAll()
  66. this.cdr.detectChanges()
  67. }
  68. changeCode() { }
  69. getCode(e: any) { }
  70. /***教材获批截图 */
  71. approvedImgList: Array<any> = [{
  72. name: '获批截图',
  73. status: 'done',
  74. url: ''
  75. }]
  76. /**
  77. * 书号自动补全函数
  78. * @param isbn 书号
  79. */
  80. async autoCompleteByISBN() {
  81. let isbn = this.validateForm.value?.ISBN;
  82. let result = await Parse.Cloud.run("tbookISBN", {
  83. isbn: isbn
  84. })
  85. if (!result?.isbn) {
  86. this.msg.warning('未找到该书号的图书信息,请手动填写')
  87. }
  88. // 其他字段,需补充接口与数据库对应关系
  89. this.validateForm.get("title")?.setValue(result?.book_name)
  90. this.validateForm.get("author")?.setValue(result?.author_name)
  91. this.validateForm.get("authors")?.setValue(result?.author)
  92. this.validateForm.get("majorPoniter")?.setValue(result?.major)
  93. this.validateForm.get("lang")?.setValue(languages.options?.[result?.languages]?.name)
  94. this.validateForm.get("editionUnit")?.setValue(result?.publisher)
  95. this.validateForm.get("editionDate")?.setValue(new Date(result?.publish_time))
  96. this.validateForm.get("carrierShape")?.setValue(result?.publication_class)
  97. console.log(result)
  98. }
  99. /**出版时间及版次不可选择时间 */
  100. disabledEditionDate = (current: Date): boolean => {
  101. return current < new Date(2022, 11, 1)
  102. }
  103. /**扩展表记录 */
  104. eduTextbookVolumeValidList: Array<any> = []
  105. /** 全册次数*/
  106. typeNumber: number = 2
  107. typeNumberChange() {
  108. if (this.typeNumber < 2) {
  109. this.msg.create('warning', '不得小于两册')
  110. this.typeNumber = 2
  111. } else {
  112. }
  113. this.eduTextbookVolumeValidList = []
  114. // for (let i = 1; i++; i <= this.typeNumber) {
  115. // this.eduTextbookVolumeValidList.push(false)
  116. // }
  117. this.eduTextbookVolumeValidList=new Array(this.typeNumber-1).fill(false)
  118. console.log(this.eduTextbookVolumeValidList)
  119. }
  120. validateForm: FormGroup<{
  121. title: FormControl<string>; //申报教材名称
  122. ISBN: FormControl<any>; //国际标准书号
  123. author: FormControl<string>; //第一主编(作者)
  124. unit: FormControl<string>; //第一主编(作者)单位
  125. unitType: FormControl<string>//第一主编(作者)单位类型
  126. type: FormControl<string>; //申报类型
  127. // typeNumber: FormControl<number|any>; //全册次数
  128. majorPoniter: FormControl<string>; //教材应用对象及所诉学科专业类
  129. lang: FormControl<string>; //教材主要语种类型
  130. authors: FormControl<string>; //其他主编姓名
  131. editor: FormControl<string>; //其他编者姓名
  132. approval: FormControl<string>; //是否为重点立项教材
  133. editionUnit: FormControl<string>; //出版单位
  134. editionFirst: FormControl<Date>; //初版时间
  135. carrierShape: FormControl<string>; //载体形式
  136. editionDate: FormControl<Date>; //出版时间
  137. editionNumber: FormControl<number>; //出版版次
  138. printDate: FormControl<Date>; //最新印次时间
  139. printNumber: FormControl<number>; //最新印次
  140. printSum: FormControl<number>; //初版以来合计印数
  141. // importantProject: FormControl<string>; //初版以来是否列为重点项目
  142. importantProjectOther: FormControl<string>; //其他省部级及以上项目
  143. approvedImgUrl: FormControl<string>//重点立项教材获批截图
  144. // remember: FormControl<boolean>;
  145. }> = this.fb.group({
  146. title: ['', [Validators.required]],
  147. ISBN: [null, [Validators.required]],
  148. author: ['', [Validators.required]],
  149. unit: ['', [Validators.required]],
  150. type: ['', [Validators.required]],
  151. // typeNumber: [2],
  152. majorPoniter: ['', [Validators.required]],
  153. lang: ['', [Validators.required]],
  154. authors: [''],
  155. editor: [''],
  156. approval: ['', [Validators.required]],
  157. editionUnit: ['', [Validators.required]],
  158. editionFirst: [new Date(), [Validators.required]],
  159. carrierShape: ['', [Validators.required]],
  160. editionDate: [new Date(), [Validators.required]],
  161. editionNumber: [0, [Validators.required]],
  162. printDate: [new Date(), [Validators.required]],
  163. printNumber: [0, [Validators.required]],
  164. printSum: [0, [Validators.required]],
  165. // importantProject: ['', [Validators.required]],
  166. importantProjectOther: [''],
  167. approvedImgUrl: [''],
  168. // copyrightImgUrl: [''],
  169. // CIPImgUrl: [''],
  170. // remember: [true],
  171. unitType: ['', [Validators.required]],
  172. });
  173. /** 所属学科专业类显示数量*/
  174. nzOptionOverflowSize = 5
  175. //教材应用对象及所诉学科专业类
  176. selectList = major.majors.options
  177. //语言选择
  178. selectLang: Array<any> = languages.options;
  179. //可选单位类型
  180. unitSelects: Array<any> = [
  181. {
  182. name: '部属高校',
  183. code: '部属高校',
  184. },
  185. {
  186. name: '部省合建高校',
  187. code: '部省合建高校',
  188. },
  189. {
  190. name: '省部共建高校',
  191. code: '省部共建高校',
  192. },
  193. {
  194. name: '其他',
  195. code: '其他',
  196. },
  197. ];
  198. //载体形式
  199. carrierOptions: Array<any> = [
  200. {
  201. name: '纸质教材',
  202. code: 'Z001',
  203. },
  204. {
  205. name: '电子教材',
  206. code: 'Z002',
  207. },
  208. {
  209. name: '纸质教材附带电子资源',
  210. code: 'Z003',
  211. },
  212. ];
  213. /**可选的重点项目 */
  214. importantProjectList: Array<any> = [
  215. {
  216. label: '首届全国教材建设奖全国优秀教材(高等教育类)',
  217. value: '首届全国教材建设奖全国优秀教材(高等教育类)',
  218. checked: false
  219. },
  220. {
  221. label: '“十二五”普通高等教育本科国家级规划教材',
  222. value: '“十二五”普通高等教育本科国家级规划教材',
  223. checked: false
  224. },
  225. {
  226. label: '“十二五”以来省级优秀教材',
  227. value: '“十二五”以来省级优秀教材',
  228. checked: false
  229. },
  230. {
  231. label: '“十二五”以来省级规划教材',
  232. value: '“十二五”以来省级规划教材',
  233. checked: false
  234. },
  235. {
  236. label: '其他省部级及以上项目',
  237. value: '其他省部级及以上项目',
  238. checked: false
  239. },
  240. ];
  241. /**选中的重点项目 */
  242. importantProject: Array<any> = []
  243. /**多选框改变 */
  244. changeImportantProject() {
  245. let checkedList = this.importantProjectList.filter(item => item.checked) || []
  246. this.importantProject = checkedList.map(item => item.value)
  247. console.log(this.importantProject)
  248. }
  249. /* 是否重点立项教材可选列表 */
  250. options: Array<any> = [
  251. {
  252. name: '经中央有关部门审定的教材',
  253. code: '经中央有关部门审定的教材',
  254. },
  255. {
  256. name: '首届全国教材建设奖优秀教材(高等教育类)教材',
  257. code: '首届全国教材建设奖优秀教材(高等教育类)教材',
  258. },
  259. {
  260. name: '“101计划”核心教材',
  261. code: '“101计划”核心教材',
  262. },
  263. {
  264. name: '“四新”重点建设教材(含战略性新兴领域教材)',
  265. code: '“四新”重点建设教材(含战略性新兴领域教材)',
  266. },
  267. {
  268. name: '否',
  269. code: '否',
  270. }
  271. ];
  272. constructor(
  273. public tbookSer: textbookServer,
  274. private fb: NonNullableFormBuilder,
  275. private modal: NzModalService,
  276. private msg: NzMessageService,
  277. private cdr: ChangeDetectorRef
  278. ) {
  279. }
  280. isShowChooseEU: boolean = true
  281. ngOnInit() {
  282. if (this.eduTextbook?.get('editionUnit')) {
  283. this.isShowChooseEU = false
  284. }
  285. this.importantProject = this.eduTextbook?.get('importantProject') || []
  286. if (this.importantProject?.length > 0) {
  287. for (let i in this.importantProjectList) {
  288. if (this.importantProject.indexOf(this.importantProjectList[i].value) != -1) {
  289. this.importantProjectList[i].checked = true
  290. }
  291. }
  292. }
  293. this.approvedImgList[0].url = this.eduTextbook?.get('approvedImgUrl')
  294. this.typeNumber = this.eduTextbook?.get('typeNumber') || 2
  295. this.eduTextbookVolumeValidList=new Array(this.typeNumber-1).fill(false)
  296. console.log(this.eduTextbookVolumeValidList)
  297. // console.log(this.approvedImgList)
  298. console.log(this.eduTextbook);
  299. this.validateForm = this.fb.group({
  300. title: [this.eduTextbook?.get('title') || '', [Validators.required]],
  301. ISBN: [parseInt(this.eduTextbook?.get('ISBN') || '') || null, [Validators.required]],
  302. author: [this.eduTextbook?.get('author') || '', [Validators.required]],
  303. unit: [this.eduTextbook?.get('unit') || '', [Validators.required]],
  304. type: [this.eduTextbook?.get('type') || '全册', [Validators.required]],
  305. // typeNumber: [this.eduTextbook?.get('typeNumber') || 2],
  306. majorPoniter: [this.eduTextbook?.get('majorPoniter')?.code || '', [Validators.required]],
  307. lang: [this.eduTextbook?.get('lang') || '', [Validators.required]],
  308. authors: [this.eduTextbook?.get('authors') || ''],
  309. editor: [this.eduTextbook?.get('editor') || '',],
  310. approval: [this.eduTextbook?.get('approval') || '', [Validators.required]],
  311. editionUnit: [this.eduTextbook?.get('editionUnit') || '', [Validators.required]],
  312. editionFirst: [this.eduTextbook?.get('editionFirst') || new Date(), [Validators.required]],
  313. carrierShape: [this.eduTextbook?.get('carrierShape') || '', [Validators.required]],
  314. editionDate: [this.eduTextbook?.get('editionDate') || new Date(), [Validators.required]],
  315. editionNumber: [this.eduTextbook?.get('editionNumber') || 0, [Validators.required]],
  316. printDate: [this.eduTextbook?.get('printDate') || new Date(), [Validators.required]],
  317. printNumber: [this.eduTextbook?.get('printNumber') || 0, [Validators.required]],
  318. printSum: [this.eduTextbook?.get('printSum') || 0, [Validators.required]],
  319. // importantProject: [this.eduTextbook?.get('importantProject') || '', [Validators.required]],
  320. importantProjectOther: [this.eduTextbook?.get('importantProjectOther') || ''],
  321. approvedImgUrl: [this.eduTextbook?.get('approvedImgUrl') || ''],
  322. unitType: [this.eduTextbook?.get('unitType') || '', [Validators.required]],
  323. // copyrightImgUrl: [this.eduTextbook?.get('copyrightImgUrl') || '', [Validators.required]],
  324. // CIPImgUrl: [this.eduTextbook?.get('CIPImgUrl') || '', [Validators.required]],
  325. });
  326. }
  327. upload(e: any, type: string) {
  328. console.log(e);
  329. let file = e[0];
  330. // if(type == 'copyrightImgUrl' || type == 'CIPImgUrl' ||type=='approvedImgUrl'){
  331. if (type == 'approvedImgUrl') {
  332. this.validateForm.value[type] = file?.url
  333. }
  334. console.log(this.validateForm.value)
  335. }
  336. async submitForm(event?: string): Promise<void> {
  337. console.log(this.validateForm.value);
  338. console.log(this.validateForm.valid);
  339. if (this.validateForm.valid) {
  340. let params = this.validateForm.value
  341. if (event == 'next') {
  342. await this.saveEduTextbook(params, this.validateForm.valid)
  343. this.state.emit({ type: 'next', textBook: this.eduTextbook });
  344. }
  345. } else {
  346. if (event == 'save') {
  347. let params = this.validateForm.value
  348. await this.saveEduTextbook(params, this.validateForm.valid)
  349. this.modal.success({
  350. nzTitle: '保存成功',
  351. nzContent: '<p>已保存并且至空间</p>',
  352. nzOnOk: () => console.log('Info OK')
  353. });
  354. return
  355. }
  356. if (event == 'next') {
  357. let params = this.validateForm.value
  358. await this.saveEduTextbook(params, this.validateForm.valid)
  359. this.state.emit({ type: 'next', textBook: this.eduTextbook });
  360. }
  361. }
  362. if (event == 'save') {
  363. let params = this.validateForm.value
  364. await this.saveEduTextbook(params, this.validateForm.valid)
  365. this.modal.success({
  366. nzTitle: '保存成功',
  367. nzContent: '<p>已保存并且至空间</p>',
  368. nzOnOk: () => console.log('Info OK')
  369. });
  370. }
  371. }
  372. async saveEduTextbook(params: any, isComplete: boolean) {
  373. this.changeImportantProject()
  374. console.log(params);
  375. if (!this.eduTextbook) {
  376. let obj = Parse.Object.extend('EduTextbook');
  377. this.eduTextbook = new obj();
  378. }
  379. //如果填写未完整,仅保存,状态修改待完善101
  380. if (this.eduTextbook.get('status') == '102' && !isComplete) {
  381. this.eduTextbook?.set('status', '101');
  382. this.eduTextbook.set('complete', false)
  383. } else if (!this.eduTextbook.get('status')) {
  384. this.eduTextbook?.set('status', '101');
  385. }
  386. this.eduTextbook?.set('user', Parse.User.current()?.toPointer());
  387. this.eduTextbook?.set('company', {
  388. __type: 'Pointer',
  389. className: 'Company',
  390. objectId: this.tbookSer.company,
  391. });
  392. this.eduTextbook?.set('title', params.title);
  393. this.eduTextbook?.set('ISBN', (params.ISBN || 0).toString());
  394. this.eduTextbook?.set('author', params.author);
  395. this.eduTextbook?.set('unit', params.unit);
  396. this.eduTextbook?.set('type', params.type);
  397. // this.eduTextbook?.set('typeNumber', params.typeNumber);
  398. this.eduTextbook?.set('typeNumber', this.typeNumber);
  399. let majorPoniter = this.selectList.find((item) => item.code == params.majorPoniter);
  400. this.eduTextbook?.set('majorPoniter', majorPoniter);
  401. this.eduTextbook?.set('lang', params.lang);
  402. this.eduTextbook?.set('authors', params.authors);
  403. this.eduTextbook?.set('editor', params.editor);
  404. this.eduTextbook?.set('approval', params.approval);
  405. this.eduTextbook?.set('editionUnit', params.editionUnit);
  406. this.eduTextbook?.set('editionFirst', params.editionFirst);
  407. this.eduTextbook?.set('carrierShape', params.carrierShape);
  408. this.eduTextbook?.set('editionDate', params.editionDate);
  409. this.eduTextbook?.set('editionNumber', params.editionNumber);
  410. this.eduTextbook?.set('printDate', params.printDate);
  411. this.eduTextbook?.set('printNumber', params.printNumber);
  412. this.eduTextbook?.set('printSum', params.printSum);
  413. // this.eduTextbook?.set('importantProject', params.importantProject);
  414. this.eduTextbook?.set('importantProject', this.importantProject);
  415. this.eduTextbook?.set('importantProjectOther', params.importantProjectOther);
  416. // this.eduTextbook?.set('copyrightImgUrl', params.copyrightImgUrl);
  417. // this.eduTextbook?.set('CIPImgUrl', params.CIPImgUrl);
  418. this.eduTextbook?.set('approvedImgUrl', params.approvedImgUrl)
  419. this.eduTextbook?.set('unitType', params.unitType)
  420. await this.eduTextbook?.save();
  421. return
  422. }
  423. selectedValue = null;
  424. listOfOption: Array<{ value: string; text: string }> = [];
  425. nzFilterOption = (): boolean => true;
  426. eduTimeout: any
  427. /**出版单位列表 */
  428. eduList: Array<Parse.Object> = []
  429. /**搜索出版单位 */
  430. async search(value: string) {
  431. clearTimeout(this.eduTimeout)
  432. this.eduTimeout = setTimeout(async () => {
  433. let query = new Parse.Query('Department')
  434. query.notEqualTo('isDeleted', true)
  435. query.equalTo('parent', '66865d66ad23a23355b12aa7')
  436. query.contains('name', value)
  437. query.limit(10)
  438. this.eduList = await query.find()
  439. }, 500);
  440. }
  441. openFile(url: any) {
  442. window.open(url)
  443. }
  444. }