(function(f){
    var nameSpace = 'field_6664988151731237757';
    if(!window[nameSpace]){
        var Builder = f();
        window[nameSpace] = {
            instance: {}
        };
        window[nameSpace].init = function (options) {
            window[nameSpace].instance[options.privateId] = new Builder(options);
        };
    }
})(function(){
    /**
	 * 构造函数
     * @param options
     * @constructor
     */
	function App(options) {
		var self = this;
		//初始化参数
		self.initParams(options);
		//初始化dom
		self.initDom();
		//事件
		self.events();
    }
    
    App.prototype = {
		initParams : function (options) {
			var self = this;
            self.adaptation = options.adaptation;
            self.adaptation.formMessage = options.formMessage;
            self.privateId = options.privateId;
            self.messageObj = options.getData;
            self.preUrl = options.url_prefix;
        },
		initDom : function () {
			var self = this;
            dynamicLoading.css(self.preUrl + 'css/formQueryBtn.css');
            self.appendChildDom();
        },
		events : function () {
			var self = this;
            // 监听是否数据刷新
			
			//$(".field0313__").css("background-color","#008BFF");
			//$(".field0313__").css("color","#FFFFFF");
			//$(".field0313__").css("border-radius","10px");
			//$(".field0313__").mouseover(function (e) {
			//	var $this = $(this);// 当前触发事件的标签对象
			//}).mouseout(function (e) {
			//	$(".field0313__").css("background-color","#008BFF");
			//}).mousemove(function (e) {
			//	$(".field0313__").css("background-color","#005297");
			//});

        },
        appendChildDom : function () {
			var self = this;
            var domStructure = '<section class="customButton_box_content">'+
                '<div class="customButton_class_box '+ self.privateId + '" title="' + self.messageObj.display.escapeHTML() + '">'+ self.messageObj.display.escapeHTML() +'</div>'+
                '</section>';
            document.querySelector('#' + self.privateId).innerHTML = domStructure;
            var jumpFun = function() {
				var url2 = window.location.origin;
				var s = self;

				var field0206 = {fieldId: 'field0206'};
				var field0206value = csdk.core.getFieldData(field0206).value;
				var field0068 = {fieldId: 'field0068'};
				var field0068value = csdk.core.getFieldData(field0068).value;
				var field0212 = {fieldId: 'field0212'};
				var field0212value = csdk.core.getFieldData(field0212).value;
				var field0213 = {fieldId: 'field0213'};
				var field0213value = csdk.core.getFieldData(field0213).value;
				var field0214 = {fieldId: 'field0214'};
				var field0214value = csdk.core.getFieldData(field0214).value;
				var field0207 = {fieldId: 'field0207'};
				var field0207value = csdk.core.getFieldData(field0207).showValue;
				
				var str = "";
				
                $.ajax({
                    type : 'post',
                    async : true,
                    // 记得加随机数，不然如果ajax轮询请求会不执行
                    url : encodeURI('/seeyon/interestMeasurementController.do?datetime=' + Math.random()),
                    data:{"startDate":field0206value,"cycle":field0207value,"credit":field0068,"principal":field0212,"money":field0213,"interestRate":field0214,},
                    dataType : 'json',
                    contentType : 'application/json; charset=UTF-8',
                    success : function(res) {
                        alert("123123123");

                        
                    }
                });
                var content = self.messageObj.formdata.content;
				
            };
            document.querySelector('.' + self.privateId).removeEventListener('click', jumpFun);
            document.querySelector('.' + self.privateId).addEventListener('click', jumpFun);
            //渲染隐藏权限
            if (self.messageObj.auth === 'hide') {
                document.querySelector('#' + self.privateId).innerHTML = '<div class="cap4-text__browse" style="line-height: 1.8; color: rgb(0, 0, 0) !important;">***</div>';
            }
        }
	};

    var dynamicLoading = {
        css: function(path) {
            if(!path || path.length === 0) {
                throw new Error('argument "path" is required !');
            }
            var head = document.getElementsByTagName('head')[0];
            var link = document.createElement('link');
            link.href = path;
            link.rel = 'stylesheet';
            link.type = 'text/css';
            head.appendChild(link);
        },
        js: function(path) {
            if(!path || path.length === 0) {
                throw new Error('argument "path" is required !');
            }
            var head = document.getElementsByTagName('head')[0];
            var script = document.createElement('script');
            script.src = path;
            script.type = 'text/javascript';
            head.appendChild(script);
        }
    }

    return App;
});