reviewStatus.js 4.71 KB
// packageWorkspace/components/reviewStatus/reviewStatus.js
import api from '../../api'
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
      },
      {
        nameObj: {
          1: '总部审核',
          2: '总部审核',
          3: '总部审核'
        },
        type: 1,
        active: false
      },
      {
        nameObj: {
          1: '待退款',
          2: '已退款',
        },
        type: 1,
        active: false
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setStatusInfo(beforeStatus, afterStatus, transferStatus) {
      const STATUS = {
        INITIATE: 0,       // 发起申请
        APPLIED: 1,        // 已申请
        REGION_REVIEW: 2,  // 区域运营审核
        REGION_PASS: 3,    // 区域运营审核通过
        REGION_REJECT: 4,  // 区域运营审核不通过
        HEAD_REVIEW: 5,    // 总部审核
        HEAD_PASS: 6,      // 总部审核通过
        HEAD_REJECT: 7,    // 总部审核不通过
        PENDING_REFUND: 8,  // 待退款
        REFUNDED: 9 // 已退款
      }
      // 定义状态类型
      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.REFUNDED
      } else 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 == 8) {
        currentStatus = STATUS.HEAD_REVIEW
      } else if (before == 7 && after == 5) {
        currentStatus = STATUS.REGION_REJECT
      } else if ([0, 1, 2, 8].includes(before) && [0, 1, 2, 3].includes(after)) {
        currentStatus = STATUS.HEAD_REVIEW
      } else if (before == 3 && after == 4) {
        currentStatus = STATUS.PENDING_REFUND
      } else if ([0, 1, 2, 3].includes(before) && after == 5) {
        currentStatus = STATUS.HEAD_REJECT
      } else if (after == 4) {
        currentStatus = STATUS.PENDING_REFUND
      }
      // 更新状态列表
      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
          }
        }
        // 第三步状态(总部审核)
        if (index === 2) {
          if (currentStatus === STATUS.HEAD_REVIEW) {
            item.type = STATUS_TYPE.CURRENT
            item.active = true
          } else if (currentStatus === STATUS.HEAD_REJECT) {
            item.type = STATUS_TYPE.REJECTED
            item.active = true
          } else if (currentStatus > STATUS.HEAD_REVIEW) {
            item.type = STATUS_TYPE.COMPLETED
            item.active = false
          }
        }
        // 第四步状态(退款)
        if (index === 3) {
          if (currentStatus == STATUS.PENDING_REFUND) {
            item.type = STATUS_TYPE.CURRENT
            item.active = true
          } else if (currentStatus > STATUS.PENDING_REFUND) {
            item.type = STATUS_TYPE.COMPLETED
            item.active = false
          }
        }
      })
      this.setData({ 
        statusList
       })
    }
  }
})