forked from fanruan/fineui
Browse Source
Merge in VISUAL/fineui from ~IMPACT/fine-ui:es6 to es6 * commit 'd8e5ffcb0ea2b36fb7ec19e63230287f3f0435c5': KERNEL-14097 refactor: widget/yearmonth、yearmonthinterval ES6化es6
Impact-吴家豪
2 years ago
9 changed files with 1278 additions and 899 deletions
@ -1,166 +1,212 @@ |
|||||||
/** |
import { |
||||||
* 年月展示面板 |
shortcut, |
||||||
* |
Widget, |
||||||
* Created by GUY on 2015/9/2. |
i18nText, |
||||||
* @class BI.YearCard |
bind, |
||||||
* @extends BI.Trigger |
VerticalLayout, |
||||||
*/ |
parseDateTime, |
||||||
BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { |
extend, |
||||||
|
checkDateVoid, |
||||||
props: { |
isNotEmptyString |
||||||
baseCls: "bi-year-month-card" |
} 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: function () { |
render() { |
||||||
var self = this; |
|
||||||
return { |
return { |
||||||
type: "bi.vertical", |
type: VerticalLayout.xtype, |
||||||
items: [{ |
items: [ |
||||||
type: "bi.label", |
{ |
||||||
text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), |
type: Label.xtype, |
||||||
|
text: i18nText("BI-Multi_Date_Relative_Current_Time"), |
||||||
textAlign: "left", |
textAlign: "left", |
||||||
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, |
||||||
}, { |
|
||||||
type: "bi.vertical", |
|
||||||
ref: function (_ref) { |
|
||||||
self.wrapper = _ref; |
|
||||||
}, |
}, |
||||||
items: [{ |
{ |
||||||
|
type: VerticalLayout.xtype, |
||||||
|
ref: _ref => { |
||||||
|
this.wrapper = _ref; |
||||||
|
}, |
||||||
|
items: [ |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.dynamic_date_param_item", |
type: DynamicDateParamItem.xtype, |
||||||
validationChecker: BI.bind(self._checkDate, self), |
validationChecker: bind(this._checkDate, this), |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.year = this; |
this.year = _ref; |
||||||
}, |
}, |
||||||
listeners: [{ |
listeners: [ |
||||||
|
{ |
||||||
eventName: "EVENT_CHANGE", |
eventName: "EVENT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
self.fireEvent("EVENT_CHANGE"); |
this.fireEvent("EVENT_CHANGE"); |
||||||
} |
}, |
||||||
}, { |
}, |
||||||
|
{ |
||||||
eventName: "EVENT_INPUT_CHANGE", |
eventName: "EVENT_INPUT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
BI.Bubbles.hide("dynamic-year-month-error"); |
Bubbles.hide( |
||||||
|
"dynamic-year-month-error" |
||||||
|
); |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}, |
}, |
||||||
bgap: 10, |
bgap: 10, |
||||||
}, { |
|
||||||
type: "bi.dynamic_date_param_item", |
|
||||||
dateType: BI.DynamicDateCard.TYPE.MONTH, |
|
||||||
ref: function () { |
|
||||||
self.month = this; |
|
||||||
}, |
}, |
||||||
listeners: [{ |
{ |
||||||
|
type: DynamicDateParamItem.xtype, |
||||||
|
dateType: DynamicDateCard.TYPE.MONTH, |
||||||
|
ref: _ref => { |
||||||
|
this.month = _ref; |
||||||
|
}, |
||||||
|
listeners: [ |
||||||
|
{ |
||||||
eventName: "EVENT_CHANGE", |
eventName: "EVENT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
self.fireEvent("EVENT_CHANGE"); |
this.fireEvent("EVENT_CHANGE"); |
||||||
} |
}, |
||||||
}, { |
}, |
||||||
|
{ |
||||||
eventName: "EVENT_INPUT_CHANGE", |
eventName: "EVENT_INPUT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
BI.Bubbles.hide("dynamic-year-month-error"); |
Bubbles.hide( |
||||||
|
"dynamic-year-month-error" |
||||||
|
); |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}] |
} |
||||||
}], |
], |
||||||
|
} |
||||||
|
], |
||||||
vgap: 10, |
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 () { |
return i18nText( |
||||||
var o = this.options; |
"BI-Basic_Year_Month_Range_Error", |
||||||
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", |
|
||||||
start.getFullYear(), |
start.getFullYear(), |
||||||
start.getMonth() + 1, |
start.getMonth() + 1, |
||||||
end.getFullYear(), |
end.getFullYear(), |
||||||
end.getMonth() + 1 |
end.getMonth() + 1 |
||||||
); |
); |
||||||
}, |
} |
||||||
|
|
||||||
_checkDate: function (obj) { |
_checkDate(obj) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this._getValue(), this._digestDateTypeValue(obj))); |
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) { |
_digestDateTypeValue(value) { |
||||||
var valueMap = {}; |
const valueMap = {}; |
||||||
switch (value.dateType) { |
switch (value.dateType) { |
||||||
case BI.DynamicDateCard.TYPE.YEAR: |
case DynamicDateCard.TYPE.YEAR: |
||||||
valueMap.year = (value.offset === 0 ? -value.value : +value.value); |
valueMap.year = |
||||||
|
value.offset === 0 ? -value.value : +value.value; |
||||||
break; |
break; |
||||||
case BI.DynamicDateCard.TYPE.MONTH: |
case DynamicDateCard.TYPE.MONTH: |
||||||
valueMap.month = (value.offset === 0 ? -value.value : +value.value); |
valueMap.month = |
||||||
|
value.offset === 0 ? -value.value : +value.value; |
||||||
break; |
break; |
||||||
default: |
default: |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
|
||||||
return valueMap; |
return valueMap; |
||||||
}, |
} |
||||||
|
|
||||||
_createValue: function (type, v) { |
_createValue(type, v) { |
||||||
return { |
return { |
||||||
dateType: type, |
dateType: type, |
||||||
value: Math.abs(v), |
value: Math.abs(v), |
||||||
offset: v > 0 ? 1 : 0 |
offset: v > 0 ? 1 : 0, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
setMinDate: function(minDate) { |
setMinDate(minDate) { |
||||||
if (BI.isNotEmptyString(this.options.min)) { |
if (isNotEmptyString(this.options.min)) { |
||||||
this.options.min = minDate; |
this.options.min = minDate; |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
if (BI.isNotEmptyString(this.options.max)) { |
if (isNotEmptyString(this.options.max)) { |
||||||
this.options.max = maxDate; |
this.options.max = maxDate; |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (v) { |
setValue(v) { |
||||||
v = v || { year: 0, month: 0 }; |
v = v || { year: 0, month: 0 }; |
||||||
this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); |
this.year.setValue( |
||||||
this.month.setValue(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); |
this._createValue(DynamicDateCard.TYPE.YEAR, v.year) |
||||||
}, |
); |
||||||
|
this.month.setValue( |
||||||
|
this._createValue(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 { |
return { |
||||||
year: (year.offset === 0 ? -year.value : year.value), |
year: year.offset === 0 ? -year.value : year.value, |
||||||
month: (month.offset === 0 ? -month.value : month.value) |
month: month.offset === 0 ? -month.value : month.value, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
getInputValue: function () { |
getInputValue() { |
||||||
return this._getValue(); |
return this._getValue(); |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return this.checkValidation() ? this._getValue() : {}; |
return this.checkValidation() ? this._getValue() : {}; |
||||||
}, |
} |
||||||
|
|
||||||
checkValidation: function (show) { |
checkValidation(show) { |
||||||
var errorText; |
let errorText; |
||||||
var yearInvalid = !this.year.checkValidation(); |
const yearInvalid = !this.year.checkValidation(); |
||||||
var monthInvalid = !this.month.checkValidation(); |
const monthInvalid = !this.month.checkValidation(); |
||||||
var invalid = yearInvalid || monthInvalid; |
let invalid = yearInvalid || monthInvalid; |
||||||
if (invalid) { |
if (invalid) { |
||||||
errorText = BI.i18nText("BI-Please_Input_Natural_Number"); |
errorText = i18nText("BI-Please_Input_Natural_Number"); |
||||||
} else { |
} else { |
||||||
invalid = !this._checkDate(this._getValue()); |
invalid = !this._checkDate(this._getValue()); |
||||||
errorText = this._getErrorText(); |
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; |
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: { |
@shortcut() |
||||||
baseCls: "bi-static-year-month-card", |
export class StaticYearMonthCard extends Widget { |
||||||
behaviors: {} |
static xtype = "bi.static_year_month_card"; |
||||||
}, |
|
||||||
|
static EVENT_CHANGE = "EVENT_CHANGE"; |
||||||
|
|
||||||
|
props = { baseCls: "bi-static-year-month-card", behaviors: {} }; |
||||||
|
|
||||||
_createMonths: function () { |
_createMonths() { |
||||||
var self = this; |
|
||||||
// 纵向排列月
|
// 纵向排列月
|
||||||
var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; |
const month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; |
||||||
var items = BI.chunk(month, 2); |
const items = chunk(month, 2); |
||||||
return BI.map(items, function (i, item) { |
|
||||||
return BI.map(item, function (j, td) { |
return map(items, (i, item) => map(item, (j, td) => { |
||||||
return { |
return { |
||||||
type: "bi.text_item", |
type: TextItem.xtype, |
||||||
cls: "bi-list-item-select", |
cls: "bi-list-item-select", |
||||||
textAlign: "center", |
textAlign: "center", |
||||||
whiteSpace: "nowrap", |
whiteSpace: "nowrap", |
||||||
once: false, |
once: false, |
||||||
forceSelected: true, |
forceSelected: true, |
||||||
height: BI.toPix(BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, 1), |
height: toPix(BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, 1), |
||||||
width: 38, |
width: 38, |
||||||
value: td, |
value: td, |
||||||
text: td, |
text: td, |
||||||
ref: function (_ref) { |
ref: _ref => { |
||||||
self.monthMap[j === 0 ? i : i + 6] = _ref; |
this.monthMap[j === 0 ? i : i + 6] = _ref; |
||||||
} |
|
||||||
}; |
|
||||||
}); |
|
||||||
}); |
|
||||||
}, |
}, |
||||||
|
}; |
||||||
|
})); |
||||||
|
} |
||||||
|
|
||||||
render: function () { |
render() { |
||||||
var self = this, o = this.options; |
const o = this.options; |
||||||
this.monthMap = {}; |
this.monthMap = {}; |
||||||
|
|
||||||
return { |
return { |
||||||
type: "bi.vertical", |
type: VerticalLayout.xtype, |
||||||
items: [{ |
items: [ |
||||||
type: "bi.year_picker", |
{ |
||||||
|
type: YearPicker.xtype, |
||||||
cls: "bi-split-bottom", |
cls: "bi-split-bottom", |
||||||
min: o.min, |
min: o.min, |
||||||
max: o.max, |
max: o.max, |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.yearPicker = this; |
this.yearPicker = _ref; |
||||||
}, |
}, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
height: 30, |
height: 30, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.YearPicker.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: YearPicker.EVENT_CHANGE, |
||||||
var value = this.getValue(); |
action: () => { |
||||||
self._checkMonthStatus(value); |
const value = this.yearPicker.getValue(); |
||||||
self._setYear(value); |
this._checkMonthStatus(value); |
||||||
} |
this._setYear(value); |
||||||
}] |
}, |
||||||
}, { |
} |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.button_group", |
type: ButtonGroup.xtype, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.month = this; |
this.month = _ref; |
||||||
}, |
}, |
||||||
items: this._createMonths(), |
items: this._createMonths(), |
||||||
layouts: [BI.LogicFactory.createLogic("table", BI.extend({ |
layouts: [ |
||||||
dynamic: true |
BI.LogicFactory.createLogic( |
||||||
}, { |
"table", |
||||||
|
extend( |
||||||
|
{ |
||||||
|
dynamic: true, |
||||||
|
}, |
||||||
|
{ |
||||||
columns: 2, |
columns: 2, |
||||||
rows: 6, |
rows: 6, |
||||||
columnSize: [1 / 2, 1 / 2], |
columnSize: [1 / 2, 1 / 2], |
||||||
rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 1 |
rowSize: |
||||||
})), { |
BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + |
||||||
type: "bi.center_adapt", |
1, |
||||||
|
} |
||||||
|
) |
||||||
|
), |
||||||
|
{ |
||||||
|
type: CenterAdaptLayout.xtype, |
||||||
vgap: 1, |
vgap: 1, |
||||||
hgap: 2 |
hgap: 2, |
||||||
}], |
} |
||||||
|
], |
||||||
value: o.value, |
value: o.value, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.ButtonGroup.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: ButtonGroup.EVENT_CHANGE, |
||||||
self.selectedYear = self.yearPicker.getValue(); |
action: () => { |
||||||
self.selectedMonth = this.getValue()[0]; |
this.selectedYear = this.yearPicker.getValue(); |
||||||
self.fireEvent(BI.StaticYearMonthCard.EVENT_CHANGE); |
this.selectedMonth = this.month.getValue()[0]; |
||||||
} |
this.fireEvent( |
||||||
}] |
StaticYearMonthCard.EVENT_CHANGE |
||||||
|
); |
||||||
}, |
}, |
||||||
vgap: 5 |
} |
||||||
}] |
], |
||||||
}; |
|
||||||
}, |
}, |
||||||
|
vgap: 5, |
||||||
|
} |
||||||
|
], |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
created: function() { |
created() { |
||||||
this._checkMonthStatus(this.selectedYear); |
this._checkMonthStatus(this.selectedYear); |
||||||
}, |
} |
||||||
|
|
||||||
_checkMonthStatus: function (year) { |
_checkMonthStatus(year) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"), maxDate = BI.parseDateTime(o.max, "%Y-%X-%d"); |
const minDate = parseDateTime(o.min, "%Y-%X-%d"), |
||||||
var minYear = minDate.getFullYear(), maxYear = maxDate.getFullYear(); |
maxDate = parseDateTime(o.max, "%Y-%X-%d"); |
||||||
var minMonth = 0; |
const minYear = minDate.getFullYear(), |
||||||
var maxMonth = 11; |
maxYear = maxDate.getFullYear(); |
||||||
|
let minMonth = 0; |
||||||
|
let maxMonth = 11; |
||||||
minYear === year && (minMonth = minDate.getMonth()); |
minYear === year && (minMonth = minDate.getMonth()); |
||||||
maxYear === year && (maxMonth = maxDate.getMonth()); |
maxYear === year && (maxMonth = maxDate.getMonth()); |
||||||
var yearInvalid = year < minYear || year > maxYear; |
const yearInvalid = year < minYear || year > maxYear; |
||||||
BI.each(this.monthMap, function (month, obj) { |
each(this.monthMap, (month, obj) => { |
||||||
var monthInvalid = month < minMonth || month > maxMonth; |
const monthInvalid = month < minMonth || month > maxMonth; |
||||||
obj.setEnable(!yearInvalid && !monthInvalid); |
obj.setEnable(!yearInvalid && !monthInvalid); |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_setYear: function (year) { |
_setYear(year) { |
||||||
var o = this.options; |
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.selectedYear = year; |
||||||
this.month.setValue(); |
this.month.setValue(); |
||||||
|
|
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
this.selectedYear = year; |
this.selectedYear = year; |
||||||
this.month.setValue(this.selectedMonth); |
this.month.setValue(this.selectedMonth); |
||||||
}, |
} |
||||||
|
|
||||||
setMinDate: function (minDate) { |
setMinDate(minDate) { |
||||||
if (this.options.min !== minDate) { |
if (this.options.min !== minDate) { |
||||||
this.options.min = minDate; |
this.options.min = minDate; |
||||||
this.yearPicker.setMinDate(minDate); |
this.yearPicker.setMinDate(minDate); |
||||||
this._checkMonthStatus(this.selectedYear); |
this._checkMonthStatus(this.selectedYear); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
if (this.options.max !== maxDate) { |
if (this.options.max !== maxDate) { |
||||||
this.options.max = maxDate; |
this.options.max = maxDate; |
||||||
this.yearPicker.setMaxDate(maxDate); |
this.yearPicker.setMaxDate(maxDate); |
||||||
this._checkMonthStatus(this.selectedYear); |
this._checkMonthStatus(this.selectedYear); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return { |
return { |
||||||
year: this.selectedYear, |
year: this.selectedYear, |
||||||
month: this.selectedMonth |
month: this.selectedMonth, |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (obj) { |
setValue(obj) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var newObj = {}; |
const newObj = {}; |
||||||
newObj.year = obj.year || 0; |
newObj.year = obj.year || 0; |
||||||
newObj.month = obj.month || 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]) { |
if ( |
||||||
var year = newObj.year || BI.getDate().getFullYear(); |
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.selectedYear = year; |
||||||
this.selectedMonth = ""; |
this.selectedMonth = ""; |
||||||
this.yearPicker.setValue(year); |
this.yearPicker.setValue(year); |
||||||
this.month.setValue(); |
this.month.setValue(); |
||||||
} else { |
} else { |
||||||
this.selectedYear = BI.parseInt(newObj.year); |
this.selectedYear = parseInt(newObj.year); |
||||||
this.selectedMonth = BI.parseInt(newObj.month); |
this.selectedMonth = parseInt(newObj.month); |
||||||
this.yearPicker.setValue(this.selectedYear); |
this.yearPicker.setValue(this.selectedYear); |
||||||
this.month.setValue(this.selectedMonth); |
this.month.setValue(this.selectedMonth); |
||||||
} |
} |
||||||
this._checkMonthStatus(this.selectedYear); |
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 @@ |
|||||||
/** |
import { |
||||||
* 年月 |
shortcut, |
||||||
* |
Widget, |
||||||
* Created by GUY on 2015/9/2. |
toPix, |
||||||
* @class BI.DynamicYearMonthPopup |
i18nText, |
||||||
* @extends BI.Trigger |
VerticalLayout, |
||||||
*/ |
GridLayout, |
||||||
BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { |
print, |
||||||
constants: { |
getDate, |
||||||
tabHeight: 40, |
checkDateVoid, |
||||||
}, |
createItems |
||||||
|
} from "@/core"; |
||||||
props: { |
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", |
baseCls: "bi-year-month-popup", |
||||||
behaviors: {}, |
behaviors: {}, |
||||||
min: "1900-01-01", // 最小日期
|
min: "1900-01-01", |
||||||
max: "2099-12-31", // 最大日期,
|
max: "2099-12-31", |
||||||
width: 180, |
width: 180, |
||||||
supportDynamic: true, |
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 { |
return { |
||||||
type: "bi.vertical", |
type: VerticalLayout.xtype, |
||||||
items: [{ |
items: [ |
||||||
el: this._getTabJson() |
{ |
||||||
}, { |
el: this._getTabJson(), |
||||||
|
}, |
||||||
|
{ |
||||||
el: { |
el: { |
||||||
type: "bi.grid", |
type: GridLayout.xtype, |
||||||
items: [[{ |
items: [ |
||||||
type: "bi.text_button", |
[ |
||||||
|
{ |
||||||
|
type: TextButton.xtype, |
||||||
cls: "bi-split-top bi-high-light", |
cls: "bi-split-top bi-high-light", |
||||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
textHeight: toPix( |
||||||
|
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
|
1 |
||||||
|
), |
||||||
shadow: true, |
shadow: true, |
||||||
text: BI.i18nText("BI-Basic_Clear"), |
text: i18nText("BI-Basic_Clear"), |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.TextButton.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: TextButton.EVENT_CHANGE, |
||||||
self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE); |
action: () => { |
||||||
} |
this.fireEvent( |
||||||
}] |
DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE |
||||||
}, { |
); |
||||||
type: "bi.text_button", |
}, |
||||||
|
} |
||||||
|
], |
||||||
|
}, |
||||||
|
{ |
||||||
|
type: TextButton.xtype, |
||||||
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
cls: "bi-split-left bi-split-right bi-high-light bi-split-top", |
||||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
textHeight: toPix( |
||||||
|
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
|
1 |
||||||
|
), |
||||||
shadow: true, |
shadow: true, |
||||||
text: BI.i18nText("BI-Basic_Current_Month"), |
text: i18nText("BI-Basic_Current_Month"), |
||||||
disabled: this._checkTodayValid(), |
disabled: this._checkTodayValid(), |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.textButton = this; |
this.textButton = _ref; |
||||||
|
}, |
||||||
|
listeners: [ |
||||||
|
{ |
||||||
|
eventName: TextButton.EVENT_CHANGE, |
||||||
|
action: () => { |
||||||
|
this.fireEvent( |
||||||
|
DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE |
||||||
|
); |
||||||
}, |
}, |
||||||
listeners: [{ |
|
||||||
eventName: BI.TextButton.EVENT_CHANGE, |
|
||||||
action: function () { |
|
||||||
self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE); |
|
||||||
} |
} |
||||||
}] |
], |
||||||
}, { |
}, |
||||||
type: "bi.text_button", |
{ |
||||||
|
type: TextButton.xtype, |
||||||
cls: "bi-split-top bi-high-light", |
cls: "bi-split-top bi-high-light", |
||||||
textHeight: BI.toPix(BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, 1), |
textHeight: toPix( |
||||||
|
BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
|
1 |
||||||
|
), |
||||||
shadow: true, |
shadow: true, |
||||||
text: BI.i18nText("BI-Basic_OK"), |
text: i18nText("BI-Basic_OK"), |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.TextButton.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: TextButton.EVENT_CHANGE, |
||||||
var type = self.dateTab.getSelect(); |
action: () => { |
||||||
if (type === BI.DynamicDateCombo.Dynamic) { |
const type = |
||||||
self.dynamicPane.checkValidation(true) && self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); |
this.dateTab.getSelect(); |
||||||
|
if ( |
||||||
|
type === |
||||||
|
DynamicDateCombo.Dynamic |
||||||
|
) { |
||||||
|
this.dynamicPane.checkValidation( |
||||||
|
true |
||||||
|
) && |
||||||
|
this.fireEvent( |
||||||
|
DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE |
||||||
|
); |
||||||
} else { |
} else { |
||||||
self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); |
this.fireEvent( |
||||||
|
DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE |
||||||
|
); |
||||||
|
} |
||||||
|
}, |
||||||
} |
} |
||||||
|
], |
||||||
} |
} |
||||||
}] |
] |
||||||
}]], |
], |
||||||
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT |
height: BI.SIZE_CONSANTS.TOOL_BAR_HEIGHT, |
||||||
}, |
}, |
||||||
}] |
} |
||||||
|
], |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
_setInnerValue: function () { |
_setInnerValue() { |
||||||
if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { |
if (this.dateTab.getSelect() === DynamicDateCombo.Static) { |
||||||
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); |
this.textButton.setValue(i18nText("BI-Basic_Current_Month")); |
||||||
this.textButton.setEnable(!this._checkTodayValid()); |
this.textButton.setEnable(!this._checkTodayValid()); |
||||||
} else { |
} else { |
||||||
var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getInputValue()); |
let date = DynamicDateHelper.getCalculation( |
||||||
date = BI.print(date, "%Y-%x"); |
this.dynamicPane.getInputValue() |
||||||
|
); |
||||||
|
date = print(date, "%Y-%x"); |
||||||
this.textButton.setValue(date); |
this.textButton.setValue(date); |
||||||
this.textButton.setEnable(false); |
this.textButton.setEnable(false); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
_checkTodayValid: function () { |
_checkTodayValid() { |
||||||
var o = this.options; |
const o = this.options; |
||||||
var today = BI.getDate(); |
const today = getDate(); |
||||||
return !!BI.checkDateVoid(today.getFullYear(), today.getMonth() + 1, today.getDate(), o.min, o.max)[0]; |
|
||||||
}, |
return !!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 { |
return { |
||||||
type: "bi.tab", |
type: Tab.xtype, |
||||||
logic: { |
logic: { |
||||||
dynamic: true |
dynamic: true, |
||||||
}, |
}, |
||||||
ref: function () { |
ref: _ref => { |
||||||
self.dateTab = this; |
this.dateTab = _ref; |
||||||
}, |
}, |
||||||
tab: { |
tab: { |
||||||
type: "bi.linear_segment", |
type: LinearSegment.xtype, |
||||||
cls: "bi-split-bottom", |
cls: "bi-split-bottom", |
||||||
invisible: !o.supportDynamic, |
invisible: !o.supportDynamic, |
||||||
height: this.constants.tabHeight, |
height: this.constants.tabHeight, |
||||||
items: BI.createItems([{ |
items: createItems( |
||||||
text: BI.i18nText("BI-Basic_Year_Month"), |
[ |
||||||
value: BI.DynamicYearCombo.Static |
{ |
||||||
}, { |
text: i18nText("BI-Basic_Year_Month"), |
||||||
text: BI.i18nText("BI-Basic_Dynamic_Title"), |
value: BI.DynamicYearCombo.Static, |
||||||
value: BI.DynamicYearCombo.Dynamic |
}, |
||||||
}], { |
{ |
||||||
textAlign: "center" |
text: i18nText("BI-Basic_Dynamic_Title"), |
||||||
}) |
value: BI.DynamicYearCombo.Dynamic, |
||||||
}, |
} |
||||||
cardCreator: function (v) { |
], |
||||||
|
{ |
||||||
|
textAlign: "center", |
||||||
|
} |
||||||
|
), |
||||||
|
}, |
||||||
|
cardCreator: v => { |
||||||
switch (v) { |
switch (v) { |
||||||
case BI.DynamicYearCombo.Dynamic: |
case BI.DynamicYearCombo.Dynamic: |
||||||
return { |
return { |
||||||
type: "bi.dynamic_year_month_card", |
type: DynamicYearMonthCard.xtype, |
||||||
cls: "dynamic-year-month-pane", |
cls: "dynamic-year-month-pane", |
||||||
min: self.options.min, |
min: this.options.min, |
||||||
max: self.options.max, |
max: this.options.max, |
||||||
listeners: [{ |
listeners: [ |
||||||
|
{ |
||||||
eventName: "EVENT_CHANGE", |
eventName: "EVENT_CHANGE", |
||||||
action: function () { |
action: () => { |
||||||
self._setInnerValue(self.year, v); |
this._setInnerValue(this.year, v); |
||||||
} |
}, |
||||||
}], |
|
||||||
ref: function () { |
|
||||||
self.dynamicPane = this; |
|
||||||
} |
} |
||||||
|
], |
||||||
|
ref: _ref => { |
||||||
|
this.dynamicPane = _ref; |
||||||
|
}, |
||||||
}; |
}; |
||||||
case BI.DynamicYearCombo.Static: |
case BI.DynamicYearCombo.Static: |
||||||
default: |
default: |
||||||
return { |
return { |
||||||
type: "bi.static_year_month_card", |
type: StaticYearMonthCard.xtype, |
||||||
behaviors: o.behaviors, |
behaviors: o.behaviors, |
||||||
min: self.options.min, |
min: this.options.min, |
||||||
max: self.options.max, |
max: this.options.max, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.StaticYearMonthCard.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: StaticYearMonthCard.EVENT_CHANGE, |
||||||
self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); |
action: () => { |
||||||
} |
this.fireEvent( |
||||||
}], |
DynamicYearMonthPopup.EVENT_CHANGE |
||||||
ref: function () { |
); |
||||||
self.year = this; |
}, |
||||||
} |
} |
||||||
|
], |
||||||
|
ref: _ref => { |
||||||
|
this.year = _ref; |
||||||
|
}, |
||||||
}; |
}; |
||||||
} |
} |
||||||
}, |
}, |
||||||
listeners: [{ |
listeners: [ |
||||||
eventName: BI.Tab.EVENT_CHANGE, |
{ |
||||||
action: function () { |
eventName: Tab.EVENT_CHANGE, |
||||||
var v = self.dateTab.getSelect(); |
action: () => { |
||||||
|
const v = this.dateTab.getSelect(); |
||||||
switch (v) { |
switch (v) { |
||||||
case BI.DynamicYearCombo.Static: |
case BI.DynamicYearCombo.Static: { |
||||||
var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); |
const date = DynamicDateHelper.getCalculation( |
||||||
self.year.setValue({year: date.getFullYear(), month: date.getMonth() + 1}); |
this.dynamicPane.getValue() |
||||||
self._setInnerValue(); |
); |
||||||
|
this.year.setValue({ |
||||||
|
year: date.getFullYear(), |
||||||
|
month: date.getMonth() + 1, |
||||||
|
}); |
||||||
|
this._setInnerValue(); |
||||||
break; |
break; |
||||||
|
} |
||||||
case BI.DynamicYearCombo.Dynamic: |
case BI.DynamicYearCombo.Dynamic: |
||||||
default: |
default: |
||||||
if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { |
if ( |
||||||
self.dynamicPane.setValue(self.storeValue.value); |
this.storeValue && |
||||||
|
this.storeValue.type === |
||||||
|
BI.DynamicYearCombo.Dynamic |
||||||
|
) { |
||||||
|
this.dynamicPane.setValue( |
||||||
|
this.storeValue.value |
||||||
|
); |
||||||
} else { |
} else { |
||||||
self.dynamicPane.setValue({ |
this.dynamicPane.setValue({ |
||||||
year: 0 |
year: 0, |
||||||
}); |
}); |
||||||
} |
} |
||||||
self._setInnerValue(); |
this._setInnerValue(); |
||||||
break; |
break; |
||||||
} |
} |
||||||
|
}, |
||||||
} |
} |
||||||
}] |
], |
||||||
}; |
}; |
||||||
}, |
} |
||||||
|
|
||||||
setMinDate: function (minDate) { |
setMinDate(minDate) { |
||||||
if (this.options.min !== minDate) { |
if (this.options.min !== minDate) { |
||||||
this.options.min = minDate; |
this.options.min = minDate; |
||||||
this.year && this.year.setMinDate(minDate); |
this.year && this.year.setMinDate(minDate); |
||||||
this.dynamicPane && this.dynamicPane.setMinDate(minDate); |
this.dynamicPane && this.dynamicPane.setMinDate(minDate); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setMaxDate: function (maxDate) { |
setMaxDate(maxDate) { |
||||||
if (this.options.max !== maxDate) { |
if (this.options.max !== maxDate) { |
||||||
this.options.max = maxDate; |
this.options.max = maxDate; |
||||||
this.year && this.year.setMaxDate(maxDate); |
this.year && this.year.setMaxDate(maxDate); |
||||||
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate); |
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (v) { |
setValue(v) { |
||||||
this.storeValue = v; |
this.storeValue = v; |
||||||
var self = this; |
|
||||||
var type, value; |
|
||||||
v = v || {}; |
v = v || {}; |
||||||
type = v.type || BI.DynamicDateCombo.Static; |
const type = v.type || DynamicDateCombo.Static; |
||||||
value = v.value || v; |
const value = v.value || v; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.dateTab.setSelect(type); |
this.dateTab.setSelect(type); |
||||||
switch (type) { |
switch (type) { |
||||||
case BI.DynamicDateCombo.Dynamic: |
case DynamicDateCombo.Dynamic: |
||||||
this.dynamicPane.setValue(value); |
this.dynamicPane.setValue(value); |
||||||
self._setInnerValue(); |
this._setInnerValue(); |
||||||
break; |
break; |
||||||
case BI.DynamicDateCombo.Static: |
case DynamicDateCombo.Static: |
||||||
default: |
default: |
||||||
this.year.setValue(value); |
this.year.setValue(value); |
||||||
this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); |
this.textButton.setValue(i18nText("BI-Basic_Current_Month")); |
||||||
this.textButton.setEnable(!this._checkTodayValid()); |
this.textButton.setEnable(!this._checkTodayValid()); |
||||||
break; |
break; |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return { |
return { |
||||||
type: this.dateTab.getSelect(), |
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