orderItem.ets 4.4 KB
import { orderRow } from '../api/recordsType'
import { quarterType } from '../api/options/optionsType'

@Extend(Text) function info () {
  .fontColor('#909399').backgroundColor('#f4f4f5')
  .borderColor('#e9e9eb')
}
@Extend(Text) function primary () {
  .fontColor('#1890ff').backgroundColor('#e8f4ff')
  .borderColor('#d1e9ff')
}
@Extend(Text) function warning () {
  .fontColor('#ffba00').backgroundColor('#fff8e6')
  .borderColor('#fff1cc')
}
@Extend(Text) function success () {
  .fontColor('#13ce66').backgroundColor('#e7faf0')
  .borderColor('#d0f5e0')
}
@Extend(Text) function danger () {
  .fontColor('#ff4949').backgroundColor('#ffeded')
  .borderColor('#ffdbdb')
}

interface listClassType {
  listClass: string,
  dictLabel: string
}

@Component
export default struct orderItem {
  @Prop orderInfo: orderRow
  @Prop sourceList: quarterType[]
  @Prop stateList: quarterType[]

  getSource = () => {
    let listClassObj: listClassType = { listClass: 'info', dictLabel: '小程序' }
    let sourceValue: string = this.orderInfo?.source.toString()
    let newArr = this.sourceList.filter((item: quarterType) => item.dictValue == sourceValue)
    return newArr[0] || listClassObj
  }
  getState = () => {
    let listClassObj: listClassType = { listClass: 'info', dictLabel: '未支付' }
    let stateValue: string = this.orderInfo.state.toString()
    let newArr = this.stateList.filter((item: quarterType) => item.dictValue == stateValue)
    return newArr[0] || listClassObj
  }
  build() {
    Row(){
      Column({space: 5}){
        Text(`订单编号:${this.orderInfo?.orderNo}`).fontSize(14).fontColor('#000').fontWeight(600)
        Row(){
          Text(`套餐:${this.orderInfo?.comboName}`).fontSize(12).fontColor('#999').margin({right: 5})
          if(this.getSource().listClass == 'info') {
            Text(this.getSource().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).info()
          } else if(this.getSource().listClass == 'primary'){
            Text(this.getSource().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).primary()
          } else if(this.getSource().listClass == 'warning'){
            Text(this.getSource().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).warning()
          } else if(this.getSource().listClass == 'success'){
            Text(this.getSource().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).success()
          } else if(this.getSource().listClass == 'danger'){
            Text(this.getSource().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).danger()
          }
        }
        Row(){
          Text(`金额:${this.orderInfo?.amount}`).fontSize(12).fontColor('#999').margin({right: 5})
          if(this.getState().listClass == 'info') {
            Text(this.getState().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).info()
          } else if(this.getState().listClass == 'primary'){
            Text(this.getState().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).primary()
          } else if(this.getState().listClass == 'warning'){
            Text(this.getState().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).warning()
          } else if(this.getState().listClass == 'success'){
            Text(this.getState().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).success()
          } else if(this.getState().listClass == 'danger'){
            Text(this.getState().dictLabel).padding({left: 10, right: 10})
              .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).danger()
          }
        }
        Text(`时间:${this.orderInfo?.createTime}`).fontSize(12).fontColor('#999')
      }.alignItems(HorizontalAlign.Start)
      Text(`+${this.orderInfo?.bean}`).fontStyle(14).fontStyle(FontStyle.Italic).fontColor('#1890ff').fontWeight(600)
    }.padding({top: 20, bottom: 20, left: 10, right: 10})
    .border({width: {bottom: 1}, color: '#eee'}).width('100%')
    .justifyContent(FlexAlign.SpaceBetween)
  }
}