review-details.component.ts 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import { Component, Input, OnInit } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { NzSpaceModule } from 'ng-zorro-antd/space';
  4. import { CommonCompModule } from '../../../../services/common.modules';
  5. import { ActivatedRoute, Router } from '@angular/router';
  6. import { NzMessageModule } from 'ng-zorro-antd/message';
  7. import { NzMessageService } from 'ng-zorro-antd/message';
  8. import Parse from 'parse';
  9. import { textbookServer } from '../../../../services/textbook';
  10. import { NzModalService } from 'ng-zorro-antd/modal';
  11. import { MatDialog } from '@angular/material/dialog';
  12. import { NzEmptyModule } from 'ng-zorro-antd/empty';
  13. import { DatePipe } from '@angular/common';
  14. import { NzPopoverModule } from 'ng-zorro-antd/popover';
  15. @Component({
  16. selector: 'app-review-details',
  17. templateUrl: './review-details.component.html',
  18. styleUrls: ['./review-details.component.scss'],
  19. imports: [
  20. CommonModule,
  21. NzSpaceModule,
  22. CommonCompModule,
  23. NzMessageModule,
  24. NzEmptyModule,
  25. NzPopoverModule,
  26. ],
  27. providers: [DatePipe],
  28. standalone: true,
  29. })
  30. export class ReviewDetailsComponent implements OnInit {
  31. reviewList: Array<Parse.Object> = [];
  32. count: number = 0;
  33. @Input('limit') limit: number = 10;
  34. pageIndex: number = 1;
  35. loading: boolean = false;
  36. @Input('maxWidth') maxWidth: any; //最大宽度
  37. @Input('eduProcess') eduProcess?: Parse.Object; //流程id,verify存在时需要
  38. @Input('listOfFilter') listOfFilter: Array<any> = []; //评审组
  39. @Input('filterObj') filterObj: any = {
  40. showGroup: false,
  41. contained: [],
  42. bookMap: {}, //教材对应评审组结构{booid:评审组名称}
  43. };
  44. searchValue: string = '';
  45. listOfColumns: any = {
  46. lang: {
  47. // listOfFilter: [{ value: '中文', text: '中文' }],
  48. onChange: (data: Array<string>) => {
  49. console.log(data);
  50. if (data?.length < 1) {
  51. this.filterObj.contained = Object.keys(this.filterObj.bookMap);
  52. } else {
  53. this.filterObj.contained = [];
  54. for (const key in this.filterObj.bookMap) {
  55. const item = this.filterObj.bookMap[key];
  56. if (data.includes(item.id)) {
  57. this.filterObj.contained.push(key);
  58. }
  59. }
  60. }
  61. this.getTextbook(this.searchValue);
  62. },
  63. },
  64. };
  65. showLoading: boolean = false; //全局
  66. time: any;
  67. constructor(
  68. private activeRoute: ActivatedRoute,
  69. public tbookSer: textbookServer,
  70. private router: Router,
  71. private msg: NzMessageService,
  72. public dialog: MatDialog,
  73. private route: Router,
  74. private datePipe: DatePipe,
  75. private modal: NzModalService
  76. ) {}
  77. ngOnInit() {
  78. this.getTextbook();
  79. }
  80. async getTextbook(val?: string, exported?: boolean): Promise<any[] | void> {
  81. if (this.loading) return;
  82. if(!exported) this.loading = true;
  83. try {
  84. let queryParams: any = {
  85. where: {
  86. $or: [
  87. {
  88. eduTextbook: {
  89. $inQuery: {
  90. where: {
  91. $or: [
  92. {
  93. title: { $regex: `.*${val || ''}.*` },
  94. },
  95. {
  96. childrens: {
  97. $inQuery: {
  98. where: {
  99. $or: [
  100. {
  101. ISBN: { $regex: `.*${val || ''}.*` },
  102. },
  103. {
  104. author: { $regex: `.*${val || ''}.*` },
  105. },
  106. ],
  107. },
  108. className: 'EduTextbookVolume',
  109. },
  110. },
  111. },
  112. ],
  113. },
  114. className: 'EduTextbook',
  115. },
  116. },
  117. },
  118. {
  119. profile: {
  120. $inQuery: {
  121. where: {
  122. $or: [
  123. {
  124. user: {
  125. $inQuery: {
  126. where: {
  127. $or: [
  128. {
  129. name: { $regex: `.*${val || ''}.*` },
  130. },
  131. ],
  132. },
  133. className: '_User',
  134. },
  135. },
  136. },
  137. ],
  138. },
  139. className: 'Profile',
  140. },
  141. },
  142. },
  143. ],
  144. eduTextbook: { $in: this.filterObj.contained },
  145. },
  146. };
  147. let query = Parse.Query.fromJSON('EduReview', queryParams);
  148. this.eduProcess?.id && query.equalTo('eduProcess', this.eduProcess.id);
  149. query.descending('updatedAt');
  150. query.notEqualTo('isDeleted', true);
  151. query.include('eduTextbook', 'profile', 'profile.user');
  152. this.count = await query.count();
  153. query.limit(this.limit);
  154. query.skip(this.limit * (this.pageIndex - 1));
  155. if (exported) {
  156. query.limit(1000);
  157. let r = await query.find();
  158. this.loading = false;
  159. return r;
  160. }
  161. this.reviewList = await query.find();
  162. console.log(this.reviewList);
  163. this.loading = false;
  164. } catch (err) {
  165. console.warn(err);
  166. this.msg.error('获取超时');
  167. }
  168. this.loading = false;
  169. }
  170. onSearch(e: string) {
  171. this.pageIndex = 1;
  172. console.log(e);
  173. if (this.time) clearTimeout(this.time);
  174. this.time = setTimeout(() => {
  175. this.getTextbook(e);
  176. }, 500);
  177. }
  178. //分页切换
  179. pageIndexChange(e: any) {
  180. console.log(e);
  181. this.pageIndex = e;
  182. this.getTextbook(this.searchValue);
  183. }
  184. //切换分页条数
  185. onPageSizeChange($event: any): void {
  186. console.log(this.limit);
  187. // this.onAllChecked(false)
  188. this.pageIndex = 1;
  189. this.getTextbook();
  190. }
  191. toUrl(url: string, param?: Object) {
  192. console.log(url);
  193. if (param) {
  194. this.route.navigate([url, param]);
  195. return;
  196. }
  197. this.route.navigate([url]);
  198. }
  199. //导出表格
  200. async export() {
  201. if (this.showLoading) return;
  202. this.showLoading = true;
  203. try {
  204. let data: any = await this.getTextbook('', true);
  205. let table = `<table border="1px" cellspacing="0" cellpadding="0">
  206. <thead>
  207. <tr>
  208. <th>序号</th>
  209. <th>申报教材名称</th>
  210. <th>所属评审组</th>
  211. ${this.filterObj.showGroup ? '<th>评审专家</th>' : ''}
  212. <th>提交时间</th>
  213. <th>分值</th>
  214. </tr>
  215. </thead>
  216. <tbody>
  217. `;
  218. let _body = '';
  219. for (var row = 0; row < data.length; row++) {
  220. _body += '<tr>';
  221. _body += '<td>';
  222. _body += `${row + 1}`;
  223. _body += '</td>';
  224. _body += '<td>';
  225. _body += `&nbsp;${data[row]?.get('eduTextbook')?.get('title') || ''}`;
  226. _body += '</td>';
  227. if(this.filterObj.showGroup){
  228. _body += '<td>';
  229. _body += ` &nbsp;${
  230. this.filterObj.bookMap[data[row]?.get('eduTextbook')?.id].name || '-'
  231. }`;
  232. _body += '</td>';
  233. }
  234. _body += '<td>';
  235. _body += `${
  236. data[row]?.get('profile')?.get('user')?.get('name') || '-'
  237. }`;
  238. _body += '</td>';
  239. _body += '<td>';
  240. _body += `&nbsp;${this.datePipe.transform(
  241. data[row]?.updatedAt,
  242. 'yyyy-MM-dd HH:mm:ss'
  243. )}`;
  244. _body += '</td>';
  245. _body += '<td>';
  246. _body += `${data[row]?.get('score') ?? '-'}`;
  247. _body += '</td>';
  248. _body += '</tr>';
  249. }
  250. table += _body;
  251. table += '</tbody>';
  252. table += '</table>';
  253. let title = '评审详情表';
  254. this.excel(table, `${title}.xls`);
  255. this.showLoading = false;
  256. } catch (err) {
  257. console.log(err);
  258. this.showLoading = false;
  259. this.msg.error('导出超时');
  260. }
  261. }
  262. excel(data: any, filename: string) {
  263. let html =
  264. "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
  265. html +=
  266. '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
  267. html += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
  268. html += '; charset=UTF-8">';
  269. html += '<head>';
  270. html += '</head>';
  271. html += '<body>';
  272. html += data;
  273. html += '</body>';
  274. html += '</html>';
  275. let uri =
  276. 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(html);
  277. let link = document.createElement('a');
  278. link.href = uri;
  279. link.download = `${filename}`;
  280. document.body.appendChild(link);
  281. link.click();
  282. document.body.removeChild(link);
  283. }
  284. }