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.

206 lines
5.9 KiB

import { shortcut, Widget, extend, createWidget, getDate, bind, Controller, isKey, HTapeLayout, CenterAdaptLayout, Layout, each, isNotEmptyString, checkDateVoid, parseInt } from "@/core";
import { YearCalendar } from "@/case";
import { IconButton, Navigation } from "@/base";
@shortcut()
export class StaticYearCard extends Widget {
static xtype = "bi.static_year_card";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-year-card",
behaviors: {},
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期
});
}
_createYearCalendar(v) {
const o = this.options,
y = this._year;
const calendar = createWidget({
type: YearCalendar.xtype,
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: IconButton.xtype,
cls: "pre-page-h-font",
width: 25,
height: 25,
value: -1,
listeners: [
{
eventName: IconButton.EVENT_CHANGE,
action :() => {
this.navigation.setSelect(
this.navigation.getSelect() - 1
);
this._checkLeftValid();
this._checkRightValid();
},
}
],
});
this.preBtn = createWidget({
type: IconButton.xtype,
cls: "next-page-h-font",
width: 25,
height: 25,
value: 1,
listeners: [
{
eventName: IconButton.EVENT_CHANGE,
action :() => {
this.navigation.setSelect(
this.navigation.getSelect() + 1
);
this._checkLeftValid();
this._checkRightValid();
},
}
],
});
this.navigation = createWidget({
type: Navigation.xtype,
direction: "top",
element: this,
single: true,
logic: {
dynamic: true,
},
tab: {
type: HTapeLayout.xtype,
cls: "bi-split-top bi-split-bottom",
height: 30,
items: [
{
el: {
type: CenterAdaptLayout.xtype,
items: [this.backBtn],
},
width: 25,
},
{
type: Layout.xtype,
},
{
el: {
type: CenterAdaptLayout.xtype,
items: [this.preBtn],
},
width: 25,
}
],
},
cardCreator: bind(this._createYearCalendar, this),
afterCardShow: () => {
this.navigation.setValue(this.selectedYear);
// var calendar = this.getSelectedCard();
// this.backBtn.setEnable(!calendar.isFrontYear());
// this.preBtn.setEnable(!calendar.isFinalYear());
},
});
this.navigation.on(Navigation.EVENT_CHANGE, () => {
this.selectedYear = this.navigation.getValue();
this.fireEvent(Controller.EVENT_CHANGE, ...arguments);
this.fireEvent(StaticYearCard.EVENT_CHANGE, this.selectedYear);
});
if (isKey(o.value)) {
this.setValue(o.value);
}
}
_checkLeftValid() {
const valid = true;
this.backBtn.setEnable(valid);
return valid;
}
_checkRightValid() {
const valid = true;
this.preBtn.setEnable(valid);
return valid;
}
_checkMin() {
const o = this.options;
each(this.navigation.getAllCard(), (idx, calendar) => {
calendar.setMinDate(o.min);
});
}
_checkMax() {
const o = this.options;
each(this.navigation.getAllCard(), (idx, calendar) => {
calendar.setMaxDate(o.max);
});
}
setMinDate(minDate) {
if (isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this._checkLeftValid();
this._checkRightValid();
this._checkMin();
}
}
setMaxDate(maxDate) {
if (isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this._checkLeftValid();
this._checkRightValid();
this._checkMax();
}
}
getValue() {
return {
year: this.selectedYear,
};
}
setValue(obj) {
const o = this.options;
obj = obj || {};
let v = obj.year;
if (checkDateVoid(v, 1, 1, o.min, o.max)[0]) {
v = getDate().getFullYear();
this.selectedYear = "";
this.navigation.setSelect(YearCalendar.getPageByYear(v));
this.navigation.setValue("");
} else {
this.selectedYear = parseInt(v);
this.navigation.setSelect(YearCalendar.getPageByYear(v));
this.navigation.setValue(this.selectedYear);
}
this._checkLeftValid();
this._checkRightValid();
}
}