feedback.component.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Component, OnInit } from '@angular/core';
  2. import * as Parse from 'parse';
  3. import { ToastController } from '@ionic/angular';
  4. import { FormsModule } from '@angular/forms';
  5. import { NavComponent } from '../../../app/components/nav/nav.component';
  6. import { AuthService } from '../../../services/auth.service';
  7. import { UploadComponent } from '../../../app/components/upload/upload.component';
  8. import { ionicStandaloneModules } from '../../ionic-standalone.modules';
  9. @Component({
  10. selector: 'app-feedback',
  11. templateUrl: './feedback.component.html',
  12. styleUrls: ['./feedback.component.scss'],
  13. standalone: true,
  14. imports: [...ionicStandaloneModules, FormsModule, UploadComponent,NavComponent],
  15. })
  16. export class FeedbackComponent implements OnInit {
  17. fileList: any = [];
  18. content: string = '';
  19. inputNum: number = 0;
  20. company: string | null = '';
  21. constructor(
  22. private authServ: AuthService,
  23. public toastController: ToastController
  24. ) {
  25. this.company = authServ.company;
  26. }
  27. textChange(e: any) {
  28. this.content = e.detail.value;
  29. this.inputNum = e.detail.value.length;
  30. }
  31. ngOnInit() {}
  32. async presentToast(title: string, time: number, color: string) {
  33. const toast = await this.toastController.create({
  34. message: title,
  35. duration: time,
  36. color: color,
  37. });
  38. toast.present();
  39. }
  40. onFilesChange(event: any) {
  41. console.log(event);
  42. this.fileList = event;
  43. }
  44. async submit() {
  45. let user = Parse.User.current();
  46. if (!user) {
  47. this.authServ.logout();
  48. return;
  49. }
  50. console.log(this.fileList);
  51. if (
  52. (this.content == '' || this.content.trim() == '') &&
  53. this.fileList.length < 1
  54. ) {
  55. await this.presentToast('请填写内容', 1500, 'danger');
  56. return;
  57. }
  58. let images = [];
  59. for (let i = 0; i < this.fileList.length; i++) {
  60. let item = this.fileList[i];
  61. images.push({
  62. url: item,
  63. });
  64. }
  65. let mobile = user.get('mobile');
  66. let Profile = new Parse.Query('Profile');
  67. Profile.equalTo('user', user.id);
  68. Profile.notEqualTo('isDeleted',true)
  69. let profile = await Profile.first();
  70. let Feedback = Parse.Object.extend('Feedback');
  71. let feedback = new Feedback();
  72. feedback.set('user', {
  73. __type: 'Pointer',
  74. className: '_User',
  75. objectId: user.id,
  76. });
  77. feedback.set('company', {
  78. __type: 'Pointer',
  79. className: 'Company',
  80. objectId: this.company,
  81. });
  82. if (profile) {
  83. feedback.set('profile', {
  84. __type: 'Pointer',
  85. className: 'Profile',
  86. objectId: profile.id,
  87. });
  88. }
  89. feedback.set('content', this.content ? this.content : undefined);
  90. feedback.set('images', images);
  91. feedback.set('mobile', mobile);
  92. let result = await feedback.save();
  93. if (result && result.id) {
  94. await this.presentToast('提交成功', 1500, 'success');
  95. history.go(-1);
  96. } else {
  97. await this.presentToast('提交失败', 1500, 'danger');
  98. setTimeout(() => {
  99. history.go(-1);
  100. }, 1500);
  101. }
  102. }
  103. }