import { getRangeYears } from './utils';
import "./quarter-select.css";
import './quarter-select-sfc.css';

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

  var _h = _vm.$createElement;

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

  return _c('div', {
    ref: "body",
    staticClass: "van-calendar__body"
  }, _vm._l(_vm.years, function (y) {
    return _c('div', {
      key: y,
      staticClass: "van-calendar__month"
    }, [_c('div', {
      staticClass: "van-calendar__month-title"
    }, [_vm._v(_vm._s(y) + "年")]), _vm._v(" "), _c('div', {
      staticClass: "van-calendar__days"
    }, _vm._l(_vm.cnQuarters, function (value, key) {
      return _c('div', {
        key: key,
        staticClass: "van-calendar__day ks-quarter__day",
        on: {
          "click": function click($event) {
            return _vm.handleSelect(y, key);
          }
        }
      }, [_c('div', {
        class: {
          'ks-quarter__selected-day': String(y) === String(_vm.currentYear) && String(key) === String(_vm.currentQuarter)
        }
      }, [_vm._v("\n          " + _vm._s(value) + "\n        ")])]);
    }), 0)]);
  }), 0);
};

var __vue_staticRenderFns__ = [];
export default {
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__,
  name: 'quarter-select',
  props: {
    defaultValue: {
      type: String,
      default: function () {
        var _quarters = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4];

        var _date = new Date();

        var y = _date.getFullYear();

        var m = _date.getMonth();

        return y + "-" + _quarters[m];
      }()
    },
    yearRange: {
      type: Array,
      default: function _default() {
        return [new Date().getFullYear() - 2, new Date().getFullYear()];
      }
    },
    horizontal: {
      type: Boolean,
      default: false
    }
  },
  data: function data() {
    return {
      years: getRangeYears(this.yearRange),
      cnQuarters: {
        '1': '一季度',
        '2': '二季度',
        '3': '三季度',
        '4': '四季度'
      },
      currentYear: null,
      currentQuarter: null
    };
  },
  methods: {
    init: function init() {
      var arr = this.defaultValue.split('-');
      this.handleSelect(arr[0], arr[1]);
      this.scrollInto();
    },
    scrollInto: function scrollInto() {
      var _this = this;

      setTimeout(function () {
        var top = _this.$el.querySelector('.ks-quarte__selected-day');

        _this.$refs.body.scrollTop = top ? top.getBoundingClientRect().top - 100 : 0;
      }, 240);
    },
    handleSelect: function handleSelect(y, q) {
      this.currentYear = y;
      this.currentQuarter = q;
      this.$emit('select', {
        year: y,
        quarter: q,
        cn: this.cnQuarters[q]
      });
    }
  }
};