| |
| |
| (function () { |
| |
| // TODO:修改接口的服务地址 |
| var serverUrl = 'http://dev-center.paas.newcapec.cn'; |
| // TODO:修改岗位代码(APISHBMGLY 部门管理员, APISHBMLD 部门领导) |
| var postCode = 'APISHBMLD'; |
| |
| var fieldSonformId = "sonform_colorful_egg_1616556009894"; |
| |
| //从localStorage中获取currentUser以获取工号 |
| var username = JSON.parse(localStorage.currentUser).username; // console.log('username', username); |
| // var username = '20210324'; |
| //从localStorage中获取token |
| // var token = localStorage.getItem('Admin-Token'); console.log('token', token); |
| |
| function httpRequest(paramObj,fun,errFun){ |
| var xmlhttp = null; |
| /*创建XMLHttpRequest对象, |
| *老版本的 Internet Explorer(IE5 和 IE6)使用 ActiveX 对象:new ActiveXObject("Microsoft.XMLHTTP") |
| * */ |
| if(window.XMLHttpRequest){ |
| xmlhttp = new XMLHttpRequest(); |
| }else if(window.ActiveXObject) { |
| xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
| } |
| /*判断是否支持请求*/ |
| if(xmlhttp == null){ |
| window.formMsgBox.alert('你的浏览器不支持XMLHttp'); |
| return; |
| } |
| /*请求方式,并且转换为大写*/ |
| var httpType = (paramObj.type || 'GET').toUpperCase(); |
| /*数据类型*/ |
| var dataType = paramObj.dataType || 'json'; |
| /*请求接口*/ |
| var httpUrl = paramObj.httpUrl || ''; |
| /*是否异步请求*/ |
| var async = paramObj.async || true; |
| /*请求参数--post请求参数格式为:foo=bar&lorem=ipsum*/ |
| var paramData = paramObj.data || []; |
| /*var requestData = ''; |
| for(var name in paramData){ |
| requestData += name + '='+ paramData[name] + '&'; |
| } |
| requestData = requestData == '' ? '' : requestData.substring(0,requestData.length - 1);*/ |
| /*请求接收*/ |
| var requestData = JSON.stringify(paramData); |
| xmlhttp.onreadystatechange = function(){ |
| if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { |
| /*成功回调函数*/ |
| fun(xmlhttp.responseText); |
| }else{ |
| /*失败回调函数*/ |
| errFun; |
| } |
| } |
| /*接口连接,先判断连接类型是post还是get*/ |
| if(httpType == 'GET') { |
| xmlhttp.open("GET",httpUrl,async); |
| //加入token |
| // xmlhttp.setRequestHeader("X-Id-Token", token); |
| xmlhttp.send(null); |
| }else if(httpType == 'POST'){ |
| xmlhttp.open("POST",httpUrl,async); |
| //发送合适的请求头信息 |
| //xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
| xmlhttp.setRequestHeader("Content-type", "application/json;charset=UTF-8"); |
| //加入token |
| // xmlhttp.setRequestHeader("X-Id-Token", token); |
| xmlhttp.send(requestData); |
| } |
| } |
| |
| //获取表单数据 |
| function getData(model){ |
| var temp; |
| window.globalBus.$on('getData',function(data){ |
| //子表数据返回list |
| if(data.model.indexOf("sonform") != -1){ |
| temp = data.sonValues; |
| }else{ |
| temp = data.options.value; |
| } |
| }); |
| window.globalBus.$emit('findData',model); |
| return temp; |
| } |
| |
| function contains(arr, obj) { |
| var i = arr.length; |
| while (i--) { |
| if (arr[i] === obj) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| function filterSonformData(model, sonformData, orgIds) { |
| |
| var dataList = []; |
| sonformData.forEach(function(item){ |
| if(contains(orgIds, item.OrganizationId)){ |
| dataList.push(item); |
| } |
| }); |
| |
| window.globalBus.$emit('resetSonFormData',{sonFormModel:model, sonFormData:dataList}); |
| } |
| |
| var fieldSonformData = JSON.stringify(getData(fieldSonformId)); // console.log('fieldSonformData', fieldSonformData); |
| |
| |
| var url = serverUrl + '/api/v1/portal/public/account/'+ username +'/post/'+ postCode +'/organizations'; |
| // ajax 请求接口,获取当前用户在岗位下的所属部门 |
| httpRequest( |
| {httpUrl: url, type: 'get'}, |
| function(respondDada) { |
| console.log('respondDada', respondDada); |
| var jsonResponse = JSON.parse(respondDada); |
| console.log('jsonResponse', jsonResponse); |
| |
| var orgIds = []; |
| jsonResponse.data.forEach(function(organization) { |
| orgIds.push(organization.organizationId); |
| }); |
| console.log('orgIds', orgIds); |
| |
| filterSonformData(fieldSonformId, JSON.parse(fieldSonformData), orgIds); // console.log('fieldSonformData', fieldSonformData); |
| |
| }, |
| function(err) { |
| console.log('err', err); |
| } |
| ); |
| |
| window.btnBus.$emit('btn',{name:'同意',funcAwaitEmit:true});//禁用默认方法 |
| window.btnBus.$emit('btn',{name:'不同意',funcAwaitEmit:true});//禁用默认方法 |
| window.btnBus.$on('btnClicked',function(btn){ |
| |
| var unselectFieldSonformData = []; |
| |
| var currentFieldSonformData = getData(fieldSonformId); |
| currentFieldSonformData.forEach(function(item){ |
| unselectFieldSonformData.push(item.ApiFieldKey); |
| }); |
| |
| // console.log(btn); |
| |
| if(btn.c_name=="同意") { |
| |
| var originalFieldSonformData = JSON.parse(fieldSonformData); |
| originalFieldSonformData.forEach(function(item) { |
| if (contains(unselectFieldSonformData, item.ApiFieldKey)) { |
| item.Selection = true; |
| } |
| }); |
| console.log('originalFieldSonformData', originalFieldSonformData); |
| |
| window.globalBus.$emit('resetSonFormData',{sonFormModel:fieldSonformId, sonFormData:originalFieldSonformData}); |
| |
| window.setTimeout(function(){window.btnBus.$emit('btnFunc',btn);},200);//重启默认方法 |
| } else if(btn.c_name=="不同意") { |
| |
| var originalFieldSonformData = JSON.parse(fieldSonformData); |
| originalFieldSonformData.forEach(function(item) { |
| if (contains(unselectFieldSonformData, item.ApiFieldKey)) { |
| item.Selection = false; |
| } |
| }); |
| console.log('originalFieldSonformData', originalFieldSonformData); |
| |
| window.globalBus.$emit('resetSonFormData',{sonFormModel:fieldSonformId, sonFormData:originalFieldSonformData}); |
| |
| window.setTimeout(function(){window.btnBus.$emit('btnFunc',btn);},200);//重启默认方法 |
| } |
| |
| }); |
| |
| })(); |