基于HarmonyOS_Next的外卖送餐骑手端应用开发笔记(下)

                                个人开发笔记,大佬留情

47. 交货列表加载

分析:

一个任务,如果已经提货,那么下一步应该就是司机去送货,完成交货,上一节我们完成了提货, 那么完成的这个任务应该在在途里面,所以我来先把在途的数据进行查询一下

  • 在途和待提货的区别就是查询的状态不同,刚刚好,我们前面定义了枚举,所以这里可以直接复用前面提货的TaskList的组件

entry模块

接下来,根据状态去调整按钮的显示和文本内容

  • 当任务的状态为待提货并且可提货时,按钮显示提货并且可用
  • 当任务的状态为待交货时,按钮显示提货并且可用
  • 当任务的状态为待回车登记时,按钮显示回车登记并且可用
  • 给之前的任务状态枚举再加一个属性
  • 在TaskItemCard组件中根据状态获取按钮的文本及可用状态

如果enablePickup为true 表示可提货

如果status 为 2 表示为待交货 显示交货

如果status 为 4表示 待回车登记

  • 按钮显示文本

⚠️: 这里的去提货的逻辑不用发生任何变化,因为交货的业务也是到详情页去提货,完成可以复用一摸一样的逻辑

效果:

48. 交货详情内容控制

根据状态显示不同的按钮


当一个任务提完货后,status应该是Line(在途),如果是Waiting(待提货)的话显示提货按钮,如果是Line(在途),显示交货按钮
1提货


2交货

  1. 交货时,隐藏提货上传组件,显示交货上传组件
  • 实现一个Builder函数来放置交货的上传

显示组件



 

49. 交货按钮状态控制

控制按钮enable

50. 交货

Entry模块

标准流程

  1. 定义类型封装api
  2. 引入api
  3. 注册事件-调用api重新加载
  1. 定义请求参数类型
import { ImageList } from '@hm/basic'
export interface DeliverParamsType {
  /** 交付凭证列表 */
  certificatePictureList: ImageList[];
  /** 交付图片列表 */
  deliverPictureList: ImageList[];
  /** 司机作业id */
  id: string;
}
export class DeliverParamsTypeModel implements DeliverParamsType {
  certificatePictureList: ImageList[] = []
  deliverPictureList: ImageList[] = []
  id: string = ''

  constructor(model: DeliverParamsType) {
    this.certificatePictureList = model.certificatePictureList
    this.deliverPictureList = model.deliverPictureList
    this.id = model.id
  }
}
  1. 封装API

  1. 调用

51. 底部显示回车登记按钮

在已经交货的情况下,显示提货信息-交货信息- 底部的回车登记按钮,全部显示

52. 回车登记模式下-上传组件只读

因为货已经交了,所以回车登记模式下,此时只可以看,不能再传图片了

basic模块

  1. 给HmUpload一个属性来控制是否可上传和删除

  1. 通过该属性来控制上传部分的显示和隐藏

  1. 在TaskDetail中传入该属性

53. 回车登记页面

2024.8.24

  • 新建回车登记页面 pages/CardRecord/Record
import { HmNavBar, HmCard, HmCardItem } from '@hm/basic'
@Entry
  @Component
  struct CarRecord {
    build() {
      Column() {
        HmNavBar({ title: '回车登记' })
        Scroll() {
          Column() {
            HmCard(){
              HmCardItem({
                leftTitle: '出车时间',
                rightText: '2022.05.04 13:00',
                showRightIcon:false
              })
              HmCardItem({
                leftTitle: '回车时间',
                rightText: '请选择',
                showBottomBorder: false
              })
            }
          }
          .height('100%')
        }
        .layoutWeight(1)
        // 底部内容
        Row() {
          Button("交车",{ type: ButtonType.Capsule })
            .backgroundColor($r('app.color.primary'))
            .width(207)
            .height(50)
        }
        .backgroundColor($r('app.color.white'))
          .height(70)
          .width('100%')
          .justifyContent(FlexAlign.Center)
          .alignItems(VerticalAlign.Center)
      }
      .backgroundColor($r('app.color.background_page'))
        .height('100%')
    }
  }
  • TaskDetail页面跳转到回车登记

  • 在CarRecord接收参数id,并且获取任务的详情,赋值出车时间

