const wx2my = require('../../wx2my');
const Behavior = require('../../Behavior');
var utils = require('../../wxs/utils.wxs');

function hanlderIntegralPrice(product) {
  var integarlGoods, singleGoods, maxIntegarlPrice, minPrice, maxPrice, prices, minIntegarlPrice;
  integarlGoods = product.exchange_credits > 0;
  singleGoods = product.minSkuPrice === product.maxSkuPrice;
  minPrice = utils.numberFormat(product.minSkuPrice / 100) || 0;
  maxPrice = utils.numberFormat(product.maxSkuPrice / 100) || 0;
  prices = '';

  if (integarlGoods) {
    minIntegarlPrice = utils.numberFormat(product.exchange_credits * product.integral_role / 100 - product.minSkuPrice / 100) || 0;
    maxIntegarlPrice = utils.numberFormat(product.exchange_credits * product.integral_role / 100 - product.maxSkuPrice / 100) || 0;
    prices = minIntegarlPrice * 1 < 0 ? product.exchange_credits + '积分+￥' + Math.abs(minIntegarlPrice) : product.exchange_credits + '积分';
  } else if (singleGoods && !integarlGoods) {
    prices = maxPrice;
  } else {
    prices = ['￥', minPrice, '-', maxPrice].join('');
  }

  return prices;
}

module.exports = {
  hanlderIntegralPrice: hanlderIntegralPrice
};