feedback.component.ts 2.9 KB

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