index.js 1.12 KB
// pages/crowdfunding/components/progress/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    detail: {
      type: Object,
      value: {}
    },
    groupInfo: {
      type: Object,
      value: {},
      observer: function (n) {
        this.init(n)
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    progress: 0,
    count: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 初始化
    init() {
      let data = this.data.groupInfo
      let m = 0
      let count = 0
      if (data.fictitiousLadderQuantity != 0) {
        m = this.decimal((data.groupQuantity / data.fictitiousLadderQuantity) * 100, 2)
      } else {
        m = this.decimal(data.groupQuantity * 100, 2)
      }
      if (m < 20) {
        count = this.decimal(data.progress, 2)
      } else {
        count = m;
      }

      this.setData({
        progress: Math.min(100,m),
        count: Math.min(100,count)
      })
    },

    /**num:要转换的数值,fixed:精确几位小数 */
    decimal(num, fixed) {
      let pow = Math.pow(10, fixed)
      return Math.round(num * pow) / pow
    }
  }
})