|
@@ -119,7 +119,7 @@ export struct MainView {
|
|
|
Swiper(){
|
|
Swiper(){
|
|
|
ForEach(this.vm.week, (item: string, index: number) => {
|
|
ForEach(this.vm.week, (item: string, index: number) => {
|
|
|
Row(){
|
|
Row(){
|
|
|
- RecipeWidget({ week: item, vm: this.vm })
|
|
|
|
|
|
|
+ RecipeWidget({ week: item, vm: this.vm, index: index })
|
|
|
}
|
|
}
|
|
|
.padding(5)
|
|
.padding(5)
|
|
|
.width(320)
|
|
.width(320)
|
|
@@ -168,14 +168,24 @@ export struct MainView {
|
|
|
|
|
|
|
|
Column(){
|
|
Column(){
|
|
|
Column(){
|
|
Column(){
|
|
|
- if(true){ // 菜品列表
|
|
|
|
|
- ForEach(new Array(3).fill(0), (item: number, index: number) =>{
|
|
|
|
|
|
|
+ if(this.vm.purchaseList && this.vm.purchaseList?.length > 0){ // 菜品列表
|
|
|
|
|
+ ForEach(new Array(Math.min(this.vm.purchaseList?.length ?? 0, 3)).fill(0), (item: number, index: number) =>{
|
|
|
Row(){
|
|
Row(){
|
|
|
- Text('南瓜-100g')
|
|
|
|
|
|
|
+ Text(){
|
|
|
|
|
+ Span(this.vm.purchaseList?.[index].ingredientName ?? '南瓜')
|
|
|
|
|
+ Span('-')
|
|
|
|
|
+ Span((this.vm.purchaseList?.[index].amount ?? 1) + '')
|
|
|
|
|
+ Span(this.vm.purchaseList?.[index].unit ?? 'g')
|
|
|
|
|
+ }
|
|
|
|
|
+ .fontSize(14)
|
|
|
|
|
+ .fontColor('#4F4F4F')
|
|
|
|
|
|
|
|
- Image($r('app.media.icon_select'))
|
|
|
|
|
|
|
+ // 是否购买按钮
|
|
|
|
|
+ Image(this.vm.purchaseList?.[index].purchased ?
|
|
|
|
|
+ $r('app.media.icon_select') : $r('app.media.icon_unSelect'))
|
|
|
.width(20)
|
|
.width(20)
|
|
|
.aspectRatio(1)
|
|
.aspectRatio(1)
|
|
|
|
|
+ .onClick(() => { this.vm.updateBuyStatus(this.vm.purchaseList?.[index].id ?? 0, index) })
|
|
|
}
|
|
}
|
|
|
.width("100%")
|
|
.width("100%")
|
|
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
@@ -196,11 +206,13 @@ export struct MainView {
|
|
|
Text('查看全部')
|
|
Text('查看全部')
|
|
|
.fontSize(12)
|
|
.fontSize(12)
|
|
|
.fontColor('#95C50A')
|
|
.fontColor('#95C50A')
|
|
|
|
|
+ .onClick(() => { this.vm.goToPurchaseDetail() })
|
|
|
}
|
|
}
|
|
|
.width("100%")
|
|
.width("100%")
|
|
|
.alignItems(VerticalAlign.Center)
|
|
.alignItems(VerticalAlign.Center)
|
|
|
.justifyContent(FlexAlign.End)
|
|
.justifyContent(FlexAlign.End)
|
|
|
.padding({ left: 16, right: 16, top: 5, bottom: 16 })
|
|
.padding({ left: 16, right: 16, top: 5, bottom: 16 })
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
Row(){
|
|
Row(){
|
|
|
Text('暂无数据')
|
|
Text('暂无数据')
|
|
@@ -258,59 +270,112 @@ export struct MainView {
|
|
|
*/
|
|
*/
|
|
|
@ComponentV2
|
|
@ComponentV2
|
|
|
struct RecipeWidget{
|
|
struct RecipeWidget{
|
|
|
- @Require @Param week: string = "周一"
|
|
|
|
|
- @Require @Param vm: MainViewModel = new MainViewModel()
|
|
|
|
|
|
|
+ @Require @Param week: string
|
|
|
|
|
+ @Require @Param index: number
|
|
|
|
|
+ @Require @Param vm: MainViewModel
|
|
|
|
|
|
|
|
- @Local isShowEnum: string = ''
|
|
|
|
|
|
|
+ // 当前选中的菜品
|
|
|
|
|
+ @Local selectCuisine: number = -1
|
|
|
@Local toDayPlan?: DayPlan
|
|
@Local toDayPlan?: DayPlan
|
|
|
|
|
|
|
|
- threeMeals: Array<BasicType<Cuisine>> = []
|
|
|
|
|
|
|
+ threeMeals: Array<BasicType<Cuisine>> = [
|
|
|
|
|
+ {
|
|
|
|
|
+ text: '早餐',
|
|
|
|
|
+ id: 'breakfast'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ text: '午餐',
|
|
|
|
|
+ id: 'lunch'
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ text: '晚餐',
|
|
|
|
|
+ id: 'dinner'
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
|
|
|
- getToDayPlan(){
|
|
|
|
|
|
|
+ getToDayPlan(needReload: boolean = true){
|
|
|
switch (this.week) {
|
|
switch (this.week) {
|
|
|
case '周一':
|
|
case '周一':
|
|
|
- this.toDayPlan = this.vm.planList?.monday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.monday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.monday
|
|
|
case '周二':
|
|
case '周二':
|
|
|
- this.toDayPlan = this.vm.planList?.tuesday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.tuesday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.tuesday
|
|
|
case '周三':
|
|
case '周三':
|
|
|
- this.toDayPlan = this.vm.planList?.wednesday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.wednesday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.wednesday
|
|
|
case '周四':
|
|
case '周四':
|
|
|
- this.toDayPlan = this.vm.planList?.thursday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.thursday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.thursday
|
|
|
case '周五':
|
|
case '周五':
|
|
|
- this.toDayPlan = this.vm.planList?.friday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.friday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.friday
|
|
|
case '周六':
|
|
case '周六':
|
|
|
- this.toDayPlan = this.vm.planList?.saturday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.sunday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.saturday
|
|
|
case '周日':
|
|
case '周日':
|
|
|
- this.toDayPlan = this.vm.planList?.sunday
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ if(needReload){
|
|
|
|
|
+ this.toDayPlan = new DayPlan(this.vm.planList?.sunday)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.vm.planList?.sunday
|
|
|
|
|
+ }
|
|
|
|
|
+ return new DayPlan()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 返回对应的菜品
|
|
|
|
|
+ getCuisine(text: string): Cuisine | undefined {
|
|
|
|
|
+ if(text === '早餐') {
|
|
|
|
|
+ return this.toDayPlan?.breakfast
|
|
|
|
|
+ } else if(text === '午餐') {
|
|
|
|
|
+ return this.toDayPlan?.lunch
|
|
|
|
|
+ } else if(text === '晚餐') {
|
|
|
|
|
+ return this.toDayPlan?.dinner
|
|
|
|
|
+ }
|
|
|
|
|
+ return undefined
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 展开菜单
|
|
|
|
|
+ openMenu(text: string){
|
|
|
|
|
+ let cuisine: Cuisine | undefined = this.getCuisine(text)
|
|
|
|
|
+ if(cuisine) {
|
|
|
|
|
+ this.selectCuisine = cuisine.id ?? -1
|
|
|
}
|
|
}
|
|
|
- if(this.toDayPlan && this.toDayPlan.breakfast) {
|
|
|
|
|
- this.toDayPlan!.breakfast!.name = "我改一改看看"
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 选中修改菜品
|
|
|
|
|
+ updateCuisine(id: number){
|
|
|
|
|
+ let origin = this.getToDayPlan(false)
|
|
|
|
|
+ let cuisine: Cuisine | undefined = this.vm.getCuisineInfo(id)
|
|
|
|
|
+ if(this.toDayPlan?.breakfast?.id == this.selectCuisine) {
|
|
|
|
|
+ this.toDayPlan.breakfast = cuisine
|
|
|
|
|
+ origin!.breakfast = this.toDayPlan?.breakfast
|
|
|
|
|
+ } else if (this.toDayPlan?.lunch?.id == this.selectCuisine) {
|
|
|
|
|
+ this.toDayPlan.lunch = cuisine
|
|
|
|
|
+ origin!.lunch = this.toDayPlan?.lunch
|
|
|
|
|
+ } else if (this.toDayPlan?.dinner?.id == this.selectCuisine) {
|
|
|
|
|
+ this.toDayPlan.dinner = cuisine
|
|
|
|
|
+ origin!.dinner = this.toDayPlan?.dinner
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ this.vm.updateWeeklyPlan()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
aboutToAppear(): void {
|
|
aboutToAppear(): void {
|
|
|
- this.getToDayPlan()
|
|
|
|
|
- this.threeMeals = [
|
|
|
|
|
- {
|
|
|
|
|
- text: '早餐',
|
|
|
|
|
- id: 'breakfast'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- text: '午餐',
|
|
|
|
|
- id: 'lunch'
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- text: '晚餐',
|
|
|
|
|
- id: 'dinner'
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ this.vm.addEvent(() => {
|
|
|
|
|
+ this.getToDayPlan()
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
build() {
|
|
build() {
|
|
@@ -337,20 +402,8 @@ struct RecipeWidget{
|
|
|
|
|
|
|
|
Row({space: 8}){
|
|
Row({space: 8}){
|
|
|
Text(){
|
|
Text(){
|
|
|
- // if(true) {
|
|
|
|
|
- // Span('南瓜-100g')
|
|
|
|
|
- // } else {
|
|
|
|
|
- // Span('无')
|
|
|
|
|
- // .fontSize(14)
|
|
|
|
|
- // .fontColor('#A6A6AB')
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- if(item.text === '早餐') {
|
|
|
|
|
- Span(this.toDayPlan?.breakfast?.name)
|
|
|
|
|
- } else if(item.text === '午餐') {
|
|
|
|
|
- Span(this.toDayPlan?.lunch?.name)
|
|
|
|
|
- } else if(item.text === '晚餐') {
|
|
|
|
|
- Span(this.toDayPlan?.dinner?.name)
|
|
|
|
|
|
|
+ if(this.getCuisine(item.text!)?.name){
|
|
|
|
|
+ Span(this.getCuisine(item.text!)?.name)
|
|
|
} else {
|
|
} else {
|
|
|
Span('无')
|
|
Span('无')
|
|
|
.fontSize(14)
|
|
.fontSize(14)
|
|
@@ -363,9 +416,10 @@ struct RecipeWidget{
|
|
|
.rotate({ angle:270 })
|
|
.rotate({ angle:270 })
|
|
|
.width(20)
|
|
.width(20)
|
|
|
}
|
|
}
|
|
|
- .width(90)
|
|
|
|
|
|
|
+ .justifyContent(FlexAlign.End)
|
|
|
|
|
+ .width(110)
|
|
|
.bindMenu(this._MenuWidget, { hapticFeedbackMode: HapticFeedbackMode.ENABLED })
|
|
.bindMenu(this._MenuWidget, { hapticFeedbackMode: HapticFeedbackMode.ENABLED })
|
|
|
- .onClick(() => { this.isShowEnum = '七七八八'+item.text })
|
|
|
|
|
|
|
+ .onClick(() => { this.openMenu(item.text!) })
|
|
|
}
|
|
}
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.padding({top: 14, bottom: 14})
|
|
.padding({top: 14, bottom: 14})
|
|
@@ -384,14 +438,23 @@ struct RecipeWidget{
|
|
|
|
|
|
|
|
// 菜单结构
|
|
// 菜单结构
|
|
|
@Builder _MenuWidget(){
|
|
@Builder _MenuWidget(){
|
|
|
- Column(){
|
|
|
|
|
- ForEach(new Array(5).fill(0), (item:number, index: number) => {
|
|
|
|
|
- Text(this.isShowEnum ?? "南瓜米糊米糊")
|
|
|
|
|
- .fontSize(16)
|
|
|
|
|
- .fontWeight(500)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ Scroll(){
|
|
|
|
|
+ Column(){
|
|
|
|
|
+ ForEach(this.vm.dishList, (item:Cuisine, index: number) => {
|
|
|
|
|
+ Text(item.name)
|
|
|
|
|
+ .fontSize(16)
|
|
|
|
|
+ .width("100%")
|
|
|
|
|
+ .fontWeight(500)
|
|
|
|
|
+ .borderRadius(8)
|
|
|
|
|
+ .textAlign(TextAlign.Center)
|
|
|
|
|
+ .padding({left: 36, right: 36, top: 15, bottom: 15})
|
|
|
|
|
+ .backgroundColor(item.id == this.selectCuisine ? '#F3F3F3' : '#FFFFFF')
|
|
|
|
|
+ .onClick(() => { this.updateCuisine(item.id!) })
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- .width(160)
|
|
|
|
|
|
|
+ .width(220)
|
|
|
|
|
+ .height(250)
|
|
|
.padding({left: 12, right: 12, top: 5, bottom: 5})
|
|
.padding({left: 12, right: 12, top: 5, bottom: 5})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -405,6 +468,7 @@ struct RecipeWidget{
|
|
|
.backgroundColor(color)
|
|
.backgroundColor(color)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
+ .width("100%")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|