|
@@ -0,0 +1,60 @@
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
+import { ActivatedRoute } from '@angular/router';
|
|
|
+import { NavController } from '@ionic/angular';
|
|
|
+import Parse from "parse";
|
|
|
+@Component({
|
|
|
+ selector: 'app-case-pet-edit',
|
|
|
+ templateUrl: './case-pet-edit.page.html',
|
|
|
+ styleUrls: ['./case-pet-edit.page.scss'],
|
|
|
+})
|
|
|
+export class CasePetEditPage implements OnInit {
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private route:ActivatedRoute,
|
|
|
+ private navCtrl:NavController
|
|
|
+ ) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 宠物相关可编辑字段
|
|
|
+ petInfo:any = {
|
|
|
+
|
|
|
+ }
|
|
|
+ async save(){
|
|
|
+ // 将petInfo当前编辑元素,逐个set到this.pet的Parse.Object里面去
|
|
|
+ console.log(this.petInfo)
|
|
|
+ console.log(this.pet)
|
|
|
+ Object.keys(this.petInfo).forEach(key=>{
|
|
|
+ this.pet?.set(key,this.petInfo[key])
|
|
|
+ })
|
|
|
+ // 判断,当创建宠物无创建者,则将Parse.User的.toPointer()指针,赋值给user字段
|
|
|
+ if(!this.pet?.get("user")?.id) this.pet?.set("user",this.user?.toPointer())
|
|
|
+ await this.pet?.save()
|
|
|
+ this.navCtrl.back();
|
|
|
+ }
|
|
|
+ cancel(){
|
|
|
+ this.navCtrl.back();
|
|
|
+ }
|
|
|
+
|
|
|
+ user:Parse.User|undefined
|
|
|
+ ngOnInit() {
|
|
|
+ this.user = Parse.User.current();
|
|
|
+ this.loadPetById()
|
|
|
+ }
|
|
|
+
|
|
|
+ pet:Parse.Object|undefined
|
|
|
+ async loadPetById(){
|
|
|
+ // let id = location.pathname.split("/").pop();
|
|
|
+ let id = this.route.snapshot.params["id"]
|
|
|
+
|
|
|
+ if(id&&id!="new"){
|
|
|
+ let query = new Parse.Query("Pet");
|
|
|
+ this.pet = await query.get(id);
|
|
|
+ }else{
|
|
|
+ let Pet = Parse.Object.extend("Pet");
|
|
|
+ this.pet = new Pet();
|
|
|
+ }
|
|
|
+ this.petInfo = this.pet?.toJSON()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|