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 { StringUtil } from '../../../../../../../common/src/main/ets/util/StringUtil'; 17 18/** 19 * Select the contact item component, which is responsible for displaying a single contact. 20 */ 21@Component 22export default struct BatchSelectRecentItemView { 23 private onRecentItemClicked: Function; 24 @State private item: { [key: string]: any } = {}; 25 private index: number; 26 27 build() { 28 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { 29 Row() { 30 if (StringUtil.isEmpty(this.item.suffix)) { 31 Image($r('app.media.ic_user_portrait')) 32 .width($r('app.float.id_card_image_mid')) 33 .height($r('app.float.id_card_image_mid')) 34 .backgroundColor(this.item.portraitColor) 35 .borderRadius($r('app.float.id_card_image_mid')) 36 .objectFit(ImageFit.Contain) 37 } else { 38 Text(this.item.suffix.toUpperCase()) 39 .fontSize(20) 40 .fontWeight(FontWeight.Bold) 41 .fontColor(Color.White) 42 .backgroundColor(this.item.portraitColor) 43 .height($r('app.float.id_card_image_mid')) 44 .width($r('app.float.id_card_image_mid')) 45 .textAlign(TextAlign.Center) 46 .borderRadius($r('app.float.id_card_image_mid')) 47 } 48 } 49 .width($r('app.float.id_card_image_mid')) 50 .height($r('app.float.id_card_image_mid')) 51 .margin({ left: $r('app.float.id_card_margin_max') }) 52 53 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Center }) { 54 Text(StringUtil.isEmpty(this.item.displayName) ? this.item.phoneNumber : this.item.displayName) 55 .fontColor($r('sys.color.ohos_id_color_text_primary')) 56 .fontSize($r('sys.float.ohos_id_text_size_body1')) 57 .fontWeight(FontWeight.Medium) 58 .margin({ left: $r('app.float.id_card_margin_xl'), bottom: $r('app.float.id_card_margin_sm') }) 59 60 Row() { 61 Text(this.item.formattedNumber) 62 .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 63 .fontSize($r('sys.float.ohos_id_text_size_body2')) 64 .fontWeight(FontWeight.Regular) 65 .visibility(StringUtil.isEmpty(this.item.formattedNumber) ? Visibility.None : Visibility.Visible) 66 .margin({ left: $r('app.float.id_card_margin_xl') }) 67 68 Text(this.item.numberLocation) 69 .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 70 .fontSize($r('sys.float.ohos_id_text_size_body2')) 71 .fontWeight(FontWeight.Regular) 72 .visibility(StringUtil.isEmpty(this.item.numberLocation) ? Visibility.None : Visibility.Visible) 73 .margin({ left: $r('app.float.id_card_margin_xl') }) 74 75 if (StringUtil.isEmpty(this.item.displayName) && StringUtil.isEmpty(this.item.numberLocation)) { 76 Text($r('app.string.unknow_location')) 77 .fontColor($r('sys.color.ohos_id_color_text_tertiary')) 78 .fontSize($r('sys.float.ohos_id_text_size_body2')) 79 .fontWeight(FontWeight.Regular) 80 .margin({ left: $r('app.float.id_card_margin_xl') }) 81 } 82 } 83 } 84 .flexGrow(1) 85 .height($r('app.float.id_item_height_max')) 86 87 Toggle({ type: ToggleType.Checkbox, isOn: this.item.checked }) 88 .width($r('app.float.id_card_image_small')) 89 .height($r('app.float.id_card_image_small')) 90 .enabled(false) 91 .margin({ left: $r('app.float.id_card_margin_max'), right: $r('app.float.id_card_margin_max') }) 92 .selectedColor($r('sys.color.ohos_id_color_connected')) 93 94 } 95 .height($r('app.float.id_item_height_max')) 96 .width('100%') 97 .onClick(() => { 98 this.onRecentItemClicked(this.index); 99 }) 100 } 101}