fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

143 lines
3.9 KiB

import { shortcut, Widget, extend, createWidget, isKey, Controller, bind, isNotNull, isNotEmptyString, getDate, parseInt } from "@/core";
import { Navigation } from "@/base";
import { YearCalendar } from "@/case";
/**
* 年份展示面板
*
* Created by GUY on 2015/9/2.
* @class YearPopup
* @extends Widget
*/
@shortcut()
export class YearPopup extends Widget {
static xtype = "bi.year_popup"
static EVENT_CHANGE = "EVENT_CHANGE"
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-year-popup",
behaviors: {},
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期
});
}
_createYearCalendar(v) {
const o = this.options,
y = this._year;
const calendar = createWidget({
type: "bi.year_calendar",
behaviors: o.behaviors,
min: o.min,
max: o.max,
logic: {
dynamic: true,
},
year: y + v * 12,
});
calendar.setValue(this._year);
return calendar;
}
_init() {
super._init(...arguments);
const o = this.options;
this.selectedYear = this._year = getDate().getFullYear();
this.backBtn = createWidget({
type: "bi.icon_button",
cls: "pre-page-h-font",
width: 24,
height: 24,
value: -1,
});
this.preBtn = createWidget({
type: "bi.icon_button",
cls: "next-page-h-font",
width: 24,
height: 24,
value: 1,
});
this.navigation = createWidget({
type: "bi.navigation",
element: this,
single: true,
logic: {
dynamic: true,
},
tab: {
cls: "year-popup-navigation bi-high-light bi-split-top",
height: 24,
items: [this.backBtn, this.preBtn],
},
cardCreator: bind(this._createYearCalendar, this),
afterCardCreated: () => {
this.navigation.setValue(this.selectedYear);
},
});
this.navigation.on(Navigation.EVENT_CHANGE, (...args) => {
this.selectedYear = this.navigation.getValue();
this.fireEvent(Controller.EVENT_CHANGE, ...args);
this.fireEvent(YearPopup.EVENT_CHANGE, this.selectedYear);
});
if (isKey(o.value)) {
this.setValue(o.value);
}
}
_checkMin() {
const calendar = this.navigation.getSelectedCard();
if (isNotNull(calendar)) {
calendar.setMinDate(this.options.min);
}
}
_checkMax() {
const calendar = this.navigation.getSelectedCard();
if (isNotNull(calendar)) {
calendar.setMaxDate(this.options.max);
}
}
setMinDate(minDate) {
if (isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this._checkMin();
}
}
setMaxDate(maxDate) {
if (isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this._checkMax();
}
}
getValue() {
return this.selectedYear;
}
setValue(v) {
v = parseInt(v);
// 切换年不受范围限制
// 对于年控件来说,只要传入的minDate和maxDate的year区间包含v就是合法的
// var startDate = parseDateTime(o.min, "%Y-%X-%d");
// var endDate = parseDateTime(o.max, "%Y-%X-%d");
// if (checkDateVoid(v, 1, 1, print(getDate(startDate.getFullYear(), 0, 1), "%Y-%X-%d"), print(getDate(endDate.getFullYear(), 0, 1), "%Y-%X-%d"))[0]) {
// v = getDate().getFullYear();
// }
this.selectedYear = v;
this.navigation.setSelect(YearCalendar.getPageByYear(v));
this.navigation.setValue(v);
}
}