• 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 } from '../../../../../../../common/src/main/ets/util/StringUtil';
17import { EventBean } from "../../../model/bean/EventBean";
18import AccountantsPresenter from '../../../presenter/contact/accountants/AccountantsPresenter';
19import StringFormatUtil from "../../../util/StringFormatUtil"
20import { Birthday } from '../../../../../../../feature/contact/src/main/ets/contract/Birthday';
21
22@CustomDialog
23export struct ShowDayTime {
24  private date = new Date(2000, 0, 1);
25  @Link mPresent: AccountantsPresenter;
26  @Prop itemIndex: number;
27  @Prop itemType: number;
28  @State showTime: Resource = $r("app.string.yearMonthDay", this.date.getFullYear(),
29    (this.date.getMonth() + 1), this.date.getDate());
30  controller: CustomDialogController
31  cancel: () => void
32  confirm: () => void
33
34  build() {
35    Column() {
36      Row() {
37        Text(this.showTime)
38          .height("56vp")
39          .fontSize(20)
40          .textAlign(TextAlign.Center)
41          .fontWeight(FontWeight.Medium)
42          .fontColor($r("sys.color.ohos_id_color_text_primary"))
43      }
44      .width("85%")
45
46      DatePicker({ selected: this.date })
47        .width("85%")
48        .height("200vp")
49        .margin({ bottom: 8 })
50        .lunar(this.itemType == Birthday.TYPE_LUNARBIRTHDAY)
51        .onChange((value: DatePickerResult) => {
52          this.date = new Date(value.year, value.month, value.day);
53          this.showTime = $r("app.string.yearMonthDay", value.year, (value.month + 1), value.day);
54        })
55
56      Row() {
57        Flex({
58          direction: FlexDirection.Column,
59          justifyContent: FlexAlign.Center,
60          alignItems: ItemAlign.Center
61        }) {
62          Text($r("app.string.dialog_cancel"))
63            .fontColor('#007DFF')
64            .fontSize(16)
65            .fontWeight(FontWeight.Medium)
66        }
67        .layoutWeight(1)
68        .height(40)
69        .onClick(() => {
70          this.controller.close()
71          this.cancel()
72        })
73
74        Line().width(1).height(40).backgroundColor($r("sys.color.ohos_id_color_list_separator")).margin({
75          left: 4,
76          right: 4
77        })
78
79        Flex({
80          direction: FlexDirection.Column,
81          justifyContent: FlexAlign.Center,
82          alignItems: ItemAlign.Center
83        }) {
84          Text($r("app.string.save"))
85            .fontColor('#007DFF')
86            .fontSize(16)
87            .fontWeight(FontWeight.Medium)
88        }
89        .layoutWeight(1)
90        .height(40)
91        .onClick(() => {
92          this.mPresent.addState = true;
93          this.date.setFullYear(this.date.getFullYear(), this.date.getMonth(), this.date.getDate());
94          if (StringUtil.isEmpty(this.mPresent.contactInfoAfter.events[this.itemIndex].eventType)) {
95            this.mPresent.contactInfoAfter.events[this.itemIndex] = new EventBean("", "", "1", "");
96          }
97          this.mPresent.contactInfoAfter.events[this.itemIndex].data = StringFormatUtil.numberFormatDateString(this.date.getFullYear(), this.date.getMonth() + 1, this.date.getDate());
98          this.mPresent.refresh();
99          this.controller.close();
100          this.confirm();
101        })
102      }
103      .alignItems(VerticalAlign.Top)
104      .height("56vp")
105      .width('85%')
106    }.height("320vp")
107  }
108}