54. 封装选择组件

basic模块

分析

  • 可以控制显示文本
  • 右侧的是否文本可以控制
  • 值改变时通知外部组件
  • 这个组件通用性不是那么大,简单封装一下
  • 在components下新建HmCheckBox.ets - 直接复制
@Component
  struct HmCheckBox {
    title: string = "测试"
    confirmText: string = "是"
    cancelText: string = '否'
    @Prop
    value: boolean = true // 决定选中左侧还是右侧\
    checkChange: (value: boolean) => void = () => {}
    build() {
      Row () {
        Row () {
          Text(this.title)
            .fontSize(14)
            .fontColor($r("app.color.text_primary"))

          // 右侧内容
          Row ({ space: 10 }) {
            Row () {
              Image(this.value ? $r("app.media.ic_radio_true") : $r("app.media.ic_radio_false"))
                .width(32)
                .aspectRatio(1)
              Text(this.confirmText)
            }
            .onClick(() => {
              this.value = true
              this.checkChange(this.value)
            })
            Row () {
              Image(!this.value ? $r("app.media.ic_radio_true") : $r("app.media.ic_radio_false"))
                .width(32)
                .aspectRatio(1)
              Text(this.cancelText)
            }
            .onClick(() => {
              this.value = false
              this.checkChange(this.value)
            })
          }
        }
        .width("100%")
          .borderRadius(10)
          .height(60)
          .padding({
            left: 15,
            right: 15
          })
          .justifyContent(FlexAlign.SpaceBetween)
          .backgroundColor($r("app.color.white"))

      }
      .width("100%")
        .padding({
          left: 15,
          right: 15
        })
        .margin({
          top: 15
        })
    }
  }
export { HmCheckBox }
  • 在回车登记中放置三个组件

效果:

55. DatePickerDialog时间选择器弹窗

效果:

56. 回车登记提交

  1. 定义提交数据类型
  2. 绑定数据到数据
  3. 提交回车登记

entry模块

  • 声明回车登记类型
import { ImageList } from '@hm/basic'
export interface CarRecordType {
  /** 事故说明,类型为“其他”时填写 */
  accidentDescription: string | null;
  /** 事故图片列表 */
  accidentImagesList: ImageList[] | null;
  /** 事故类型,1-直行事故,2-追尾事故,3-超车事故,4-左转弯事故,5-右转弯事故,6-弯道事故,7-坡道事故,8-会车事故,9-其他, */
  accidentType: string | null;
  /** 违章说明,类型为“其他”时填写 */
  breakRulesDescription: string | null;
  /** 违章类型,1-闯红灯,2-无证驾驶,3-超载,4-酒后驾驶,5-超速行驶,6-其他,可用 */
  breakRulesType: string | null;
  /** 扣分数据 */
  deductPoints: number | null;
  /** 回车时间,回车时间,格式yyyy-MM-dd HH:mm:ss,比如:2023-07-18 17:00:00 */
  endTime: string;
  /** 故障说明,类型为“其他”时填写 */
  faultDescription: string | null;
  /** 故障图片列表 */
  faultImagesList: ImageList[] | null;
  /** 故障类型,1-发动机启动困难,2-不着车,3-漏油,4-漏水,5-照明失灵,6-有异响,7-排烟异常,8-温度异常,9-其他,可用 */
  faultType: string | null;
  /** 运输任务id */
  id: string;
  /** 是否出现事故 */
  isAccident: boolean | null;
  /** 车辆是否可用 */
  isAvailable: boolean | null;
  /** 车辆是否违章 */
  isBreakRules: boolean | null;
  /** 车辆是否故障 */
  isFault: boolean | null;
  /** 罚款金额 */
  penaltyAmount: string | null;
  /** 出车时间,出车时间,格式yyyy-MM-dd HH:mm:ss,比如:2023-07-18 17:00:00 */
  startTime: string;
}
export class CarRecordTypeModel implements CarRecordType {
  accidentDescription: string | null = null
  accidentImagesList: ImageList[] | null = null
  accidentType: string | null = null
  breakRulesDescription: string | null = null
  breakRulesType: string | null = null
  deductPoints: number | null = null
  endTime: string = ''
  faultDescription: string | null = null
  faultImagesList: ImageList[] | null = null
  faultType: string | null = null
  id: string = ''
  isAccident: boolean | null = null
  isAvailable: boolean | null = null
  isBreakRules: boolean | null = null
  isFault: boolean | null = null
  penaltyAmount: string | null = null
  startTime: string = ''

