/*! bxs-vue-ui v3.3.0 */
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

require('../utils/entry-virtual.js');
var normalizeComponent = require('../utils/normalize-component.js');
require('../utils/object-create.js');
require('../utils/html.js');
require('../utils/es.number.constructor.js');
require('../utils/string-trim.js');
var _parseInt = require('../utils/parse-int.js');
require('../utils/a-function.js');
require('../utils/species-constructor.js');
require('../utils/es.string.split.js');
var isNan = require('../utils/is-nan.js');
require('../utils/es.number.to-fixed.js');
var _parseFloat = require('../utils/parse-float.js');

var quot = /"/g;

// B.2.3.2.1 CreateHTML(string, tag, attribute, value)
// https://tc39.github.io/ecma262/#sec-createhtml
var createHtml = function (string, tag, attribute, value) {
  var S = String(normalizeComponent.requireObjectCoercible(string));
  var p1 = '<' + tag;
  if (attribute !== '') p1 += ' ' + attribute + '="' + String(value).replace(quot, '&quot;') + '"';
  return p1 + '>' + S + '</' + tag + '>';
};

// check the existence of a method, lowercase
// of a tag and escaping quotes in arguments
var forcedStringHtmlMethod = function (METHOD_NAME) {
  return normalizeComponent.fails(function () {
    var test = ''[METHOD_NAME]('"');
    return test !== test.toLowerCase() || test.split('"').length > 3;
  });
};

// `String.prototype.fontsize` method
// https://tc39.github.io/ecma262/#sec-string.prototype.fontsize
normalizeComponent.$({ target: 'String', proto: true, forced: forcedStringHtmlMethod('fontsize') }, {
  fontsize: function fontsize(size) {
    return createHtml(this, 'font', 'size', size);
  }
});

var script = normalizeComponent.create({
  name: 'price',
  props: {
    // 价格数额
    price: {
      default: '0'
    },
    // 价格后缀单位
    suffix: {
      type: String,
      default: '元'
    },
    // 价格类型，默认1:1
    type: {
      type: String,
      default: 'normal'
    },
    // 是否精确到小数点后两位显示
    precise: {
      type: Boolean,
      default: true
    },
    // 价格前缀
    prefix: {
      type: String,
      default: ''
    },
    // 字体大小
    fontsize: {
      type: String,
      default: '20'
    },
    // 颜色
    color: {
      type: String,
      default: ''
    },
    // 删除线
    deleted: {
      type: Boolean,
      default: false
    }
  },
  data: function data() {
    return {};
  },
  computed: {
    priceText: function priceText() {
      var val = _parseFloat._parseFloat(this.price) || 0;
      return this.toFixed(val);
    },
    priceTextFront: function priceTextFront() {
      return this.prefix + this.priceText.split('.')[0];
    },
    priceTextEnd: function priceTextEnd() {
      var val = this.precise ? "." + (this.priceText.split('.')[1] || '00') : '';
      return val + this.suffix;
    },
    fontStyle: function fontStyle() {
      var size = isNan._Number$isNaN(Number(this.fontsize)) ? this.fontsize : this.fontsize + "px";
      var color = this.deleted ? '' : this.color;
      return {
        'font-size': size,
        color: color
      };
    },
    frontFontStyle: function frontFontStyle() {
      if (this.type === 'big') {
        var size = _parseFloat._parseFloat(this.fontsize) * 2;
        var fontsize = isNan._Number$isNaN(Number(this.fontsize)) ? size + this.fontsize.replace(/[0-9.]/g, '') : this.fontsize * 2 + "px";
        return {
          'font-size': fontsize
        };
      }

      return '';
    }
  },
  methods: {
    toFixed: function toFixed(value, decimal) {
      if (decimal === void 0) {
        decimal = 2;
      }

      // 四舍五入
      var symbol = value < 0 ? -1 : 1;
      /* eslint-disable */

      var times = Math.pow(10, decimal);
      /* eslint-enable */

      var des = symbol * value * times + 0.5;
      des = symbol * _parseInt._parseInt(des, 10) / times;
      des = des.toFixed(decimal);
      return des;
    }
  }
});

/* script */
var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    class: ['bx-price', {
      'bx-price--deleted': _vm.deleted
    }],
    style: _vm.fontStyle
  }, [_c('span', {
    style: _vm.frontFontStyle
  }, [_vm._v(_vm._s(_vm.priceTextFront))]), _c('span', [_vm._v(_vm._s(_vm.priceTextEnd))])]);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

var index = normalizeComponent.__vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

exports.default = index;
