(function(f){
    var nameSpace = 'field_6903530450190094319';
    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 formmain_3757 = self.adaptation.formdata.field0313__.formmains.formmain_3757;
				var field0249 = formmain_3757.field0249.value;
				var field0108 = formmain_3757.field0108.value;	
				var field0115 = formmain_3757.field0115.value;
				var field0312 = formmain_3757.field0312.value;
				if(field0312.includes("推送BIP成功")){
					alert("当前合同已成功推送BIP系统，禁止重复生成合同编号");
					return;
				}
				var result = true;
				if(field0249 !=''){
					result = confirm('当前合同已经存在合同编号是否选择变更！'); 
				}
				if(field0108==''){
					alert("合同主体编号为空，填写合同主体编号");
					return ;
				}
				var url2 = window.location.origin;
				var s = self;
				var str = "";
				console.log(s);
				if(result){
				$.ajax({
                //请求url
                url: url2+'/seeyon/servlet/ordinaryCodeServlet',
				contentType:"application/json",
                //请求参数
                data: {"unitCode":field0108,"oanum":field0115},
                //请求类型
                type: 'POST',
                //响应体结果设置
                dataType: 'json',
                //成功的回调函数
                success: function(data){
					if("200"==data.isSucceed){
						self.adaptation.formdata.field0313__.formmains.formmain_3757.field0249.value = data.newCode;
					}else if ("500"==data.isSucceed){
						alert(data.msg);
					}else{
						alert("生成失败，请联系管理员");
					}
                },
                //失败的回调函数
                error: function(){
                    top.$.alert("生成失败，请联系管理员");
                }
            });
				}
                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;
});