(function(f){
    var nameSpace = 'field_7310965329196191710';
    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 s = self;
				var tableName = s.messageObj.formdata.alldata.tableInfo.formmain.tableName;
                var recordId = s.messageObj.recordId;
                const fieldInfo = s.messageObj.formdata.alldata.tableInfo.formmain.fieldInfo;
                var thirdPartyFlowId = "";
                var thirdPartyCode = "";
                for (const key in fieldInfo) {
                    const field = fieldInfo[key];
                    if (field.display === "第三方系统流程ID") {
                        thirdPartyFlowId = field.value;
                    } else if (field.display === "第三方系统标识"){
                        thirdPartyCode = field.value;
                    }
                }
                var url2 = window.location.origin;
                // window.open(url2+'/seeyon/urlSkipController.do?thirdPartyFlowId='+thirdPartyFlowId+'&thirdPartyCode='+thirdPartyCode+'&tableName='+tableName+'&recordId='+recordId, '_blank');
                window.open(url2+'/seeyon/urlSkipController.do?thirdPartyCode='+thirdPartyCode+'&tableName='+tableName+'&recordId='+recordId, '_blank');

                console.log(s);
                
                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;
});