• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import inputMethod from '@ohos.inputMethod';
17import { HiLog } from '../../../../../../../common/src/main/ets/util/HiLog';
18import { StringUtil } from '../../../../../../../common/src/main/ets/util/StringUtil';
19import { ArrayUtil } from '../../../../../../../common/src/main/ets/util/ArrayUtil';
20import { ObjectUtil } from '../../../../../../../common/src/main/ets/util/ObjectUtil';
21import { AccountTypeService } from '../../../../../../../feature/account/src/main/ets/AccountTypeService';
22import { AccountType } from '../../../../../../../feature/account/src/main/ets/type/AccountType';
23import { House } from '../../../../../../../feature/contact/src/main/ets/contract/House';
24import { Relation } from '../../../../../../../feature/contact/src/main/ets/contract/Relation';
25import { Phone } from '../../../../../../../feature/contact/src/main/ets/contract/Phone';
26import { Email } from '../../../../../../../feature/contact/src/main/ets/contract/Email';
27import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday';
28import { Aim } from '../../../../../../../feature/contact/src/main/ets/contract/Aim';
29import { EmailBean } from '../../../model/bean/EmailBean';
30import { ContactInfo } from '../../../model/bean/ContactInfo';
31import { PhoneNumBean } from '../../../model/bean/PhoneNumBean';
32import { HouseBean } from '../../../model/bean/HouseBean';
33import { AIMBean } from '../../../model/bean/AIMBean';
34import { EventBean } from '../../../model/bean/EventBean';
35import { AssociatedPersonBean } from '../../../model/bean/AssociatedPersonBean';
36import PreferencesUtil from './../../../util/PreferencesUtil'
37import Prompt from '@system.prompt';
38import router from '@ohos.router';
39
40const TAG = 'AccountantsPresenter  ';
41
42/**
43 * Add Contact Presenter
44 */
45export default class AccountantsPresenter {
46  private static instance: AccountantsPresenter;
47  static readonly timeSub: number = 1000;
48  getPhones: Array<{ [key: string]: any }> = [];
49  getEmails: Array<{ [key: string]: any }> = [];
50  clickBefEvent: Date = new Date();
51  clickAftEvent: Date = new Date();
52  contactId: string = '';
53  routerAvtiveFlag: boolean = false;
54
55  // update mark
56  updateShow: boolean = false;
57  isShowPosition: boolean = false;
58  showMore: boolean = false;
59  addState: boolean = false;
60  phones: string = '';
61  editContact: number = -1;
62  phoneNumberShow: string = '';
63  callId: string = '';
64
65  // refresh mark
66  changed: boolean = false;
67  originalContactInfo = JSON.stringify(new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0));
68  // contact detail
69  contactInfoBefore: ContactInfo = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
70  contactInfoAfter: ContactInfo = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
71  nullContactInfo: string = JSON.stringify(new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0));
72  MagList: object = [];
73
74  private constructor() {
75  }
76
77  public static getInstance(): AccountantsPresenter {
78    if (!AccountantsPresenter.instance) {
79      AccountantsPresenter.instance = new AccountantsPresenter()
80    }
81    return AccountantsPresenter.instance
82  }
83
84  refreshState: (presenter: AccountantsPresenter) => void;
85  clickEnable = true;
86
87  init(refreshState?) {
88    this.contactId = '';
89    this.updateShow = false;
90    this.MagList = [1];
91    this.contactInfoBefore = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
92    this.contactInfoAfter = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
93    this.refreshState = refreshState;
94    this.routerAvtiveFlag = false;
95  }
96
97  refresh() {
98    this.contactInfoBefore = this.contactInfoAfter;
99    this.getPhones = this.getArray(this.contactInfoBefore.phones);
100    this.getEmails = this.getArray(this.contactInfoBefore.emails);
101    this.changed = !this.changed;
102    this.refreshAddState();
103    if (this.refreshState) {
104      this.refreshState(this);
105    }
106  }
107
108  refreshAddState() {
109    let addState = this.originalContactInfo != this.getExistenceInfoString(this.contactInfoAfter);
110    if (this.addState != addState) {
111      HiLog.i(TAG, 'refreshAddState addState change:' + addState)
112      this.addState = addState
113    }
114  }
115
116  updatesInit() {
117    HiLog.i(TAG, ' init start');
118    this.contactInfoAfter.setID(this.contactId);
119    if (this.updateShow === true) {
120      HiLog.i(TAG, ' getPageData start ');
121      this.getPageData(this.contactId);
122    }
123  }
124
125  getExistenceInfoString(afterInfo: ContactInfo) {
126    let temp = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
127    if (!afterInfo) {
128      return JSON.stringify(temp);
129    } else {
130      if (!StringUtil.isEmpty(afterInfo.display_name)) {
131        temp.display_name = afterInfo.display_name;
132      }
133      if (!StringUtil.isEmpty(afterInfo.nickname)) {
134        temp.nickname = afterInfo.nickname
135      }
136      if (!StringUtil.isEmpty(afterInfo.remarks)) {
137        temp.remarks = afterInfo.remarks;
138      }
139      if (!StringUtil.isEmpty(afterInfo.position)) {
140        temp.position = afterInfo.position
141      }
142      if (!StringUtil.isEmpty(afterInfo.company)) {
143        temp.company = afterInfo.company
144      }
145      if (!ArrayUtil.isEmpty(afterInfo.phones)) {
146        for (let item of afterInfo.phones) {
147          if (!StringUtil.isEmpty(item?.num)) {
148            temp.phones.push(item)
149          }
150        }
151      }
152      if (!ArrayUtil.isEmpty(afterInfo.emails)) {
153        for (let item of afterInfo.emails) {
154          if (!StringUtil.isEmpty(item?.address)) {
155            temp.emails.push(item)
156          }
157        }
158      }
159      if (!ArrayUtil.isEmpty(afterInfo.aims)) {
160        for (let item of afterInfo.aims) {
161          if (!StringUtil.isEmpty(item?.aimName)) {
162            temp.aims.push(item)
163          }
164        }
165      }
166      if (!ArrayUtil.isEmpty(afterInfo.houses)) {
167        for (let item of afterInfo.houses) {
168          if (!StringUtil.isEmpty(item?.houseName)) {
169            temp.houses.push(item)
170          }
171        }
172      }
173      if (!ArrayUtil.isEmpty(afterInfo.websites)) {
174        for (let item of afterInfo.websites) {
175          if (!StringUtil.isEmpty(item)) {
176            temp.websites.push(item)
177          }
178        }
179      }
180      if (!ArrayUtil.isEmpty(afterInfo.events)) {
181        for (let item of afterInfo.events) {
182          if (!StringUtil.isEmpty(item?.data)) {
183            temp.events.push(item)
184          }
185        }
186      }
187      if (!ArrayUtil.isEmpty(afterInfo.relationships)) {
188        for (let item of afterInfo.relationships) {
189          if (!StringUtil.isEmpty(item?.name)) {
190            temp.relationships.push(item)
191          }
192        }
193      }
194      return JSON.stringify(temp);
195    }
196  }
197
198  getPageData(id: string) {
199    if (StringUtil.isEmpty(id)) {
200      HiLog.e(TAG, 'The parameter ID is empty.');
201    }
202    globalThis.DataWorker.sendRequest('getContactById', {
203      context: globalThis.context,
204      contactId: id
205    }, result => {
206      if (StringUtil.isEmpty(result)) {
207        HiLog.e(TAG, 'The result in the database is empty.');
208        return;
209      }
210      this.dealRecordDetailsData(result.data);
211    });
212  }
213
214  private dealRecordDetailsData(data) {
215    let contactTemp = new ContactInfo('', '', '', [], [], '', '', '', [], [], [], [], [], [], 0);
216    if (!data.hasOwnProperty('id') || data.id != this.contactId) {
217      HiLog.e(TAG, 'Failed to query the database based on the ID.');
218      return;
219    }
220    contactTemp.setID(data.id);
221    let nameUpdate = 0;
222    if (data.hasOwnProperty('nameUpdate')) {
223      nameUpdate = data.nameUpdate;
224    }
225    if (data.hasOwnProperty('display_name') && nameUpdate == 0) {
226      contactTemp.setDisplayName(data.display_name);
227    }
228    if (data.hasOwnProperty('nickname')) {
229      contactTemp.setNickName(data.nickname);
230    }
231    if (data.hasOwnProperty('phones')) {
232      contactTemp.setPhones(data.phones);
233    }
234    if (data.hasOwnProperty('emails')) {
235      contactTemp.setEmails(data.emails);
236    }
237    if (data.hasOwnProperty('remarks')) {
238      contactTemp.setRemarks(data.remarks);
239    }
240    if (data.hasOwnProperty('position')) {
241      contactTemp.setPosition(data.position);
242      this.isShowPosition = true;
243    }
244    if (data.hasOwnProperty('company')) {
245      contactTemp.setCompany(data.company);
246    }
247    if (data.hasOwnProperty('aims')) {
248      contactTemp.setAims(data.aims);
249    }
250    if (data.hasOwnProperty('houses')) {
251      contactTemp.setHouses(data.houses);
252    }
253    if (data.hasOwnProperty('websites')) {
254      contactTemp.setWebsites(data.websites);
255    }
256    if (data.hasOwnProperty('relationships')) {
257      contactTemp.setRelationships(data.relationships);
258    }
259    if (data.hasOwnProperty('events')) {
260      contactTemp.setEvents(data.events);
261    }
262    if (data.hasOwnProperty('groups')) {
263      contactTemp.setGroups(data.groups);
264    }
265    this.contactInfoBefore = contactTemp;
266    this.originalContactInfo = this.getExistenceInfoString(contactTemp)
267    if (0 === this.editContact) {
268      if ('' !== this.phones) {
269        let saveTemp: Array<{ [key: string]: any }>  = this.getArray(this.phones);
270        for(let i = 0; i < saveTemp?.length ; i ++){
271          let phoneNumBean: PhoneNumBean = new PhoneNumBean('','','','','');
272          phoneNumBean.id = saveTemp[i]?.item?.id;
273          phoneNumBean.num = saveTemp[i]?.item?.num;
274          phoneNumBean.numType = saveTemp[i]?.item?.type;
275          phoneNumBean.homeArea = '';
276          phoneNumBean.carriers = '';
277          this.contactInfoBefore.phones.push(phoneNumBean);
278        }
279      }
280    } else if (1 === this.editContact || 2 === this.editContact) {
281      let phoneNumBean: PhoneNumBean = new PhoneNumBean('','','','','');
282      phoneNumBean.id = this.callId;
283      phoneNumBean.num = this.phoneNumberShow;
284      phoneNumBean.numType = '';
285      phoneNumBean.homeArea = '';
286      phoneNumBean.carriers = '';
287      this.contactInfoBefore.phones.push(phoneNumBean);
288    }
289    this.getPhones = this.getArray(this.contactInfoBefore.phones);
290    this.getEmails = this.getArray(this.contactInfoBefore.emails);
291    this.contactInfoAfter = contactTemp;
292    this.refreshAddState()
293  }
294
295  public getData(type: string, index: number): { [key: string]: any } {
296    let data = new Array<{ [key: string]: any }>();
297    switch (type) {
298      case 'phone':
299        if (!this.updateShow) {
300          data = this.getArray(this.contactInfoBefore.phones);
301        } else {
302          data = this.getPhones;
303        }
304        break;
305      case 'email':
306        if (!this.updateShow) {
307          data = this.getArray(this.contactInfoBefore.emails);
308        } else {
309          data = this.getEmails;
310        }
311        break;
312      case 'AIM':
313        data = this.getArray(this.contactInfoBefore.aims);
314        break;
315      case 'house':
316        data = this.getArray(this.contactInfoBefore.houses);
317        break;
318      case 'relationships':
319        data = this.getArray(this.contactInfoBefore.relationships);
320        break;
321      case 'events':
322        data = this.getArray(this.contactInfoBefore.events);
323        break;
324      default:
325        break;
326    }
327    if (index < data.length) {
328      return data[index];
329    }
330    return {
331      i: index + 1, item: {}
332    };
333  }
334
335  public getArray(array): Array<{ [key: string]: any }> {
336    if (ArrayUtil.isEmpty(array)) {
337      array = [{}];
338    }
339    let itemList = ArrayUtil.isEmpty(array) ? this.MagList : array;
340    itemList = itemList.map((item, index) => {
341      return {
342        i: index + 1, item: item
343      };
344    })
345    return itemList;
346  }
347
348  public getDataArray(type: string) {
349    let data = new Array<{ [key: string]: any }>();
350    switch (type) {
351      case 'phone':
352        if (!this.updateShow) {
353          data = this.getArray(this.contactInfoBefore.phones);
354        } else {
355          data = this.getPhones;
356        }
357        break;
358      case 'email':
359        if (!this.updateShow) {
360          data = this.getArray(this.contactInfoBefore.emails);
361        } else {
362          data = this.getEmails;
363        }
364        break;
365      case 'AIM':
366        data = this.getArray(this.contactInfoBefore.aims);
367        break;
368      case 'house':
369        data = this.getArray(this.contactInfoBefore.houses);
370        break;
371      case 'relationships':
372        data = this.getArray(this.contactInfoBefore.relationships);
373        break;
374      case 'events':
375        data = this.getArray(this.contactInfoBefore.events);
376        break;
377      default:
378        break;
379    }
380    HiLog.i(TAG, 'getDataArray type: ' + type + ', length: ' + data.length);
381    return data;
382  }
383
384  public addMore(type: any) {
385    switch (type) {
386      case 'phone':
387        this.contactInfoAfter.phones.push(new PhoneNumBean('', '', '1', '', ''));
388        break;
389      case 'email':
390        this.contactInfoAfter.emails.push(new EmailBean('', '', '1'));
391        break;
392      case 'AIM':
393        this.contactInfoAfter.aims.push(new AIMBean('', '', '1', ''));
394        break;
395      case 'house':
396        this.contactInfoAfter.houses.push(new HouseBean('', '', '1', ''));
397        break;
398      case 'relationships':
399        this.contactInfoAfter.relationships.push(new AssociatedPersonBean('', '', '', '1'));
400        break;
401      case 'events':
402        this.contactInfoAfter.events.push(new EventBean('', '', '1', ''));
403        break;
404      default:
405        break;
406    }
407    this.refresh();
408  }
409
410  public deleteItem(typeName: string, startIndex) {
411    HiLog.i(TAG, `deleteItem ${typeName} ${startIndex}`);
412    switch (typeName) {
413      case 'phone':
414        if (this.contactInfoAfter.phones.length > 1) {
415          this.contactInfoAfter.phones.splice(startIndex, 1);
416        } else {
417          this.contactInfoAfter.phones[0].num = '';
418        }
419        this.getPhones = this.getArray(this.contactInfoAfter.phones);
420        break;
421      case 'email':
422        if (this.contactInfoAfter.emails.length > 1) {
423          this.contactInfoAfter.emails.splice(startIndex, 1);
424        } else {
425          this.contactInfoAfter.emails[0].address = '';
426        }
427        this.getEmails = this.getArray(this.contactInfoAfter.emails);
428        break;
429      case 'AIM':
430        if (this.contactInfoAfter.aims.length > 1) {
431          this.contactInfoAfter.aims.splice(startIndex, 1);
432        } else {
433          this.contactInfoAfter.aims[0].aimName = '';
434        }
435        break;
436      case 'house':
437        if (this.contactInfoAfter.houses.length > 1) {
438          this.contactInfoAfter.houses.splice(startIndex, 1);
439        } else {
440          this.contactInfoAfter.houses[0].houseName = '';
441        }
442        break;
443      case 'relationships':
444        if (this.contactInfoAfter.relationships.length > 1) {
445          this.contactInfoAfter.relationships.splice(startIndex, 1);
446        } else {
447          this.contactInfoAfter.relationships[0].name = '';
448        }
449        break;
450      case 'events':
451        if (this.contactInfoAfter.events.length > 1) {
452          this.contactInfoAfter.events.splice(startIndex, 1);
453        } else {
454          this.contactInfoAfter.events[0].data = '';
455        }
456        break;
457      default:
458        break;
459    }
460    this.refresh();
461  }
462
463  public getTextDisplay(typeName: string, data: any) {
464    let display: string = '';
465    if (data && data.item) {
466      switch (typeName) {
467        case 'phone':
468          if (data.item.hasOwnProperty('num')) {
469            display = data.item.num;
470          }
471          break;
472        case 'email':
473          if (data.item.hasOwnProperty('address')) {
474            display = data.item.address;
475          }
476          break;
477        case 'AIM':
478          if (data.item.hasOwnProperty('aimName')) {
479            display = data.item.aimName;
480          }
481          break;
482        case 'house':
483          if (data.item.hasOwnProperty('houseName')) {
484            display = data.item.houseName;
485          }
486          break;
487        case 'relationships':
488          if (data?.item.hasOwnProperty('name')) {
489            display = data.item.name;
490          }
491          break;
492        case 'events':
493          if (data.item.hasOwnProperty('data')) {
494            display = data.item.data;
495          }
496          break;
497        default:
498          break;
499      }
500    }
501    return display;
502  }
503
504  public listItemChange(typeName: string, data: any, arg: string) {
505    try {
506      switch (typeName) {
507        case 'phone':
508          if (StringUtil.isEmpty(this.contactInfoAfter?.phones[data?.i - 1]?.numType)) {
509            this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean('', '', '1', '', '');
510          }
511          this.contactInfoAfter.phones[data.i - 1].num = arg.toString();
512          break;
513        case 'email':
514          if (StringUtil.isEmpty(this.contactInfoAfter?.emails[data?.i - 1]?.emailType)) {
515            this.contactInfoAfter.emails[data.i - 1] = new EmailBean('', '', '1');
516          }
517          this.contactInfoAfter.emails[data.i - 1].address = arg.toString();
518          break;
519        case 'AIM':
520          if (StringUtil.isEmpty(this.contactInfoAfter?.aims[data?.i - 1]?.aimType)) {
521            this.contactInfoAfter.aims[data.i - 1] = new AIMBean('', '', '1', '');
522          }
523          this.contactInfoAfter.aims[data.i - 1].aimName = arg.toString();
524          break;
525        case 'house':
526          if (StringUtil.isEmpty(this.contactInfoAfter?.houses[data?.i - 1]?.houseType)) {
527            this.contactInfoAfter.houses[data.i - 1] = new HouseBean('', '', '1', '');
528          }
529          this.contactInfoAfter.houses[data.i - 1].houseName = arg.toString();
530          break;
531        case 'relationships':
532          if (StringUtil.isEmpty(this.contactInfoAfter?.relationships[data?.i - 1]?.associatedType)) {
533            this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean('', '', '', '1');
534          }
535          this.contactInfoAfter.relationships[data.i - 1].name = arg.toString();
536          break;
537        default:
538          break;
539      }
540      this.refreshAddState()
541    } catch (error) {
542      HiLog.e(TAG, 'something error happened: ' + JSON.stringify(error));
543    }
544  }
545
546  public menuSelect(typeName: string, data: any) {
547    let typeId = 1;
548    switch (typeName) {
549      case 'phone':
550        if (data.item.hasOwnProperty('numType')) {
551          typeId = Number(data.item.numType)
552        }
553        return Phone.getTypeLabelResource(typeId);
554        break;
555      case 'email':
556        if (data.item.hasOwnProperty('emailType')) {
557          typeId = Number(data.item.emailType)
558        }
559        return Email.getTypeLabelResource(typeId);
560        break;
561      case 'AIM':
562        if (data.item.hasOwnProperty('aimType')) {
563          typeId = Number(data.item.aimType)
564        }
565        return Aim.getTypeLabelResource(typeId);
566        break;
567      case 'house':
568        if (data.item.hasOwnProperty('houseType')) {
569          typeId = Number(data.item.houseType)
570        }
571        return House.getTypeLabelResource(typeId);
572        break;
573      case 'relationships':
574        if (data.item.hasOwnProperty('associatedType')) {
575          typeId = Number(data.item.associatedType)
576        }
577        return Relation.getTypeLabelResource(typeId);
578        break;
579      case 'events':
580        if (data.item.hasOwnProperty('eventType')) {
581          typeId = Number(data.item.eventType)
582        }
583        return Birthday.getTypeLabelResource(typeId);
584        break;
585      default:
586        return '';
587        break;
588    }
589  }
590
591  getMenuList(typeName: string) {
592    let accountTypeService = new AccountTypeService();
593    let menuKindTypeList;
594    let phoneType = accountTypeService.getAccountType(AccountType.PHONE_ACCOUNT_TYPE);
595    switch (typeName) {
596      case 'phone':
597        menuKindTypeList = phoneType.mineKinds.get(Phone.CONTENT_ITEM_TYPE).typeList;
598        break;
599      case 'email':
600        menuKindTypeList = phoneType.mineKinds.get(Email.CONTENT_ITEM_TYPE).typeList;
601        break;
602      case 'AIM':
603        menuKindTypeList = phoneType.mineKinds.get(Aim.CONTENT_ITEM_TYPE).typeList;
604        break;
605      case 'house':
606        menuKindTypeList = phoneType.mineKinds.get(House.CONTENT_ITEM_TYPE).typeList;
607        break;
608      case 'relationships':
609        menuKindTypeList = phoneType.mineKinds.get(Relation.CONTENT_ITEM_TYPE).typeList;
610        break;
611      case 'events':
612        menuKindTypeList = phoneType.mineKinds.get(Birthday.CONTENT_ITEM_TYPE).typeList;
613        break;
614      default:
615        break;
616    }
617    return menuKindTypeList;
618  }
619
620  public menuChange(typeName: string, data: any, item: any) {
621    switch (typeName) {
622      case 'phone':
623        if (ObjectUtil.isEmpty(this.contactInfoAfter.phones[data.i - 1])) {
624          this.contactInfoAfter.phones[data.i - 1] = new PhoneNumBean('', '', '', '', '');
625        }
626        this.contactInfoAfter.phones[data.i - 1].numType = item.rawValue.toString();
627        data.numType = item.rawValue.toString();
628        break;
629      case 'email':
630        if (ObjectUtil.isEmpty(this.contactInfoAfter.emails[data.i - 1])) {
631          this.contactInfoAfter.emails[data.i - 1] = new EmailBean('', '', '');
632        }
633        this.contactInfoAfter.emails[data.i - 1].emailType = item.rawValue.toString();
634        data.emailType = item.rawValue.toString();
635        break;
636      case 'AIM':
637        if (ObjectUtil.isEmpty(this.contactInfoAfter.aims[data.i - 1])) {
638          this.contactInfoAfter.aims[data.i - 1] = new AIMBean('', '', '', '');
639        }
640        this.contactInfoAfter.aims[data.i - 1].aimType = item.rawValue.toString();
641        break;
642      case 'house':
643        if (ObjectUtil.isEmpty(this.contactInfoAfter.houses[data.i - 1])) {
644          this.contactInfoAfter.houses[data.i - 1] = new HouseBean('', '', '', '');
645        }
646        this.contactInfoAfter.houses[data.i - 1].houseType = item.rawValue.toString();
647        break;
648      case 'relationships':
649        if (ObjectUtil.isEmpty(this.contactInfoAfter.relationships[data.i - 1])) {
650          this.contactInfoAfter.relationships[data.i - 1] = new AssociatedPersonBean('', '', '', '');
651        }
652        this.contactInfoAfter.relationships[data.i - 1].associatedType = item.rawValue.toString();
653        break;
654      case 'events':
655        if (ObjectUtil.isEmpty(this.contactInfoAfter.events[data.i - 1])) {
656          this.contactInfoAfter.events[data.i - 1] = new EventBean('', '', '', '');
657        }
658        this.contactInfoAfter.events[data.i - 1].eventType = item.rawValue.toString();
659        break;
660      default:
661        break;
662    }
663    this.addState = true;
664    this.refresh();
665  }
666
667  saveClickEnable() {
668    HiLog.i(TAG, 'msl, saveClickEnable in addState:' + this.addState + ',clickEnable:' + this.clickEnable)
669    return this.addState && this.clickEnable;
670  }
671
672  public saveContact() {
673    if (this.saveClickEnable()) {
674      this.clickEnable = false
675      if (this.updateShow === false) {
676        globalThis.DataWorker.sendRequest('addContact',
677          {
678            context: globalThis.context,
679            contactInfoAfter: JSON.stringify(this.contactInfoAfter)
680          }
681          , (arg) => {
682            this.clickEnable = true
683            this.contactId = arg.toString();
684            this.routerAvtiveFlag = true;
685            if (!PreferencesUtil.isUsed()) {
686              PreferencesUtil.setIsUsed(true);
687            }
688          })
689      } else {
690        if (this.nullContactInfo == this.getExistenceInfoString(this.contactInfoAfter)) {
691          globalThis.DataWorker.sendRequest('deleteContactById', {
692            context: globalThis.context,
693            contactId: this.contactId
694          }, (result: number | undefined) => {
695            if (result == 0 || result == undefined) {
696              HiLog.w(TAG, 'doDeleteContact succ');
697            } else {
698              HiLog.w(TAG, `doDeleteContact Failed ${JSON.stringify(result)}`);
699              Prompt.showToast({
700                message: 'contactDetail Failed to delete data.'
701              });
702            }
703            this.clickEnable = true
704            if (!PreferencesUtil.isUsed()) {
705              PreferencesUtil.setIsUsed(true);
706            }
707          });
708          router.back();
709        } else {
710          globalThis.DataWorker.sendRequest('updateContact', {
711            context: globalThis.context,
712            contactInfoAfter: JSON.stringify(this.contactInfoAfter)
713          }, (arg) => {
714            this.clickEnable = true
715            this.contactId = arg.toString();
716            this.routerAvtiveFlag = true;
717            if (!PreferencesUtil.isUsed()) {
718              PreferencesUtil.setIsUsed(true);
719            }
720          })
721        }
722      }
723    }
724  }
725
726  public textChange(data: string) {
727    this.refresh();
728  }
729
730  /**
731   * Hide the Keyboard to prevent occlusion dialogs.
732   */
733  hideKeyboard() {
734    inputMethod.getController().hideSoftKeyboard((err) => {
735    })
736  }
737}