18779efd5Sopenharmony_ci/** 28779efd5Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 38779efd5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48779efd5Sopenharmony_ci * you may not use this file except in compliance with the License. 58779efd5Sopenharmony_ci * You may obtain a copy of the License at 68779efd5Sopenharmony_ci * 78779efd5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88779efd5Sopenharmony_ci * 98779efd5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108779efd5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118779efd5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128779efd5Sopenharmony_ci * See the License for the specific language governing permissions and 138779efd5Sopenharmony_ci * limitations under the License. 148779efd5Sopenharmony_ci */ 158779efd5Sopenharmony_ci 168779efd5Sopenharmony_ciimport { HiLog, sharedPreferencesUtils } from '../../../../../../common'; 178779efd5Sopenharmony_ci 188779efd5Sopenharmony_ciconst TAG = 'SelectMultiNumDialog'; 198779efd5Sopenharmony_ci 208779efd5Sopenharmony_ci@CustomDialog 218779efd5Sopenharmony_ciexport struct SelectMultiNumDialog { 228779efd5Sopenharmony_ci @Link builder: SelectNumDialogBuilder; 238779efd5Sopenharmony_ci private controller: CustomDialogController; 248779efd5Sopenharmony_ci private selectDefault: Boolean = false; 258779efd5Sopenharmony_ci 268779efd5Sopenharmony_ci aboutToAppear() { 278779efd5Sopenharmony_ci HiLog.i(TAG, JSON.stringify(this.builder)); 288779efd5Sopenharmony_ci sharedPreferencesUtils.init(globalThis.getContext()) 298779efd5Sopenharmony_ci } 308779efd5Sopenharmony_ci 318779efd5Sopenharmony_ci build() { 328779efd5Sopenharmony_ci Column() { 338779efd5Sopenharmony_ci Text(this.builder.title) 348779efd5Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) 358779efd5Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_primary')) 368779efd5Sopenharmony_ci .fontWeight(FontWeight.Bold) 378779efd5Sopenharmony_ci .alignSelf(ItemAlign.Center) 388779efd5Sopenharmony_ci .width('100%') 398779efd5Sopenharmony_ci .height('48vp') 408779efd5Sopenharmony_ci .padding({ left: '16vp', }) 418779efd5Sopenharmony_ci List() { 428779efd5Sopenharmony_ci ForEach(this.builder.multiNumCardItems, (item, index) => { 438779efd5Sopenharmony_ci ListItem() { 448779efd5Sopenharmony_ci Row() { 458779efd5Sopenharmony_ci Image(item.img) 468779efd5Sopenharmony_ci .height('30vp') 478779efd5Sopenharmony_ci .width('30vp') 488779efd5Sopenharmony_ci .margin({ right: '8vp' }) 498779efd5Sopenharmony_ci .onError((event => { 508779efd5Sopenharmony_ci HiLog.e(TAG, 'Num:' + index + ' Image onError' + JSON.stringify(event)) 518779efd5Sopenharmony_ci })) 528779efd5Sopenharmony_ci Column() { 538779efd5Sopenharmony_ci Text(item.number) 548779efd5Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_body1')) 558779efd5Sopenharmony_ci .fontColor($r('sys.color.ohos_id_color_text_primary')) 568779efd5Sopenharmony_ci .fontWeight(FontWeight.Lighter) 578779efd5Sopenharmony_ci Text(item.numType) 588779efd5Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_body2')) 598779efd5Sopenharmony_ci .fontColor($r('sys.color.ohos_dialog_text_alert_transparent')) 608779efd5Sopenharmony_ci .fontWeight(FontWeight.Lighter) 618779efd5Sopenharmony_ci .margin({ top: '4vp' }) 628779efd5Sopenharmony_ci }.alignItems(HorizontalAlign.Start) 638779efd5Sopenharmony_ci }.width('100%') 648779efd5Sopenharmony_ci .height('56vp') 658779efd5Sopenharmony_ci .justifyContent(FlexAlign.Start) 668779efd5Sopenharmony_ci .padding({ left: '16vp', }) 678779efd5Sopenharmony_ci }.onClick(() => { 688779efd5Sopenharmony_ci this.confirm(item, this.builder.contactId); 698779efd5Sopenharmony_ci }) 708779efd5Sopenharmony_ci }) 718779efd5Sopenharmony_ci }.divider({ 728779efd5Sopenharmony_ci strokeWidth: 0.8, 738779efd5Sopenharmony_ci startMargin: 56, 748779efd5Sopenharmony_ci endMargin: $r('app.float.id_card_margin_max'), 758779efd5Sopenharmony_ci }) 768779efd5Sopenharmony_ci 778779efd5Sopenharmony_ci Row() { 788779efd5Sopenharmony_ci Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) 798779efd5Sopenharmony_ci .select(false) 808779efd5Sopenharmony_ci .selectedColor(0x39a2db) 818779efd5Sopenharmony_ci .onChange((value: boolean) => { 828779efd5Sopenharmony_ci this.selectDefault = value 838779efd5Sopenharmony_ci console.info(' msz Checkbox2 change is' + value) 848779efd5Sopenharmony_ci }) 858779efd5Sopenharmony_ci Column() { 868779efd5Sopenharmony_ci Text($r('app.string.set_default_values')) 878779efd5Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_body1')) 888779efd5Sopenharmony_ci .fontColor($r('sys.color.ohos_dialog_text_alert_transparent')) 898779efd5Sopenharmony_ci .fontWeight(FontWeight.Lighter) 908779efd5Sopenharmony_ci }.alignItems(HorizontalAlign.Start) 918779efd5Sopenharmony_ci }.width('100%') 928779efd5Sopenharmony_ci .height('56vp') 938779efd5Sopenharmony_ci .justifyContent(FlexAlign.Start) 948779efd5Sopenharmony_ci .padding({ left: '16vp', }) 958779efd5Sopenharmony_ci 968779efd5Sopenharmony_ci Text($r('app.string.cancel')) 978779efd5Sopenharmony_ci .alignSelf(ItemAlign.Center) 988779efd5Sopenharmony_ci .textAlign(TextAlign.Center) 998779efd5Sopenharmony_ci .fontWeight(FontWeight.Medium) 1008779efd5Sopenharmony_ci .fontColor(0x39a2db) 1018779efd5Sopenharmony_ci .fontSize($r('sys.float.ohos_id_text_size_body1')) 1028779efd5Sopenharmony_ci .width('100%') 1038779efd5Sopenharmony_ci .height('48vp') 1048779efd5Sopenharmony_ci .onClick(() => { 1058779efd5Sopenharmony_ci this.cancel() 1068779efd5Sopenharmony_ci }); 1078779efd5Sopenharmony_ci }.backgroundColor(Color.White) 1088779efd5Sopenharmony_ci } 1098779efd5Sopenharmony_ci 1108779efd5Sopenharmony_ci confirm(item, contactId) { 1118779efd5Sopenharmony_ci this.controller.close() 1128779efd5Sopenharmony_ci if (this.selectDefault) { 1138779efd5Sopenharmony_ci sharedPreferencesUtils.saveToPreferences(contactId + '', item.number); 1148779efd5Sopenharmony_ci } 1158779efd5Sopenharmony_ci if (this.builder.callback) { 1168779efd5Sopenharmony_ci this.builder.callback(item); 1178779efd5Sopenharmony_ci } 1188779efd5Sopenharmony_ci } 1198779efd5Sopenharmony_ci 1208779efd5Sopenharmony_ci cancel() { 1218779efd5Sopenharmony_ci this.controller.close() 1228779efd5Sopenharmony_ci } 1238779efd5Sopenharmony_ci} 1248779efd5Sopenharmony_ci 1258779efd5Sopenharmony_ciclass MultiNumCardItems { 1268779efd5Sopenharmony_ci number: String; 1278779efd5Sopenharmony_ci numType: Resource; 1288779efd5Sopenharmony_ci img: Resource; 1298779efd5Sopenharmony_ci} 1308779efd5Sopenharmony_ci 1318779efd5Sopenharmony_ciinterface Controller { 1328779efd5Sopenharmony_ci close(); 1338779efd5Sopenharmony_ci 1348779efd5Sopenharmony_ci open(); 1358779efd5Sopenharmony_ci} 1368779efd5Sopenharmony_ci 1378779efd5Sopenharmony_ciexport class SelectNumDialogBuilder { 1388779efd5Sopenharmony_ci title: string | Resource; 1398779efd5Sopenharmony_ci contactId: String 1408779efd5Sopenharmony_ci multiNumCardItems: Array<MultiNumCardItems>; 1418779efd5Sopenharmony_ci callback?: (item: MultiNumCardItems) => void; 1428779efd5Sopenharmony_ci controller?: Controller; 1438779efd5Sopenharmony_ci} 144