impact
2 years ago
9 changed files with 1279 additions and 900 deletions
@ -1,166 +1,212 @@
|
||||
/** |
||||
* 年月展示面板 |
||||
* |
||||
* Created by GUY on 2015/9/2. |
||||
* @class BI.YearCard |
||||
* @extends BI.Trigger |
||||
*/ |
||||
BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { |
||||
|
||||
props: { |
||||
baseCls: "bi-year-month-card" |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this; |
||||
import { |
||||
shortcut, |
||||
Widget, |
||||
i18nText, |
||||
bind, |
||||
VerticalLayout, |
||||
parseDateTime, |
||||
extend, |
||||
checkDateVoid, |
||||
isNotEmptyString |
||||
} from "@/core"; |
||||
import { DynamicDateCard, DynamicDateParamItem, DynamicDateHelper } from "../dynamicdate"; |
||||
import { Label, Bubbles } from "@/base"; |
||||
|
||||
@shortcut() |
||||
export class DynamicYearMonthCard extends Widget { |
||||
static xtype = "bi.dynamic_year_month_card"; |
||||
|
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
props = { baseCls: "bi-year-month-card" }; |
||||
|
||||
render() { |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
type: "bi.label", |
||||
text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), |
||||
textAlign: "left", |
||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
||||
}, { |
||||
type: "bi.vertical", |
||||
ref: function (_ref) { |
||||
self.wrapper = _ref; |
||||
type: VerticalLayout.xtype, |
||||
items: [ |
||||
{ |
||||
type: Label.xtype, |
||||
text: i18nText("BI-Multi_Date_Relative_Current_Time"), |
||||
textAlign: "left", |
||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
||||
}, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.dynamic_date_param_item", |
||||
validationChecker: BI.bind(self._checkDate, self), |
||||
ref: function () { |
||||
self.year = this; |
||||
}, |
||||
listeners: [{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function () { |
||||
self.fireEvent("EVENT_CHANGE"); |
||||
} |
||||
}, { |
||||
eventName: "EVENT_INPUT_CHANGE", |
||||
action: function () { |
||||
BI.Bubbles.hide("dynamic-year-month-error"); |
||||
} |
||||
}] |
||||
}, |
||||
bgap: 10, |
||||
}, { |
||||
type: "bi.dynamic_date_param_item", |
||||
dateType: BI.DynamicDateCard.TYPE.MONTH, |
||||
ref: function () { |
||||
self.month = this; |
||||
{ |
||||
type: VerticalLayout.xtype, |
||||
ref: _ref => { |
||||
this.wrapper = _ref; |
||||
}, |
||||
listeners: [{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function () { |
||||
self.fireEvent("EVENT_CHANGE"); |
||||
} |
||||
}, { |
||||
eventName: "EVENT_INPUT_CHANGE", |
||||
action: function () { |
||||
BI.Bubbles.hide("dynamic-year-month-error"); |
||||
items: [ |
||||
{ |
||||
el: { |
||||
type: DynamicDateParamItem.xtype, |
||||
validationChecker: bind(this._checkDate, this), |
||||
ref: _ref => { |
||||
this.year = _ref; |
||||
}, |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: () => { |
||||
this.fireEvent("EVENT_CHANGE"); |
||||
}, |
||||
}, |
||||
{ |
||||
eventName: "EVENT_INPUT_CHANGE", |
||||
action: () => { |
||||
Bubbles.hide( |
||||
"dynamic-year-month-error" |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
}, |
||||
bgap: 10, |
||||
}, |
||||
{ |
||||
type: DynamicDateParamItem.xtype, |
||||
dateType: DynamicDateCard.TYPE.MONTH, |
||||
ref: _ref => { |
||||
this.month = _ref; |
||||
}, |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: () => { |
||||
this.fireEvent("EVENT_CHANGE"); |
||||
}, |
||||
}, |
||||
{ |
||||
eventName: "EVENT_INPUT_CHANGE", |
||||
action: () => { |
||||
Bubbles.hide( |
||||
"dynamic-year-month-error" |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
} |
||||
}] |
||||
}] |
||||
}], |
||||
], |
||||
} |
||||
], |
||||
vgap: 10, |
||||
hgap: 10 |
||||
hgap: 10, |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
_getErrorText() { |
||||
const o = this.options; |
||||
const start = parseDateTime(o.min, "%Y-%X-%d"); |
||||
const end = parseDateTime(o.max, "%Y-%X-%d"); |
||||
|
||||
_getErrorText: function () { |
||||
var o = this.options; |
||||
var start = BI.parseDateTime(o.min, "%Y-%X-%d"); |
||||
var end = BI.parseDateTime(o.max, "%Y-%X-%d"); |
||||
return BI.i18nText("BI-Basic_Year_Month_Range_Error", |
||||
return i18nText( |
||||
"BI-Basic_Year_Month_Range_Error", |
||||
start.getFullYear(), |
||||
start.getMonth() + 1, |
||||
end.getFullYear(), |
||||
end.getMonth() + 1 |
||||
); |
||||
}, |
||||
} |
||||
|
||||
_checkDate: function (obj) { |
||||
var o = this.options; |
||||
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this._getValue(), this._digestDateTypeValue(obj))); |
||||
_checkDate(obj) { |
||||
const o = this.options; |
||||
const date = DynamicDateHelper.getCalculation( |
||||
extend(this._getValue(), this._digestDateTypeValue(obj)) |
||||
); |
||||
|
||||
return !BI.checkDateVoid(date.getFullYear(), date.getMonth() + 1, date.getDate(), o.min, o.max)[0]; |
||||
}, |
||||
return !checkDateVoid( |
||||
date.getFullYear(), |
||||
date.getMonth() + 1, |
||||
date.getDate(), |
||||
o.min, |
||||
o.max |
||||
)[0]; |
||||
} |
||||
|
||||
_digestDateTypeValue: function (value) { |
||||
var valueMap = {}; |
||||
_digestDateTypeValue(value) { |
||||
const valueMap = {}; |
||||
switch (value.dateType) { |
||||
case BI.DynamicDateCard.TYPE.YEAR: |
||||
valueMap.year = (value.offset === 0 ? -value.value : +value.value); |
||||
break; |
||||
case BI.DynamicDateCard.TYPE.MONTH: |
||||
valueMap.month = (value.offset === 0 ? -value.value : +value.value); |
||||
break; |
||||
default: |
||||
break; |
||||
case DynamicDateCard.TYPE.YEAR: |
||||
valueMap.year = |
||||
value.offset === 0 ? -value.value : +value.value; |
||||
break; |
||||
case DynamicDateCard.TYPE.MONTH: |
||||
valueMap.month = |
||||
value.offset === 0 ? -value.value : +value.value; |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
|
||||
return valueMap; |
||||
}, |
||||
} |
||||
|
||||
_createValue: function (type, v) { |
||||
_createValue(type, v) { |
||||
return { |
||||
dateType: type, |
||||
value: Math.abs(v), |
||||
offset: v > 0 ? 1 : 0 |
||||
offset: v > 0 ? 1 : 0, |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
setMinDate: function(minDate) { |
||||
if (BI.isNotEmptyString(this.options.min)) { |
||||
setMinDate(minDate) { |
||||
if (isNotEmptyString(this.options.min)) { |
||||
this.options.min = minDate; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setMaxDate: function (maxDate) { |
||||
if (BI.isNotEmptyString(this.options.max)) { |
||||
setMaxDate(maxDate) { |
||||
if (isNotEmptyString(this.options.max)) { |
||||
this.options.max = maxDate; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setValue(v) { |
||||
v = v || { year: 0, month: 0 }; |
||||
this.year.setValue( |
||||
this._createValue(DynamicDateCard.TYPE.YEAR, v.year) |
||||
); |
||||
this.month.setValue( |
||||
this._createValue(DynamicDateCard.TYPE.MONTH, v.month) |
||||
); |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
v = v || {year: 0, month: 0}; |
||||
this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); |
||||
this.month.setValue(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); |
||||
}, |
||||
_getValue() { |
||||
const year = this.year.getValue(); |
||||
const month = this.month.getValue(); |
||||
|
||||
_getValue: function () { |
||||
var year = this.year.getValue(); |
||||
var month = this.month.getValue(); |
||||
return { |
||||
year: (year.offset === 0 ? -year.value : year.value), |
||||
month: (month.offset === 0 ? -month.value : month.value) |
||||
year: year.offset === 0 ? -year.value : year.value, |
||||
month: month.offset === 0 ? -month.value : month.value, |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
getInputValue: function () { |
||||
getInputValue() { |
||||
return this._getValue(); |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return this.checkValidation() ? this._getValue() : {}; |
||||
}, |
||||
} |
||||
|
||||
checkValidation: function (show) { |
||||
var errorText; |
||||
var yearInvalid = !this.year.checkValidation(); |
||||
var monthInvalid = !this.month.checkValidation(); |
||||
var invalid = yearInvalid || monthInvalid; |
||||
checkValidation(show) { |
||||
let errorText; |
||||
const yearInvalid = !this.year.checkValidation(); |
||||
const monthInvalid = !this.month.checkValidation(); |
||||
let invalid = yearInvalid || monthInvalid; |
||||
if (invalid) { |
||||
errorText = BI.i18nText("BI-Please_Input_Natural_Number"); |
||||
errorText = i18nText("BI-Please_Input_Natural_Number"); |
||||
} else { |
||||
invalid = !this._checkDate(this._getValue()); |
||||
errorText = this._getErrorText(); |
||||
} |
||||
invalid && show && BI.Bubbles.show("dynamic-year-month-error", errorText, this.wrapper); |
||||
invalid && |
||||
show && |
||||
Bubbles.show( |
||||
"dynamic-year-month-error", |
||||
errorText, |
||||
this.wrapper |
||||
); |
||||
|
||||
return !invalid; |
||||
}, |
||||
}); |
||||
BI.DynamicYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard); |
||||
} |
||||
} |
||||
|
@ -1,171 +1,215 @@
|
||||
BI.StaticYearMonthCard = BI.inherit(BI.Widget, { |
||||
import { |
||||
shortcut, |
||||
Widget, |
||||
chunk, |
||||
map, |
||||
toPix, |
||||
extend, |
||||
VerticalLayout, |
||||
CenterAdaptLayout, |
||||
parseDateTime, |
||||
each, |
||||
checkDateVoid, |
||||
contains, |
||||
getDate, |
||||
parseInt |
||||
} from "@/core"; |
||||
import { TextItem, ButtonGroup } from "@/base"; |
||||
import { YearPicker } from "../date/calendar"; |
||||
|
||||
props: { |
||||
baseCls: "bi-static-year-month-card", |
||||
behaviors: {} |
||||
}, |
||||
@shortcut() |
||||
export class StaticYearMonthCard extends Widget { |
||||
static xtype = "bi.static_year_month_card"; |
||||
|
||||
_createMonths: function () { |
||||
var self = this; |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
props = { baseCls: "bi-static-year-month-card", behaviors: {} }; |
||||
|
||||
_createMonths() { |
||||
// 纵向排列月
|
||||
var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; |
||||
var items = BI.chunk(month, 2); |
||||
return BI.map(items, function (i, item) { |
||||
return BI.map(item, function (j, td) { |
||||
return { |
||||
type: "bi.text_item", |
||||
cls: "bi-list-item-select", |
||||
textAlign: "center", |
||||
whiteSpace: "nowrap", |
||||
once: false, |
||||
forceSelected: true, |
||||
height: BI.toPix(BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, 1), |
||||
width: 38, |
||||
value: td, |
||||
text: td, |
||||
ref: function (_ref) { |
||||
self.monthMap[j === 0 ? i : i + 6] = _ref; |
||||
} |
||||
}; |
||||
}); |
||||
}); |
||||
}, |
||||
const month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; |
||||
const items = chunk(month, 2); |
||||
|
||||
return map(items, (i, item) => map(item, (j, td) => { |
||||
return { |
||||
type: TextItem.xtype, |
||||
cls: "bi-list-item-select", |
||||
textAlign: "center", |
||||
whiteSpace: "nowrap", |
||||
once: false, |
||||
forceSelected: true, |
||||
height: toPix(BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, 1), |
||||
width: 38, |
||||
value: td, |
||||
text: td, |
||||
ref: _ref => { |
||||
this.monthMap[j === 0 ? i : i + 6] = _ref; |
||||
}, |
||||
}; |
||||
})); |
||||
} |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
render() { |
||||
const o = this.options; |
||||
this.monthMap = {}; |
||||
|
||||
return { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
type: "bi.year_picker", |
||||
cls: "bi-split-bottom", |
||||
min: o.min, |
||||
max: o.max, |
||||
ref: function () { |
||||
self.yearPicker = this; |
||||
}, |
||||
behaviors: o.behaviors, |
||||
height: 30, |
||||
listeners: [{ |
||||
eventName: BI.YearPicker.EVENT_CHANGE, |
||||
action: function () { |
||||
var value = this.getValue(); |
||||
self._checkMonthStatus(value); |
||||
self._setYear(value); |
||||
} |
||||
}] |
||||
}, { |
||||
el: { |
||||
type: "bi.button_group", |
||||
behaviors: o.behaviors, |
||||
ref: function () { |
||||
self.month = this; |
||||
type: VerticalLayout.xtype, |
||||
items: [ |
||||
{ |
||||
type: YearPicker.xtype, |
||||
cls: "bi-split-bottom", |
||||
min: o.min, |
||||
max: o.max, |
||||
ref: _ref => { |
||||
this.yearPicker = _ref; |
||||
}, |
||||
items: this._createMonths(), |
||||
layouts: [BI.LogicFactory.createLogic("table", BI.extend({ |
||||
dynamic: true |
||||
}, { |
||||
columns: 2, |
||||
rows: 6, |
||||
columnSize: [1 / 2, 1 / 2], |
||||
rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 1 |
||||
})), { |
||||
type: "bi.center_adapt", |
||||
vgap: 1, |
||||
hgap: 2 |
||||
}], |
||||
value: o.value, |
||||
listeners: [{ |
||||
eventName: BI.ButtonGroup.EVENT_CHANGE, |
||||
action: function () { |
||||
self.selectedYear = self.yearPicker.getValue(); |
||||
self.selectedMonth = this.getValue()[0]; |
||||
self.fireEvent(BI.StaticYearMonthCard.EVENT_CHANGE); |
||||
behaviors: o.behaviors, |
||||
height: 30, |
||||
listeners: [ |
||||
{ |
||||
eventName: YearPicker.EVENT_CHANGE, |
||||
action: () => { |
||||
const value = this.yearPicker.getValue(); |
||||
this._checkMonthStatus(value); |
||||
this._setYear(value); |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}, |
||||
vgap: 5 |
||||
}] |
||||
{ |
||||
el: { |
||||
type: ButtonGroup.xtype, |
||||
behaviors: o.behaviors, |
||||
ref: _ref => { |
||||
this.month = _ref; |
||||
}, |
||||
items: this._createMonths(), |
||||
layouts: [ |
||||
BI.LogicFactory.createLogic( |
||||
"table", |
||||
extend( |
||||
{ |
||||
dynamic: true, |
||||
}, |
||||
{ |
||||
columns: 2, |
||||
rows: 6, |
||||
columnSize: [1 / 2, 1 / 2], |
||||
rowSize: |
||||
BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + |
||||
1, |
||||
} |
||||
) |
||||
), |
||||
{ |
||||
type: CenterAdaptLayout.xtype, |
||||
vgap: 1, |
||||
hgap: 2, |
||||
} |
||||
], |
||||
value: o.value, |
||||
listeners: [ |
||||
{ |
||||
eventName: ButtonGroup.EVENT_CHANGE, |
||||
action: () => { |
||||
this.selectedYear = this.yearPicker.getValue(); |
||||
this.selectedMonth = this.month.getValue()[0]; |
||||
this.fireEvent( |
||||
StaticYearMonthCard.EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
}, |
||||
vgap: 5, |
||||
} |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
created: function() { |
||||
created() { |
||||
this._checkMonthStatus(this.selectedYear); |
||||
}, |
||||
|
||||
_checkMonthStatus: function (year) { |
||||
var o = this.options; |
||||
var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"), maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); |
||||
var minYear = minDate.getFullYear(), maxYear = maxDate.getFullYear(); |
||||
var minMonth = 0; |
||||
var maxMonth = 11; |
||||
} |
||||
|
||||
_checkMonthStatus(year) { |
||||
const o = this.options; |
||||
const minDate = parseDateTime(o.min, "%Y-%X-%d"), |
||||
maxDate = parseDateTime(o.max, "%Y-%X-%d"); |
||||
const minYear = minDate.getFullYear(), |
||||
maxYear = maxDate.getFullYear(); |
||||
let minMonth = 0; |
||||
let maxMonth = 11; |
||||
minYear === year && (minMonth = minDate.getMonth()); |
||||
maxYear === year && (maxMonth = maxDate.getMonth()); |
||||
var yearInvalid = year < minYear || year > maxYear; |
||||
BI.each(this.monthMap, function (month, obj) { |
||||
var monthInvalid = month < minMonth || month > maxMonth; |
||||
const yearInvalid = year < minYear || year > maxYear; |
||||
each(this.monthMap, (month, obj) => { |
||||
const monthInvalid = month < minMonth || month > maxMonth; |
||||
obj.setEnable(!yearInvalid && !monthInvalid); |
||||
}); |
||||
}, |
||||
} |
||||
|
||||
_setYear: function (year) { |
||||
var o = this.options; |
||||
_setYear(year) { |
||||
const o = this.options; |
||||
|
||||
var dateVoid = BI.checkDateVoid(year, this.selectedMonth, 1, o.min, o.max); |
||||
const dateVoid = checkDateVoid(year, this.selectedMonth, 1, o.min, o.max); |
||||
|
||||
// 在切换年的时候,如果月份不在区间内了,取消选中
|
||||
if (BI.contains(["y", "m"], dateVoid[0])) { |
||||
if (contains(["y", "m"], dateVoid[0])) { |
||||
this.selectedYear = year; |
||||
this.month.setValue(); |
||||
|
||||
return; |
||||
} |
||||
|
||||
this.selectedYear = year; |
||||
this.month.setValue(this.selectedMonth); |
||||
}, |
||||
} |
||||
|
||||
setMinDate: function (minDate) { |
||||
setMinDate(minDate) { |
||||
if (this.options.min !== minDate) { |
||||
this.options.min = minDate; |
||||
this.yearPicker.setMinDate(minDate); |
||||
this._checkMonthStatus(this.selectedYear); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setMaxDate: function (maxDate) { |
||||
setMaxDate(maxDate) { |
||||
if (this.options.max !== maxDate) { |
||||
this.options.max = maxDate; |
||||
this.yearPicker.setMaxDate(maxDate); |
||||
this._checkMonthStatus(this.selectedYear); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return { |
||||
year: this.selectedYear, |
||||
month: this.selectedMonth |
||||
month: this.selectedMonth, |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
setValue: function (obj) { |
||||
var o = this.options; |
||||
var newObj = {}; |
||||
setValue(obj) { |
||||
const o = this.options; |
||||
const newObj = {}; |
||||
newObj.year = obj.year || 0; |
||||
newObj.month = obj.month || 0; |
||||
if (newObj.year === 0 || newObj.month === 0 || BI.checkDateVoid(newObj.year, newObj.month, 1, o.min, o.max)[0]) { |
||||
var year = newObj.year || BI.getDate().getFullYear(); |
||||
if ( |
||||
newObj.year === 0 || |
||||
newObj.month === 0 || |
||||
checkDateVoid(newObj.year, newObj.month, 1, o.min, o.max)[0] |
||||
) { |
||||
const year = newObj.year || getDate().getFullYear(); |
||||
this.selectedYear = year; |
||||
this.selectedMonth = ""; |
||||
this.yearPicker.setValue(year); |
||||
this.month.setValue(); |
||||
} else { |
||||
this.selectedYear = BI.parseInt(newObj.year); |
||||
this.selectedMonth = BI.parseInt(newObj.month); |
||||
this.selectedYear = parseInt(newObj.year); |
||||
this.selectedMonth = parseInt(newObj.month); |
||||
this.yearPicker.setValue(this.selectedYear); |
||||
this.month.setValue(this.selectedMonth); |
||||
} |
||||
this._checkMonthStatus(this.selectedYear); |
||||
} |
||||
}); |
||||
BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard); |
||||
} |
||||
|
@ -0,0 +1,5 @@
|
||||
export { DynamicYearMonthCard } from "./card.dynamic.yearmonth"; |
||||
export { StaticYearMonthCard } from "./card.static.yearmonth"; |
||||
export { DynamicYearMonthCombo } from "./combo.yearmonth"; |
||||
export { DynamicYearMonthPopup } from "./popup.yearmonth"; |
||||
export { DynamicYearMonthTrigger } from "./trigger.yearmonth"; |
@ -1,241 +1,329 @@
|
||||
/** |
||||
* 年月 |
||||
* |
||||
* Created by GUY on 2015/9/2. |
||||
* @class BI.DynamicYearMonthPopup |
||||
* @extends BI.Trigger |
||||
*/ |
||||
BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { |
||||
constants: { |
||||
tabHeight: 40, |
||||
}, |
||||
|
||||
props: { |
||||
import { |
||||
shortcut, |
||||
Widget, |
||||
toPix, |
||||
i18nText, |
||||
VerticalLayout, |
||||
GridLayout, |
||||
print, |
||||
getDate, |
||||
checkDateVoid, |
||||
createItems |
||||
} from "@/core"; |
||||
import { DynamicYearMonthCombo } from "./combo.yearmonth"; |
||||
import { TextButton, Tab } from "@/base"; |
||||
import { DynamicDateCombo, DynamicDateHelper } from "../dynamicdate"; |
||||
// import { DynamicYearCombo } from "../year/combo.year";
|
||||
import { StaticYearMonthCard } from "./card.static.yearmonth"; |
||||
import { LinearSegment } from "@/case"; |
||||
import { DynamicYearMonthCard } from "./card.dynamic.yearmonth"; |
||||
|
||||
@shortcut() |
||||
export class DynamicYearMonthPopup extends Widget { |
||||
static xtype = "bi.dynamic_year_month_popup"; |
||||
|
||||
constants = { tabHeight: 40 }; |
||||
props = { |
||||
baseCls: "bi-year-month-popup", |
||||
behaviors: {}, |
||||
min: "1900-01-01", // 最小日期
|
||||
max: "2099-12-31", // 最大日期,
|
||||
min: "1900-01-01", |
||||
max: "2099-12-31", |
||||
width: 180, |
||||
supportDynamic: true, |
||||
}, |
||||
}; |
||||
|
||||
static BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; |
||||
static BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; |
||||
static BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; |
||||
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
render() { |
||||
this.storeValue = { type: DynamicYearMonthCombo.Static }; |
||||
|
||||
render: function () { |
||||
var self = this, opts = this.options, c = this.constants; |
||||
this.storeValue = {type: BI.DynamicYearMonthCombo.Static}; |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
el: this._getTabJson() |
||||
}, { |
||||
el: { |
||||
type: "bi.grid", |
||||
items: [[{ |
||||
type: "bi.text_button", |
||||
cls: "bi-split-top bi-high-light", |
||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
||||
shadow: true, |
||||
text: BI.i18nText("BI-Basic_Clear"), |
||||
listeners: [{ |
||||
eventName: BI.TextButton.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE); |
||||
} |
||||
}] |
||||
}, { |
||||
type: "bi.text_button", |
||||
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
||||
shadow: true, |
||||
text: BI.i18nText("BI-Basic_Current_Month"), |
||||
disabled: this._checkTodayValid(), |
||||
ref: function () { |
||||
self.textButton = this; |
||||
}, |
||||
listeners: [{ |
||||
eventName: BI.TextButton.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE); |
||||
} |
||||
}] |
||||
}, { |
||||
type: "bi.text_button", |
||||
cls: "bi-split-top bi-high-light", |
||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
||||
shadow: true, |
||||
text: BI.i18nText("BI-Basic_OK"), |
||||
listeners: [{ |
||||
eventName: BI.TextButton.EVENT_CHANGE, |
||||
action: function () { |
||||
var type = self.dateTab.getSelect(); |
||||
if (type === BI.DynamicDateCombo.Dynamic) { |
||||
self.dynamicPane.checkValidation(true) && self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); |
||||
} else { |
||||
self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); |
||||
} |
||||
} |
||||
}] |
||||
}]], |
||||
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT |
||||
type: VerticalLayout.xtype, |
||||
items: [ |
||||
{ |
||||
el: this._getTabJson(), |
||||
}, |
||||
}] |
||||
{ |
||||
el: { |
||||
type: GridLayout.xtype, |
||||
items: [ |
||||
[ |
||||
{ |
||||
type: TextButton.xtype, |
||||
cls: "bi-split-top bi-high-light", |
||||
textHeight: toPix( |
||||
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
1 |
||||
), |
||||
shadow: true, |
||||
text: i18nText("BI-Basic_Clear"), |
||||
listeners: [ |
||||
{ |
||||
eventName: TextButton.EVENT_CHANGE, |
||||
action: () => { |
||||
this.fireEvent( |
||||
DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
}, |
||||
{ |
||||
type: TextButton.xtype, |
||||
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
||||
textHeight: toPix( |
||||
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
1 |
||||
), |
||||
shadow: true, |
||||
text: i18nText("BI-Basic_Current_Month"), |
||||
disabled: this._checkTodayValid(), |
||||
ref: _ref => { |
||||
this.textButton = _ref; |
||||
}, |
||||
listeners: [ |
||||
{ |
||||
eventName: TextButton.EVENT_CHANGE, |
||||
action: () => { |
||||
this.fireEvent( |
||||
DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
], |
||||
}, |
||||
{ |
||||
type: TextButton.xtype, |
||||
cls: "bi-split-top bi-high-light", |
||||
textHeight: toPix( |
||||
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
1 |
||||
), |
||||
shadow: true, |
||||
text: i18nText("BI-Basic_OK"), |
||||
listeners: [ |
||||
{ |
||||
eventName: TextButton.EVENT_CHANGE, |
||||
action: () => { |
||||
const type = |
||||
this.dateTab.getSelect(); |
||||
if ( |
||||
type === |
||||
DynamicDateCombo.Dynamic |
||||
) { |
||||
this.dynamicPane.checkValidation( |
||||
true |
||||
) && |
||||
this.fireEvent( |
||||
DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE |
||||
); |
||||
} else { |
||||
this.fireEvent( |
||||
DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE |
||||
); |
||||
} |
||||
}, |
||||
} |
||||
], |
||||
} |
||||
] |
||||
], |
||||
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||
}, |
||||
} |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
_setInnerValue: function () { |
||||
if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { |
||||
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); |
||||
_setInnerValue() { |
||||
if (this.dateTab.getSelect() === DynamicDateCombo.Static) { |
||||
this.textButton.setValue(i18nText("BI-Basic_Current_Month")); |
||||
this.textButton.setEnable(!this._checkTodayValid()); |
||||
} else { |
||||
var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getInputValue()); |
||||
date = BI.print(date, "%Y-%x"); |
||||
let date = DynamicDateHelper.getCalculation( |
||||
this.dynamicPane.getInputValue() |
||||
); |
||||
date = print(date, "%Y-%x"); |
||||
this.textButton.setValue(date); |
||||
this.textButton.setEnable(false); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
_checkTodayValid() { |
||||
const o = this.options; |
||||
const today = getDate(); |
||||
|
||||
return !!checkDateVoid( |
||||
today.getFullYear(), |
||||
today.getMonth() + 1, |
||||
today.getDate(), |
||||
o.min, |
||||
o.max |
||||
)[0]; |
||||
} |
||||
|
||||
_checkTodayValid: function () { |
||||
var o = this.options; |
||||
var today = BI.getDate(); |
||||
return !!BI.checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0]; |
||||
}, |
||||
_getTabJson() { |
||||
const o = this.options; |
||||
|
||||
_getTabJson: function () { |
||||
var self = this, o = this.options; |
||||
return { |
||||
type: "bi.tab", |
||||
type: Tab.xtype, |
||||
logic: { |
||||
dynamic: true |
||||
dynamic: true, |
||||
}, |
||||
ref: function () { |
||||
self.dateTab = this; |
||||
ref: _ref => { |
||||
this.dateTab = _ref; |
||||
}, |
||||
tab: { |
||||
type: "bi.linear_segment", |
||||
type: LinearSegment.xtype, |
||||
cls: "bi-split-bottom", |
||||
invisible: !o.supportDynamic, |
||||
height: this.constants.tabHeight, |
||||
items: BI.createItems([{ |
||||
text: BI.i18nText("BI-Basic_Year_Month"), |
||||
value: BI.DynamicYearCombo.Static |
||||
}, { |
||||
text: BI.i18nText("BI-Basic_Dynamic_Title"), |
||||
value: BI.DynamicYearCombo.Dynamic |
||||
}], { |
||||
textAlign: "center" |
||||
}) |
||||
items: createItems( |
||||
[ |
||||
{ |
||||
text: i18nText("BI-Basic_Year_Month"), |
||||
value: BI.DynamicYearCombo.Static, |
||||
}, |
||||
{ |
||||
text: i18nText("BI-Basic_Dynamic_Title"), |
||||
value: BI.DynamicYearCombo.Dynamic, |
||||
} |
||||
], |
||||
{ |
||||
textAlign: "center", |
||||
} |
||||
), |
||||
}, |
||||
cardCreator: function (v) { |
||||
cardCreator: v => { |
||||
switch (v) { |
||||
case BI.DynamicYearCombo.Dynamic: |
||||
return { |
||||
type: "bi.dynamic_year_month_card", |
||||
cls: "dynamic-year-month-pane", |
||||
min: self.options.min, |
||||
max: self.options.max, |
||||
listeners: [{ |
||||
case BI.DynamicYearCombo.Dynamic: |
||||
return { |
||||
type: DynamicYearMonthCard.xtype, |
||||
cls: "dynamic-year-month-pane", |
||||
min: this.options.min, |
||||
max: this.options.max, |
||||
listeners: [ |
||||
{ |
||||
eventName: "EVENT_CHANGE", |
||||
action: function () { |
||||
self._setInnerValue(self.year, v); |
||||
} |
||||
}], |
||||
ref: function () { |
||||
self.dynamicPane = this; |
||||
action: () => { |
||||
this._setInnerValue(this.year, v); |
||||
}, |
||||
} |
||||
}; |
||||
case BI.DynamicYearCombo.Static: |
||||
default: |
||||
return { |
||||
type: "bi.static_year_month_card", |
||||
behaviors: o.behaviors, |
||||
min: self.options.min, |
||||
max: self.options.max, |
||||
listeners: [{ |
||||
eventName: BI.StaticYearMonthCard.EVENT_CHANGE, |
||||
action: function () { |
||||
self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); |
||||
} |
||||
}], |
||||
ref: function () { |
||||
self.year = this; |
||||
], |
||||
ref: _ref => { |
||||
this.dynamicPane = _ref; |
||||
}, |
||||
}; |
||||
case BI.DynamicYearCombo.Static: |
||||
default: |
||||
return { |
||||
type: StaticYearMonthCard.xtype, |
||||
behaviors: o.behaviors, |
||||
min: this.options.min, |
||||
max: this.options.max, |
||||
listeners: [ |
||||
{ |
||||
eventName: StaticYearMonthCard.EVENT_CHANGE, |
||||
action: () => { |
||||
this.fireEvent( |
||||
DynamicYearMonthPopup.EVENT_CHANGE |
||||
); |
||||
}, |
||||
} |
||||
}; |
||||
], |
||||
ref: _ref => { |
||||
this.year = _ref; |
||||
}, |
||||
}; |
||||
} |
||||
}, |
||||
listeners: [{ |
||||
eventName: BI.Tab.EVENT_CHANGE, |
||||
action: function () { |
||||
var v = self.dateTab.getSelect(); |
||||
switch (v) { |
||||
case BI.DynamicYearCombo.Static: |
||||
var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); |
||||
self.year.setValue({year: date.getFullYear(), month: date.getMonth() + 1}); |
||||
self._setInnerValue(); |
||||
listeners: [ |
||||
{ |
||||
eventName: Tab.EVENT_CHANGE, |
||||
action: () => { |
||||
const v = this.dateTab.getSelect(); |
||||
switch (v) { |
||||
case BI.DynamicYearCombo.Static: { |
||||
const date = DynamicDateHelper.getCalculation( |
||||
this.dynamicPane.getValue() |
||||
); |
||||
this.year.setValue({ |
||||
year: date.getFullYear(), |
||||
month: date.getMonth() + 1, |
||||
}); |
||||
this._setInnerValue(); |
||||
break; |
||||
} |
||||
case BI.DynamicYearCombo.Dynamic: |
||||
default: |
||||
if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { |
||||
self.dynamicPane.setValue(self.storeValue.value); |
||||
}else{ |
||||
self.dynamicPane.setValue({ |
||||
year: 0 |
||||
if ( |
||||
this.storeValue && |
||||
this.storeValue.type === |
||||
BI.DynamicYearCombo.Dynamic |
||||
) { |
||||
this.dynamicPane.setValue( |
||||
this.storeValue.value |
||||
); |
||||
} else { |
||||
this.dynamicPane.setValue({ |
||||
year: 0, |
||||
}); |
||||
} |
||||
self._setInnerValue(); |
||||
this._setInnerValue(); |
||||
break; |
||||
} |
||||
} |
||||
}, |
||||
} |
||||
}] |
||||
], |
||||
}; |
||||
}, |
||||
} |
||||
|
||||
setMinDate: function (minDate) { |
||||
setMinDate(minDate) { |
||||
if (this.options.min !== minDate) { |
||||
this.options.min = minDate; |
||||
this.year && this.year.setMinDate(minDate); |
||||
this.dynamicPane && this.dynamicPane.setMinDate(minDate); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setMaxDate: function (maxDate) { |
||||
setMaxDate(maxDate) { |
||||
if (this.options.max !== maxDate) { |
||||
this.options.max = maxDate; |
||||
this.year && this.year.setMaxDate(maxDate); |
||||
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
setValue: function (v) { |
||||
setValue(v) { |
||||
this.storeValue = v; |
||||
var self = this; |
||||
var type, value; |
||||
v = v || {}; |
||||
type = v.type || BI.DynamicDateCombo.Static; |
||||
value = v.value || v; |
||||
const type = v.type || DynamicDateCombo.Static; |
||||
const value = v.value || v; |
||||
|
||||
|
||||
|
||||
this.dateTab.setSelect(type); |
||||
switch (type) { |
||||
case BI.DynamicDateCombo.Dynamic: |
||||
this.dynamicPane.setValue(value); |
||||
self._setInnerValue(); |
||||
break; |
||||
case BI.DynamicDateCombo.Static: |
||||
default: |
||||
this.year.setValue(value); |
||||
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); |
||||
this.textButton.setEnable(!this._checkTodayValid()); |
||||
break; |
||||
case DynamicDateCombo.Dynamic: |
||||
this.dynamicPane.setValue(value); |
||||
this._setInnerValue(); |
||||
break; |
||||
case DynamicDateCombo.Static: |
||||
default: |
||||
this.year.setValue(value); |
||||
this.textButton.setValue(i18nText("BI-Basic_Current_Month")); |
||||
this.textButton.setEnable(!this._checkTodayValid()); |
||||
break; |
||||
} |
||||
}, |
||||
} |
||||
|
||||
getValue: function () { |
||||
getValue() { |
||||
return { |
||||
type: this.dateTab.getSelect(), |
||||
value: this.dateTab.getValue() |
||||
value: this.dateTab.getValue(), |
||||
}; |
||||
} |
||||
|
||||
}); |
||||
BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; |
||||
BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; |
||||
BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; |
||||
BI.DynamicYearMonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup); |
||||
} |
||||
|
Loading…
Reference in new issue