/* Author: yangzeming
 * Date: 2014-02-10
 * Desc: 滚动组件
 */
define('component/radio',function (require, exports, module) {
    /*
	  html 
	  <div class="inline-b tui-radio-con" data-role="radio">
					    <div class="inline-b tui-check" data-check="yes" data-type="name"><span class="inline-b ss-pic tui-radio"></span>合同名称</div>
						<div class="inline-b" data-type="bh"><span class="inline-b ss-pic tui-radio"></span>合同编号</div>
						<div class="inline-b" data-type="time"><span class="inline-b ss-pic tui-radio"></span>时间</div>
					
					</div>
	
	*/
    var RadioA = _.Class({
		defaultOptions: {
	       con : "",
		   checkClass : "tui-check"
	    },
	    initial: function (options) {
			this._eventStack = {};
	        options = $.extend({}, this.defaultOptions, options);
	        this.options = options;
	        this.$con = $(this.options.con);
			this._bindEvent();
	    },
		_bindEvent : function(){
			var self = this;
			this.$con.delegate("[data-type]","click",function(){
			     var that = $(this),
					 type = that.data("type");
                 self.setCheck(type);
				 self.trigger("click",type);
			    
			});
		},
		// 获取选中的值
	    getValue : function(){
		    return this.$con.find('[data-check="yes"]').data("type");
		
		},
		// 选中哪个radio
		setCheck : function(val){
			var op = this.options,
				self = this,
				checkClass = op.checkClass;
		     // 去除所有的选中状态
			self.$con.find("[data-type]").each(function(){
					var that = $(this);
					that.removeClass(checkClass);
					that.attr("data-check","no");
				 
				 });
		    var that = self.$con.find('[data-type="'+val+'"]');
			 // 选中自己
				 that.addClass(checkClass);
				 that.attr("data-check","yes");
			
		}
	    
    });
    module.exports = RadioA;
});