ThirdView.ets 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { IBestToast, Pet, RDBMapper, RelationalStoreUtils, Test, YTCalendarPicker } from "basic";
  2. import dayjs from "dayjs";
  3. import { ClockTaskApi, InsertClockParam } from "../api/ClockTaskApi";
  4. import { GetRemindParams, RemindApi, RemindItem, RemindItemClass } from "../api/RemindApi";
  5. import { ButtonCom } from "../components/maincomponent/ButtonCom";
  6. import { NullBuilder } from "../components/NullCom";
  7. @Component
  8. export struct ThirdView {
  9. @State remindList:RemindItem[]=[]
  10. @State dataList:string[]=[]
  11. @StorageProp('OAIDD')
  12. odid:string=""
  13. async getRemindList(params:GetRemindParams){
  14. const arr=await RemindApi.getRemindList(params)
  15. this.remindList=arr.records as RemindItem[]
  16. }
  17. async getRed(yearMonth:string){
  18. this.dataList=await RemindApi.getRed(yearMonth,this.odid)
  19. }
  20. aboutToAppear(): void {
  21. const date=dayjs(new Date()).format('YYYY-MM-DD')
  22. this.getRemindList({page:1,pageSizes:20,remindDate:date})
  23. const yearMonth=dayjs(new Date()).format('YYYY-MM')
  24. this.getRed(yearMonth)
  25. }
  26. async insertClockLog(vm:InsertClockParam){
  27. if(vm.plantsId==0||vm.itemId==0||vm.clockDate==""||vm.clockTime==""){
  28. IBestToast.show({
  29. message:"请检查打卡项或打卡植物日期"
  30. })
  31. return
  32. }
  33. if(dayjs(vm.clockDate+" "+vm.clockTime).valueOf()>dayjs(new Date()).valueOf()){
  34. IBestToast.show({
  35. message:"打卡不得超过当前时间"
  36. })
  37. return
  38. }
  39. const params:InsertClockParam={
  40. plantsId:vm.plantsId,
  41. itemId:vm.itemId,
  42. clockDate:vm.clockDate+" 00:00:00",
  43. clockTime:vm.clockDate+" "+vm.clockTime+":00"
  44. }
  45. await ClockTaskApi.insertClockLog(params).then((res)=>{
  46. if(res==true){
  47. IBestToast.show({
  48. message:'打卡成功'
  49. })
  50. }
  51. })
  52. }
  53. build() {
  54. Column({space:20}){
  55. YTCalendarPicker({
  56. onClickItem:(date: Date)=>{
  57. const stringDate=dayjs(date).format('YYYY-MM-DD')
  58. this.getRemindList({page:1,pageSizes:20,remindDate:stringDate})
  59. },
  60. updateRed:(year:string,month:string)=>{
  61. if(month.length==1){
  62. month="0"+month
  63. }
  64. const date=year+"-"+month
  65. this.getRed(date)
  66. },
  67. dateList:this.dataList
  68. })
  69. if(this.remindList.length==0){
  70. NullBuilder()
  71. }else {
  72. List({ space: 16 }) {
  73. ForEach(this.remindList, (item: RemindItem, index: number) => {
  74. ListItem() {
  75. Row() {
  76. Column() {
  77. Image(item.plantsPicture).width(55).height(79)
  78. }
  79. .width(70)
  80. .height(90)
  81. .justifyContent(FlexAlign.Center)
  82. .alignItems(HorizontalAlign.Center)
  83. .borderRadius(20)
  84. .backgroundColor('#E8EBF0')
  85. .margin({ right: 9 })
  86. Column({ space: 11 }) {
  87. Text(item.plantsName).fontColor('#333333')
  88. Row({ space: 5 }) {
  89. Image(item.itemIcon).width(15).height(15)
  90. Text(item.itemName).fontColor('#333333').fontSize(12)
  91. }
  92. Row({ space: 5 }) {
  93. Image($r("app.media.main_icon_remindDesc")).width(15).height(15)
  94. Text(item.remindTime.slice(0, 5)).fontColor('#333333').fontSize(12)
  95. }
  96. }.justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)
  97. Blank()
  98. ButtonCom({
  99. text: "养护打卡",
  100. isShowBuilder: () => {
  101. // this.isShowMaintenanceBuilder=true
  102. //直接打卡
  103. this.insertClockLog({
  104. itemId: item.itemId,
  105. plantsId: item.plantsId,
  106. clockDate: dayjs(new Date()).format('YYYY-MM-DD'),
  107. clockTime: dayjs(new Date()).format('HH:mm')
  108. })
  109. }
  110. })
  111. }
  112. .width('100%')
  113. .height(115)
  114. .backgroundColor('#fff')
  115. .justifyContent(FlexAlign.Center)
  116. .alignItems(VerticalAlign.Center)
  117. .borderRadius(12)
  118. .padding({
  119. left: 17,
  120. top: 17,
  121. right: 20,
  122. bottom: 17
  123. })
  124. }
  125. })
  126. }.width('100%')
  127. }
  128. }.height('100%')
  129. .padding({top:44,left:16,right:16})
  130. .justifyContent(FlexAlign.Start)
  131. .backgroundColor('#EAF3F2')
  132. }
  133. }