背景:商品详情页对好评数进行统计,但是现在只有商品数据
使用wxs编写方法,module.exports导出,wxml中使用module名进行获取{{goodsRate.getRate(goodsInfoList)}}
<wxs module="goodsRate">
module.exports = {
getRate: function (goodsInfoList) {
if (!goodsInfoList || !goodsInfoList.basicInfo) {
return "100"
}
var goodReputation = goodsInfoList.basicInfo.numberGoodReputation / goodsInfoList.basicInfo.numberOrders * 100
goodReputation = goodReputation.toFixed(0)
return goodReputation
}
}
</wxs>
<view id="goods-rate" class="goods-rate-box">
<view class="label-title">
<view class="left">宝贝评价 {{basicInfo.numberGoodReputation}}</view>
<view class="right">好评度:{{goodsRate.getRate(goodsInfoList)}}%</view>
</view>
</view>