labelRefundStatus.js 2.88 KB
// tabWorkOrder/pages/refundApply/components/labelRefundStatus/labelRefundStatus.js
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    infoData: {
      type: Object,
      observer: function(n) {
        this.setStatusInfo(n.beforeStatus, n.afterStatus, n.transferStatus)
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    statusList: [  //进度条
      {
        nameObj: {
          1: '申请标记退款',
          2: '已申请'
        },
        type: 1,
        active: true
      },
      {
        nameObj: {
          1: '区域运营审核',
          2: '区域运营审核',
          3: '区域运营审核'
        },
        type: 1,
        active: false
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setStatusInfo(beforeStatus, afterStatus, transferStatus) {
      const STATUS = {
        INITIATE: 0,       // 发起申请
        APPLIED: 1,        // 已申请
        REGION_REVIEW: 2,  // 区域运营审核
        REGION_PASS: 3,    // 区域运营审核通过
        REGION_REJECT: 4,  // 区域运营审核不通过
      }
      // 定义状态类型
      const STATUS_TYPE = {
        CURRENT: 1,    // 当前进行中
        COMPLETED: 2,  // 已完成
        REJECTED: 3    // 已驳回
      }
      // 处理空值
      const before = beforeStatus ?? ''
      const after = afterStatus ?? ''
      const transfer = transferStatus ?? ''
      // 确定当前状态
      let currentStatus
      if (transfer == 3) {
        currentStatus = STATUS.REGION_PASS
      }
      if (before === '' && after === '') {
        currentStatus = STATUS.INITIATE
      } else if (before === '' && after == 6) {
        currentStatus = STATUS.APPLIED
      } else if (before == 6 && after == 7) {
        currentStatus = STATUS.REGION_REVIEW
      } else if (before == 7 && after == 5) {
        currentStatus = STATUS.REGION_REJECT
      }
      // 更新状态列表
      const { statusList } = this.data
      statusList.forEach((item, index) => {
        // 第一步状态
        if (index === 0) {
          item.type = currentStatus === STATUS.INITIATE ? STATUS_TYPE.CURRENT : STATUS_TYPE.COMPLETED
          item.active = currentStatus === STATUS.INITIATE
        }
        // 第二步状态(区域审核)
        if (index === 1) {
          if (currentStatus === STATUS.REGION_REVIEW) {
            item.type = STATUS_TYPE.CURRENT
            item.active = true
          } else if (currentStatus === STATUS.REGION_REJECT) {
            item.type = STATUS_TYPE.REJECTED
            item.active = true
          } else if (currentStatus > STATUS.REGION_REVIEW) {
            item.type = STATUS_TYPE.COMPLETED
            item.active = false
          }
        }
      })
      this.setData({ 
        statusList
       })
    }
  }
})