  constructor(model: CarRecordType) {
    this.accidentDescription = model.accidentDescription
    this.accidentImagesList = model.accidentImagesList
    this.accidentType = model.accidentType
    this.breakRulesDescription = model.breakRulesDescription
    this.breakRulesType = model.breakRulesType
    this.deductPoints = model.deductPoints
    this.endTime = model.endTime
    this.faultDescription = model.faultDescription
    this.faultImagesList = model.faultImagesList
    this.faultType = model.faultType
    this.id = model.id
    this.isAccident = model.isAccident
    this.isAvailable = model.isAvailable
    this.isBreakRules = model.isBreakRules
    this.isFault = model.isFault
    this.penaltyAmount = model.penaltyAmount
    this.startTime = model.startTime
  }
}
  • 在CarRecord中定义数据

转化时间

获取时间

获取三个选择

  • 封装交车api

回车登记方法

绑定按钮

同学们到现在,我们已经将神领物流中的 提货-交货-回车登记业务跑通,剩下的将完成 对整个项目的一些核心点的优化

57. 延迟收货业务

entry模块

  1. 新建pages/Delay/Delay.ets -(Page)
  • 复制静态-快速布局

定义延迟提货提交类型参数

export interface DelayParamsType {
  /** 延迟原因 */
  delayReason: string;
  /** 延迟时间,格式:yyyy-MM-dd HH:mm */
  delayTime: string;
  /** 司机作业单id */
  id: string;
}
export class DelayParamsTypeModel implements DelayParamsType {
  delayReason: string = ''
  delayTime: string = ''
  id: string = ''

  constructor(model: DelayParamsType) {
    this.delayReason = model.delayReason
    this.delayTime = model.delayTime
    this.id = model.id
  }
}

封装一个转化时间函数

export  const  DateFormat =(value:Date)=>{
  //2023-12-23 05:12
  return value.getFullYear()+"-"+(value.getMonth()+1).toString().padStart(2,"0")+"-"
    +(value.getDate()).toString().padStart(2,"0")+""
    +value.getHours().toString().padStart(2,"0")+":"
    +value.getMinutes().toString().padStart(2,"0")
}

显示时间

效果:

封装延迟提货api

调用api

效果:

58. 没有数据页面

因为item有可能为null,所以加一个短路表达式

效果;

59. 上报异常页面基础布局

59. 上报异常页面基础布局

新建上报异常页面-复制静态-pages/ExceptionReport/ExceptionReport.ets

import { CommonRouterParams, DateFormat, HmCard, HmCardItem, HmNavBar, HmUpload } from '@hm/basic'
import { router } from '@kit.ArkUI'
import { ExceptionListModel, ExceptionParamsType, ExceptionParamsTypeModel } from '../../modals'

@Entry
  @Component
  struct ExceptionReport {
    @State
    exceptionForm: ExceptionParamsTypeModel = new ExceptionParams
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值