• 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(this.mPresent.getTextDisplay(this.typeName, this.mPresent.getData(this.typeName, this.index - 1)))
64                ? $r("app.string.date")
65                : StringFormatUtil.stringFormatDateResource(this.mPresent.getData(this.typeName, this.index - 1).item.data,
66                  this.mPresent.getData(this.typeName, this.index - 1)?.item?.eventType == Birthday.TYPE_LUNARBIRTHDAY)
67            )
68              .margin({ left: $r("app.float.id_card_margin_xxl") })
69              .height($r("app.float.id_item_height_large"))
70              .fontSize($r("sys.float.ohos_id_text_size_body1"))
71              .fontColor(
72                StringUtil.isEmpty(this.mPresent.getTextDisplay(this.typeName, this.mPresent.getData(this.typeName, this.index - 1)))
73                  ? $r("sys.color.ohos_id_color_text_secondary")
74                  : $r("sys.color.ohos_id_color_text_primary")
75              )
76          }
77          .alignItems(HorizontalAlign.Start)
78          .flexGrow(1)
79          .onClick(() => {
80            let data = this.mPresent.getData(this.typeName, this.index - 1)
81            if (data.item && data.item.hasOwnProperty("eventType")) {
82              this.eventType = Number(data.item.eventType)
83            }
84            this.itemIndex = this.index - 1;
85            this.controller.open()
86          })
87
88          Column() {
89            Image($r("app.media.ic_public_close_filled"))
90              .objectFit(ImageFit.Contain)
91              .height($r("app.float.id_card_image_small"))
92              .width($r("app.float.id_card_image_small"))
93              .fillColor($r("sys.color.ohos_id_color_tertiary"))
94              .onClick(() => {
95                try {
96                  this.mPresent.deleteItem(this.typeName, this.index - 1);
97                } catch (err) {
98                  HiLog.e("deleteItem", ' deleteItem error ' + JSON.stringify(err));
99                }
100              })
101          }
102        }
103
104        Divider()
105          .padding({ left: $r("app.float.id_card_margin_xxl") })
106          .height($r("app.float.account_Divider_height"))
107          .width("100%")
108          .color($r("sys.color.ohos_id_color_list_separator"))
109      }
110      .alignItems(HorizontalAlign.Start)
111      .height($r("app.float.id_item_height_large"))
112    }
113    .margin({
114      left: $r("app.float.id_card_margin_xxl"),
115      right: this.curBp === 'lg' ? $r("app.float.id_card_margin_max") : $r("app.float.id_card_margin_xl")
116    })
117  }
118
119  @Builder MenuBuilder() {
120    Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
121      ForEach(this.mPresent.getMenuList(this.typeName),
122        (item) => {
123          Text(item.labelRes)
124            .fontSize($r("sys.float.ohos_id_text_size_body1"))
125            .width("156vp")
126            .height($r("app.float.id_item_height_mid"))
127            .fontColor($r("sys.color.ohos_id_color_text_primary"))
128            .textAlign(TextAlign.Start)
129            .margin({ left: $r("app.float.id_card_margin_xxl") })
130            .onClick(() => {
131              this.mPresent.menuChange(this.typeName, this.mPresent.getData(this.typeName, this.index - 1), item);
132            })
133
134          Divider()
135            .height($r("app.float.account_Divider_height"))
136            .width($r("app.float.account_Divider_width"))
137            .color($r("sys.color.ohos_id_color_list_separator"))
138        },
139        (item) => item.rawValue.toString())
140    }
141    .width($r("app.float.account_MenuBuilder_width"))
142    .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
143  }
144}