collect-file.component.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. import {
  2. Component,
  3. Input,
  4. OnInit,
  5. QueryList,
  6. ViewChildren,
  7. } from '@angular/core';
  8. import { CommonModule } from '@angular/common';
  9. import { NzSpaceModule } from 'ng-zorro-antd/space';
  10. import { CommonCompModule } from '../../../services/common.modules';
  11. import { ActivatedRoute, Router } from '@angular/router';
  12. import { NzMessageModule } from 'ng-zorro-antd/message';
  13. import { NzMessageService } from 'ng-zorro-antd/message';
  14. import Parse from 'parse';
  15. import { textbookServer } from '../../../services/textbook';
  16. import { NzModalService } from 'ng-zorro-antd/modal';
  17. import { MatDialog } from '@angular/material/dialog';
  18. import { NzEmptyModule } from 'ng-zorro-antd/empty';
  19. import { DatePipe } from '@angular/common';
  20. import { NzPopoverModule } from 'ng-zorro-antd/popover';
  21. import { UploadCollectComponent } from '../components/upload-collect/upload-collect.component';
  22. import { NzCollapseModule } from 'ng-zorro-antd/collapse';
  23. @Component({
  24. selector: 'app-collect-file',
  25. templateUrl: './collect-file.component.html',
  26. styleUrls: ['./collect-file.component.scss'],
  27. imports: [
  28. CommonModule,
  29. NzSpaceModule,
  30. CommonCompModule,
  31. NzMessageModule,
  32. NzEmptyModule,
  33. NzPopoverModule,
  34. UploadCollectComponent,
  35. NzCollapseModule,
  36. ],
  37. providers: [DatePipe],
  38. standalone: true,
  39. })
  40. export class CollectFileComponent implements OnInit {
  41. textbookList: Array<Parse.Object> = [];
  42. // eduProcess?: Parse.Object; //流程
  43. count: number = 0;
  44. limit: number = 10;
  45. pageIndex: number = 1;
  46. loading: boolean = false;
  47. @Input('maxWidth') maxWidth: any; //最大宽度
  48. @ViewChildren(UploadCollectComponent) children:
  49. | QueryList<UploadCollectComponent>
  50. | any;
  51. searchValue: string = '';
  52. time: any;
  53. showLoading: boolean = false; //全局
  54. /* 格式化拓展表字段 */
  55. fromatFiled(list: Array<Parse.Object>, filed: string): string {
  56. let arr: Array<string | null> = [];
  57. let isDate = false;
  58. list.forEach((item: Parse.Object) => {
  59. if (
  60. isDate ||
  61. Object.prototype.toString.call(item.get(filed)).indexOf('Date') != -1
  62. ) {
  63. arr.push(this.datePipe.transform(item.get(filed), 'yyyy-MM'));
  64. isDate = true;
  65. } else {
  66. arr.push(item.get(filed));
  67. }
  68. });
  69. let j = Array.from(arr).join(',');
  70. if (!isDate) {
  71. j = Array.from(new Set(arr)).join(' ');
  72. }
  73. return j || '-';
  74. }
  75. isVisible: boolean = false;
  76. currentTextbook?: Parse.Object; //当前编辑教材
  77. statusMap: any = {}; //任务状态
  78. constructor(
  79. private msg: NzMessageService,
  80. public tbookSer: textbookServer,
  81. public dialog: MatDialog,
  82. private route: Router,
  83. private datePipe: DatePipe,
  84. private modal: NzModalService
  85. ) {}
  86. async ngOnInit() {
  87. // await this.getEduProcess();
  88. if(!this.tbookSer.profile.user?.department?.name) return
  89. this.getTextbook();
  90. }
  91. async getEduProcess() {
  92. let query = new Parse.Query('EduProcess');
  93. query.notEqualTo('isDeleted', true);
  94. query.equalTo('profileSubmitted', this.tbookSer.profile.objectId);
  95. query.containedIn('status', ['400']);
  96. let r = await query.first();
  97. console.log(r);
  98. // this.eduProcess = r;
  99. }
  100. async getTextbook(val?: string): Promise<any[] | void> {
  101. if (this.loading) return;
  102. this.loading = true;
  103. try {
  104. let queryParams: any = {
  105. where: {
  106. $or: [
  107. {
  108. title: { $regex: `.*${val || ''}.*` },
  109. },
  110. {
  111. code: { $regex: `.*${val || ''}.*` },
  112. },
  113. {
  114. childrens: {
  115. $inQuery: {
  116. where: {
  117. $or: [
  118. {
  119. ISBN: { $regex: `.*${val || ''}.*` },
  120. },
  121. ],
  122. },
  123. className: 'EduTextbookVolume',
  124. },
  125. },
  126. },
  127. ],
  128. childrens: {
  129. $inQuery: {
  130. where: {
  131. editionUnit: this.tbookSer.profile.user?.department?.name,
  132. // editionUnit: '高等教育出版社',
  133. },
  134. className: 'EduTextbookVolume',
  135. },
  136. },
  137. eduProcess:{
  138. $inQuery: {
  139. where: {
  140. status: '400',
  141. collectStartData:{
  142. $lt:{
  143. "__type": "Date",
  144. "iso": new Date()
  145. },
  146. },
  147. collectEndData:{
  148. $gt:{
  149. "__type": "Date",
  150. "iso": new Date()
  151. },
  152. }
  153. },
  154. className: 'EduProcess',
  155. },
  156. }
  157. },
  158. };
  159. let query = Parse.Query.fromJSON('EduTextbook', queryParams);
  160. query.descending('updatedAt');
  161. query.notEqualTo('isDeleted', true);
  162. query.equalTo('status', '400');
  163. query.equalTo('recommend', true);
  164. query.notEqualTo('discard', true);
  165. query.include(
  166. 'childrens',
  167. 'eduProcess.profileSubmitted.user',
  168. 'eduProcess.collectStartData',
  169. 'eduProcess.collectEndData',
  170. 'department'
  171. );
  172. this.count = await query.count();
  173. query.limit(this.limit);
  174. query.skip(this.limit * (this.pageIndex - 1));
  175. this.textbookList = await query.find();
  176. //获取对应出版单位管理员
  177. this.textbookList.forEach((item) => {
  178. this.statusMap[item.id] = {
  179. status: '待上传',
  180. color: '#1890ff',
  181. btn: '上传',
  182. };
  183. //是否保存
  184. let isSave = item?.get('childrens').some((child: Parse.Object) => {
  185. return (
  186. this.tbookSer.profile.user?.department?.name == child?.get('editionUnit') &&
  187. child?.get('collectStatus') == '100'
  188. );
  189. });
  190. if (isSave) {
  191. this.statusMap[item.id] = {
  192. status: '已保存',
  193. color: '#20c94e',
  194. btn: '编辑',
  195. };
  196. return;
  197. }
  198. //是否提交
  199. let isSbmit = item?.get('childrens').every((child: Parse.Object) => {
  200. return (
  201. this.tbookSer.profile.user?.department?.name != child?.get('editionUnit') ||
  202. (this.tbookSer.profile.user?.department?.name == child?.get('editionUnit') &&
  203. child?.get('collectStatus') == '200')
  204. );
  205. });
  206. console.log(isSbmit);
  207. if (isSbmit) {
  208. this.statusMap[item.id] = {
  209. status: '已提交',
  210. color: '#7a7a7a',
  211. btn: false,
  212. };
  213. }
  214. });
  215. console.log(this.textbookList);
  216. this.loading = false;
  217. } catch (err) {
  218. console.warn(err);
  219. this.msg.error('获取超时');
  220. }
  221. this.loading = false;
  222. }
  223. onSearch(e: string) {
  224. this.pageIndex = 1;
  225. console.log(e);
  226. if (this.time) clearTimeout(this.time);
  227. this.time = setTimeout(() => {
  228. this.getTextbook(e);
  229. }, 500);
  230. }
  231. //分页切换
  232. pageIndexChange(e: any) {
  233. console.log(e);
  234. this.pageIndex = e;
  235. this.getTextbook(this.searchValue);
  236. }
  237. //切换分页条数
  238. onPageSizeChange(): void {
  239. console.log(this.limit);
  240. this.pageIndex = 1;
  241. this.getTextbook(this.searchValue);
  242. }
  243. toUrl(url: string, param?: Object) {
  244. console.log(url);
  245. if (param) {
  246. this.route.navigate([url, param]);
  247. return;
  248. }
  249. this.route.navigate([url]);
  250. }
  251. //打开上传弹窗
  252. onEditModal(data: Parse.Object) {
  253. if (
  254. !data.get('eduProcess')?.get('collectStartData') ||
  255. !data.get('eduProcess')?.get('collectEndData') ||
  256. data.get('eduProcess')?.get('collectStartData') > new Date() ||
  257. data.get('eduProcess')?.get('collectEndData') < new Date()
  258. ) {
  259. this.msg.warning('非收集文件工作期内');
  260. return;
  261. }
  262. this.currentTextbook = data;
  263. this.isVisible = true;
  264. }
  265. handleCancel(): void {
  266. this.isVisible = false;
  267. this.currentTextbook = undefined;
  268. }
  269. btnLoading: boolean = false;
  270. async saveCollect(type: string): Promise<any> {
  271. console.log(type);
  272. this.btnLoading = true;
  273. if (type == 'sbmit') {
  274. this.modal.confirm({
  275. nzTitle: '温馨提示',
  276. nzContent: '由于“教材资源上传”工作阶段持续时间较短,教材资源一经上传将无法撤回或修改,请务必在确认无误之后再上传。',
  277. nzOkText: '确定',
  278. nzOkType: 'primary',
  279. nzOkDanger: false,
  280. nzOnOk: async () => {
  281. let isVrifly = await this.saveEduTextbookVolume(type);
  282. if (!isVrifly) {
  283. this.btnLoading = false;
  284. this.msg.warning('已保存,填写信息不完整');
  285. return;
  286. }
  287. this.msg.success('提交成功');
  288. this.btnLoading = false;
  289. this.isVisible = false;
  290. this.getTextbook(this.searchValue);
  291. },
  292. nzCancelText: '取消',
  293. nzOnCancel: () => {
  294. this.btnLoading = false;
  295. },
  296. });
  297. } else {
  298. await this.saveEduTextbookVolume(type);
  299. this.msg.success('保存成功');
  300. this.btnLoading = false;
  301. this.isVisible = false;
  302. this.getTextbook(this.searchValue);
  303. }
  304. }
  305. /**上传分册数据 */
  306. async saveEduTextbookVolume(type: string): Promise<any> {
  307. let isVrifly = true; //默认都通过,若一项填写未完成,则不通过
  308. return Promise.all(
  309. this.children.map(async (comp: any) => {
  310. let complete = await comp.submitForm(type);
  311. console.log(comp?.eduTextbookVolume?.id + '===' + complete);
  312. if (!complete) {
  313. isVrifly = false;
  314. }
  315. return isVrifly;
  316. })
  317. ).then((data) => {
  318. console.log(isVrifly);
  319. return isVrifly;
  320. });
  321. }
  322. }