angular.module('expend_standard', [])
.directive('orgSelectorStandard', ['$rootScope', 'http_service', '$compile', '$timeout', 'myServeice', function($rootScope, http_service, $compile, $timeout, myServeice) {
return {
restrict: 'EACM',
scope: {
datamodel: '=',
options: '='
},
template: '
' +
'
' +
'' +
'{{org.orgName}} ' +
'' +
' 选择组织机构' +
'' +
'
',
replace: true,
controller: ['$scope', '$element', function($scope, $element) {
$scope.org_selected = [];
$scope.select_org = function(e) {
$('div[name="org_select_popup"]').remove();
var activeclass = "{true:'hr_name',false:'hr_name_selected'}[user.state]";
var pop_element = $('');
$($element).append(pop_element);
$compile(pop_element)($scope);
$scope.init_tree();
var form_el_div = $($element).closest('div.sub_form_container').children('div').not('[name="journel_budget"]');
e.stopPropagation();
};
}],
link: function($scope, element, attrs) {
$scope.stop_prg = function(event) {
event.stopPropagation();
};
$scope.close = function() {
$('div[name="org_select_popup"]').remove();
myServeice.setpd($scope.parentitem, $scope.users_selected, $scope.type);
// $scope.query_journel_budget();
};
//清除选择
$scope.clear_org = function(){
$scope.org_selected = [];
$scope.datamodel = [""];
}
//选择组织机构
$scope.add_org = function(treeNode) {
if(treeNode.children && treeNode.children.length != 0){
_.each(treeNode.children,function(cd){
$scope.add_org(cd);
});
}else{
var org_selecting = {
"orgName":treeNode.name,
"orgCode":treeNode.orgCode
};
var push_flag = true;
_.each($scope.org_selected,function(_org){
if(_org.orgCode == org_selecting.orgCode){
push_flag = false;
}
});
if(push_flag){
$scope.org_selected.push(org_selecting);
if($scope.datamodel && $scope.datamodel.length > 0){
$scope.datamodel.splice(0, $scope.datamodel.length);
}
_.each($scope.org_selected, function(item) {
if(!$scope.datamodel)
$scope.datamodel = [];
$scope.datamodel.push(item.orgCode);
})
}
}
};
$scope.remove_org = function(org) {
_.remove($scope.org_selected,function(n){
return n == org;
});
_.pull($scope.datamodel,org.orgCode);
};
function get_org(data,arr){
_.each(data,function(_data){
if(_data.orgCode == arr){
$scope.org_selected.push({
"orgName":_data.orgName,
"orgCode":_data.orgCode
})
}
});
if(data.child){
get_org(data.child,arr);
}
}
$scope.init_tree = function() {
http_service.post('base/data/search/institutionData', {}, function(res) {
console.log('33333333');
if(res.data.opState){
var hr_data_str = JSON.stringify(res.data.data).replace(/child/g, 'children').replace(/orgName/g, 'name');
var hr_data_json = JSON.parse(hr_data_str);
var setting = {
'callback': {
'onClick': function(event, treeId, treeNode) {
var orgName = treeNode.name;
var md_id = treeNode.orgCode;
if(treeNode.level > 0){
$scope.add_org(treeNode);
}
}
}
};
console.log('1110');
$.fn.zTree.init($("div.hr_tree"), setting, hr_data_json);
}else{
$scope.$parent.$parent.$parent.$parent.$parent.terro(res.data.errMsg)
}
});
}
$scope.init_org = function(){
http_service.post('base/data/search/institutionData', {}, function(res) {
console.log(22222222);
if(res.data.opState){
if($scope.datamodel && $scope.datamodel.length != 0){
_.each($scope.datamodel,function(_arr){
_.each(res.data.data,function(data){
get_org(data.child,_arr);
})
})
}
}
});
};
$scope.init_org();
}
}
}])
.directive('select4', ['$rootScope', 'http_service', '$timeout', '$interval',
function($rootScope, http_service, $timeout, $interval) {
return {
restrict: 'ACEM',
templateUrl: './static/templates/select3.html',
transclude: true,
scope: {
style: '=',
datamodel: '=',
options: '='
},
compile: function() {
return {
pre: function(scope, iElement, iAttrs, controller) {
var $scope = scope;
$scope.type = scope.$parent.type;
$scope.billid = scope.$parent.billid;
$scope.$watchGroup(['datamodel','options'], function() {
if(scope.datamodel){
if(scope.datamodel.length == 0){//替换控件时清空
scope.sel_val_lst = [];
}else if(scope.datamodel[0] == ''){
scope.sel_val_lst = [];
}
}else{
scope.sel_val_lst = [];
}
var mp = _.filter(scope.options, function(op) {
return _.indexOf(scope.datamodel, op.code) > -1;
});
if(mp.length !== 0){
scope.sel_val_lst = _.map(mp, function(m) {
return { 'value': m.code, 'label': m.value };
});
}
var typename = _.filter(scope.options, function(op) {
return _.indexOf(scope.datamodel, op.mdCode) > -1||_.indexOf(scope.datamodel, op.cdCode) > -1;
});
if(typename.length !== 0 && !scope.sel_val_lst){
scope.sel_val_lst = _.map(typename, function(n) {
return {'value': n.mdCode||n.cdCode, 'label': n.mdName||n.cdValue };
});
// scope.sel_val_lst = scope.datamodel;
}
}, true);
var $el = $(iElement);
$el.find('div.select-container').css({"padding-left":'10px',"width":"90%"});
$el.find('div.suffix').css({"width":"30%","max-width":"26px"});
$el.find('div.val-card').css({"padding":"0px","height":"28px","line-height":"28px"});
$el.find('div.select-container').on('click', function(event) {
$('div.drop_down_sel').remove();
var $select = $el.find('select');
var isMultiple = $select.attr('multiple');
var $options = $el.find('select > option');
// 增加搜索框
var $options_str = '';
// 可多选时 增加全选复选框
if($select.attr('multiple')) {
$options_str += '' +
'- ' +
'
' +
'
' +
'' +
'
' +
'
全选
' +
'
' +
' ' +
'
';
}
_.each(scope.options, function(option) {
var checked = '';
if(_.indexOf(scope.datamodel, option.code) > -1) {
checked = 'checked';
}
var optionvalue = option.value || option.mdName || option.cdValue;
var optioncode = option.code || option.mdCode || option.cdCode;
$options_str += '' +
'- ' +
'
' +
'
' +
'' +
'
' +
'
' + optionvalue + '
' +
'
' +
' ' +
'
';
});
var $select_obj = $('' +
$options_str +
'
');
$el.find('div.select3-element').append($select_obj);
$('body').off('click').on('click', function() {
$('div.drop_down_sel').remove();
});
$('div.drop_down_sel').off('click').on('click', function(event) {
event.stopPropagation();
});
// 查询功能
$select_obj.find('input[name="query"]').on('keyup', function() {
var $el = $(this);
var inputs = $select_obj.find('input[name="checkbox"]');
inputs.each(function() {
var val = $(this).attr('label');
var input_val = $el.val();
if(val.indexOf(input_val) > -1) {
$(this).closest('ul').show();
} else {
$(this).closest('ul').hide();
}
});
});
// 点击选择
$select_obj.find('input[name="checkbox"]').on('click', function() {
var vals_selected = [];
if(!isMultiple) {
$('div.drop_down_sel input[name="checkbox"]').prop('checked', false);
$(this).prop('checked', true);
$select.val($(this).val());
vals_selected = [{ 'value': $(this).val(), 'label': $(this).attr('label') }];
} else {
var vls = [];
$('div.drop_down_sel input[name="checkbox"]:checked').each(function() {
vals_selected.push({ 'value': $(this).val(), 'label': $(this).attr('label') });
vls.push($(this).val());
});
$select.val(vls);
}
$timeout(function() {
scope.sel_val_lst = vals_selected;
}, 0);
if(scope.datamodel && scope.datamodel.length > 0){
scope.datamodel.splice(0, scope.datamodel.length);
}
_.each(vals_selected, function(item) {
if(!scope.datamodel)
scope.datamodel = [];
scope.datamodel.push(item.value);
})
/*
$timeout(function(){
scope.datamodel.concat(select_vals);
}, 0);
*/
});
$select_obj.find('input[name="all"]').on('click', function() {
if($(this).prop("checked") == false) {
$('div.drop_down_sel input[name="checkbox"]').each(function() {
if($(this).prop("checked") == true) {
$(this).click();
}
});
} else {
$('div.drop_down_sel input[name="checkbox"]').each(function() {
if($(this).prop("checked") == false) {
$(this).click();
}
});
}
})
event.stopPropagation();
});
scope.rm_option = function(event) {
var $elt = $(event.target);
$elt.closest('div.val-card').remove();
var val = $elt.attr('val');
var value = JSON.parse(val).value;
scope.sel_val_lst = _.filter(scope.sel_val_lst, function(t) {
return JSON.stringify(t) != value;
});
$timeout(function() {
_.pull(scope.datamodel, value);
}, 0);
event.stopPropagation();
};
},
post: function($scope, element, attrs) {}
}
}
}
}
])
.directive('expenseStandardRow', ['$rootScope', 'http_service', '$timeout','$compile', function($rootScope, http_service, $timeout,$compile) {
return {
restrict: 'ACEM',
template: '' +
'' +
' 1" ' +
'>' +
// '' +
// '' +
'' +
'' +
'' +
// '' +
// '' +
'' +
'' +
''+
'' +
'' +
'' +
''+
''+
''+
''+
'Fx'+
'' +
'' +
'' +
''+
'Fx'+
' | ' +
'
',
replace: true,
scope: {
tabletitlescfg: '=',
expenserowdata: '=',
expensedata: '='
},
compile: function() {
return {
pre: function(scope, iElement, iAttrs, controller) {
scope.style = {
'width': '80%'
}
scope.isEmpty = function(obj) {
return _.keys(obj).length === 1;
};
scope.rm_row = function(rowData) {
var delete_index;
_.each(scope.expensedata, function(_row_data, index) {
if(_row_data === rowData) {
delete_index = index;
}
});
if(scope.expensedata.length > 1){
scope.expensedata.splice(delete_index,1);
}else{
var ex_keys = _.keys(scope.expensedata[0]);
_.each(ex_keys,function(ekey){
scope.expensedata[0][ekey] = {"asInverse":1,"grant_value":""}
})
}
};
$('body').off('click').on('click', function() {
$('div.showtype').remove();
});
$('div.showtype').off('click').on('click', function(event) {
event.stopPropagation();
});
//正选、反选
scope.change_Inverse = function(index){
if(scope.expenserowdata[index].asInverse == 1){
scope.expenserowdata[index].asInverse = 0;
}else{
scope.expenserowdata[index].asInverse = 1;
}
}
scope.unfold = function(allData, rowData, colNum) {
var colValues = _.uniq(rowData[colNum]['grant_value']);
var uid = rowData[colNum]['group_id'] || _.uuid();
var newRowData = [];
_.each(allData, function(data) {
if(data === rowData) {
for(var i = 0, len = colValues.length; i < len; i++) {
var dt = _.cloneDeep(data);
dt[colNum]['grant_value'] = [colValues[i]];
dt[colNum]['group_id'] = uid;
newRowData.push(dt);
}
} else {
newRowData.push(data);
}
});
scope.expensedata.splice(0, scope.expensedata.length);
$timeout(function() {
_.each(newRowData, function(rd) {
scope.expensedata.push(rd);
});
}, 1);
};
scope.fold = function(allData, rowData, colNum) {
var colValues = rowData[colNum]['grant_value'];
var uid = rowData[colNum]['group_id'];
var newRowData = [];
var gt_vals = [];
var tmp = {};
_.each(allData, function(data) {
if(!data[colNum]) return false;
var _uid = data[colNum] && data[colNum]['group_id'];
if(_uid === uid) {
if(!tmp[uid]) {
newRowData.push(rowData);
tmp[uid] = rowData;
}
gt_vals = gt_vals.concat(data[colNum]['grant_value']);
} else {
newRowData.push(data);
}
});
if(!!gt_vals.length && tmp[uid]) {
tmp[uid][colNum]['grant_value'] = gt_vals;
tmp[uid][colNum]['group_id'] = null;
}
scope.expensedata.splice(0, scope.expensedata.length);
$timeout(function() {
_.each(newRowData, function(rd) {
scope.expensedata.push(rd);
});
}, 1);
};
// scope.$watch(function(){
// return $rootScope.relate
// },function(){
// if($rootScope.relate != undefined){
// scope.relation = $rootScope.relate.split(" ")[0];
// scope.amounts = $rootScope.relate.split(" ")[1];
// }
// })
//
// scope.$watch(function(){
// return $rootScope.pervalue
// },function(){
// if($rootScope.pervalue != undefined){
// scope.per = $rootScope.pervalue;
// }
// })
scope.sys_fx = function(col,$index){//系统变量编辑
scope.sys_fx_index = $index;
if(scope.expenserowdata[$index] && scope.expenserowdata[$index]['sys_val'].id == undefined){
_.extend(scope.expenserowdata[$index]['sys_val'],col);
// scope.expenserowdata[$index]['sys_val'] = _.cloneDeep(col);
}
scope.sys_col = _.cloneDeep(scope.expenserowdata[$index]['sys_val']);
scope.joinMath = [];
_.each(scope.sys_col.children,function(cd){
if(cd.joinMathId && cd.joinchildren == undefined){
_.each($rootScope.system_titles,function(sys_tit){
if(sys_tit.id == cd.joinMathId){
_.extend(cd,{'joinchildren':_.cloneDeep(sys_tit.child)});
scope.joinMath.push(cd);
}
})
}else if(cd.joinMathId){
scope.joinMath.push(cd);
}
})
// if(col.group == 1 || col.group == 2){
// scope.sys_count_show = true;
// }else{
// scope.sys_count_show = false;
// }
scope.sys_count_show = col.group;
scope.col_type = col.resultFromat;
if(scope.sys_count_show == 3){
scope.sys_sign_list = ["+","-","*","/"];
}else{
if(col.resultFromat == 10 || col.resultFromat == 30){//系统变量类型为 数值
scope.sys_sign_list = ["<",">",">=","<=","==","<>"];
// scope.sys_data_type_list = [{"label":"字符","value":"string"},{"label":"数值","value":"number"}];
}else if(col.resultFromat == 20){//系统变量类型为 比较
scope.sys_sign_list = ["=="];
scope.sys_data_type_list = [{"label":"真","value":"true"},{"label":"假","value":"false"}];
}
}
scope.sys_sign = undefined;
scope.sys_data = undefined;
scope.sys_data_type = undefined;
if(scope.sys_col.sys_count){
var sys_relation = _.drop(scope.sys_col.sys_count.split(" "));
if(col.resultFromat == 10 || col.resultFromat == 30){
scope.sys_sign = sys_relation[0];
scope.sys_data = sys_relation[1];
// scope.sys_data_type = sys_relation[2].replace("{","");
// scope.sys_data_type = scope.sys_data_type.replace("}","");
// _.each(scope.sys_data_type_list,function(data_type){
// if(data_type.value == scope.sys_data_type){
// $timeout(function(){
// scope.sys_data_type = _.cloneDeep(data_type);
// },1)
//
// }
// })
}else if(col.resultFromat == 20){
scope.sys_sign = sys_relation[0];
scope.sys_data_type = sys_relation[1];
_.each(scope.sys_data_type_list,function(data_type){
if(data_type.value == scope.sys_data_type){
$timeout(function(){
scope.sys_data_type = _.cloneDeep(data_type);
},1)
}
})
}
}
var sys_null = '';
var sys_fx = ""+
"
"+
"
" +
"
"+
"
"+
"系统变量"+
"运算符"+
"数据类型"+
"输入值"+
"
"+
"
"+
""+col.mdName+""+
"
"+
"
"+
""+
"
"+
"
"+
""+
"
"+
"
"+
""+
"
"+
"
"+
"
"+
""+
""+
"
"+
"
"+
"
"+
"
"+
""+
""+
"
"+
"
"+
"
" +
"
"+
"
"+
"
"
var $sys_fx = $compile(sys_fx)(scope);
$('body').append($sys_fx);
}
scope.sys_close = function(){
$('.bg-modal').remove();
}
scope.clear_data = function(){
if(scope.sys_sign == '' || _.isNull(scope.sys_sign)){
scope.sys_data = '';
scope.sys_data_type = "";
}
}
scope.save_sys_fx = function(){
scope.expenserowdata[scope.sys_fx_index]['sys_val'] = _.cloneDeep(scope.sys_col);
var sys_arr = [];
_.each(scope.sys_col.children,function(cd){
if(cd.val && cd.val != ""){
if(cd.joinMathId == undefined){
sys_arr.push(cd.val);
}else{
_.each(scope.joinMath,function(join){
if(join.joinMathId == cd.joinMathId){
_.each(cd.joinchildren,function(jcd){
if(jcd.val && jcd.val != ""){
sys_arr.push(jcd.val)
}
})
}
})
}
}
});
scope.expenserowdata[scope.sys_fx_index]['sys_val']['show_sys_fx'] = scope.sys_col.name + "(" + sys_arr.join(",") + ")";
// if(scope.sys_count_show){//补助条件 与 标准
var sys_count = '';
var sys_count_str = '';
if(scope.sys_sign != undefined && scope.sys_sign != "" && _.isNull(scope.sys_sign) == false){
sys_count += " " + scope.sys_sign;
sys_count_str += " " + scope.sys_sign;
}
if(scope.sys_data != undefined && scope.sys_data != "" && _.isNull(scope.sys_data) == false){
sys_count += " "+scope.sys_data;
sys_count_str += " " + scope.sys_data;
}
if(scope.sys_data_type != '' && scope.sys_data_type != undefined && scope.sys_data_type.value != "" && _.isNull(scope.sys_data_type.value) == false){
if(scope.col_type == 10 || scope.col_type == 30){
sys_count += " {"+scope.sys_data_type.value + "}";
}else{
sys_count += " "+ scope.sys_data_type.value;
}
sys_count_str += " "+ scope.sys_data_type.label;
}
if((scope.sys_sign == undefined || scope.sys_sign == "" || _.isNull(scope.sys_sign) || scope.sys_data == undefined || scope.sys_data == "" || _.isNull(scope.sys_data)) && (scope.col_type == 10 || scope.col_type == 30 || scope.sys_count_show == 3)){//运算符 与输入值必须同时存在
scope.expenserowdata[scope.sys_fx_index]['sys_val']['sys_count'] = '';
sys_count_str = '';
}else if(scope.col_type == 20 && (scope.sys_sign == undefined || scope.sys_sign == "" || _.isNull(scope.sys_sign) || scope.sys_data_type == '' || scope.sys_data_type == undefined || scope.sys_data_type.value == "" || _.isNull(scope.sys_data_type.value))){
scope.expenserowdata[scope.sys_fx_index]['sys_val']['sys_count'] = '';
sys_count_str = '';
}else{
scope.expenserowdata[scope.sys_fx_index]['sys_val']['sys_count'] = sys_count;
}
scope.expenserowdata[scope.sys_fx_index]['sys_val']['show_sys_fx'] += sys_count_str
// }
scope.sys_close();
}
scope.fxdiv = function(col,$index){
scope.fixdiv_index = $index;
var fxdiv = ""+
"
"+
"
" +
"
"+
"
补助标准内容布尔运算符数据类型输入值" +
"
"+col.mdName+"
"+
"
"+
"
"+
"
{{relation}}"+
"
"+
""+
"
"+
"
"+
"
"+
"- <
"+
"- <=
"+
"- >
"+
"- >=
"+
"- ==
"+
"
"+
"
"+
"
"+
"
"+
"
"+
"
公式结果:{{aa}}"+ col.mdName +" {{relation}} {{amounts}} {{per}}
"+
"
" +
"
"+
"
"+
"
"
var $fxdiv = $compile(fxdiv)(scope);
$('body').append($fxdiv);
if(scope.expenserowdata[$index] && scope.expenserowdata[$index].grant_value){
if(_.isArray(scope.expenserowdata[$index].grant_value)){
var fx_data = scope.expenserowdata[$index].grant_value[0].split(" ");
}else{
var fx_data = scope.expenserowdata[$index].grant_value.split(" ");
}
scope.relation = fx_data[1];
scope.amounts = fx_data[2];
scope.per = fx_data[3];
}
// $('body').off('click').on('click',function() {
// if(scope.fxshows){
// $('#showfx').hide();
// scope.fxshows = false;
// }
// if(scope.fxshowss){
// $('#showfxs').hide();
// scope.fxshowss = false;
// }
// });
// $('body').off('click').on('click', function() {
// $('div.showfx').remove();
// });
// $('div.drop_down_sel').off('click').on('click', function(event) {
// event.stopPropagation();
// });
// $('div.select3-element').off('click').on('click', function(event) {
// event.stopPropagation();
// });
}
scope.getper = function(event){
var event = event || window.event;
scope.per = event.target.innerHTML;
scope.per = scope.per.split("").slice(0,-1).join("");
scope.fxshows = true;
}
scope.getrelation = function(event){
var event = event || window.event;
scope.relation = event.target.innerText;
scope.fxshowss = false;
}
scope.close = function(){
$('.fxresult').text("");
$('.bg-modal').hide();
}
scope.savefx = function(){
if(!scope.per || !scope.relation || !scope.amounts){
scope.$parent.$parent.$parent.tinfo('请填写完成后保存');
}else if(isNaN(scope.amounts)){
scope.$parent.$parent.$parent.tinfo('请在输入值处填写数字');
}else{
scope.result = $('.fxresult').text().substring(5);
$('.fxresult').text("");
if(scope.expenserowdata[scope.fixdiv_index] == undefined){
var grant_value_now = {"grant_value":scope.result};
var fixdiv_index = scope.fixdiv_index;
scope.expenserowdata[fixdiv_index] = grant_value_now;
}else{
scope.expenserowdata[scope.fixdiv_index].grant_value = scope.result;
}
scope.close();
}
}
function refreshRowData() {
scope.rowData = [];
//
_.each(scope.expenserowdata,function(row_data){
if(row_data != undefined && row_data.asInverse == undefined){
_.extend(row_data,{"asInverse":1});
}
})
var conditionCfg = scope.tabletitlescfg.expenseConditionsTitles;
var criteriaCfg = scope.tabletitlescfg.expenseCtriteraTitles;
var budgetCfg = scope.tabletitlescfg.expenseBudgetTitles;
var i = 0;
_.each(conditionCfg, function(cfg) {
// if(!cfg.mdId) {
// scope.rowData[i] = {};
// } else {
scope.rowData[i] = cfg;
// }
i++;
});
_.each(criteriaCfg, function(cfg) {
// if(!cfg.mdId) {
// scope.rowData[i] = {};
// } else {
scope.rowData[i] = cfg;
// }
i++;
});
//
_.each(budgetCfg, function(cfg) {
_.each(cfg.child, function(sub_cfg) {
if(!sub_cfg.code && cfg.id == undefined) {
scope.rowData[i] = {};
} else if(cfg.id != undefined){//系统变量处理
scope.rowData[i] = cfg;
} else{
scope.rowData[i] = _.extend(
sub_cfg, {
'mdId': cfg.mdId,
'mdDesc': cfg.mdDesc,
'mdCode': cfg.mdCode,
'mdName': cfg.mdName,
'mdType': cfg.mdType
}
);
}
i++;
});
});
_.each(scope.rowData, function(title) {
if(!title.code && title.mdCode && title.eleCode) {
http_service.post('base/data/search', { "code": title.mdCode,"cache_id":title.mdCode }, function(res) {
if(!res.data.opState){
return false;
}
title['values'] = res.data.data.child;
title['elIden'] = res.data.data.elIden;
},true)
}
});
var is_org;
_.each(filed,function(_filed){
if(_filed.busCode == "orgCode"){
is_org = _filed.mdCode;
}
})
_.each(scope.rowData, function(title){
if(title.mdCode == is_org){
title[is_org] == true;
}
// if(title.mdCode == "F085"){
// title['is_org'] = true;
// }
})
}
scope.$watch('tabletitlescfg', function() {
refreshRowData();
}, true);
}
}
}
}
}])
.directive('expenseTable', ['$rootScope', 'http_service','$timeout', function($rootScope, http_service,$timeout) {
return {
restrict: 'ACEM',
templateUrl: './static/templates/expense_standard_table.html',
replace: true,
scope: {
allexpensedata: '=',
expensedata: '=',
index: '=',
tabletitlescfg: '=',
tabletitlescfgs: '=',
sstype: '=',
ssname: '=',
// ssSubType:'=',
sstypes: '=',
ssnames: '=',
ssrules:'=',
// ssSubTypes:'=',
sstypename: '=',
ssnamename:'=',
sstnames:'=',
ssnnames:'='
},
compile: function() {
return {
pre: function(scope, iElement, iAttrs, controller) {
scope.$watch("tabletitlescfg",function(){
scope.expenseConditionsTitles = scope.tabletitlescfg['expenseConditionsTitles'];
scope.expenseCtriteraTitles = scope.tabletitlescfg['expenseCtriteraTitles'];
scope.expenseBudgetTitles = scope.tabletitlescfg['expenseBudgetTitles'];
});
scope.expenseConditionsTitles = scope.tabletitlescfg['expenseConditionsTitles'];
scope.expenseCtriteraTitles = scope.tabletitlescfg['expenseCtriteraTitles'];
scope.expenseBudgetTitles = scope.tabletitlescfg['expenseBudgetTitles'];
scope.$watch(function(){
return scope.ssrules;
},function(){
scope.ssRule = scope.ssrules[scope.index];
})
scope.ssRuleOps = [
{"val":"0","name":"无"},
{"val":"1","name":"最大"},
{"val":"2","name":"最小"},
{"val":"3","name":"平均"},
{"val":"4","name":"最先到达"},
{"val":"5","name":"最后到达"}
];
scope.budgetColspan = function(titles) {
var colspan = 0;
_.each(titles, function(title) {
if(title.child && title.child.length) {
colspan += title.child.length;
} else {
colspan += 1;
}
});
return colspan;
};
scope.duplicate_expense_strd_table = function() {
$('div.drop_down_sel').remove();
scope.allexpensedata.push(_.cloneDeep(scope.expensedata));
scope.tabletitlescfgs.push(_.cloneDeep(scope.tabletitlescfg));
// scope.sstypename.push(_.cloneDeep(scope.sstypename));
// scope.ssnamename.push(_.cloneDeep(scope.ssnamename));
scope.ssnames.push(_.cloneDeep(scope.ssname));
scope.sstypes.push(_.cloneDeep(scope.sstype));
// scope.ssSubTypes.push(_.cloneDeep(scope.ssSubType));
};
scope.rm_expense_strd_table = function() {
$('div.drop_down_sel').remove();
_.remove(scope.allexpensedata, function(item) {
return item === scope.expensedata
});
_.remove(scope.tabletitlescfgs, function(item) {
return item === scope.tabletitlescfg;
});
// _.remove(scope.ssnames,function(item){
// return item === scope.ssname
// })
// _.remove(scope.types,function(item){
// return item === scope.sstype
// })
// _.remove(scope.expenseBudgetTitles,function(item){
// return item === scope.expenseBudgetTitles[0]
// })
// _.remove(scope.expenseConditionsTitles,function(item){
// return item === scope.expenseConditionsTitles[0]
// })
// _.remove(scope.expenseCtriteraTitles,function(item){
// return item === scope.expenseCtriteraTitles[0]
// })
// scope.addConditions();
// scope.addCritera();
// scope.addBudget();
// _.each(scope.expenseBudgetTitles,function(budgettitle){
// _.remove(scope.tabletitlescfg,function(item){
// return item === budgettitle
// })
// })
// _.each(scope.expenseConditionsTitles,function(conditiontitle){
// _.remove(scope.tabletitlescfg,function(item){
// return item === conditiontitle
// })
// })
// _.each(scope.expenseCtriteraTitles,function(ctriteratitle){
// _.remove(scope.tabletitlescfg,function(item){
// return item === ctriteratitle
// })
// })
// scope.sstypename=''
// scope.ssnamename=''
scope.sstypes.splice(scope.index,1)
scope.ssnames.splice(scope.index,1)
scope.ssrules.splice(scope.index,1)
scope.ssRule = scope.ssrules[scope.index];
};
// scope.$watch('tabletitlescfgs', function() {
// scope.$parent.table();
// });
//添加一个条件目录
scope.addConditions = function() {
var index = _.cloneDeep(scope.expenseConditionsTitles).length;
for(i in scope.expensedata){
var data = _.cloneDeep(scope.expensedata[i]);
var newdata = {};
var num = -1;
for(j in scope.expensedata[i]){
num++;
newdata[num] = _.cloneDeep(data[j]);
if(j == (index-1)){
num++;
newdata[num] = {"grant_value":[""]};
}else if(j > (index-1)){
newdata[num] = _.cloneDeep(data[j]);
}
}
scope.expensedata[i] = newdata;
}
scope.expenseConditionsTitles.push({
enable: true
});
};
//添加一个标准目录
scope.addCritera = function() {
var index1 = _.cloneDeep(scope.expenseConditionsTitles).length;
var index2 = _.cloneDeep(scope.expenseCtriteraTitles).length;
var index = index1+index2;
for(i in scope.expensedata){
var data = _.cloneDeep(scope.expensedata[i]);
var newdata = {};
var num = -1;
for(j in scope.expensedata[i]){
num++;
newdata[num] = _.cloneDeep(data[j]);
if(j == (index-1)){
num++;
newdata[num] = {"grant_value":[""]};
}else if(j > (index-1)){
newdata[num] = _.cloneDeep(data[j]);
}
}
scope.expensedata[i] = newdata;
}
scope.expenseCtriteraTitles.push({
enable: true
});
// var sliceinfo = [];
// _.each(scope.allexpensedata,function(data){
//// if(data.length > 1){
// _.each(data,function(info,index){
// for(i in info){
// var infos = info[i];
// info[2] = {'grant_value':['']}
// if(parseInt(i) > 2){
//// info[i] = info[i+1];
// sliceinfo.push(infos);
// }
// }
// })
//// }
// })
};
//添加一个横向显示的目录
scope.addBudget = function() {
for(i in scope.expensedata){
var data = _.cloneDeep(scope.expensedata[i]);
var num = -1;
for(j in scope.expensedata[i]){
num++;
}
num++;
scope.expensedata[i][num] = {"grant_value":[""]};
}
scope.expenseBudgetTitles.push({
enable: true,
child: [{}]
});
};
//移出目录
scope.rmTitle = function(title,indexs,type) {
var index1 = _.cloneDeep(scope.expenseConditionsTitles).length;
var index2 = _.cloneDeep(scope.expenseCtriteraTitles).length;
var index3 = _.cloneDeep(scope.expenseBudgetTitles).length;
var typeindex;
var index;
var childnum;
var thischildnum;
switch (type){
case 1:
index = indexs+1;
typeindex = index1;
thischildnum = 1;
break;
case 2:
index = parseInt(index1)+indexs+1;
typeindex = index2;
thischildnum = 1;
break;
case 3:
index = parseInt(index1)+parseInt(index2);
typeindex = index3;
childnum = 0;
for(i in scope.expenseBudgetTitles){
childnum += scope.expenseBudgetTitles[i].child.length;
if(scope.expenseBudgetTitles[i] == title){
break;
}
}
// index += childnum;
thischildnum = title.child.length;
index = index + childnum - thischildnum +1;
break;
}
for(i in scope.expensedata){
var data = _.cloneDeep(scope.expensedata[i]);
var newdata = {};
var num = -1;
for(j in scope.expensedata[i]){
// num++;
// if(index == 1){
// newdata[j] = {"grant_value":[""]};
// }else{
// newdata[j] = _.cloneDeep(data[j]);
// }
num++;
if(j != (index-1)){
if(data[num] != undefined){
newdata[j] = _.cloneDeep(data[num]);
}
}else{
if(typeindex != 1){
num += thischildnum;
newdata[j] = _.cloneDeep(data[num]);
}else{
newdata[j] = {"grant_value":[""]};
if(type == 3){
break;
}
}
}
}
scope.expensedata[i] = newdata;
}
_.remove(scope.expenseConditionsTitles, function(item) {
if(title == item){
_.extend(title,{"id":false});
}
if(title == item && scope.expenseConditionsTitles.length === 1) {
_.extend(item, {
"mdId": "",
"mdDesc": "",
"mdName": "",
"mdType": "",
"mdCode":""
});
return false;
}
return item === title;
});
_.remove(scope.expenseCtriteraTitles, function(item) {
if(title == item){
_.extend(title,{"id":false});
}
if(title == item && scope.expenseCtriteraTitles.length === 1) {
_.extend(item, {
"mdId": "",
"mdDesc": "",
"mdName": "",
"mdType": "",
"mdCode":""
});
return false;
}
return item === title;
});
_.remove(scope.expenseBudgetTitles, function(item) {
if(title == item){
_.extend(title,{"id":false});
}
if(title == item && scope.expenseBudgetTitles.length === 1) {
item.child = [{}];
_.extend(item, {
"child": [{}],
"mdId": "",
"mdDesc": "",
"mdName": "",
"mdType": "",
"mdCode":""
});
return false;
}
return item === title;
});
};
//关系选择
scope.togle_relation = function(title,index,type){
switch(type){
case 1:
//
if(scope.expenseConditionsTitles[index]['asRelation'] != undefined && scope.expenseConditionsTitles[index]['asRelation'] == 0){
scope.expenseConditionsTitles[index]['asRelation'] = 1;
}else{
scope.expenseConditionsTitles[index]['asRelation'] = 0;
}
break;
case 2:
if(scope.expenseCtriteraTitles[index]['asRelation'] != undefined && scope.expenseCtriteraTitles[index]['asRelation'] == 0){
scope.expenseCtriteraTitles[index]['asRelation'] = 1;
}else{
scope.expenseCtriteraTitles[index]['asRelation'] = 0;
}
break;
}
}
// function refreshRowData() {
// scope.rowData = [];
// var conditionCfg = scope.expenseConditionsTitles;
// var criteriaCfg = scope.expenseCtriteraTitles;
// var budgetCfg = scope.expenseBudgetTitles;
// var i = 0;
// _.each(conditionCfg, function(cfg) {
// if(!cfg.mdId) {
// scope.rowData[i] = {};
// } else {
// scope.rowData[i] = cfg;
// }
// i++;
// });
// _.each(criteriaCfg, function(cfg) {
// if(!cfg.mdId) {
// scope.rowData[i] = {};
// } else {
// scope.rowData[i] = cfg;
// }
// i++;
// });
// _.each(budgetCfg, function(cfg) {
// _.each(cfg.child, function(sub_cfg) {
// if(!sub_cfg.code) {
// scope.rowData[i] = {};
// } else {
// scope.rowData[i] = _.extend(
// sub_cfg, {
// 'mdId': cfg.mdId,
// 'mdDesc': cfg.mdDesc,
// 'mdCode': cfg.mdCode,
// 'mdName': cfg.mdName,
// 'mdType': cfg.mdType
// }
// );
// }
// i++;
// });
// });
// _.each(scope.rowData, function(title) {
// if(!title.code && title.mdCode) {
// http_service.post('base/data/search', { "code": title.mdCode }, function(res) {
// title['values'] = res.data.data.child;
// title['elIden'] = res.data.data.elIden;
// })
// }else{
// title['values']=[]
// }
// });
// }
// scope.$watch('tabletitlescfgs', function() {
// refreshRowData();
// }, true);
scope.$watch('expenseBudgetTitles', function() {
var budgetSubTitles = [];
_.each(scope.expenseBudgetTitles, function(title) {
if(title.child && title.child.length !== 0){
budgetSubTitles = budgetSubTitles.concat(title.child);
}
else{
title.child = [{"value":title.mdName}];
budgetSubTitles.push([{
"child": [{}],
"mdId": "",
"mdDesc": "",
"mdName": "",
"mdType": ""
}])
}
});
scope.budgetSubTitles = budgetSubTitles;
}, true);
//添加数据
scope.addRow = function() {
$('div.drop_down_sel').remove();
var data = _.cloneDeep(scope.expensedata);
_.each(data[0],function(exdata){
exdata['grant_value'] = [""];
if(exdata['sys_val'] && exdata['sys_val'].id != undefined){
exdata['sys_val'] = {"show_sys_fx":exdata['sys_val'].name + "()"};
}
})
scope.expensedata.push(data[0]);
};
scope.selecttype = function($index) {
// TODO
scope.sstype = scope.ssTypeOptions[$index].mdCode;
scope.sstypename.push(scope.ssTypeOptions[$index].mdName);
}
scope.selectname = function($index) {
scope.ssname = scope.ssNameOptions[$index].cdCode;
scope.ssnamename = scope.ssNameOptions[$index].cdValue;
}
},
post: function($scope, element, attrs) {
if(!$scope.expensedata.length){
$scope.expensedata.push({});
}
http_service.post('supp/search/money/type', {}, function(res) {
$scope.ssTypeOptions = res.data.data;
$scope.$watch(function(){
return $scope.sstype
},function(){
_.each($scope.ssTypeOptions,function(opt){
if(opt.code == $scope.sstype){
$scope.sstypename = opt.value;
}
})
})
$scope.$watch(function(){
return $scope.ssname
},function(){
if($scope.ssname != "222"){
$timeout(function(){
$scope.ssSubType = true;
$scope.ssRule = "0";
},1)
}
_.each($scope.ssNameOptions,function(opt){
if(opt.cdCode == $scope.ssname){
$scope.ssnamename = opt.cdValue;
}
})
})
});
// http_service.post('supp/search/const', { "cdType": "90" }, function(res) {
$scope.ssNameOptions = _.filter(cddata,function(o){
return o.cdType == 90;
})
// $scope.ssNameOptions = res.data.data;
$scope.$watch(function(){
return $scope.$parent.ssSubTypes;
},function(){
$scope.ssSubType = $scope.$parent.ssSubTypes[$scope.index];
})
$scope.$watch(function(){
return $scope.ssSubType;
},function(){
$scope.$parent.ssSubTypes[$scope.index] = $scope.ssSubType;
})
$scope.$watch(function(){
return $scope.$parent.ssrules;
},function(){
$scope.ssRule = $scope.$parent.ssrules[$scope.index];
})
$scope.$watch(function(){
return $scope.ssRule;
},function(){
$scope.$parent.ssrules[$scope.index] = $scope.ssRule;
})
// });
// $(document).off('click').on('click',function(event){
//// $scope.showname = false;
//// $scope.showclass = false;
// $('.showtype').hide();
// $('.showname').hide();
// event.stopPropagation()
// event.preventDefault()
// })
// $scope.showtype = function(event){
// $(event).closest('.select3-element').find('.showtype').show();
//// $scope.showclass = true
// event.stopPropagation()
// event.preventDefault();
// }
// $('.type').off('click').on('click',function(event){
// $('.showtype.typeshow').show();
// $(event.target).show();
//// $scope.showtype = true
// event.stopPropagation();
// })
// $('.name').off('click').on('click',function(event){
//// $('.showname.showtype').show();
// $(event.target).show();
//// $scope.showname = true
// event.stopPropagation();
// })
}
}
}
}
}])
.controller('expendStandardCtrl', ['$scope', 'http_service', '$timeout','$rootScope', function($scope, http_service, $timeout,$rootScope) {
$scope.sstypes = [''];
$scope.ssnames = [''];
$scope.ssrules = ['0'];//最大、最小、平均、最先到达、最后到达、无
$scope.ssSubTypes = ['1'];
$scope.allexpensedata = [
[]
];
$scope.tabletitlescfgs = [{
"expenseConditionsTitles": [{}],
"expenseCtriteraTitles": [{}],
"expenseBudgetTitles": [{ "child": [{}] }]
}];
function refreshMas(obj) {
var title;
if(obj.type != 5){
title = _.get(_.filter($scope.expense_titles, function(o) {
return o.mdCode === obj.mdCode;
}), 0);
}else{//系统变量回调
title =_.cloneDeep(_.get(_.filter($scope.system_titles,function(o){
return o.id == obj.id;
}), 0))
if(title != undefined){
if(obj.child != undefined && title.child != undefined){
_.extend(title,{'children':title.child});
title.child = [{'value':title.name}];
}
_.extend(title,{'mdName':title.name});
}else{
title = {'mdName':'此系统变量已被删除','notFound':true};
}
}
_.extend(obj,title);
return obj;
}
function refreshBudget(obj) {
if(obj.mdCode){
http_service.post('base/data/search', { "code": obj.mdCode,"ceche":obj.mdCode }, function(res) {
if(!res.data.data) return false;
$timeout(function() {
obj.child = res.data.data.child;
obj.elIden = res.data.data.elIden;
}, 1);
},true);
}
}
function getTableCFG(data) {
//添加关系属性
//
_.each(data.child,function(dt){
if(dt.asRelation == undefined){
dt['asRelation'] = 1;
}
})
var firstColumnDT = _.filter(data.child, function(dt) {
return dt.asRowNo === 0;
});
var conditions = _.filter(firstColumnDT, function(dt) {
return dt.asType == 1;
});
// var relations = _.filter(firstColumnDT, function(dt) {
// return dt.asDefType === 11;
// });
conditions = _.sortBy(conditions, function(o) {
return o.asColNo;
});
// relations = _.sortBy(relations, function(o) {
// return o.asColNo;
// });
var criterias = _.filter(firstColumnDT, function(dt) {
return dt.asType == 2;
});
criterias = _.sortBy(criterias, function(o) {
return o.asColNo;
});
var budgets = _.filter(firstColumnDT, function(dt) {
return dt.asType == 3;
});
budgets = _.groupBy(budgets, 'asMasDefineCode');
var tableCFG = {
"expenseConditionsTitles": [{}],
"expenseCtriteraTitles": [{}],
"expenseBudgetTitles": [{ "child": [{}] }]
};
var conditionCFG = [];
_.each(conditions, function(condition, k) {
if(condition.asDefType != 5){
conditionCFG.push(refreshMas({
"mdId": "",
"mdCode": condition.asMasDefineCode,
"mdName": "",
"mdDesc": "",
"mdType": "1",
"mdDef1": "",
"mdDef2": "",
"mdDef3": "",
"mdDef4": "",
"mdDef5": "",
"values": [],
"elIden": condition.asElIden,
"type": condition.asDefType,
"enable": !!k,
'asRelation':condition.asRelation,
'group':1
}));
}else{
conditionCFG.push(refreshMas({
"elIden": condition.asElIden,
'id':condition.asMasDefineCode,
"type": condition.asDefType,
"enable": !!k,
'asRelation':condition.asRelation,
'group':1
}));
}
});
// _.each(relations,function(relation,j){
// if(relation.asDefType != 5){
// conditionCFG.push(refreshMas({
// "mdId": "",
// "mdCode": relation.asMasDefineCode,
// "mdName": "",
// "mdDesc": "",
// "mdType": "1",
// "mdDef1": "",
// "mdDef2": "",
// "mdDef3": "",
// "mdDef4": "",
// "mdDef5": "",
// "values": [],
// "elIden": relation.asElIden,
// "type": relation.asDefType,
// "enable": !!j,
// 'asRelation':relation.asRelation
// }));
// }else{
// conditionCFG.push(refreshMas({
// "id": relation.asMasDefineCode,
// "elIden": relation.asElIden,
// "type": relation.asDefType,
// "enable": !!j,
// 'asRelation':relation.asRelation
// }));
// }
//
// })
tableCFG['expenseConditionsTitles'] = conditionCFG;
var criteriaCFG = [];
_.each(criterias, function(criteria, k) {
if(criteria.asDefType != 5){
criteriaCFG.push(refreshMas({
"mdId": "tmp",
"mdCode": criteria.asMasDefineCode,
"mdName": "",
"mdDesc": "",
"mdType": "1",
"mdDef1": "",
"mdDef2": "",
"mdDef3": "",
"mdDef4": "",
"mdDef5": "",
"values": [],
"elIden": criteria.asDefName,
"type": criteria.asDefType,
"enable": !!k,
'asRelation':criteria.asRelation,
'group':2
}));
}else{
criteriaCFG.push(refreshMas({
"id": criteria.asMasDefineCode,
"elIden": criteria.asDefName,
"type": criteria.asDefType,
"enable": !!k,
'asRelation':criteria.asRelation,
'group':2
}));
}
});
tableCFG['expenseCtriteraTitles'] = criteriaCFG;
var budgetCFG = [];
_.each(budgets, function(budget, k) {
budget = budget[0]
if(budget.asDefType == 5){
var cfg = refreshMas({
"child": [],
"id": budget.asMasDefineCode,
"elIden": budget.asDefName,
"type": budget.asDefType,
'group':3
});
}else{
var cfg = refreshMas({
"child": [],
"mdId": "",
"mdCode": budget.asMasDefineCode,
"mdName": "",
"mdDesc": "",
"mdType": budget.asDefType,
"mdDef1": "",
"mdDef2": "",
"mdDef3": "",
"mdDef4": "",
"mdDef5": "",
"elIden": budget.asDefName,
'group':3
});
}
if(k > 0) {
cfg['enable'] = true;
}
refreshBudget(cfg);
budgetCFG.push(cfg);
});
tableCFG['expenseBudgetTitles'] = budgetCFG;
return tableCFG;
};
function toRowData(data) {
var rowData = {};
_.each(data, function(o, k) {
if(o['asDefValues'][0].indexOf('${') > -1){
var value = o['asDefValues'][0].match(/{(.*)} /)[1];
var relate = o['asDefValues'][0].match(/} (.*) /)[1];
var per = o['asDefValues'][0].match(/{(\d)}$/)[1];
var pervalue;
switch(per){
case "1":
pervalue = '天';
break;
case "2":
pervalue = '小时';
break;
case "3":
pervalue = '公里';
break;
}
$rootScope.relate = relate;
$rootScope.pervalue = pervalue;
// http_service.post('supp/search/master', { "mdType": "2" }, function(res) {
_.each($scope.expense_titles_first.data.data,function(info){
if(info.mdCode == value){
o['asDefValues'] = [info.mdName +" "+ relate + " " + pervalue];
rowData[o.asColNo] = { "grant_value": o['asDefValues'] }
}
})
// })
}else{
if(o.asDefType == 5){//系统变量 回调
var sys_back;
_.each($scope.system_titles,function(title){
if(title.id == o.asMasDefineCode){
sys_back = _.cloneDeep(title);
}
});
if(sys_back != undefined){
var sys_value = JSON.parse(o.asDefValues);
var sys_value_key = _.keys(sys_value);
_.each(sys_back.child,function(cd){//引用公式 回调
if(cd.joinMathId){
_.each($scope.system_titles,function(title){
if(cd.joinMathId == title.id){
_.extend(cd,{"joinchildren":_.cloneDeep(title.child)})
}
})
}
})
_.each(sys_back.child,function(cd){
_.each(sys_value_key,function(sk){
if(cd.pIndex == sk){
if(cd.joinMathId == undefined){
cd['val'] = sys_value[sk];
}else{
var sys_jval_key = _.keys(sys_value[sk]);
_.each(cd.joinchildren,function(jcd){
_.each(sys_jval_key,function(jk){
if(jk == jcd.pIndex){
jcd['val'] = sys_value[sk][jk];
}
})
})
}
}
})
})
_.extend(sys_back,{'children':sys_back.child,'show_sys_fx':o['asShowCount']});
if(o.asCount){
_.extend(sys_back,{'sys_count':o.asCount});
}
if(o.asInverse != undefined){//正、反选属性回调
rowData[o.asColNo] = { "grant_value": o['asShowCount'],"asInverse": o.asInverse,"sys_val":sys_back};
}else{
rowData[o.asColNo] = { "grant_value": o['asShowCount'],"asInverse": 1,"sys_val":sys_back}
}
}else{
rowData[o.asColNo] = { "grant_value": o['asShowCount'],"asInverse": 1};
}
}else{
if(o.asInverse != undefined){//正、反选属性回调
rowData[o.asColNo] = { "grant_value": o['asDefValues'],"asInverse": o.asInverse};
}else{
rowData[o.asColNo] = { "grant_value": o['asDefValues'],"asInverse": 1 }
}
}
}
});
//
return rowData;
}
function getExpenseData(data) {
var expense_data = data.child;
if(!expense_data.length) return false;
var expense_data_row_group = _.groupBy(expense_data, 'asRowNo');
function sortNumber(a,b)
{
return a - b
}
var keys = _.keys(expense_data_row_group).sort(sortNumber);
var tableData = [];
var rowData;
_.each(keys, function(i) {
var data = expense_data_row_group[i];
rowData = toRowData(data);
tableData.push(rowData);
});
return tableData;
};
$scope.table = function(){
expenseTableOnceMore()
}
function expenseTableOnceMore() {
http_service.post('supp/search', {}, function(res) {
$scope.get_all_data = true;
var data_list = res.data.data;
var tableCFG = [];
_.each(data_list, function(data) {
tableCFG.push(getTableCFG(_.cloneDeep(data)));
});
_.each(tableCFG, function(cfg, index) {
if($scope.tabletitlescfgs[index])
_.each(cfg, function(v, k) {
_.extend($scope.tabletitlescfgs[index][k], v);
});
else
$scope.tabletitlescfgs.push(cfg);
});
// _.each($scope.tabletitlescfgs,function(cfg,index){
// _.each(cfg,function(m,n){
// if(m.length != 1){
// }
// _.each(m,function(ms){
// })
// })
// })
var expenseData = [];
_.each(data_list, function(data) {
expenseData.push(getExpenseData(_.cloneDeep(data)));
});
_.each(expenseData, function(cfg, index) {
if($scope.allexpensedata[index]){
// _.each(cfg, function(v, k) {
// if($scope.allexpensedata[index][k]){
// _.extend($scope.allexpensedata[index][k], v);
// }
// else{
// $scope.allexpensedata[index].push(v);
// }
$scope.allexpensedata[index] = cfg
// });
}else{
$scope.allexpensedata.push(cfg);
}
});
var sstypes = [];
// http_service.post('supp/search/master', { "mdType": "3" }, function(res) {
// var typedata = res.data.data;
// for(i in data_list){
// var data = data_list[i]
// sstypes.push(data.ssType);
// http_service.post('supp/search/master', { "mdType": "3" }, function(res) {
// if(typedata.mdCode == data.ssType){
// sstypenames.push(typedata.mdCode)
// }
// });
// }
// });
http_service.post('supp/search/money/type', {}, function(res) {
for(i in data_list){
var data = data_list[i]
sstypes.push(data.ssType);
var typedata = res.data.data;
if(typedata.code == data.ssType){
sstypenames.push(typedata.code)
}
}
_.each(sstypes, function(type, index) {
if($scope.sstypes[index] === '') {
$scope.sstypes[index] = type;
} else {
$scope.sstypes.push(type);
}
});
var ssnames = [];
_.each(data_list, function(data) {
ssnames.push(data.ssName);
});
_.each(ssnames, function(name, index) {
if($scope.ssnames[index] === '') {
$scope.ssnames[index] = name;
} else {
$scope.ssnames.push(name);
}
});
var ssSubTypes=[];
$scope.ssSubTypes = [];
_.each(data_list,function(data){
ssSubTypes.push(data.ssSubType);
})
_.each(ssSubTypes,function(sub){
if(sub == 0){
$scope.ssSubTypes.push(false);
}else{
$scope.ssSubTypes.push(true);
}
})
$scope.ssrules = [];
_.each(data_list,function(data){
$scope.ssrules.push(data.ssRule);
})
//费用类型
$scope.ssTypeOptions = res.data.data;
$scope.sstypename = [];
_.each($scope.sstypes,function(type){
_.each($scope.ssTypeOptions,function(typeoption){
if(type == typeoption.code){
$scope.sstypename.push(typeoption.value);
}
})
})
//报销方式
// http_service.post('supp/search/const', { "cdType": "90" }, function(res) {
$scope.ssNameOptions = _.filter(cddata,function(o){
return o.cdType == 90;
})
// $scope.ssNameOptions = res.data.data;
$scope.ssnamename = [];
_.each($scope.ssnames,function(name){
_.each($scope.ssNameOptions, function(nameoption){
if(name == nameoption.cdCode){
$scope.ssnamename.push(nameoption.cdValue);
}
})
})
// });
});
// for(i in data_list){
// var data = data_list[i]
// sstypes.push(data.ssType);
// // sstypenames.push(data.ss)
// http_service.post('supp/search/money/type', {}, function(res) {
// var typedata = res.data.data;
// if(typedata.mdCode == data.ssType){
// sstypenames.push(typedata.mdCode)
// }
// });
//// });
// }
//费用类型
// http_service.post('supp/search/money/type', {}, function(res) {
// $scope.ssTypeOptions = res.data.data;
// $scope.sstypename = [];
// _.each($scope.sstypes,function(type){
// _.each($scope.ssTypeOptions,function(typeoption){
// if(type == typeoption.mdCode){
// $scope.sstypename.push(typeoption.mdName);
// }
// })
// })
// });
});
}
//修改公式保存样式
function change_relation_style(data){
if(data != undefined){
// if(data.length < 2){
// return false;
// }
if(_.isArray(data)){
data = data[0]
if(data.length <2){
return false;
}
}
var value = data.split(" ");
var per = value.slice(-1);
var percode;
switch(per[0]){
case '天':
percode = 1;
break;
case '小时':
percode = 2;
break;
case '公里':
percode = 3;
break;
}
data = data.split(" ").slice(1,-1).join(" ")+" ${"+percode+"}";
return data;
}
}
//保存的格式
function get_expense_standard_data(data, cfg, type, name,sub,rule) {
if(sub){
sub = 1;
}else{
sub = 0;
}
var expenseStandardData = [];
var rowCfgs = [];
//
//
//删除关系属性
cfg['expenseConditionsTitles'][cfg['expenseConditionsTitles'].length-1].asRelation = undefined;
cfg['expenseCtriteraTitles'][cfg['expenseCtriteraTitles'].length-1].asRelation = undefined;
_.each(cfg['expenseBudgetTitles'],function(cfg){
cfg.asRelation = undefined;
})
var expense_condtions = cfg['expenseConditionsTitles'];
var expense_criters = cfg['expenseCtriteraTitles'];
var expense_budgets = cfg['expenseBudgetTitles'];
//补助条件
var m = 0;
for(i in expense_condtions){
var cfgItem = expense_condtions[i];
if(!cfgItem.eleCode && cfgItem.id == undefined){
_.each(data,function(ex_data){
if(ex_data[m] == undefined){
return false;
}
if(_.isArray(ex_data[m].grant_value)){
ex_data[m].grant_value = ex_data[m].grant_value[0];
}
cfgItem.grant_value = "${"+cfgItem.mdCode+ "} " + change_relation_style(ex_data[m].grant_value);
})
// for(j in document.getElementsByClassName("fxinput")){
// var fxinput = document.getElementsByClassName("fxinput");
// if(change_relation_style(fxinput[j].value) !== undefined){
// cfgItem.grant_value = "${"+cfgItem.mdCode+ "} " + change_relation_style(fxinput[m].value);
// m++;
// }
// }
rowCfgs.push(_.extend(cfgItem, { 'type': 11 ,'elIden': cfgItem['eleValue'] || '','code':cfgItem['elIden']||'','asType':1}));
break;
}else{
rowCfgs.push(_.extend(cfgItem, { 'type': 1,'code':cfgItem['elIden'] || '','elIden': cfgItem['eleValue'] || '','asType':1}));
}
m++;
}
_.each(expense_criters, function(cfgItem) {
rowCfgs.push(_.extend(cfgItem, { 'type': 2 ,'elIden': cfgItem['eleValue'] || '','code':cfgItem['elIden'] || '' ,'asType':2}));
});
_.each(expense_budgets, function(cfgItem) {
if(cfgItem.child && cfgItem.child.length) {
_.each(cfgItem.child, function(_cfgItem) {
if(cfgItem.id != undefined){
rowCfgs.push(_.extend(_cfgItem, { 'type': 3, 'elIden': cfgItem['eleValue'] || '','code':_cfgItem['code'] || '' ,'mdCode':cfgItem['mdCode'] || $scope.types,"id":cfgItem.id,'asType':3}));
}else{
rowCfgs.push(_.extend(_cfgItem, { 'type': 3, 'elIden': cfgItem['eleValue'] || '','code':_cfgItem['code'] || '' ,'mdCode':cfgItem['mdCode'] || $scope.types,'asType':3}));
}
});
}
})
_.each(rowCfgs,function(cfg){//系统变量处理 修改type
if(cfg.id != undefined && cfg.id != false){
cfg['type'] = 5;
}
})
_.each(rowCfgs, function(cfg, column) {
_.each(data, function(dtRow, row) {
var columnValue = dtRow[column];
if(dtRow[column] != undefined){
if(dtRow[column]['grant_value'] && dtRow[column]['grant_value'].length == 0){
dtRow[column]['grant_value'] = [""];
}
if(cfg.values && cfg.values.length == 0 && !cfg.is_org){
if(change_relation_style(dtRow[column].grant_value) != false && cfg.mdCode){
cfg['grant_value'] = "${"+cfg.mdCode+ "} " + change_relation_style(dtRow[column].grant_value);
}else{
cfg['grant_value'] = "";
}
}
}
if(!cfg.eleCode){//非下拉框 排除反选属性
if(dtRow[column] != undefined){
dtRow[column]["asInverse"] = undefined;
}else{
dtRow[column] = {"asInverse":undefined};
}
}
if(cfg.type != 5){
expenseStandardData.push({
'asType':cfg.asType,//1:补助标准条件,2:补助标准结果,3:补助金额
"asColNo": column, //列号
"asDefName": cfg['elIden'], //主数据元素标识符
"asDefType": cfg['type'], //1:补助标准条件,2:补助标准结果,3:补助金额,90:报销方式
"asDefValues": cfg['grant_value'] || (dtRow && dtRow[column] && dtRow[column]['grant_value']) || [''], //主数据元素值code
// "group_id": dtRow && dtRow[column] && dtRow[column]['group_id'], //group id
"asElIden": cfg['code'], //暂时为空
"asMasDefineCode": cfg['mdCode'],
"asRowNo": row,
'asRelation':cfg.asRelation,
'asInverse':dtRow[column]['asInverse']
});
}else{
var sys_fx_val = {};
var show_sys_val = '';
if(dtRow[column].sys_val){
show_sys_val = dtRow[column].sys_val.show_sys_fx;
_.each(dtRow[column].sys_val.children,function(cd){
if(cd.joinMathId == undefined){
if(cd.val && cd.val != ""){
sys_fx_val[cd.pIndex] = cd.val;
}
}else{
var jval = {};
_.each(cd.joinchildren,function(jcd){
if(jcd.val && jcd.val != ""){
jval[jcd.pIndex] = jcd.val;
}
})
sys_fx_val[cd.pIndex] = jval;
}
})
}
sys_fx_val = JSON.stringify(sys_fx_val);
expenseStandardData.push({
'asType':cfg.asType,//1:补助标准条件,2:补助标准结果,3:补助金额
"asColNo": column, //列号
"asElIden": "", //暂时为空
"asDefType": cfg['type'], //1:补助标准条件,2:补助标准结果,3:补助金额,90:报销方式
"asDefValues": cfg.notFound?['{}']:sys_fx_val,
"asMasDefineCode": cfg['id'],
"asRowNo": row,
'asRelation':cfg.asRelation,
'asShowCount':show_sys_val,
"asCount":cfg.notFound?"":dtRow[column].sys_val.sys_count
});
}
});
});
//
_.each(expenseStandardData,function(expense){
if(expense.asRelation == undefined){
delete expense.asRelation;
}
if(expense.asInverse == undefined){
delete expense.asInverse;
}
})
//
return {
"child": expenseStandardData,
"ssDispFun": "显示用逻辑公式",
"ssLogicFun": "计算用逻辑公式",
"ssName": name,
"ssSubType": sub,
"ssType": type,
"ssRule":rule
}
}
$scope.$on('$viewContentLoaded', function() {
var frm_height = $(document).height() - 52;
$('div.split_form').height(frm_height);
$(window).resize(function() {
var frm_height = $(document).height() - 52;
$('div.split_form').height(frm_height);
});
});
//新建表格
$scope.create_expense_strd_table = function() {
$('div.drop_down_sel').remove();
// $timeout(function(){
$scope.allexpensedata.push([]);
$scope.tabletitlescfgs.push({
"expenseConditionsTitles": [{}],
"expenseCtriteraTitles": [{}],
"expenseBudgetTitles": [{ "child": [{}] }]
});
$scope.ssnames.push('');
$scope.sstypes.push('');
$scope.ssSubTypes.push(true);
// },1)
}
//保存报销标准
$scope.saveExpense = function() {
$('div.drop_down_sel').remove();
var data = [];
var pst_dt = { "data": [] };
_.each($scope.allexpensedata, function(dt, index) {
var cfg = _.cloneDeep($scope.tabletitlescfgs[index]);
var type = _.cloneDeep($scope.sstypes[index]);
var name = _.cloneDeep($scope.ssnames[index]);
var sub = _.cloneDeep($scope.ssSubTypes[index]);
var rule = _.cloneDeep($scope.ssrules[index]);
var expense_dt = get_expense_standard_data(dt, cfg, type, name,sub,rule);
pst_dt['data'].push(expense_dt);
});
http_service.post('supp/save', pst_dt, function(res) {
if(res.data.opState) {
//alert('保存补助标准成功。')
$scope.$parent.tsuccess( "保存补助标准成功!")
} else {
//alert('后台错误保存补助标准失败。')
$scope.$parent.terro("后台错误,保存补助标准失败。")
}
});
};
//切换补助标准内容 与 系统变量
$scope.title_type = true;//默认显示补助标准内容
http_service.post('supp/search/master', {"mdType":2}, function(res) {
if(res.data.data){
_.each(res.data.data,function(title){
//添加默认的关系属性
// if(title.asRelation == undefined){
// _.extend(title,{'asRelation':1});
// }
})
}
$scope.expense_titles_first = res;
var expense_titles = res.data.data;
$scope.expense_titles = expense_titles;
expense_titles = _.map(expense_titles, function(title, n) {
return {
'type': n,
'btn': '',
'field': '' + title.mdName + '',
'data': title
}
});
var fb = new form_builder.create();
fb.no_wrapper(false);
fb.add_elements(expense_titles);
fb.add_forms('td.expenseTitle');
fb.add_elements_box('.expense_titles');
fb.element_appended_before_allback(before_el_append);
fb.element_appended_callback(after_el_append);
fb.bootstrap();
//将拖动的数据加入表格
function after_el_append(title, holder) {
var this_title = title;
var title_data = arguments[0] && arguments[0][0] && arguments[0][0]['data'];
var $td_holder = $(arguments[2]);
var group = $td_holder.attr('group');
var index = $td_holder.attr('index');
var tableindex = $td_holder.attr('tableindex');
var cellIndex = 0;
//
//
//
//
//
switch(group) {
case 'condition':
var title = $scope.tabletitlescfgs[tableindex]['expenseConditionsTitles'][index];
$timeout(function() {
_.extend(title_data, {
"asRelation": 1
}); //默认关系属性
for(var key in title){
delete title[key];
}
_.extend(title, title_data);
_.extend(title, {"group":1});
}, 1);
//单元格index
cellIndex = index;
break;
case 'criteria':
var title = $scope.tabletitlescfgs[tableindex]['expenseCtriteraTitles'][index];
$timeout(function() {
for(var key in title){
delete title[key];
}
if(this_title[0].data.eleCode) {
_.extend(title_data, {
"asRelation": 1
}); //默认关系属性
_.extend(title, title_data);
_.extend(title, {"group":2});
} else {
var errMsg = "补助标准不支持" + title_data.mdName + "控件";
$scope.$parent.terro(errMsg);
if(!title.mdCode) {
_.extend(title, {
"enable": true
});
}
}
}, 1);
//单元格index
cellIndex = $scope.tabletitlescfgs[tableindex]['expenseConditionsTitles'].length + parseInt(index);
break;
case 'expense':
var title = $scope.tabletitlescfgs[tableindex]['expenseBudgetTitles'][index];
for(var key in title){
delete title[key];
}
$timeout(function() {
_.extend(title, title_data);
_.extend(title, {"group":3});
}, 1);
//单元格index
cellIndex = $scope.tabletitlescfgs[tableindex]['expenseCtriteraTitles'].length +
$scope.tabletitlescfgs[tableindex]['expenseConditionsTitles'].length +
parseInt(index);
http_service.post('base/data/search', {
"code": title_data.mdCode,
"cache_id": title_data.mdCode
}, function(res) {
if(!res.data.data) return false;
$timeout(function() {
title.child = res.data.data.child;
title.elIden = res.data.data.elIden;
title.drag = true;
}, 1);
}, true);
break;
}
// var data_list = $scope.allexpensedata[tableindex];
// var grant_val;
// _.each(data_list, function(data) {
// if(data[cellIndex]){
// grant_val = data[cellIndex]['grant_value'];
// }else{
// grant_val = [''];
// }
//
// if(grant_val && _.isArray(grant_val)) {
// grant_val.splice(0, grant_val.length);
// }
// });
if(cellIndex && (group === 'condition' || group === 'criteria')) {
var data_list = $scope.allexpensedata[tableindex];
_.each(data_list, function(data) {
if(data && data[cellIndex]) {
if(this_title[0].data.eleCode != undefined && group != 'criteria') {
data[cellIndex]['grant_value'] = [];
}
data[cellIndex]['asInverse'] = 1;
} else {
var asobj = {};
asobj[cellIndex] = {
'asInverse': 1
}
_.extend(data, asobj);
}
// var grant_val = data[cellIndex]['grant_value'];
// if(grant_val && _.isArray(grant_val)) {
// grant_val.splice(0, grant_val.length);
// }
});
} else if(cellIndex) {
var data_list = $scope.allexpensedata[tableindex];
_.each(data_list, function(data) {
for(i in data) {
if(i >= cellIndex) {
data[i]['grant_value'] = [];
}
}
});
}
}
// $scope.$watch(function(){
// return $scope.tabletitlescfgs.length
// },function(){
// after_el_append()
// })
function before_el_append(title, holder) {
$(holder).find('span').remove();
}
});
http_service.post('systemMath/search/list', {}, function(response) { //获得系统变量
var system_titles = response.data.data;
$scope.system_titles = system_titles;
$rootScope.system_titles = system_titles;
system_titles = _.map(system_titles, function(title, n) {
return {
'type': n,
'btn': '',
'field': '' + title.name + '',
'data': title
}
});
var sys = new form_builder_s.create();
sys.no_wrapper(false);
sys.add_elements(system_titles);
sys.add_forms('td.expenseTitle');
sys.add_elements_box('.system_titles');
sys.element_appended_before_allback(before_el_append_s);
sys.element_appended_callback(after_el_append_s);
sys.bootstrap();
function after_el_append_s(title, holder) {
var this_title = title;
var title_data = arguments[0] && arguments[0][0] && arguments[0][0]['data'];
var $td_holder = $(arguments[2]);
var group = $td_holder.attr('group');
var index = $td_holder.attr('index');
var tableindex = $td_holder.attr('tableindex');
var cellIndex = 0;
_.extend(title_data,{'children':title_data.child})
switch(group) {
case 'condition':
var title = $scope.tabletitlescfgs[tableindex]['expenseConditionsTitles'][index];
for(var key in title){
delete title[key];
}
$timeout(function() {
_.extend(title_data, {
"asRelation": 1,
'mdName':title_data.name
}); //默认关系属性
_.extend(title, title_data);
_.extend(title, {"group":1});
}, 1);
//单元格index
cellIndex = index;
break;
case 'criteria':
var title = $scope.tabletitlescfgs[tableindex]['expenseCtriteraTitles'][index];
for(var key in title){
delete title[key];
}
$timeout(function() {
_.extend(title_data, {
"asRelation": 1,
'mdName':title_data.name
}); //默认关系属性
_.extend(title, title_data);
_.extend(title, {"group":2});
}, 1);
//单元格index
cellIndex = $scope.tabletitlescfgs[tableindex]['expenseConditionsTitles'].length + parseInt(index);
break;
case 'expense':
var title = $scope.tabletitlescfgs[tableindex]['expenseBudgetTitles'][index];
for(var key in title){
delete title[key];
}
$timeout(function() {
_.extend(title_data, {
'mdName':title_data.name
});
_.extend(title, title_data);
_.extend(title, {"group":3});
title.child = [{"value":title_data.name}];
title.drag = true;
}, 1);
//单元格index
cellIndex = $scope.tabletitlescfgs[tableindex]['expenseCtriteraTitles'].length +
$scope.tabletitlescfgs[tableindex]['expenseConditionsTitles'].length +
parseInt(index);
// http_service.post('base/data/search', {
// "code": title_data.mdCode,
// "cache_id": title_data.mdCode
// }, function(res) {
// if(!res.data.data) return false;
// $timeout(function() {
// title.child = res.data.data.child;
// title.elIden = res.data.data.elIden;
// title.drag = true;
// }, 1);
// }, true);
break;
}
if(cellIndex && (group === 'condition' || group === 'criteria')) {
var data_list = $scope.allexpensedata[tableindex];
_.each(data_list, function(data) {
if(data[cellIndex]) {
data[cellIndex]['grant_value'] = [];
data[cellIndex]['asInverse'] = 1;
} else {
var asobj = {};
asobj[cellIndex] = {
'asInverse': 1
}
_.extend(data, asobj);
}
data[cellIndex]['sys_val'] = {'show_sys_fx':title_data.name+"()"}
});
} else if(cellIndex) {
var data_list = $scope.allexpensedata[tableindex];
_.each(data_list, function(data) {
for(i in data) {
if(i >= cellIndex) {
data[i]['grant_value'] = [];
// data[i]['sys_val'] = {'show_sys_fx':title_data.name+"()"}
}
}
data[cellIndex] ={'sys_val':{'show_sys_fx':title_data.name+"()"}}
});
}
}
function before_el_append_s(title, holder) {
$(holder).find('span').remove();
}
$scope.table = function() {
expenseTableOnceMore();
}
$scope.$watch('tabletitlescfgs', function() {
expenseTableOnceMore();
});
})
}]);