From 421c919ba0c6ee4e638059f44aca52174eae1db2 Mon Sep 17 00:00:00 2001
From: fang_S <221250199@smail.nju.edu.cn>
Date: Fri, 17 Jan 2025 23:40:05 +0800
Subject: [PATCH] dateselect

---
 entry/src/main/ets/view/AddItem.ets | 169 +++++++++-------------------
 1 file changed, 56 insertions(+), 113 deletions(-)

diff --git a/entry/src/main/ets/view/AddItem.ets b/entry/src/main/ets/view/AddItem.ets
index 4fbda9c..473ea2e 100644
--- a/entry/src/main/ets/view/AddItem.ets
+++ b/entry/src/main/ets/view/AddItem.ets
@@ -12,10 +12,11 @@ interface SysTimeResponse {
 @Component
 export default struct AddItem {
   @Consume('localPageStack') LocalPageStack: NavPathStack
-
+  private selectedTime: Date = new Date('2022-07-22T08:00:00')
+  selectedDate: Date = new Date("2010-1-1")
   @State itemName: string = ''
   @State itemDisc: string = ''
-
+  @State isMilitaryTime: boolean = false
   build() {
     NavDestination() {
       Column() {
@@ -75,90 +76,11 @@ export default struct AddItem {
           })
       }
     }
+
   }
 
   @Builder
   MainPage() {
-/*    Column() {
-      Row() {
-        Text('鏍囬')
-          .fontSize(CommonConstants.detail_title_font_size)
-          .fontWeight(FontWeight.Bold)
-          .width(CommonConstants.add_name_width)
-          .margin({
-            left: CommonConstants.detail_margin_Left
-          })
-
-        TextInput({ placeholder: '璇疯緭鍏ヤ簨椤瑰悕瀛�'})
-          .width(CommonConstants.input_container_width)
-          .margin({ left: CommonConstants.input_margin_left })
-          .backgroundColor($r('app.color.grey'))
-          .caretColor(Color.Blue) //鍏夋爣
-          .placeholderColor(Color.Grey)
-          .placeholderFont({size: CommonConstants.detail_font_size})
-          .fontSize(CommonConstants.detail_font_size)
-          .onChange((value: string) => {
-            this.itemName = value;
-          })
-      }
-    }
-    .margin({
-      top: CommonConstants.list_margin_top
-    })
-    .width(CommonConstants.list_width)
-    .height(CommonConstants.name_height)
-    .backgroundColor($r('app.color.white'))
-    .borderRadius(CommonConstants.border_radius)
-    .justifyContent(FlexAlign.Center)
-    .alignItems(HorizontalAlign.Start)
-
-    Column() {
-      Row() {
-        Text('璇︽儏')
-          .fontSize(CommonConstants.detail_title_font_size)
-          .fontWeight(FontWeight.Bold)
-          .width(CommonConstants.add_name_width)
-          .margin({
-            left: CommonConstants.detail_margin_Left
-          })
-
-*//*        TextArea({ placeholder: '璇疯緭鍏ヤ簨椤规弿杩�'})
-          .width(CommonConstants.input_container_width)
-          .height(CommonConstants.input_disc_height)
-          .margin({ left: CommonConstants.input_margin_left })
-          .backgroundColor($r('app.color.grey'))
-          .caretColor(Color.Blue) //鍏夋爣
-          .placeholderColor(Color.Grey)
-          .placeholderFont({size: CommonConstants.detail_font_size})
-          .fontSize(CommonConstants.detail_font_size)
-          .onChange((value: string) => {
-            this.itemDisc = value;
-          })*//*
-      }
-      Row(){
-        TextArea({ placeholder: '璇疯緭鍏ヤ簨椤规弿杩�'})
-          .width('80%')
-          .height(CommonConstants.input_disc_height)
-          .margin({ left: CommonConstants.input_margin_left })
-          .backgroundColor($r('app.color.grey'))
-          .caretColor(Color.Blue) //鍏夋爣
-          .placeholderColor(Color.Grey)
-          .placeholderFont({size: CommonConstants.detail_font_size})
-          .fontSize(CommonConstants.detail_font_size)
-          .onChange((value: string) => {
-            this.itemDisc = value;
-          })
-      }
-    }
-    .margin({
-      top: CommonConstants.list_margin_top
-    })
-    .width(CommonConstants.list_width)
-    .height(CommonConstants.disc_height)
-    .backgroundColor($r('app.color.white'))
-    .borderRadius(CommonConstants.border_radius)
-    .justifyContent(FlexAlign.Center)
-    .alignItems(HorizontalAlign.Start)*/
     Column() {
       // 鏍囬鍜岃緭鍏ユ琛�
       Row() {
@@ -187,6 +109,7 @@ export default struct AddItem {
       .justifyContent(FlexAlign.Center)
       .alignItems(VerticalAlign.Top)
 
+
       // 璇︽儏杈撳叆妗�
       Row() {
         Text('璇︽儏')
@@ -195,8 +118,16 @@ export default struct AddItem {
           .width('15%')
           .margin({ left: 40 })
 
-/*        TextArea({ placeholder: '璇疯緭鍏ヤ簨椤规弿杩�' })
-          .width('70%')
+      }
+      .margin({ top: CommonConstants.list_margin_top })
+      .width(CommonConstants.list_width)
+      .height('10vp')
+      .borderRadius(CommonConstants.border_radius)
+      .justifyContent(FlexAlign.Start)
+
+      Row() {
+        TextArea({ placeholder: '璇疯緭鍏ヤ簨椤规弿杩�' })
+          .width('90%')
           .height(CommonConstants.input_disc_height)
           .margin({ left: CommonConstants.input_margin_left })
           .backgroundColor('#EDEDED') // 璁剧疆鑳屾櫙閫忔槑
@@ -206,39 +137,51 @@ export default struct AddItem {
           .fontSize(CommonConstants.detail_font_size)
           .onChange((value: string) => {
             this.itemDisc = value;
-          })*/
+          })
       }
       .margin({ top: CommonConstants.list_margin_top })
       .width(CommonConstants.list_width)
-      .height('10vp')
+      .height('400vp')
+      .borderRadius(CommonConstants.border_radius)
+      .justifyContent(FlexAlign.Center)
+      .alignItems(VerticalAlign.Top)
+
+
+      Row() {
+        Button("閫夋嫨鎴鏃ユ湡")
+          .margin({ left: 40 })
+          .onClick(() => {
+            DatePickerDialog.show({
+              start: new Date("2025-1-18"),
+              end: new Date("2030-12-31"),
+              selected: this.selectedDate,
+              onAccept: (value: DatePickerResult) => {
+                // 閫氳繃Date鐨剆etFullYear鏂规硶璁剧疆鎸変笅纭畾鎸夐挳鏃剁殑鏃ユ湡锛岃繖鏍峰綋寮圭獥鍐嶆寮瑰嚭鏃舵樉绀洪€変腑鐨勬槸涓婁竴娆$‘瀹氱殑鏃ユ湡
+                this.selectedDate.setFullYear(value.year, value.month, value.day)
+                console.info("DatePickerDialog:onAccept()" + JSON.stringify(value))
+              },
+              onCancel: () => {
+                console.info("DatePickerDialog:onCancel()")
+              },
+              onChange: (value: DatePickerResult) => {
+                console.info("DatePickerDialog:onChange()" + JSON.stringify(value))
+              }
+            })
+          })
+          .height('50pv')
+          .width('50%')
+
+      }
+      .margin({ top: CommonConstants.list_margin_top })
+      .width(CommonConstants.list_width)
+      .height('80vp')
       .borderRadius(CommonConstants.border_radius)
       .justifyContent(FlexAlign.Start)
-/*      .justifyContent(FlexAlign.Center)
-      .alignItems(VerticalAlign.Top )*/
-    }
-    Row() {
-      TextArea({ placeholder: '璇疯緭鍏ヤ簨椤规弿杩�' })
-        .width('90%')
-        .height(CommonConstants.input_disc_height)
-        .margin({ left: CommonConstants.input_margin_left })
-        .backgroundColor('#EDEDED') // 璁剧疆鑳屾櫙閫忔槑
-        .caretColor(Color.Blue) // 鍏夋爣棰滆壊
-        .placeholderColor(Color.Grey)
-        .placeholderFont({ size: CommonConstants.detail_font_size })
-        .fontSize(CommonConstants.detail_font_size)
-        .onChange((value: string) => {
-          this.itemDisc = value;
-        })
+
     }
-    .margin({ top: CommonConstants.list_margin_top })
-    .width(CommonConstants.list_width)
-    .height('400vp')
-    .borderRadius(CommonConstants.border_radius)
-    .justifyContent(FlexAlign.Center)
-    .alignItems(VerticalAlign.Top)
   }
 
-  private async requestTime(): Promise<string> { //Todo:杩欎釜鏄姹傚綋鍓嶆椂闂达紝娌℃湁鎰忎箟锛岄渶瑕佹坊鍔犱竴涓緭鍏dl鐨勬棩鏈熺粍浠�
+/*  private async requestTime(): Promise<string> { //Todo:杩欎釜鏄姹傚綋鍓嶆椂闂达紝娌℃湁鎰忎箟锛岄渶瑕佹坊鍔犱竴涓緭鍏dl鐨勬棩鏈熺粍浠�
     let httpRequest = http.createHttp()
     let res = ''
     try {
@@ -259,14 +202,14 @@ export default struct AddItem {
       httpRequest.destroy()
     }
     return res
-  }
+  }*/
 
   private async addItem() {
-    let time = ''
+/*    let time = ''
     while(time == '') {
       time = await this.requestTime()
-    }
-    const res = await webAPI.addSingleItem(this.itemName, time, this.itemDisc)
+    }*/
+    const res = await webAPI.addSingleItem(this.itemName, this.selectedDate.toLocaleDateString('en-CA'), this.itemDisc)
     if(res == 'error') {
       promptAction.showToast({
         message: '娣诲姞澶辫触锛�'
-- 
GitLab