/*! 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/sloppy-array-method.js');
var indexOf = require('../utils/index-of.js');
require('../utils/string-trim.js');
var _parseInt = require('../utils/parse-int.js');
var icon = require('../icon/index.js');
var isNan = require('../utils/is-nan.js');
require('../utils/es.number.to-fixed.js');
var _parseFloat = require('../utils/parse-float.js');

var _components;
var count = 5;
var script = normalizeComponent.create({
  name: 'rate',
  data: function data() {
    var iconSize;

    if (this.size) {
      if (isNan._Number$isNaN(Number(this.size))) {
        iconSize = this.size;
      } else {
        iconSize = this.size + "px";
      }
    } else {
      iconSize = this.position === 'right' ? '18px' : '30px';
    }

    return {
      currentValue: this.value,
      iconSize: iconSize,
      count: count,
      beforeTouchValue: this.value,
      currentTag: this.tag,
      defaultTagList: ['服务好', '速度快', '效率高']
    };
  },
  props: {
    value: {
      type: Number,
      default: null,
      validator: function validator(value) {
        return value <= count;
      }
    },
    textList: {
      type: Array,
      default: function _default() {
        return ['非常差', '差', '一般', '好', '非常好'];
      }
    },
    size: {
      type: String,
      default: null
    },
    position: {
      type: String,
      default: 'bottom',
      validator: function validator(value) {
        var _context;

        // 这个值必须匹配下列字符串中的一个
        return indexOf._indexOfInstanceProperty(_context = ['bottom', 'right']).call(_context, value) !== -1;
      }
    },
    color: {
      type: String,
      default: '#FF9224'
    },
    voidColor: {
      type: String,
      default: '#E5E5E5'
    },
    readonly: {
      type: Boolean,
      default: false
    },
    tag: {
      type: Number,
      default: null
    },
    tagList: {
      type: [Boolean, Array]
    },
    starWidth: {
      type: String,
      default: '114px'
    },
    starSize: {
      type: String,
      required: false,
      default: ''
    },
    rateLabel: {
      type: String,
      required: ''
    },
    showRateNum: {
      type: Boolean,
      required: false,
      default: true
    }
  },
  methods: {
    setCurrentValue: function setCurrentValue(value) {
      if (!this.readonly && this.currentValue !== value) {
        this.currentValue = value;
        this.$emit('change', this.currentValue, this.currentTag);
      }
    },
    setCurrentTag: function setCurrentTag(tag) {
      if (!this.readonly) {
        if (this.currentTag !== tag) {
          this.currentTag = tag;
        } else {
          this.currentTag = null;
        }

        this.$emit('change', this.currentValue, this.currentTag);
      }
    },
    touchstartRate: function touchstartRate() {
      this.beforeTouchValue = this.currentValue;
    },
    touchmoveRate: function touchmoveRate(event) {
      if (document.elementFromPoint) {
        var getTouchElement = document.elementFromPoint(event.touches[0].clientX, event.touches[0].clientY);

        if (getTouchElement && getTouchElement.dataset && getTouchElement.dataset.rateValue !== undefined) {
          if (!this.readonly && this.currentValue !== getTouchElement.dataset.rateValue) {
            this.currentValue = getTouchElement.dataset.rateValue;
          }
        }
      } else {
        var _getTouchElement = event.currentTarget;

        if (_getTouchElement && event.touches[0]) {
          var distanceX = event.touches[0].clientX - _getTouchElement.offsetLeft;
          var touchRateValue = Math.ceil(distanceX / (_getTouchElement.offsetWidth / this.count));

          if (touchRateValue < 1) {
            touchRateValue = 1;
          }

          if (touchRateValue > this.count) {
            touchRateValue = this.count;
          }

          if (!this.readonly && this.currentValue !== touchRateValue) {
            this.currentValue = touchRateValue;
          }
        }
      }
    },
    touchendRate: function touchendRate() {
      if (!this.readonly && this.currentValue !== this.beforeTouchValue) {
        this.$emit('change', this.currentValue, this.currentTag);
      }
    },
    // 星星裁切框的宽度
    getClipperWidth: function getClipperWidth(n) {
      return this.currentValue % 1 && n > this.currentValue ? this.currentValue % 1 * 100 + "%" : '100%';
    },
    // 评分文案
    getRateText: function getRateText() {
      return this.textList[_parseInt._parseInt((this.currentValue > count ? count : this.currentValue) - 1, 10)] || '请选择评分';
    }
  },
  components: (_components = {}, _components[icon.default.name] = icon.default, _components),
  computed: {
    txFontSize: function txFontSize() {
      return _parseFloat._parseFloat(this.iconSize) * (13 / 30) + this.iconSize.replace(/(\d|\.)+/g, '');
    }
  }
});

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', {
    staticClass: "bx-rate-wrapper",
    style: {
      display: _vm.position === 'right' ? 'inline-block' : 'block'
    }
  }, [_vm.position === 'right' ? _c('div', {
    staticClass: "bx-rate-content bx-rate-right"
  }, [_vm.rateLabel ? _c('label', {
    staticClass: "bx-rate-label"
  }, [_vm._v("\n      " + _vm._s(_vm.rateLabel) + "\n    ")]) : _vm._e(), _c('div', {
    staticClass: "bx-rate-star-wrapper"
  }, [_c('ul', {
    staticClass: "bx-rate-star",
    style: {
      width: _vm.starWidth
    },
    on: {
      "touchstart": _vm.touchstartRate,
      "touchmove": _vm.touchmoveRate,
      "touchend": _vm.touchendRate,
      "touchcancel": _vm.touchendRate
    }
  }, _vm._l(_vm.count, function (n) {
    return _c('li', {
      key: n,
      staticClass: "bx-rate-star-li",
      attrs: {
        "data-rate-value": n
      },
      on: {
        "click": function click($event) {
          _vm.setCurrentValue(n);
        }
      }
    }, [_c('span', {
      staticClass: "bx-rate-star-li-wrapper"
    }, [_c('bxs-icon', {
      staticClass: "bx-rate-star-li-icon",
      class: n < Math.ceil(_vm.currentValue) ? 'bx-rate-star-li-icon--opacity' : '',
      style: {
        fontSize: _vm.starSize || _vm.iconSize,
        color: _vm.voidColor
      },
      attrs: {
        "name": "star-solid"
      }
    }), n <= Math.ceil(_vm.currentValue) ? _c('span', {
      staticClass: "bx-rate-star-li-clipper",
      style: {
        width: _vm.getClipperWidth(n)
      }
    }, [_c('bxs-icon', {
      staticClass: "bx-rate-star-li-icon",
      style: {
        fontSize: _vm.starSize || _vm.iconSize,
        color: _vm.color
      },
      attrs: {
        "name": "star-solid"
      }
    })], 1) : _vm._e()], 1)]);
  }))]), _vm.showRateNum ? _c('span', {
    staticClass: "bx-rate-number",
    style: {
      color: _vm.currentValue === null ? '#ccc' : _vm.color
    }
  }, [_vm._v("\n      " + _vm._s(_vm.currentValue === null ? '0.0' : (_vm.currentValue * 1).toFixed(1)) + "\n    ")]) : _vm._e(), _vm.textList && _vm.textList.length && _vm.currentValue ? _c('span', {
    staticClass: "bx-rate-text"
  }, [_vm._v("\n      " + _vm._s(_vm.getRateText()) + "\n    ")]) : _vm._e()]) : _c('div', {
    staticClass: "bx-rate-content bx-rate-bottom"
  }, [_vm.showRateNum ? _c('header', {
    staticClass: "bx-rate-header",
    style: {
      color: _vm.currentValue === null ? '#ccc' : _vm.color
    }
  }, [_vm._v("\n      " + _vm._s(_vm.currentValue === null ? '0.0' : (_vm.currentValue * 1).toFixed(1)) + "分\n    ")]) : _vm._e(), _c('ul', {
    staticClass: "bx-rate-star",
    on: {
      "touchstart": _vm.touchstartRate,
      "touchmove": _vm.touchmoveRate,
      "touchend": _vm.touchendRate,
      "touchcancel": _vm.touchendRate
    }
  }, _vm._l(_vm.count, function (n) {
    return _c('li', {
      key: n,
      staticClass: "bx-rate-star-li",
      attrs: {
        "data-rate-value": n
      },
      on: {
        "click": function click($event) {
          _vm.setCurrentValue(n);
        }
      }
    }, [_c('bxs-icon', {
      staticClass: "bx-rate-star-li-icon",
      class: n < Math.ceil(_vm.currentValue) ? 'bx-rate-star-li-icon--opacity' : '',
      style: {
        fontSize: _vm.iconSize,
        color: _vm.voidColor
      },
      attrs: {
        "name": "star-solid"
      }
    }), n <= Math.ceil(_vm.currentValue) ? _c('span', {
      staticClass: "bx-rate-star-li-clipper",
      style: {
        width: _vm.getClipperWidth(n)
      }
    }, [_c('bxs-icon', {
      staticClass: "bx-rate-star-li-icon",
      style: {
        fontSize: _vm.iconSize,
        color: _vm.color
      },
      attrs: {
        "name": "star-solid"
      }
    })], 1) : _vm._e()], 1);
  })), _vm.textList && _vm.textList.length ? _c('p', {
    staticClass: "bx-rate-text",
    style: {
      color: _vm.currentValue === null ? '#999' : _vm.color,
      fontSize: _vm.txFontSize
    }
  }, [_vm._v("\n      " + _vm._s(_vm.getRateText()) + "\n    ")]) : _vm._e(), _vm.tagList ? _c('ul', {
    staticClass: "bx-rate-tag"
  }, _vm._l(_vm.tagList.constructor === Array ? _vm.tagList : _vm.defaultTagList, function (t, ti) {
    return _c('li', {
      key: t,
      staticClass: "bx-rate-tag-li",
      style: {
        'color': ti === _vm.currentTag ? _vm.color : '#333',
        'border-color': ti === _vm.currentTag ? _vm.color : '#ccc'
      },
      on: {
        "click": function click($event) {
          _vm.setCurrentTag(ti);
        }
      }
    }, [_vm._v("\n        " + _vm._s(t) + "\n      ")]);
  })) : _vm._e()])]);
};

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;
