• 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 { StringUtil, HiLog } from '../../../../../../../common';
17import AccountantsPresenter from '../../../presenter/contact/accountants/AccountantsPresenter';
18import StringFormatUtil from '../../../util/StringFormatUtil';
19import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday';
20
21const TAG = 'ItemEvent'
22
23@Component
24export struct ItemEvent {
25  @Link mPresent: AccountantsPresenter;
26  @Link itemIndex: number;
27  @Link eventType: number;
28  private controller: { [key: string]: any };
29  private index: number;
30  private typeName: string;
31  @LocalStorageProp('breakpoint') curBp: string = 'sm';
32
33  build() {
34    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
35      Column() {
36        Row() {
37          Text(this.mPresent.menuSelect(
38            this.typeName,
39            this.mPresent.getData(this.typeName, this.index - 1)
40          ))
41            .fontSize($r('sys.float.ohos_id_text_size_body1'))
42            .fontWeight(FontWeight.Medium)
43            .fontColor($r('sys.color.ohos_id_color_text_primary'))
44            .textOverflow({ overflow: TextOverflow.None })
45            .maxLines(1)
46            .constraintSize({ minWidth: $r('app.float.account_ItemList_text_width') })
47            .bindMenu(this.MenuBuilder)
48
49          Image($r('app.media.ic_public_spinner'))
50            .objectFit(ImageFit.Contain)
51            .height($r('app.float.id_card_image_small'))
52            .width($r('app.float.id_card_image_xs'))
53        }
54        .height($r('app.float.id_item_height_sm'))
55        .constraintSize({ minWidth: $r('app.float.account_listItem_text_common_width') })
56      }
57      .flexShrink(0)
58
59      Column() {
60        Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) {
61          Column() {
62            Text(
63              StringUtil.isEmpty(
64                this.mPresent.getTextDisplay(this.typeName, this.mPresent.getData(this.typeName, this.index - 1)))
65                ? $r('app.string.date')
66                : StringFormatUtil.stringFormatDateResource(this.mPresent.getData(this.typeName, this.index - 1)
67                .item
68                .data,
69                this.mPresent.getData(this.typeName, this.index - 1)?.item?.eventType == Birthday.TYPE_LUNARBIRTHDAY)
70            )
71              .margin({ left: $r('app.float.id_card_margin_xxl') })
72              .height($r('app.float.id_item_height_large'))
73              .fontSize($r('sys.float.ohos_id_text_size_body1'))
74              .fontColor(
75                StringUtil.isEmpty(this.mPresent.getTextDisplay(
76                  this.typeName, this.mPresent.getData(this.typeName, this.index - 1)))
77                  ? $r('sys.color.ohos_id_color_text_secondary')
78                  : $r('sys.color.ohos_id_color_text_primary')
79              )
80          }
81          .alignItems(HorizontalAlign.Start)
82          .flexGrow(1)
83          .onClick(() => {
84            let data = this.mPresent.getData(this.typeName, this.index - 1)
85            if (data.item && data.item.hasOwnProperty('eventType')) {
86              this.eventType = Number(data.item.eventType)
87            }
88            this.itemIndex = this.index - 1;
89            this.controller.open()
90          })
91
92          Column() {
93            Image($r('app.media.ic_public_close_filled'))
94              .objectFit(ImageFit.Contain)
95              .height($r('app.float.id_card_image_small'))
96              .width($r('app.float.id_card_image_small'))
97              .fillColor($r('sys.color.ohos_id_color_tertiary'))
98              .onClick(() => {
99                try {
100                  this.mPresent.deleteItem(this.typeName, this.index - 1);
101                } catch (err) {
102                  HiLog.e('deleteItem', ' deleteItem error ' + JSON.stringify(err));
103                }
104              })
105          }
106        }
107
108        Divider()
109          .padding({ left: $r('app.float.id_card_margin_xxl') })
110          .height($r('app.float.account_Divider_height'))
111          .width('100%')
112          .color($r('sys.color.ohos_id_color_list_separator'))
113      }
114      .alignItems(HorizontalAlign.Start)
115      .height($r('app.float.id_item_height_large'))
116    }
117    .margin({
118      left: $r('app.float.id_card_margin_xxl'),
119      right: this.curBp === 'lg' ? $r('app.float.id_card_margin_max') : $r('app.float.id_card_margin_xl')
120    })
121  }
122
123  @Builder MenuBuilder() {
124    Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
125      ForEach(this.mPresent.getMenuList(this.typeName),
126        (item) => {
127          Text(item.labelRes)
128            .fontSize($r('sys.float.ohos_id_text_size_body1'))
129            .width('156vp')
130            .height($r('app.float.id_item_height_mid'))
131            .fontColor($r('sys.color.ohos_id_color_text_primary'))
132            .textAlign(TextAlign.Start)
133            .margin({ left: $r('app.float.id_card_margin_xxl') })
134            .onClick(() => {
135              this.mPresent.menuChange(this.typeName, this.mPresent.getData(this.typeName, this.index - 1), item);
136            })
137
138          Divider()
139            .height($r('app.float.account_Divider_height'))
140            .width($r('app.float.account_Divider_width'))
141            .color($r('sys.color.ohos_id_color_list_separator'))
142        },
143        (item) => item.rawValue.toString())
144    }
145    .width($r('app.float.account_MenuBuilder_width'))
146    .borderRadius($r('sys.float.ohos_id_corner_radius_default_l'))
147  }
148}