Commit e9e43939 authored by zhijie.xue's avatar zhijie.xue

修复抽奖概率 undefined

parent 3925e313
......@@ -55,3 +55,26 @@ export function compressShareImage(url) {
}
return url;
}
function getCommonDivisor(firstNum, secondNum) {
if (secondNum === 0) return firstNum;
var remainder = parseInt(firstNum % secondNum);
return getCommonDivisor(secondNum, remainder);
}
export function getProbability(quantity, coinQuantity) {
if (!quantity) return 0;
// 如果用户克币数是0
if (quantity === 0) {
return '0%';
}
var divisor = getCommonDivisor(quantity, coinQuantity);
var value = quantity / divisor;
var value2 = coinQuantity / divisor;
// 如果分子比分母大说明中奖概率是100%,那么返回中奖概率
if (value >= value2) {
return '100%';
} else {
return value + '/' + value2;
}
}
......@@ -53,6 +53,7 @@
<script>
import wepy from '@wepy/core';
import { getAwardsDetail, getPrizeList } from '../../common/api.js';
import {getProbability} from '../../common/utils';
wepy.component({
props: {
videoList: {
......@@ -230,12 +231,12 @@
},
updateAwardsInfo(current) {
if (this.curQueue[current]) {
const { id, photoUrl, name, probability } = this.curQueue[current];
const { id, photoUrl, name, coinQuantity } = this.curQueue[current];
this.$emit('getAwardsInfo', {
id,
photoUrl: encodeURIComponent(photoUrl),
name,
chance: probability
chance: getProbability(this.userAccount, coinQuantity)
});
}
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment