123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- import { Component, OnInit, ViewChild } from '@angular/core';
- import {
- AlertController,
- LoadingController,
- ToastController,
- } from '@ionic/angular';
- import { NavComponent } from '../../../app/components/nav/nav.component';
- import * as Parse from 'parse';
- import { Router } from '@angular/router';
- import { UploadComponent } from '../../../app/components/upload/upload.component';
- import { AuthService } from '../../../services/auth.service';
- import { ionicStandaloneModules } from '../../ionic-standalone.modules';
- import { province } from '../../../services/address';
- @Component({
- selector: 'app-setting',
- templateUrl: './setting.component.html',
- styleUrls: ['./setting.component.scss'],
- standalone: true,
- imports: [...ionicStandaloneModules, NavComponent, UploadComponent],
- })
- export class SettingComponent implements OnInit {
- @ViewChild('upload') upload!: UploadComponent;
- profile?: Parse.Object; //身份信息
- formData: any = {
- avatar: '',
- name: '',
- nickname: '',
- sex: '',
- age: '',
- remark: '',
- };
- mobile: string = '';
- loading: any;
- isOpen: boolean = false;
- address: string = '';
- provinceColumns = province.map((item) => item.provinceName);
- cityColumns = province[0].citys.map((item) => item.cityName);
- province: string = ''; //省份
- city: string = ''; //市
- constructor(
- private alertController: AlertController,
- public loadingCtrl: LoadingController,
- public toastController: ToastController,
- private authServ: AuthService,
- private router: Router
- ) {}
- ngOnInit() {
- this.getProfile();
- }
- // 获取用户信息
- async getProfile() {
- this.loading = await this.loadingCtrl.create({
- message: '加载中',
- });
- this.loading.present();
- let user = Parse.User.current();
- let query = new Parse.Query('Profile');
- query.equalTo('user', user?.id);
- query.notEqualTo('isDeleted', true);
- this.profile = await query.first();
- this.formData.avatar =
- user?.get('avatar') ||
- 'https://file-cloud.fmode.cn/DXNgcD6zo6/20221202/j6p8kb034039.png';
- this.formData.nickname = user?.get('nickname') || '';
- this.formData.sex = user?.get('sex') || '';
- this.formData.age = user?.get('age') || '';
- this.mobile = user?.get('mobile');
- this.formData.name = this.profile?.get('name') || '';
- this.formData.age = this.profile?.get('birthdate') || '';
- this.formData.remark = this.profile?.get('remark') || '';
- this.loading.dismiss();
- if(user?.get('city') && user?.get('province')){
- this.address = user?.get('province') +'-'+user?.get('city');
- }
- this.province = user?.get('province') || this.provinceColumns[0]
- this.city = user?.get('city') || this.cityColumns[0]
- }
- onChange(e: any, type: string) {
- this.formData[type] = e.detail.value;
- }
- async saveEdit(e: any) {
- this.loading = await this.loadingCtrl.create({
- message: '正在保存修改',
- });
- this.loading.present();
- console.log(e);
- console.log(this.formData);
- let urls = e?.map((item: any) => item.url);
- let user = Parse.User.current();
- if (!user?.id) {
- this.loading.dismiss();
- const alert = await this.alertController.create({
- header: '提示',
- message: '登录信息已过期,请重新登录',
- buttons: [
- {
- text: '好的',
- role: 'confirm',
- handler: () => {
- this.authServ.logout();
- },
- },
- ],
- });
- await alert.present();
- return;
- }
- user.set('avatar', urls[0]);
- user.set('nickname', this.formData.nickname);
- user.set('sex', this.formData.sex);
- // user.set('age', Number(this.formData.age));
- user.set('address', this.address);
- user.set('city', this.city);
- user.set('province', this.province);
- await user.save();
- if (!this.profile?.id) {
- let obj = Parse.Object.extend('Profile');
- this.profile = new obj();
- this.profile?.set('user', Parse.User.current()?.toPointer());
- this.profile?.set('company', {
- __type: 'Pointer',
- className: 'Company',
- objectId: this.authServ.company,
- });
- }
- this.profile?.set('mobile', Parse.User.current()?.get('mobile'));
- this.profile?.set('sex', this.formData.sex);
- this.profile?.set('birthdate', this.formData.age);
- this.profile?.set('remark', this.formData.remark);
- this.profile?.set('address', this.address);
- await this.profile?.save();
- this.loading.dismiss();
- this.getProfile();
- this.presentAlert('修改成功');
- }
- async presentToast(title: string, time: number, color: string) {
- const toast = await this.toastController.create({
- message: title,
- duration: time,
- color: color,
- });
- toast.present();
- }
- async presentAlert(msg: string) {
- const alert = await this.alertController.create({
- header: '提示',
- message: msg,
- buttons: [
- {
- text: '好的',
- role: 'confirm',
- handler: () => {},
- },
- ],
- });
- await alert.present();
- }
- cancel(type: string) {
- if (type === 'cancel') {
- this.province = this.address.split('-')[0];
- this.city = this.address.split('-')[1];
- } else {
- this.address = this.province + '-' + this.city;
- }
- this.isOpen = false;
- console.log(this.address);
- }
- onIonChange(event: CustomEvent, type: string) {
- let val = event.detail.value;
- switch (type) {
- case 'province':
- this.province = event.detail.value;
- this.cityColumns = province
- .find((item) => item.provinceName === val)
- ?.citys.map((item) => item.cityName)!;
- console.log(this.cityColumns);
- this.city = this.cityColumns[0];
- break;
- case 'city':
- this.city = event.detail.value;
- break;
- }
- console.log(this.province, this.city);
- }
- }
|