ThemeStaticText.ets 3.6 KB

let getInfoColor = (index: string | undefined) => {
  let colorStr: string = ''
  switch (index) {
    case '1': colorStr = '#909399';break;
    case '2': colorStr = '#1890ff';break;
    case '4': colorStr = '#ffba00';break;
    case '3': colorStr = '#13ce66';break;
    default : colorStr = '#909399'
  }
  return colorStr
}

let getInfoBgColor = (index: string | undefined) => {
  let colorStr: string = ''
  switch (index) {
    case '1': colorStr = '#f4f4f5';break;
    case '2': colorStr = '#e8f4ff';break;
    case '4': colorStr = '#fff8e6';break;
    case '3': colorStr = '#e7faf0';break;
    default : colorStr = '#f4f4f5'
  }
  return colorStr
}

let getInfoBorderColor = (index: string | undefined) => {
  let colorStr: string = ''
  switch (index) {
    case '1': colorStr = '#e9e9eb';break;
    case '2': colorStr = '#d1e9ff';break;
    case '4': colorStr = '#fff1cc';break;
    case '3': colorStr = '#d0f5e0';break;
    default : colorStr = '#f4f4f5'
  }
  return colorStr
}

let getStateInfoColor = (index: string | undefined) => {
  let colorStr: string = ''
  switch (index) {
    case '4': colorStr = '#909399';break;
    case '0': colorStr = '#1890ff';break;
    case '5': colorStr = '#ffba00';break;
    case '2': colorStr = '#ff4949';break;
    case '1': colorStr = '#13ce66';break;
    default : colorStr = '#909399'
  }
  return colorStr
}

let getStateInfoBgColor = (index: string | undefined) => {
  let colorStr: string = ''
  switch (index) {
    case '4': colorStr = '#f4f4f5';break;
    case '0': colorStr = '#e8f4ff';break;
    case '5': colorStr = '#fff8e6';break;
    case '2': colorStr = '#ffeded';break;
    case '1': colorStr = '#e7faf0';break;
    default : colorStr = '#f4f4f5'
  }
  return colorStr
}

let getStateInfoBorderColor = (index: string | undefined) => {
  let colorStr: string = ''
  switch (index) {
    case '4': colorStr = '#e9e9eb';break;
    case '0': colorStr = '#d1e9ff';break;
    case '5': colorStr = '#fff1cc';break;
    case '2': colorStr = '#ffdbdb';break;
    case '1': colorStr = '#d0f5e0';break;
    default : colorStr = '#f4f4f5'
  }
  return colorStr
}

@Component
export default  struct ThemeStaticTest {
  @Prop textValue: string
  @Prop type: string = '0'
  // 获取维保记录类型
  MaintenanceType = (index: string | undefined): string => {
    let str: string = ''
    switch (index) {
      case '1': str = '月度';break;
      case '2': str = '季度';break;
      case '4': str = '半年度';break;
      case '3': str = '年度';break;
      default : str = ''
    }
    return str
  }

  // 获取维保记录状态
  MaintenanceState = (index: string | undefined): string => {
    let str: string = ''
    switch (index) {
      case '0': str = '编辑中';break;
      case '1': str = '已签发';break;
      case '2': str = '已删除';break;
      case '3': str = '正常(除”删除“外)';break;
      case '4': str = '待维保人员签字';break;
      case '5': str = '待甲方签字';break;
      default : str = ''
    }
    return str
  }
  build() {
    if(this.type == '0') {
      Text(this.MaintenanceType(this.textValue))
        .padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).fontColor(getInfoColor(this.textValue))
        .backgroundColor(getInfoBgColor(this.textValue)).borderColor(getInfoBorderColor(this.textValue))
    } else if(this.type == '1'){
      Text(this.MaintenanceState(this.textValue)).padding({left: 6, right: 6})
        .borderWidth(1).fontSize(12).borderRadius(4).lineHeight(16).fontColor(getStateInfoColor(this.textValue))
        .backgroundColor(getStateInfoBgColor(this.textValue)).borderColor(getStateInfoBorderColor(this.textValue))
    }
  }
}