|
|
@@ -0,0 +1,101 @@
|
|
|
+import { YTAvoid, yTRouter } from 'basic'
|
|
|
+import { _YtHeader } from '../components/_YtHeader'
|
|
|
+import { AppStorageV2 } from '@kit.ArkUI'
|
|
|
+import { BabyInfo, PurchaseList } from '../model/Index'
|
|
|
+import { BabyFoodApi } from '../Apis/BabyFoodApi'
|
|
|
+
|
|
|
+// 采购清单页面
|
|
|
+@ComponentV2
|
|
|
+struct PurchasingPage {
|
|
|
+ @Local safeTop: number = 0
|
|
|
+ @Local babyInfo: BabyInfo = AppStorageV2.connect<BabyInfo>(BabyInfo, () => new BabyInfo())!
|
|
|
+ // 本周的采购清单
|
|
|
+ @Local purchaseList?: PurchaseList[]
|
|
|
+
|
|
|
+
|
|
|
+ _onBackPress(){
|
|
|
+ yTRouter.pop('')
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取本周所有采购清单
|
|
|
+ async getWeeklyPurchaseList(): Promise<void>{
|
|
|
+ this.purchaseList = await BabyFoodApi.getWeeklyPurchaseList(this.babyInfo.id!)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改购买状态 - 清单 id
|
|
|
+ async updateBuyStatus(Id: number, index: number){
|
|
|
+ try {
|
|
|
+ let ans = await BabyFoodApi.updatePurchaseStatus(Id)
|
|
|
+ let l = this.purchaseList![index]
|
|
|
+ l.purchased = l.purchased == '1' ? '0' : '1'
|
|
|
+ this.purchaseList?.splice(index, 1, l)
|
|
|
+ } catch (e) {
|
|
|
+ console.log(`e = ${JSON.stringify(e)}`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ aboutToAppear(): void {
|
|
|
+ this.safeTop = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
|
|
|
+
|
|
|
+ this.getWeeklyPurchaseList()
|
|
|
+ }
|
|
|
+
|
|
|
+ build() {
|
|
|
+ NavDestination() {
|
|
|
+ Column() {
|
|
|
+ _YtHeader({
|
|
|
+ title: '采购清单',
|
|
|
+ _onBackPress: () => { this._onBackPress() },
|
|
|
+ })
|
|
|
+
|
|
|
+ Column(){
|
|
|
+ List({space: 12}){
|
|
|
+ ForEach(this.purchaseList, (item: number, index: number) =>{
|
|
|
+ ListItem(){
|
|
|
+ Row(){
|
|
|
+ Text(){
|
|
|
+ Span(this.purchaseList?.[index].ingredientName ?? '南瓜')
|
|
|
+ Span('-')
|
|
|
+ Span((this.purchaseList?.[index].amount ?? 1) + '')
|
|
|
+ Span(this.purchaseList?.[index].unit ?? 'g')
|
|
|
+ }
|
|
|
+ .fontSize(14)
|
|
|
+ .fontColor('#4F4F4F')
|
|
|
+
|
|
|
+ // 是否购买按钮
|
|
|
+ Image(this.purchaseList?.[index].purchased == '1' ?
|
|
|
+ $r('app.media.icon_select') : $r('app.media.icon_unSelect'))
|
|
|
+ .width(20)
|
|
|
+ .aspectRatio(1)
|
|
|
+ .onClick(() => { this.updateBuyStatus(this.purchaseList?.[index].id ?? 0, index) })
|
|
|
+ }
|
|
|
+ .width("100%")
|
|
|
+ .borderRadius(10)
|
|
|
+ .backgroundColor(Color.White)
|
|
|
+ .justifyContent(FlexAlign.SpaceBetween)
|
|
|
+ .padding({ left: 16, right: 16, top: 15, bottom: 10 })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .height('100%')
|
|
|
+ .scrollBar(BarState.Off)
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .layoutWeight(1)
|
|
|
+ .alignItems(HorizontalAlign.Center)
|
|
|
+ .justifyContent(FlexAlign.Center)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .hideTitleBar(true)
|
|
|
+ .backgroundColor('#F7F9FA')
|
|
|
+ .onBackPressed(() => { return this._onBackPress() })
|
|
|
+ .padding({ top: this.safeTop, left: 25, right: 25, bottom: 30 })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@Builder
|
|
|
+function PurchasingBuilder() {
|
|
|
+ PurchasingPage()
|
|
|
+}
|