/**
* Created by seeker910 on 2017/6/11.
* 包含:日期和时间
* 输入值为 int型
* 返回 类型与输入值类型一致,为 int型。
* 该控件用于 对timestamp值 使用用int 类型存储对数据
*/
Rsd.define('Rsd.form.Timestamp', {
extend: 'Rsd.control.Component',
xtype: 'timestamp',
ctrlTagName: 'div',
formatString:'yyyy-MM-dd hh:mm:ss',
precision:3,
/**
*
* @param {*} config
*/
constructor: function Timestamp(config) {
config = config || {};
this.apply(config);
},
/***
*
*/
initComponentEx: function initComponentEx() {
var me = this;
this.callParent();
this.___date = document.createElement('input');
this.___date.type = "date";
this.___date.style.width ="48%";
this.___date.style.height ="100%"
this.ctrl.element.appendChild(this.___date);
this.___time = document.createElement('input');
this.___time.type = "time";
this.___time.step = 1;
this.___time.style.width ="48%";
this.___time.style.height ="100%";
this.___time.style.float = "right";
this.ctrl.element.appendChild(this.___time);
},
/*
* */
onAfterInit: function onAfterInit() {
this.callParent();
var me = this;
me.dom.style.textAlign = 'left';
me.ctrl.element.name = me.dataIndex;
me.___date.readOnly = me.readOnly;
me.___date.disabled = me.disabled;
me.___date.required = me.required?'required':'';
me.___date.autocomplete="off";
me.___date.accessKey = me.accessKey;
me.___date.onchange = function (evt) {
me.funApplyByIOC(me.onchange||me.textChanged,[me,evt]);
}
me.___time.readOnly = me.readOnly;
me.___time.disabled = me.disabled;
me.___time.required = me.required?'required':'';
me.___time.autocomplete="off";
me.___time.accessKey = me.accessKey;
me.___time.onchange = function (evt) {
me.funApplyByIOC(me.onchange||me.textChanged,[me,evt]);
}
if (me.__value != undefined) {
me.setValue(me.__value) ;
}
},
/*
* */
setDisabled: function setDisabled(disabled) {
this.callParent(disabled);
if( this.___date)
{
this.___date.disabled = this.disabled;
this.___time.disabled = this.disabled;
}
},
/***
* 重写setValue
* 因为继承了Rsd.form.Date 所以 this.__value 的实际指类型必须是Date
*/
setValue:function setValue(value)
{
if( this.__value == value)
{
return;
}
var _date = null;
if(value == null)
{
_date = new Date(0);
}
if(value instanceof Date)
{
_date = value;
}
if(_date==null && !Rsd.isNumber(value))
{
Rsd.error('Timestamp值设置错误:【'+ value + '】不是有效的数字类型。');
return;
}
if(_date == null)
{
var _value = parseInt(value);
for(var i = _value.toString().length ;i < 13;i++)
{
_value = _value * 10;
}
_date = new Date(_value) ;
}
this.__value = _date;
if (this.___date) {
if( _date != null && _date > 0)
{
this.___date.value = _date.format('yyyy-MM-dd');
this.___time.value = _date.format('hh:mm:ss');
}
else
{
this.___date.value = "";
this.___time.value = "";
}
}
},
/**
* 重写getValue
* 无效时间值,返回null.
*/
getValue:function getValue() {
//js 能表现出来的值 是13位长度
var _value = Date.parse( this.___date.value + ' ' + this.___time.value) ;
if(isNaN(_value))
{
return 0;
}
if(this.precision > 3)
{
for(var i = 0 ;i < (this.precision - 3);i++)
{
_value = _value * 10;
}
}
if(this.precision < 3)
{
for(var i = 0 ;i < (3-this.precision );i++)
{
_value = _value / 10;
}
}
return _value;
}
});