import { Component, OnInit } from '@angular/core'; import { AlertController } from '@ionic/angular'; import {SharedService} from 'src/modules/user/service-user/Share.service' import { Router } from '@angular/router'; import {NavController } from '@ionic/angular'; import * as Parse from "parse" (Parse as any).serverURL = "https://web2023.fmode.cn/parse" Parse.initialize("dev") @Component({ selector: 'app-add-frends', templateUrl: './add-frends.page.html', styleUrls: ['./add-frends.page.scss'], }) export class AddFrendsPage implements OnInit { public userInput:string=''; cares :any = []; search:any={ userId:'', usename:'', userImg:'' }; careUsername:any='' public ifSearch:boolean=false; userId:any='' ngOnInit() { this.findMyCare() } constructor(private navCtrl:NavController,private sharedService: SharedService,private router:Router,private alertCtrl:AlertController){ this.userId=this.sharedService.getUserId() // findMyCare(this.userId,this.cares) // console.log(this.cares) } goAiChatPage(){ this.router.navigate(["/pocket-local/social-interactions/ai-chat-page"],{ }) } goChatPage(spot:Parse.Object){ this.router.navigate(["/pocket-local/social-interactions/chat-page"],{ queryParams:spot }) } async findMyCare() { const GzpCare = Parse.Object.extend('GzpCare'); const query = new Parse.Query(GzpCare); query.equalTo("userId", this.userId); try { const Cares = await query.find(); for (const care of Cares) { this.cares.push({ careUserId:care.get("careUserId"), careUsername:care.get('careUsername'), careUserImg:"http://q1.qlogo.cn/g?b=qq&nk="+care.get("careUserId")+"&s=100" }) } } catch (error) { console.error("查询消息时出错:", error); } } async searchCare(){ const GzpUser = Parse.Object.extend('GzpUser'); const query = new Parse.Query(GzpUser); query.equalTo("userId", this.userInput); try{ const Search = await query.find(); this.careUsername=Search[0].get("username"), this.search={ userId:Search[0].get("userId"), username:Search[0].get("username"), userImg:"http://q1.qlogo.cn/g?b=qq&nk="+Search[0].get("userId")+"&s=100", } this.ifSearch=true }catch(error){ const alert = await this.alertCtrl.create({ header: '查询错误', subHeader: '没有找到该用户', buttons: ['好的'], }); await alert.present(); } console.log(this.search) } backNoSearvh(){ this.ifSearch=false } async careThis(){ if(this.userId!=null){ const GzpCare = Parse.Object.extend('GzpCare'); const carethis = new GzpCare(); carethis.set("userId",this.userId); carethis.set("careUserId",this.userInput); carethis.set("careUsername",this.careUsername); carethis.save(); } const alert = await this.alertCtrl.create({ header: '添加成功', subHeader: '该用户已成为你的关注用户', buttons: ['好的'], }); await alert.present(); this.ifSearch=false this.cares=[] this.findMyCare() } async noCareThis(care: any) { if (this.userId != null) { const GzpCare = Parse.Object.extend('GzpCare'); const query = new Parse.Query(GzpCare); query.equalTo("userId", this.userId); query.equalTo("careUserId", care.careUserId); query.equalTo("careUsername", care.careUsername); const noCare = await query.find(); for (const obj of noCare) { await obj.destroy(); } const alert = await this.alertCtrl.create({ header: '取关成功', subHeader: '该用户已不是你的关注用户', buttons: ['好的'], }); await alert.present(); this.cares=[] this.findMyCare() } } back(){ this.navCtrl.back() } }