fd-gulp-convert-encoding
Version:
convert file to assigned charset
125 lines (101 loc) • 3.2 kB
JavaScript
/**
* purchasingList view交互逻辑
*/
define('detail.lib.specOperator.SpecOperator',
['jQuery', 'Class', 'detail.core.Event'],
function($, Class, Event) {
return Class({
init: function(node, group) {
this.onEvent = $.os.supportsTouch ? 'tap' : 'click';
this.node = node;
this.callback = function(){};
this.stateCompleted = false;
this.config = node && node.data('unit-config') ? node.data('unit-config'): {};
this.config.name = this.config.name ? this.config.name: '';
this.data = {};
this.outStock = false;
//快速模式,即不需要动作展示
this.quickMode = false;
this.group = group || 0;
this.selected = false;
if (!this.node.length){
return;
}
this._bindClickEvent();
},
_bindClickEvent: function(){
var that = this;
this.action = $('a', this.node);
this.specList = [];
this.action.on(this.onEvent, function(e){
e.preventDefault();
var erase = false,
elm = $(this);
if (elm.hasClass('fui-btn-disabled')){
return;
}
if (!elm.hasClass('fui-btn-checked')){
erase = false;
Event.trigger('skuSelecte', that.group);
elm.removeClass('fui-btn')
.addClass('fui-btn-checked');
that.selected = true;
that.callback.call(that, that.config.name, erase);
} else {
erase = true;
Event.trigger('skuSelecte', that.group);
elm.removeClass('fui-btn-checked')
.addClass('fui-btn');
that.selected = false;
that.callback.call(that, that.config.name, erase);
}
});
Event.on('skuSelecte', function(group){
if (that.group === group){
that.action.removeClass('fui-btn-checked')
.addClass('fui-btn');
that.selected = false;
}
});
},
getName: function(){
return this.config.name;
},
setSkuData: function(func){
if (typeof(func) === 'function'){
this.data = func(this.config.name, this.group);
}
},
getSkuData: function(){
return this.data;
},
getGroup: function(){
return this.group;
},
setSelected: function(){
if (this.node){
this.action.trigger('tap');
} else {
this.callback.call(this, this.config.name);
this.selected = true;
}
},
getSelected: function(){
return this.selected;
},
setCallback: function(func){
if (typeof(func) === 'function'){
this.callback = func;
}
},
//设置缺货状态
setOutStock: function(isOutStock){
this.outStock = isOutStock ? true : false;
if (this.outStock){
this.action.addClass('fui-btn-disabled');
} else {
this.action.removeClass('fui-btn-disabled');
}
}
});
});