LearnStatistics.js 1.93 KB
// packageStudyCenter/pages/myTask/components/LearnStatistics/LearnStatistics.js
Component({
  properties: {
    isBeisen: {
      type: Boolean,
      value: false
    },
    dataInfo: {
      type: Object,
      value: {}
    },
    isHmzx: {
      type: Boolean,
      value: false
    },
    isYb: {
      type: Boolean,
      value: false
    }
  },

  data: {
    progressList: [
      {
        type: 3,
        title: '短课程进度',
        unit: '%',
        key: 'shortCourseProgress',
        ratio: 'shortCourseCompletedLearnRatio',
        hidden: false
      },
      {
        type: 4,
        title: '长课程进度',
        unit: '%',
        key: 'longCourseProgress',
        ratio: 'longCourseCompletedLearnRatio',
        hidden: false
      }
    ],
    progressListFiltered: []
  },

  observers: {
    'isHmzx, isYb, isBeisen': function(isHmzx, isYb, isBeisen) {
      this.updateProgressList();
    },
    'dataInfo': function(dataInfo) {
      this.updateProgressList();
    }
  },

  lifetimes: {
    attached() {
      this.updateProgressList();
    }
  },

  methods: {
    updateProgressList() {
      const { isHmzx, isYb, isBeisen, progressList } = this.data;
      
      const updatedList = progressList.map(item => {
        let hidden = item.hidden;
        
        if (item.type === 3) {
          // 短课程:非慧营销或非延保时隐藏
          hidden = !isHmzx || !isYb;
        } else if (item.type === 4) {
          // 长课程:非北森时隐藏
          hidden = !isBeisen;
        }
        
        return { ...item, hidden };
      });
      
      // 过滤出需要显示的项
      const filteredList = updatedList.filter(item => !item.hidden);
      
      this.setData({
        progressList: updatedList,
        progressListFiltered: filteredList
      });
    },

    getDisplayValue(value) {
      if (value === 0 || value === '0') {
        return '0';
      }
      return value || '-';
    }
  }
});