angular.module('budget_form_customize', [])
|
|
.directive('select3', ['$rootScope', 'http_service', '$timeout', '$interval', '$compile',
|
function($rootScope, http_service, $timeout, $interval, $compile) {
|
return {
|
restrict: 'ACEM',
|
templateUrl: './static/templates/select3.html',
|
transclude: true,
|
scope: {
|
item: "=",
|
edit: "=",
|
form_items: "=",
|
childitem: "=",
|
editFlag: "=",
|
billCheck: "&"
|
},
|
compile: function() {
|
return {
|
pre: function(scope, iElement, iAttrs, controller) {
|
|
// });
|
|
var $scope = scope;
|
$scope.type = scope.$parent.type;
|
$scope.billid = scope.$parent.billid;
|
scope.sel_val_lst = [];
|
var $el = $(iElement);
|
//关联公式显示控件
|
function show_item(form,item){
|
var show_flag = true;
|
_.each(form.has_hide,function(hide){
|
_.each(item,function(_item){
|
if(hide.gcMeCode == _item.gcMeCode){
|
if(_item.render_value && _item.render_value.indexOf(",") != -1){
|
var item_value = _item.render_value.split(",");
|
}else{
|
var item_value = [_item.render_value];
|
}
|
_.each(item_value,function(val){
|
if(val == hide.hide_value){
|
show_flag = false;
|
}
|
})
|
}
|
})
|
})
|
return show_flag;
|
}
|
//关联公式隐藏控件
|
function hide_item() {
|
var ischild = true;
|
var check_form;
|
_.each(scope.$parent.form_items,function(form){
|
if(show_item(form,scope.$parent.form_items) && form.has_hide != undefined){
|
form.gcShowFlag = 1;
|
}
|
if(form.gcMeCode == scope.item.gcMeCode) {
|
ischild = false;
|
check_form = scope.$parent.form_items;
|
}
|
})
|
if(ischild){
|
_.each(scope.$parent.form_items,function(form){
|
if(form.gcCpnType == 10 || form.gcCpnType == 17){
|
_.each(form.child,function(cd){
|
if(show_item(cd,form.child) && cd.has_hide != undefined){
|
cd.gcShowFlag = 1;
|
}
|
// if(cd.render_value != "" && cd.render_value != undefined && cd.gcMeCode == scope.item.gcMeCode) {
|
check_form = scope.childitem.child;
|
// }
|
})
|
}
|
})
|
}
|
//
|
_.each(check_form,function(form){
|
if(scope.item.cpnHide){
|
_.each(scope.item.cpnHide,function(formula){
|
if(scope.item.render_value != "" && scope.item.render_value != undefined){
|
if(scope.item.render_value.indexOf(",") != -1){
|
var i_value = scope.item.render_value.split(",");
|
}else{
|
var i_value = [scope.item.render_value];
|
}
|
_.each(i_value,function(val){
|
if(val == formula.cVal){
|
_.each(formula.cHideItem,function(hide){
|
if(form.gcMeCode == hide){
|
|
|
form.gcShowFlag = 0;
|
if(form.has_hide == undefined){
|
form['has_hide'] = [{
|
'gcMeCode':scope.item.gcMeCode,
|
'hide_value':formula.cVal
|
}];
|
}else{
|
form['has_hide'].push({
|
'gcMeCode':scope.item.gcMeCode,
|
'hide_value':formula.cVal
|
})
|
}
|
}
|
})
|
}
|
})
|
|
}
|
})
|
}
|
|
})
|
}
|
//预算部门为总公司时隐藏并不判断占用预算控件的必填
|
function Corporation_choose(val) {
|
var superBudget_code;
|
_.each(filed, function(_filed) {
|
if(_filed.busCode == 'superBudget') {
|
superBudget_code = _filed.mdCode;
|
}
|
});
|
_.each(scope.$parent.form_items, function(form) {
|
if(form.gcMeCode == superBudget_code) {
|
if(val == 'F172004') {
|
form.gcInputMust = 0;
|
form.gcShowFlag = 0;
|
} else {
|
form.gcInputMust = 1;
|
form.gcShowFlag = 1;
|
}
|
}
|
|
})
|
|
}
|
//部门变更则清空占用预算或社申请选择
|
function clear_budget() {
|
if($rootScope.budget_back == false) {
|
_.each(scope.$parent.form_items, function(form) {
|
if(form.gcCpnType == 0) { //占用预算
|
form.render_value = "";
|
$rootScope.startTime = undefined;
|
$rootScope.endTime = undefined;
|
$rootScope.sumMoney_budget = undefined;
|
$rootScope.budget_selected = null;
|
|
scope.$parent.$parent.$parent.heads = [];
|
scope.$parent.$parent.$parent.selectinfo = [];
|
}
|
})
|
}
|
}
|
//公式计算
|
$scope.formula_conut = function(formula, val) {
|
//判断公式应用于哪个表单
|
// var travelType = formula.travelType;//获取公式对应的表单
|
// var account_flag =false;//控制是否计算
|
// if(travelType == $scope.type){
|
// account_flag = true;
|
// }else if(travelType == 0){
|
// account_flag = true;
|
// }
|
// if(account_flag == false){
|
// return false;
|
// }
|
var target_code = formula.child[0];
|
var orgin_code = formula.child[1];
|
var target_value;
|
_.each($scope.sreach_data, function(data) {
|
if(data.code == val) {
|
target_value = data[orgin_code.pMeCode];
|
}
|
})
|
var is_inchild = false;
|
_.each($scope.$parent.form_items, function(_form) {
|
if(_form.gcMeCode == target_code.pMdCode) {
|
if(_form.gcCpnType == 6) {
|
$rootScope.formula_num_id.push(formula.id)//前端公式计数
|
$rootScope.formula_num++;
|
_form.render_value = target_value;
|
} else {
|
if(target_code.mathMdType == "code") {
|
formula_setdata(orgin_code, target_value, function(res) {
|
$rootScope.formula_num_id.push(formula.id)//前端公式计数
|
$rootScope.formula_num++;
|
_form.render_value = res.data.data;
|
})
|
} else {
|
$rootScope.formula_num_id.push(formula.id)//前端公式计数
|
$rootScope.formula_num++;
|
_form.render_value = target_value;
|
}
|
}
|
} else {
|
is_inchild = true;
|
}
|
});
|
if(is_inchild) {
|
_.each($scope.$parent.form_items, function(_form) {
|
if(_form == scope.childitem) {
|
_.each(_form.child, function(cd) {
|
if(cd.gcMeCode == target_code.pMdCode) {
|
if(cd.gcCpnType == 6) {
|
$rootScope.formula_num_id.push(formula.id)//前端公式计数
|
$rootScope.formula_num++;
|
cd.render_value = target_value;
|
} else {
|
if(target_code.mathMdType == "code") {
|
formula_setdata(orgin_code, target_value, function(res) {
|
$rootScope.formula_num_id.push(formula.id)//前端公式计数
|
$rootScope.formula_num++;
|
cd.render_value = res.data.data;
|
})
|
} else {
|
$rootScope.formula_num_id.push(formula.id)//前端公式计数
|
$rootScope.formula_num++;
|
cd.render_value = target_value;
|
}
|
}
|
}
|
})
|
}
|
})
|
}
|
}
|
function getItem() {
|
http_service.post('base/data/search', { "code": scope.item.gcMeCode, "cache_id": scope.item.gcMeCode }, function(res) {
|
if(res.data.opState) {
|
var data = res.data.data.child;
|
$scope.sreach_data = res.data.data.child;
|
$timeout(function() {
|
var $sel = $el.find('select');
|
_.each(data, function(item) {
|
$sel.append('<option value=' + item.code + '>' + item.value + '</option>');
|
});
|
var budget_back;
|
_.each(filed, function(_filed) {
|
if(_filed.busCode == "orgName") {
|
budget_back = _filed.mdCode;
|
}
|
});
|
$scope.$watch(function() {
|
return scope.item.render_value;
|
}, function() {
|
if($rootScope.stepCode != undefined && ($rootScope.stepCode == 30 || $rootScope.stepCode == 10)){// 已完成/审核中 表单显示 特殊处理
|
return false;
|
}
|
//下拉框 根据公式联动
|
_.each($scope.$parent.formula, function(formula) {
|
// if(formula.mathFormat == "select"){
|
if(scope.item.gcMeCode == formula.child[1].pMdCode) {
|
$scope.formula_conut(formula, scope.item.render_value);
|
}
|
// }
|
})
|
|
if($rootScope.sort_bytime){
|
$rootScope.sort_bytime(scope.item);//子表单排序
|
}
|
//
|
var arr = scope.item.render_value;
|
// arr = arr.split(",");
|
// if(arr != undefined && arr.indexOf("[") != -1){
|
// arr = JSON.parse(arr);
|
// scope.item.render_value = JSON.parse(scope.item.render_value);
|
// }else if(_.isArray(arr) == false){
|
// arr = [arr];
|
// scope.item.render_value = [scope.item.render_value];
|
// }
|
scope.sel_val_lst = [];
|
if(scope.item.gcMeCode == budget_back) {
|
clear_budget();
|
Corporation_choose(arr);
|
if($rootScope.budget_back != false) {
|
$rootScope.budget_back = false;
|
}
|
}
|
if(arr) {
|
if(arr.length>1){
|
arr = arr.split(",");
|
// arr.pop();
|
//
|
_.each(arr, function(_arr) {
|
_.each(data, function(_data) {
|
if(_data.code == _arr) {
|
scope.sel_val_lst.push({ "value": _data.code, "label": _data.value });
|
}
|
})
|
})
|
var select_value = [];
|
for(i in scope.sel_val_lst) {
|
select_value.push(scope.sel_val_lst[i].label);
|
}
|
$timeout(function() {
|
if($scope.item.render_value != undefined){
|
$scope.item = _.extend($scope.item, { "select_value": select_value.join(",") });
|
}
|
}, 10)
|
}
|
}
|
scope.$watch(function() {
|
return scope.item.ismultiple
|
}, function() {
|
if(scope.item.ismultiple !== undefined) {
|
if(scope.item.ismultiple) {
|
$sel.attr('multiple', 'multiple');
|
} else {
|
$sel.attr('multiple', null);
|
}
|
}
|
})
|
|
// if(arr) {
|
// $sel.val($scope.item.render_value);
|
// _.each(arr,function(_arr){
|
// _.each($scope.sreach_data,function(_data){
|
// if(_data.code == _arr){
|
// scope.sel_val_lst.push({ 'value': _data.code, 'label':_data.value});
|
// }
|
// })
|
// })
|
//// $sel.find('option:selected').each(function() {
|
//// scope.sel_val_lst.push({ 'value': $(this).val(), 'label': $(this).text() });
|
//// });
|
// var select_value = [];
|
// for(i in scope.sel_val_lst) {
|
// select_value.push(scope.sel_val_lst[i].label);
|
// }
|
// $timeout(function() {
|
// $scope.item = _.extend($scope.item, { "select_value": select_value.join(",") });
|
// }, 10)
|
// }
|
hide_item()//关联公式隐藏控件
|
|
//匹配控件 并进行系统变量公式计算
|
_.each($scope.$parent.sys_formula,function(sformula){
|
_.each(sformula.formula.child,function(_formula){
|
if(_formula.mdCode == scope.item.gcMeCode){
|
if(scope.childitem){
|
if($rootScope.sys_formula_computing){
|
$rootScope.sys_formula_computing(sformula,scope.childitem);
|
}
|
}else{
|
if($rootScope.sys_formula_computing){
|
$rootScope.sys_formula_computing(sformula);
|
}
|
}
|
return false;
|
}
|
});
|
})
|
});
|
$timeout(function(){//用于检测显示是否完全
|
$scope.item['inited'] = true;
|
},100);
|
}, 1)
|
|
} else {
|
$scope.$parent.$parent.$parent.$parent.$parent.terro(res.data.errMsg);
|
$timeout(function(){//用于检测显示是否完全 失败也算显示完全 否则会无法结束监听
|
$scope.item['inited'] = true;
|
},100);
|
}
|
}, true);
|
}
|
getItem();
|
if(scope.editFlag !== 0) {
|
$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 isMultiple = $scope.item.gcCpnMultiple;
|
var $options = $el.find('select > option');
|
var $options_str = '<ul>' +
|
'<li class="sel_query">' +
|
'<input type="text" name="query" >' +
|
'<i class="fa fa-search" aria-hidden="true"></i>' +
|
'</li>' +
|
'</ul>';
|
if($select.attr('multiple')) {
|
$options_str += '<ul>' +
|
'<li>' +
|
'<div>' +
|
'<div>' +
|
'<input type="checkbox" name="all">' +
|
'</div>' +
|
'<div>全选</div>' +
|
'</div>' +
|
'</li>' +
|
'</ul>';
|
}
|
// $scope.$watch(function(){
|
// return isMultiple
|
// },function(){
|
//// alert(isMultiple);
|
// if(scope.item.gcMeCode == 'F008'){
|
//// getItem();
|
// }
|
// })
|
$options.each(function() {
|
var checked = '';
|
var val_list = _.map(scope.sel_val_lst, function(op) {
|
return op.value;
|
});
|
if(_.indexOf(val_list, $(this).val()) > -1) {
|
checked = 'checked';
|
}
|
|
$options_str += '<ul>' +
|
'<li>' +
|
'<div>' +
|
'<div>' +
|
'<input type="checkbox" name="checkbox" label="' + $(this).text() + '" value="' + $(this).val() + '" ' + checked + ' >' +
|
'</div>' +
|
'<div class="overhidden" title="' + $(this).text() + '">' + $(this).text() + '</div>' +
|
'</div>' +
|
'</li>' +
|
'</ul>';
|
});
|
|
var $select_obj = $('<div drop-down-selector="" filterlist="searchlist" class="drop_down_sel" >' +
|
$options_str +
|
'</div>');
|
$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();
|
}
|
});
|
});
|
//下拉框关联非下拉框 取值
|
function formula_setdata(orgin, val, callback) {
|
http_service.post("supp/getName", {
|
"mdCode": orgin.pMdCode,
|
"mvCode": val
|
}, function(res) {
|
callback(res);
|
})
|
}
|
|
|
$select_obj.find('input[name="checkbox"]').on('click', function() {
|
var vals_selected = [];
|
var vals_selected_item = [];
|
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') }];
|
vals_selected_item = $(this).val();
|
scope.set_valueleft(_.map(vals_selected, "value"));
|
vals_selected_item = $(this).val();
|
$('div.drop_down_sel').remove();
|
} else {
|
var vls = [];
|
$('div.drop_down_sel input[name="checkbox"]:checked').each(function() {
|
vals_selected.push({ 'value': $(this).val(), 'label': $(this).attr('label') });
|
vals_selected_item.push($(this).val());
|
vls.push($(this).val());
|
});
|
$select.val(vls);
|
// 查询条件赋值
|
scope.set_valueleft(vls);
|
|
}
|
if(!$('div.drop_down_sel input[name="checkbox"]').prop('checked')) {
|
$('input[name="all"]').attr('checked', null)
|
}
|
$timeout(function() {
|
scope.sel_val_lst = vals_selected;
|
//
|
if(_.isArray(vals_selected_item)){
|
scope.item.render_value = vals_selected_item.join(",");
|
$scope.item.render_value = vals_selected_item.join(",");
|
}else{
|
scope.item.render_value = vals_selected_item;
|
$scope.item.render_value = vals_selected_item;
|
}
|
|
//验证错误信息
|
scope.billCheck();
|
// if(scope.item.render_value && scope.$parent.select_value == '002'){
|
// $scope.$parent.showcontrol = true;
|
// $scope.$parent.deptbudget();
|
// }
|
}, 1);
|
|
//下拉框 根据公式联动
|
var this_val = $(this).val();
|
_.each($scope.$parent.formula, function(formula) {
|
// if(formula.mathFormat == "select"){
|
if(scope.item.gcMeCode == formula.child[1].pMdCode) {
|
$scope.formula_conut(formula, this_val);
|
}
|
// }
|
})
|
|
});
|
$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();
|
}
|
});
|
}
|
})
|
|
var allflag = true
|
$('div.drop_down_sel input[name="checkbox"]').each(function() {
|
if($(this).prop("checked") == false) {
|
allflag = false;
|
}
|
});
|
|
if(allflag) {
|
$('input[name="all"]').attr('checked', 'checked')
|
} else {
|
$('input[name="all"]').attr('checked', null)
|
}
|
|
event.stopPropagation();
|
});
|
}
|
scope.set_valueleft = function(val) {
|
if(scope.item) {
|
if(val) {
|
if(val.length > 0) {
|
scope.item.valueLeft = val;
|
} else {
|
scope.item.valueLeft = false;
|
}
|
}
|
}
|
};
|
scope.rm_option = function(event) {
|
$timeout(function() {
|
// var new_item = _.cloneDeep(scope.item);
|
// new_item.render_value = "";
|
// scope.item = new_item;
|
scope.item.render_value = "";
|
var $elt = $(event.target);
|
$elt.closest('div.select-container').attr('value', '');
|
$elt.closest('div.val-card').remove();
|
var val = ($elt).attr('val');
|
if(val) {
|
val = JSON.parse(val);
|
}
|
scope.sel_val_lst = _.filter(scope.sel_val_lst, function(t) {
|
return t.value != val.value;
|
});
|
// 多选改变时更新查询条件
|
scope.set_valueleft(_.map(scope.sel_val_lst, "value"));
|
$el.find('select').val(scope.sel_val_lst);
|
|
$('div.drop_down_sel input[name="checkbox"]:checked').each(function() {
|
// 点取消时 将查询条件中值删除
|
scope.set_valueleft([]);
|
if($(this).val() == val.value) {
|
$(this).prop("checked", false);
|
}
|
});
|
if(scope.$parent.select_value == '002') {
|
$scope.$parent.showcontrol = false;
|
$scope.$parent.deptbudget();
|
}
|
|
event.stopPropagation();
|
}, 1)
|
|
};
|
},
|
post: function($scope, element, attrs) {}
|
}
|
}
|
}
|
}
|
])
|
.directive('frmElemCloudAttr', ['$rootScope', 'http_service', function($rootScope, http_service) {
|
return {
|
restrict: 'ACEM',
|
templateUrl: './static/templates/frm_elem_cloud_attr.html',
|
scope: {
|
type: "=",
|
data: "=",
|
action: "@"
|
},
|
compile: function() {
|
return {
|
pre: function(scope, iElement, iAttrs, controller) {
|
scope.masDataDefineCode = null;
|
// scope.masDataEleList_types = [{ "type": "预算" }, { "type": "申请" }, { "type": "报销" }];
|
scope.math_ceil = function(value) {
|
return Math.ceil(value);
|
};
|
scope.close = function() {
|
$(iElement).remove();
|
};
|
scope.pre_page = function() {
|
var pageNum = _.toInteger(scope.pageNumber);
|
if(pageNum && pageNum > 1) {
|
scope.pageNumber = --pageNum;
|
}
|
};
|
scope.next_page = function() {
|
var pageNum = _.toInteger(scope.pageNumber);
|
if(pageNum && pageNum < Math.ceil(scope.total / scope.pageSize)) {
|
scope.pageNumber = ++pageNum;
|
}
|
};
|
if(scope.action == 3) {
|
scope.url = 'cloud/cpn/masDataEleList';
|
} else {
|
scope.url = 'template/cpn/masDataEleList';
|
}
|
scope.$watchGroup(["pageNumber", "pageSize"], function() {
|
if(!scope.pageNumber || !scope.pageSize) return false;
|
http_service.post(
|
scope.url, {
|
"code": scope.type,
|
"keyWord": scope.keyWord,
|
"num_per_page": scope.pageSize,
|
"page_num": scope.pageNumber
|
},
|
function(res) {
|
$rootScope.search_hint(res.data.data.rows, 'arrary');
|
var data = res.data.data;
|
scope.total = data.total;
|
scope.attr_rows = data.rows;
|
}
|
);
|
|
});
|
|
scope.pageNumber = "1";
|
scope.pageSize = "10";
|
scope.keyWord = "";
|
scope.changed_page_size = function() {
|
scope.pageNumber = 1;
|
}
|
//pagenum键盘触发事件
|
check_number = function(strings){
|
//_.each(strings,function(string){
|
// if(strings.indexOf(string) == -1){
|
// return true;
|
// }
|
//})
|
//return false;
|
var patrn = /^[0-9]*$/;
|
if (patrn.exec(strings) == null) {
|
return false
|
} else {
|
return true
|
}
|
}
|
scope.search_keydown = function(pageNumber){
|
if(check_number(pageNumber)){
|
scope.pageNumber =parseInt(pageNumber);
|
if(scope.pageNumber > Math.ceil(scope.total/scope.pageSize)){
|
scope.pageNumber = Math.ceil(scope.total/scope.pageSize);
|
}else if(scope.pageNumber < 1 || scope.pageNumber == 0){
|
scope.pageNumber = 1;
|
}
|
}else if(!check_number(pageNumber) && check_number(pageNumber.charAt(0))){
|
//遍历pagenumber字符
|
var pageNum = '';
|
_.each(pageNumber,function(pageCode){
|
if(check_number(pageCode)){
|
pageNum = pageNum + pageCode;
|
}else{
|
return false;
|
}
|
})
|
scope.pageNumber = pageNum;
|
}else{
|
scope.pageNumber = 1;
|
}
|
}
|
//按回车键则查询主数据
|
scope.search_masDataEleList_keydown = function(event) {
|
if(event.keyCode == 13) {
|
scope.search_masDataEleList();
|
}
|
}
|
scope.search_masDataEleList = function() {
|
// scope.type
|
// switch(scope.masDataEleList_type.type) {
|
// case "预算":
|
// scope.type = 10;
|
// break;
|
// case "申请":
|
// scope.type = 20;
|
// break;
|
// case "报销":
|
// scope.type = 30;
|
// break;
|
// }
|
|
scope.keyWord = scope.masDataEleList_keywords;
|
scope.pageNumber = 1;
|
http_service.post(
|
scope.url, {
|
// "code": scope.type,
|
"keyWord": scope.keyWord,
|
"num_per_page": scope.pageSize,
|
"page_num": scope.pageNumber
|
},
|
function(res) {
|
var data = res.data.data;
|
scope.total = data.total;
|
scope.attr_rows = data.rows;
|
}
|
);
|
},
|
scope.get_cloud_attr = function(defineCode) {
|
var attr_rows = scope.attr_rows;
|
var attr_select = _.filter(scope.attr_rows, function(attr) {
|
return attr.masDataDefineCode == defineCode;
|
})[0];
|
if(attr_select) {
|
scope.data = _.extend(scope.data, {
|
'gcCpnName': attr_select.masDataDefineName,
|
//'gcElType': attr_select.eleValueType,
|
//'gcCpnAlias': attr_select.eleNameName,
|
'gcElIden': attr_select.eleCodeCode || attr_select.eleNameCode,
|
'gcMeCode': attr_select.masDataDefineCode
|
//'gcValField': attr_select.eleCodeCode,
|
//'gcElType': attr_select.eleValueType,
|
//'gcElLeng': attr_select.eleValueLen
|
//'gcTxtField': attr_select.eleNameCode,
|
//'gcBindDs': attr_select.masDataDefineCode
|
});
|
}
|
|
scope.close();
|
};
|
},
|
post: function($scope, element, attrs) {
|
|
}
|
}
|
}
|
}
|
}])
|
//控件属性
|
.directive('frmElementAttrEditor', ['$rootScope', '$compile', 'http_service', function($rootScope, $compile, http_service) {
|
return {
|
restrict: 'EACM',
|
templateUrl: './static/templates/frm_elem_attrs_editor.html',
|
scope: {
|
element: '=',
|
data: '=',
|
type: '='
|
},
|
compile: function() {
|
return {
|
pre: function(scope, iElement, iAttrs, controller) {},
|
post: function($scope, element, attrs) {
|
|
//获取主数据
|
$scope.showMasDataEleList = function() {
|
var $directive = $('<div frm-elem-Cloud-attr action="' + $scope.$parent.action + '" type="type" data="data" ></div>');
|
$('div[ng-view]').append($directive);
|
$compile($directive)($scope);
|
};
|
$scope.add_select_option = function() {
|
$scope.data.gcOptList.push({
|
'value': '',
|
'selected': true
|
});
|
};
|
//获取系统变量
|
function ReturnDataType() {
|
http_service.post('systemMath/search/list', {}, function(res) {
|
$scope.type_eill = res.data.data;
|
|
})
|
}
|
ReturnDataType();
|
//长度检查
|
$scope.check_length = function() {
|
$scope.data.gcElLeng = $scope.data.gcElLeng.replace(/\D/g, '');
|
$scope.data['length_err'] = undefined;
|
if($scope.data.gcElLeng != '') {
|
if($scope.data.gcElLeng > 100) {
|
$scope.data['length_err'] = '长度不能超过100';
|
}
|
}
|
}
|
$scope.remove_select_option = function(option) {
|
_.remove($scope.data.gcOptList, function(n) {
|
return n === option;
|
});
|
};
|
|
$scope.manadatory_ifd_check = function(event) {
|
var $this = $(event.target);
|
var $element = $($scope.element);
|
if($this.prop('checked')) {
|
$element.find('h8[name="el_title"]').prepend('<span class="manadatory_ifd">*</span>');
|
} else {
|
$element.find('h8[name="el_title"] > span.manadatory_ifd').remove();
|
}
|
}
|
|
$scope.process_ifd_check = function(event) {
|
var $this = $(event.target);
|
var $element = $($scope.element);
|
if($this.prop('checked')) {
|
$element.find('h8[name="el_title"] > span.process_ifd').html('△');
|
} else {
|
$element.find('h8[name="el_title"] > span.process_ifd').html('');
|
}
|
}
|
//关联公式编辑
|
$scope.add_hide_formula = function() {
|
http_service.post("base/data/search", { "code": $scope.data.gcMeCode, "cache_id": $scope.data.gcMeCode }, function(res) {
|
$scope.base_data = res.data.data.child;
|
$scope.relate_formula_content = []; //关联公式集合
|
$scope.relate_form_data_choose = []; //可隐藏的控件
|
$scope.item_choose = [];
|
|
$('.el_form').find('div[name="form_el_row"]').each(function(index, el) {
|
el_data = $(el).data('data');
|
if(el_data.gcShowFlag != 0 && el_data.gcMeCode != undefined && el_data.gcCpnType != 9 && el_data.gcCpnType != 10 && el_data != $scope.data && el_data.gcCpnType != 17) {
|
if($scope.data.parent_type == 0) {
|
if(el_data.parent_type == 0) {
|
$scope.relate_form_data_choose.push(el_data);
|
}
|
} else if($scope.data.parent_type == 1) {
|
if(el_data.parent_type == 1) {
|
$scope.relate_form_data_choose.push(el_data);
|
}
|
} else if($scope.data.parent_type == 2) {
|
if(el_data.parent_type == 2) {
|
$scope.relate_form_data_choose.push(el_data);
|
}
|
}
|
}
|
});
|
if($scope.data.cpnHide) { //回调
|
$scope.relate_formula_content = _.cloneDeep($scope.data.cpnHide);
|
|
_.each($scope.relate_formula_content, function(formula) {
|
_.each($scope.base_data, function(base) {
|
if(formula.cVal == base.code) {
|
formula.cVal = _.cloneDeep(base);
|
}
|
})
|
var formula_back = [];
|
|
_.each(formula.cHideItem, function(_formula) {
|
_.each($scope.relate_form_data_choose, function(choose) {
|
if(_formula == choose.gcMeCode) {
|
formula_back.push(_.cloneDeep(choose));
|
}
|
})
|
})
|
formula.cHideItem = formula_back;
|
})
|
|
}
|
var $pop = $('<div class="bg-modal"><div ng-click="close_edl($event)" class="pop_panel_formula" onMouseOver ="$(this).draggable();event.stopPropagation()" ;>' +
|
'<div class="custom_validate_relate_formula">' +
|
'<div class="cv_title_relate_formula">关联公式编辑 <div class="close" ><img src="./static/img/close.png" style="width:60%;margin-top:5px;"></div></div>' +
|
'<div class="col-md-3 formula_left">' +
|
'<p>表单控件</p>' +
|
'<ul>' +
|
'<li ng-repeat="item in relate_form_data_choose">' +
|
'<span ng-click="add_hide_item(item)" class="btn choose_item">{{item.gcCpnAlias}}</span>' +
|
'</li>' +
|
'</ul>' +
|
'</div>' +
|
'<div class="cv_fields_formula col-md-9">' +
|
'<div class="field_name_father">' +
|
'<div class="field_name">' +
|
$scope.data.gcCpnAlias + " =" +
|
'</div>' +
|
'<div class="formula_type">' +
|
'控件值 ' +
|
'<select ng-model="base_data_now" ng-options="base.value for base in base_data" ng-change="clear_hide_item()">' +
|
'</select>' +
|
'</div>' +
|
'</div>' +
|
'<div class="hide_content">' +
|
'<div class="hide_item">' +
|
'<ul>' +
|
'<li ng-repeat="item in item_choose">{{item.gcCpnAlias}}</li>' +
|
'</ul>' +
|
'</div>' +
|
'<button ng-click="insert_hide_item()" class="btn btn-action btn-success btn-favourite">确定</button>' +
|
'<button ng-click="clear_hide_item()" class="btn btn-action btn-success btn-favourite">清除</button>' +
|
'</div>' +
|
'<table class="table relate_talble">' +
|
'<thead>' +
|
'<tr>' +
|
'<th>控件值</th>' +
|
'<th>被隐藏的控件</th>' +
|
'</tr>' +
|
'</thead>' +
|
'<tbody>' +
|
'<tr ng-repeat="relate_item in relate_formula_content">' +
|
'<td>{{relate_item.cVal.value}}</td>' +
|
'<td>' +
|
'<span ng-repeat="single_item in relate_item.cHideItem">{{single_item.gcCpnAlias}}</span>' +
|
'<i ng-click="remove_relate_formula(relate_item)"><img src="./static/img/delete.png" class="deleteelment"></i>' +
|
'</td>' +
|
'</tr>' +
|
'</tbody>' +
|
'</table>' +
|
'</div>' +
|
'<div class="formula_btn">' +
|
'<button ng-click="relate_formula_commit()" class="btn btn-action btn-success btn-favourite confirm">保存</button>' +
|
'<button class="btn btn-action btn-success btn-favourite cancel">取消</button>' +
|
'</div>' +
|
'</div>' +
|
'</div></div>');
|
var $popdiv = $compile($pop)($scope);
|
$('body').append($popdiv);
|
$pop.find('div.close, button.cancel').on('click', function() {
|
$(this).closest('div.bg-modal').remove();
|
});
|
$scope.add_hide_item = function(item) {
|
var push_flag = true;
|
_.each($scope.item_choose, function(choose) {
|
if(_.isEqual(choose, item)) {
|
push_flag = false;
|
}
|
})
|
if(push_flag) {
|
$scope.item_choose.push(_.cloneDeep(item));
|
}
|
}
|
$scope.insert_hide_item = function() { //将要隐藏的控件加入表格中
|
if($scope.base_data_now != undefined && $scope.item_choose.length !==0) {
|
$scope.relate_formula_content.push({
|
"cVal": $scope.base_data_now,
|
"cHideItem": _.cloneDeep($scope.item_choose)
|
});
|
}else if($scope.base_data_now == undefined){
|
$rootScope.twarning("请选择控件值");
|
}else if($scope.item_choose.length == 0){
|
$rootScope.twarning("请选择表单控件");
|
}
|
$scope.clear_hide_item();
|
}
|
$scope.clear_hide_item = function() { //清空要隐藏的控件
|
$scope.item_choose = [];
|
}
|
$scope.remove_relate_formula = function(relate_item) { //删除一条关联公式
|
_.remove($scope.relate_formula_content, function(o) {
|
return o == relate_item;
|
})
|
}
|
$scope.relate_formula_commit = function() { //保存关联公式
|
var save_relate_formula = [];
|
_.each($scope.relate_formula_content, function(formula) {
|
var item_arr = [];
|
_.each(formula.cHideItem, function(item) {
|
item_arr.push(item.gcMeCode);
|
})
|
save_relate_formula.push({
|
"cVal": formula.cVal.code,
|
"cHideItem": item_arr
|
})
|
})
|
|
_.extend($scope.data, { "cpnHide":save_relate_formula});
|
|
$('div.bg-modal').remove();
|
}
|
}, true);
|
}
|
//公式编辑
|
$scope.add_formula = function() {
|
$scope.formula_content = "";
|
$scope.form_data_choose = [];
|
$('.el_form').find('div[name="form_el_row"]').each(function(index, el) {
|
var el_data = $(el).data('data');
|
if(el_data.gcMeCode != undefined && el_data.gcCpnType != 9 && el_data.gcCpnType != 10 && el_data.gcCpnType != 0 && el_data.gcCpnType != 14 && el_data != $scope.data && el_data.gcCpnType != 17) {
|
if($scope.data.parent_type == 1) { //公式条件不可跨子表单
|
if(el_data.parent_type != 2) {
|
$scope.form_data_choose.push(el_data);
|
}
|
} else if($scope.data.parent_type == 2) {
|
if(el_data.parent_type != 1) {
|
$scope.form_data_choose.push(el_data);
|
}
|
} else {
|
$scope.form_data_choose.push(el_data);
|
}
|
}
|
})
|
$scope.mResultFromat = [
|
{ "code": 1, "value": "parseInt({val})" },
|
{ "code": 2, "value": "parseFloat({val}.toFixed(2))" },
|
{ "code": 3, "value": "parseFloat({val}.toFixed(3))" }
|
];
|
$scope.fx_data = [{
|
"fx_name": "日期函数",
|
"fx_value": "Day()",
|
"fx_str": "Day",
|
"fx_formula_str": "(1/(24*60*60*1000))*"
|
}]
|
var edl_arr = [];
|
$scope.value_type = "";
|
// if($scope.data.joinMath){
|
if($scope.data.joinMath && $scope.data.joinMath.length > 0) {
|
if($scope.data.joinMath[0].cpnMath.mView) {
|
$scope.formula_content = $scope.data.joinMath[0].cpnMath.mView; //显示公式回调
|
}
|
_.each($scope.mResultFromat, function(_result) {
|
if(_result.value == $scope.data.joinMath[0].cpnMath.mResultFromat) {
|
$scope.value_type = _result.code;
|
}
|
})
|
_.each($scope.data.joinMath[0].cpnMath.child, function(cpn) {
|
if(cpn.pIndex != 0) {
|
edl_arr.push(cpn);
|
}
|
})
|
}
|
// }
|
|
_.each($scope.form_data_choose, function(data) {
|
data['edl'] = "";
|
_.each(edl_arr, function(edl) {
|
if(data.gcMeCode == edl.pMdCode && edl.meName != undefined) {
|
data['edl'] = { "meCode": edl.pMeCode, "meName": edl.meName }; //元素选择回调
|
}
|
})
|
});
|
var $pop = $('<div class="bg-modal"><div ng-click="close_edl($event)" class="pop_panel_formula" onMouseOver ="$(this).draggable();event.stopPropagation()" ;>' +
|
'<div class="custom_validate_formula">' +
|
'<div class="cv_title_formula">公式编辑 <div class="close" ><img src="./static/img/close.png" style="width:60%;margin-top:5px;"></div></div>' +
|
'<div class="col-md-4 formula_left">' +
|
'<p>表单控件</p>' +
|
'<ul>' +
|
'<li ng-repeat="item in form_data_choose">' +
|
'<span ng-click="add_item(item)" class="btn choose_item">{{item.gcCpnAlias}}</span>' +
|
'<span class="btn choose_edl" ng-click="add_mecode(item,$event)">元素选择</span>' +
|
'<ul ng-show="item.show_edl" class="fromula_edl">' +
|
'<li ng-click="add_edl(item,data)" ng-repeat="data in item.edl_data">{{data.meName}}</li>' +
|
'</ul>' +
|
'<span class="edl" ng-show="item.edl">{{item.edl.meName}}</span>' +
|
'</li>' +
|
'</ul>' +
|
'</div>' +
|
'<div class="cv_fields_formula col-md-6">' +
|
'<div class="field_name_father">' +
|
'<div class="field_name">' +
|
$scope.data.gcCpnAlias + " =" +
|
'</div>' +
|
'<div class="formula_type">' +
|
'结果格式' +
|
'<select ng-model="value_type">' +
|
'<option ng-value=""> 无限制 </option>' +
|
'<option ng-value="1"> 整数</option>' +
|
'<option ng-value="2"> 保留2位小数 </option>' +
|
'<option ng-value="3"> 保留3位小数</option>' +
|
'</select>' +
|
'</div>' +
|
'</div>' +
|
// '<div class="col-md-12">'+
|
// '<div>'+
|
'<textarea id="formula_content" ng-model="formula_content">' +
|
|
'</textarea>' +
|
// '</div>'+
|
// '</div>'+
|
'</div>' +
|
'<div class="col-md-2 formula_right">' +
|
'<p>公式函数</p>' +
|
'<ul>' +
|
'<li class="btn" ng-repeat="fx in fx_data" ng-click="add_fx(fx)">{{fx.fx_name}}</li>' +
|
'</ul>' +
|
'</div>' +
|
'<div class="formula_btn">' +
|
'<button ng-click="formula_commit()" class="btn btn-action btn-success btn-favourite confirm">确定</button>' +
|
'<button class="btn btn-action btn-success btn-favourite cancel">取消</button>' +
|
'</div>' +
|
'</div>' +
|
'</div></div>');
|
var $popdiv = $compile($pop)($scope);
|
$('body').append($popdiv);
|
$pop.find('div.close, button.cancel').on('click', function() {
|
$(this).closest('div.bg-modal').remove();
|
});
|
|
function insertAfterText(textDom, value) { //在光标后插入文本
|
var selectRange;
|
if(document.selection) {
|
// IE Support
|
textDom.focus();
|
selectRange = document.selection.createRange();
|
selectRange.text = value;
|
$scope.formula_content = selectRange.text;
|
textDom.focus();
|
} else if(textDom.selectionStart || textDom.selectionStart == '0') {
|
// Firefox support
|
var startPos = textDom.selectionStart;
|
var endPos = textDom.selectionEnd;
|
var scrollTop = textDom.scrollTop;
|
$scope.formula_content = $scope.formula_content.substring(0, startPos) + value + $scope.formula_content.substring(endPos, $scope.formula_content.length);
|
textDom.focus();
|
textDom.selectionStart = startPos + value.length;
|
textDom.selectionEnd = startPos + value.length;
|
textDom.scrollTop = scrollTop;
|
} else {
|
$scope.formula_content += value;
|
textDom.focus();
|
}
|
}
|
$scope.add_item = function(item) { //添加控件
|
var formula_str = "[" + item.gcCpnAlias + "]";
|
insertAfterText(document.getElementById("formula_content"), formula_str);
|
}
|
$scope.add_mecode = function(item, event) {
|
http_service.post("base/data/element/info", { "code": item.gcMeCode }, function(res) {
|
_.each($scope.form_data_choose, function(_form) {
|
if(_form == item) {
|
_form['edl_data'] = res.data.data;
|
_form['show_edl'] = true;
|
} else {
|
_form['show_edl'] = false;
|
}
|
})
|
});
|
|
event.stopPropagation();
|
}
|
$scope.close_edl = function(event) {
|
_.each($scope.form_data_choose, function(_form) {
|
_form['show_edl'] = false;
|
});
|
event.stopPropagation();
|
event.preventDefault();
|
}
|
$scope.add_edl = function(item, data) {
|
_.each($scope.form_data_choose, function(_form) {
|
if(_form == item) {
|
_form['edl'] = data;
|
}
|
});
|
}
|
$scope.add_fx = function(fx) {
|
insertAfterText(document.getElementById("formula_content"), fx.fx_value);
|
}
|
$scope.formula_commit = function() { //保存公式
|
var formula_str = $scope.formula_content;
|
var str = $scope.formula_content,
|
reg = /\[(.*?)\]/g,
|
code_arr = [],
|
x = null;
|
while((x = reg.exec(str)) != null) {
|
code_arr.push(x[1]);
|
}
|
var formula_code = [];
|
formula_code.push({ "pMdCode": $scope.data.gcMeCode, "pType": 10, "pIndex": 0, "pMeCode": "code" });
|
|
_.each(code_arr, function(code, i) {
|
_.each($scope.form_data_choose, function(item) {
|
if(code == item.gcCpnAlias) {
|
if(item.edl && item.edl != '') {
|
formula_code.push({ "pMdCode": item.gcMeCode, "pType": 10, "pIndex": (i + 1), "pMeCode": item.edl.meCode, "meName": item.edl.meName });
|
} else {
|
formula_code.push({ "pMdCode": item.gcMeCode, "pType": 10, "pIndex": (i + 1), "pMeCode": "code" });
|
}
|
if(item.gcCpnType == 5) {
|
formula_str = formula_str.replace("[" + code + "]", "new Date({" + (i + 1) + "})");
|
} else {
|
formula_str = formula_str.replace("[" + code + "]", "{" + (i + 1) + "}");
|
}
|
|
}
|
})
|
});
|
_.each($scope.fx_data, function(fx) {
|
if(formula_str.indexOf(fx.fx_str) != -1) {
|
formula_str = formula_str.replace(new RegExp(fx.fx_str, 'g'), fx.fx_formula_str);
|
}
|
})
|
var mResultFromat;
|
_.each($scope.mResultFromat, function(_result) {
|
if(_result.code == $scope.value_type) {
|
mResultFromat = _result.value;
|
}
|
});
|
// var post_data = {
|
// "child":formula_code,
|
// "mCount":formula_str,
|
// "mType":10,
|
// "mView":$scope.formula_content,
|
// "mResultFromat":mResultFromat
|
// }
|
// http_service.post("form/math/insert",post_data,function(res){
|
if($scope.formula_content == "" || $scope.formula_content == undefined) {
|
$scope.data['joinMath'] = [];
|
} else {
|
$scope.data['joinMath'] = [{
|
"cpnMath": {
|
"mCount": formula_str,
|
// "mName" : "公式名称",
|
"mResultFromat": mResultFromat,
|
"mType": 10,
|
"mView": $scope.formula_content,
|
"child": formula_code
|
}
|
}];
|
}
|
$pop.find('div.close, button.cancel').closest('div.bg-modal').remove();
|
// });
|
}
|
}
|
$scope.add_customize_validation = function() {
|
// 加入的控件数据项
|
if($scope.data.gcErrorMsg == undefined) {
|
$scope.data.gcErrorMsg = "";
|
}
|
var isfixed;
|
if($scope.data.gcCheckCpnCode == -1) {
|
isfixed = 0;
|
} else {
|
isfixed = 1;
|
}
|
// $rootScope.checkdata = $scope.data;
|
var titleText = '';
|
$('.el_form').find('div[name="form_el_row"]').each(function(index, el) {
|
el_data = $(el).data('data');
|
if(el_data.gcCpnType != 9 && el_data.gcCpnType != 10 && el_data.gcCpnType != 17) {
|
if($scope.data.parent_type != 2) { //支付方式子表单中的比较控件只能是支付方式子表单中的控件
|
if(el_data.parent_type != 2) {
|
titleText += '<option value="' + el_data.gcMeCode + '">' + el_data.gcCpnAlias + '</option>';
|
}
|
} else {
|
if(el_data.parent_type == 2) {
|
titleText += '<option value="' + el_data.gcMeCode + '">' + el_data.gcCpnAlias + '</option>';
|
}
|
}
|
}
|
})
|
|
var $pop = $('<div class="bg-modal"><div class="pop_panel" onMouseOver ="$(this).draggable();event.stopPropagation()" style="width:450px;height:270px;" id="create_order" ;>' +
|
'<div class="custom_validate">' +
|
'<div class="cv_title">校验规则设置 <div class="close" ><img src="./static/img/close.png" style="width:60%;margin-top:5px;"></div></div>' +
|
'<div class="cv_fields">' +
|
'<div class="col-md-3">控件名称</div><div class="col-md-3">比较符号</div><div class="col-md-3">数据项</div><div class="col-md-3">固定值</div>' +
|
'<div class="col-md-3">' +
|
'<div class="field_name">' +
|
$scope.data.gcCpnAlias +
|
'</div>' +
|
'</div>' +
|
'<div class="col-md-3">' +
|
'<select name="operator" ng-model="data.gcCheckOp">' +
|
'<option value=""> --请选择-- </option>' +
|
'<option value="<"> < </option>' +
|
'<option value="<="> <= </option>' +
|
'<option value=">"> > </option>' +
|
'<option value=">="> >= </option>' +
|
'<option value="=="> == </option>' +
|
'<option value="<>"> <> </option>' +
|
'</select>' +
|
'</div>' +
|
'<div class="col-md-3">' +
|
'<select name="data" ng-model="data.gcCheckCpnCode">' +
|
'<option value=""> --请选择-- </option>' +
|
//'<option value="0"> 已选择控件 </option>'+
|
titleText +
|
'<option value="-1"> 固定值 </option>' +
|
'</select>' +
|
'</div>' +
|
'<div class="col-md-3" >' +
|
'<input type="text" ng-disabled="' + isfixed + '" name="fixed_value" ng-model="data.gcCheckValue" >' +
|
'</div>' +
|
'</div>' +
|
'<div class="cv_label">提示信息</div>' +
|
'<div class="cv_msg_field">' +
|
'<input type="text" name="msg" value="' + $scope.data.gcErrorMsg + '">' +
|
'</div>' +
|
'<div class="cv_btns">' +
|
// '<div><button class="cancel">取消</button></div>' +
|
'<div><button class="confirm btn btn-action btn-success btn-favourite">确认</button></div>' +
|
'</div>' +
|
'</div>' +
|
'</div></div>');
|
var $popdiv = $compile($pop)($scope);
|
$('body').append($popdiv);
|
$pop.find('div.close, button.cancel').on('click', function() {
|
$(this).closest('div.bg-modal').remove();
|
});
|
$pop.find('select[name="data"]').on('change', function() {
|
$('input[name="fixed_value"]').val("");
|
if($(this).val() === '-1') {
|
$('input[name="fixed_value"]').removeAttr('disabled');
|
} else {
|
$('input[name="fixed_value"]').attr('disabled', 'disabled');
|
}
|
});
|
$pop.find('button.confirm').on('click', function() {
|
var operator = $pop.find('select[name="operator"]').val();
|
var data = $pop.find('select[name="data"]').val();
|
var fixed_value = $pop.find('input[name="fixed_value"]').prop('disabled') ? null : $pop.find('input[name="fixed_value"]').val();
|
var msg = $pop.find('input[name="msg"]').val();
|
if(operator) {
|
$scope.data.gcCheckOp = operator;
|
} else {
|
$scope.data.gcCheckOp = '';
|
}
|
if(data) {
|
$scope.data.gcCheckCpnCode = data;
|
} else {
|
$scope.data.gcCheckCpnCode = '';
|
}
|
if(fixed_value) {
|
$scope.data.gcCheckValue = fixed_value;
|
} else {
|
$scope.data.gcCheckValue = '';
|
}
|
if(msg) {
|
$scope.data.gcErrorMsg = msg;
|
} else {
|
$scope.data.gcErrorMsg = '';
|
}
|
$rootScope.swalsuccess({ "text": "校验规则设置完成" });
|
// $('.bg-modal').hide();
|
$(this).closest('div.bg-modal').remove();
|
});
|
}
|
|
$scope.$watch('data', function(data) {
|
var $element = $($scope.element);
|
for(var el_attr in data) {
|
var el_attr_val = data[el_attr];
|
switch(el_attr) {
|
case 'gcCpnAlias':
|
$element.find(' > h8 > span.text').html(el_attr_val);
|
break;
|
case 'gcCpnDisc':
|
$element.find('> div[name="el_desc"]').html(el_attr_val);
|
break;
|
case 'gcDefVal':
|
$element.find('> div > input, > div > textarea').val(el_attr_val);
|
break;
|
}
|
}
|
}, true);
|
|
}
|
}
|
}
|
}
|
}])
|
|
//设置空白模板的控制器
|
.controller('budgetFormCustomizeCtrl', ['$scope', '$compile', 'http_service', '$routeParams', '$rootScope', '$timeout', '$route', function($scope, $compile, http_service, $routeParams, $rootScope, $timeout, $route) {
|
$scope.business = $routeParams.business;
|
$scope.type = $routeParams.type;
|
$scope.form_id = $routeParams.id;
|
$scope.action = $routeParams.action;
|
|
//点击保存触发的事件
|
var create_forms_flag = true;
|
$scope.create_forms = function() {
|
if(!create_forms_flag) {
|
return false;
|
}
|
create_forms_flag = false;
|
var post_data = [];
|
var el_data;
|
$('.el_form').find('div[name="form_el_row"]').each(function(index, el) {
|
el_data = $(el).data('data');
|
|
if(el_data && !$(el).parent().closest('div.sub_form').length) {
|
if(el_data['gcCpnType'] === 10 || el_data['gcCpnType'] === 17) {
|
var children = [];
|
$(el).find('div[name="form_el_row"]').each(function(index, _el) {
|
if($(_el).data('data')) {
|
var _el_data = $(_el).data('data');
|
children.push(_el_data);
|
}
|
});
|
el_data['child'] = children;
|
}
|
el_data.gcInputMust = !el_data.gcInputMust ? 0 : 1;
|
post_data.push(el_data);
|
|
}
|
});
|
var child_num = 0;
|
var people_item = true;
|
var org_item = true;
|
var length_err_arr = []; //判断长度限制
|
_.each(post_data, function(_pd) {
|
delete _pd.show_edl;
|
delete _pd.edl;
|
delete _pd.edl_data;
|
delete _pd.parent_type;
|
if(_pd.length_err) {
|
length_err_arr.push(_pd.gcCpnAlias);
|
}
|
if(_pd.gcCpnType == 10) {
|
child_num++
|
_.each(_pd.child, function(cd) {
|
if(cd.length_err) {
|
length_err_arr.push(cd.gcCpnAlias);
|
}
|
delete cd.show_edl;
|
delete cd.edl;
|
delete cd.edl_data;
|
delete cd.parent_type;
|
if(cd.gcCpnType == 12) {
|
people_item = false;
|
} else if(cd.gcCpnType == 10) {
|
child_num = -1000;
|
} else if(cd.gcCpnType == 16) {
|
org_item = false;
|
}
|
})
|
}
|
if(_pd.gcCpnType == 17) {
|
_.each(_pd.child, function(cd) {
|
if(cd.length_err) {
|
length_err_arr.push(cd.gcCpnAlias);
|
}
|
delete cd.show_edl;
|
delete cd.edl;
|
delete cd.edl_data;
|
delete cd.parent_type;
|
if(cd.gcCpnType == 12) {
|
people_item = false;
|
} else if(cd.gcCpnType == 16) {
|
org_item = false;
|
}
|
})
|
}
|
})
|
if(length_err_arr.length > 0) {
|
var length_err_str = length_err_arr.join(",");
|
$scope.$parent.terro(length_err_str + "长度限制错误");
|
create_forms_flag = true;
|
return false;
|
}
|
if(child_num > 1) {
|
$scope.$parent.terro('只能有一个子表单');
|
create_forms_flag = true;
|
return false;
|
} else if(child_num < 0) {
|
$scope.$parent.terro('子表单中不能嵌套子表单');
|
create_forms_flag = true;
|
return false;
|
}
|
// if(people_item == false) {
|
// $scope.$parent.terro('人员控件不可以在子表单中');
|
// create_forms_flag = true;
|
// return false;
|
// }
|
if(org_item == false) {
|
$scope.$parent.terro('组织结构控件不可以在子表单中');
|
create_forms_flag = true;
|
return false;
|
}
|
if(!$scope.guTempName) {
|
//alert('模本名称未填写。');
|
$scope.twarning("模本名称未填写!");
|
create_forms_flag = true;
|
create_forms_flag = true;
|
/*
|
}else if(!$scope.guTempDisc){
|
alert('模板描述为填写。');
|
*/
|
} else if(post_data.length != 0) {
|
var forms_data = {
|
"guTempType": $scope.type,
|
"guTempName": $scope.guTempName,
|
"guTempDisc": $scope.guTempDisc,
|
"child": post_data
|
};
|
if($scope.form_id) {
|
// action != 3 表单修改 else 模板修改
|
if($scope.action != 3) {
|
forms_data = _.extend(forms_data, {
|
'guId': $scope.form_id,
|
'cache_id': $scope.type
|
});
|
http_service.post('form/save', forms_data, function(res) {
|
if(res.status == 200) {
|
if(res.data.errMsg) {
|
$scope.$parent.terro(res.data.errMsg)
|
|
//alert(res.data.errMsg);
|
} else {
|
if(res.data.opState) {
|
$scope.$parent.tsuccess('表单' + $scope.guTempName + '更新成功。');
|
window.history.go(-1);
|
} else {
|
$scope.$parent.terro('表单' + $scope.guTempName + '更新失败。')
|
|
}
|
// alert('表单'+$scope.guTempName+'更新成功。');
|
}
|
}
|
create_forms_flag = true;
|
});
|
} else {
|
forms_data = _.extend(forms_data, {
|
'guId': $scope.form_id,
|
'cache_id': $scope.type
|
});
|
http_service.post('template/update', forms_data, function(res) {
|
if(res.status == 200) {
|
if(res.data.errMsg) {
|
$scope.$parent.terro(res.data.errMsg)
|
|
//alert(res.data.errMsg);
|
} else {
|
if(res.data.opState) {
|
|
$scope.$parent.tsuccess('模板' + $scope.guTempName + '更新成功。')
|
} else {
|
$scope.$parent.terro('模板' + $scope.guTempName + '更新失败。')
|
}
|
|
//alert('模板'+$scope.guTempName+'更新成功。');
|
}
|
}
|
create_forms_flag = true;
|
});
|
}
|
} else {
|
// action != 3 表单新增 else 模板新增
|
if($scope.action != 3) {
|
forms_data = _.extend(forms_data, {
|
'cache_id': $scope.type
|
});
|
http_service.post('form/save', forms_data, function(res) {
|
if(res.status == 200) {
|
if(res.data.errMsg) {
|
// swal({
|
// title: "错误",
|
// text: res.data.errMsg,
|
// type: "error",
|
// confirmButtonText: "确定",
|
// })
|
$scope.$parent.terro(res.data.errMsg)
|
|
//alert(res.data.errMsg);
|
} else {
|
if(res.data.opState) {
|
$scope.$parent.tsuccess('表单' + $scope.guTempName + '创建成功。');
|
var new_form_data = res;
|
new_form_data.data.data = forms_data;
|
window.history.go(-1);
|
} else {
|
$scope.$parent.terro('表单' + $scope.guTempName + '创建失败。')
|
|
}
|
//alert('表单'+$scope.guTempName+'创建成功。');
|
}
|
}
|
create_forms_flag = true;
|
});
|
} else {
|
forms_data = _.extend(forms_data, {
|
"guIndusId": $scope.business,
|
"guTempSource": 1
|
})
|
http_service.post('template/insert', forms_data, function(res) {
|
if(res.status == 200) {
|
if(res.data.errMsg) {
|
$scope.$parent.terro(res.data.errMsg)
|
|
//alert(res.data.errMsg);
|
} else {
|
if(res.data.opState) {
|
$scope.$parent.tsuccess('模板' + $scope.guTempName + '创建成功。')
|
window.history.go(-1);
|
} else {
|
$scope.$parent.terro('模板' + $scope.guTempName + '创建失败。')
|
|
}
|
|
//alert('模板'+$scope.guTempName+'创建成功。');
|
}
|
}
|
create_forms_flag = true;
|
});
|
}
|
}
|
|
} else {
|
$scope.twarning("表单不能为空!")
|
}
|
};
|
|
$scope.$on('$viewContentLoaded', function() {
|
if($scope.form_id) {
|
// action:1 编辑已有表单 action:2 || 3 根据模板编辑
|
if($scope.action == 1) {
|
http_service.post('form/list', {
|
"guTempType": parseInt($scope.type),
|
"cache_id": parseInt($scope.type)
|
}, function(res) {
|
if(!res.data.opState) {
|
return false;
|
}
|
var data = res.data.data;
|
$scope.guTempName = data.guTempName;
|
$scope.guTempDisc = data.guTempDisc;
|
build_form_editor(data);
|
}, true);
|
} else if($scope.action == 2 || $scope.action == 3) {
|
http_service.post('template/cpn/search', {
|
"gcTempId": $scope.form_id
|
}, function(res) {
|
var data = res.data.data;
|
if(data) {
|
$scope.guTempName = data.guTempName;
|
$scope.guTempDisc = data.guTempDisc;
|
build_form_editor(data);
|
}
|
})
|
}
|
} else {
|
build_form_editor();
|
}
|
|
$('div.split_form').height($(document).height() - 52);
|
$(window).resize(function() {
|
$('div.split_form').height($(document).height() - 52);
|
});
|
|
function build_form_editor(edit_form_data) {
|
var fb = new form_builder.create();
|
var data = {
|
'gcCpnName': '',
|
'gcCpnType': '',
|
'gcDmlLeng': '', //精度
|
'gcShowFlag': 1, // show flag
|
'gcEditFlag': 1,
|
'gcCpnAlias': '未命名',
|
'gcCpnDisc': '',
|
'gcDefVal': '',
|
'gcInputMust': 0,
|
'gcCpnInCol': 2,
|
'gcElIden': "元素标志符", // adding
|
'gcElLeng': 50, //adding
|
'gcMathId': 0
|
|
};
|
fb.add_elements([{
|
'type': 0,
|
'btn': '<button class="btn btn-success btn-elb">预算选择</button>',
|
'field': '<div class="multi_level_select"><div>点击选择</div></div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '预算选择',
|
'gcCpnType': 0,
|
'gcCpnInCol': 2
|
}))
|
},
|
{
|
'type': 1,
|
'btn': '<button class="btn btn-success btn-elb"><span class="fa fa-font"></span> 单行文本 </button>',
|
'field': '<input readonly >',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '单行文本',
|
'gcCpnType': 1,
|
'gcCpnFormat': 0
|
|
}))
|
|
},
|
{
|
'type': 2,
|
'btn': '<button class="btn btn-success btn-elb"><i class="fa fa-paragraph"></i> 多行文本 </button>',
|
'field': '<textarea readonly></textarea>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '多行文本',
|
'gcCpnType': 2
|
}))
|
},
|
// {
|
// 'type': 3,
|
// 'btn': '<button class="btn btn-success btn-elb"><i class="fa fa-square-o"></i> 复选框 </button>',
|
// 'field': '<div>' +
|
// '<div>' +
|
// '<input type="checkbox" name="test_multi_radio">' +
|
// '</div>' +
|
// '</div>',
|
// 'data': _.cloneDeep(_.extend(data, {
|
// 'gcCpnAlias': '复选框',
|
// 'gcCpnType': 3,
|
// 'gcOptList': [{ 'value': '', 'selected': true }]
|
// }))
|
// },
|
// {
|
// 'type': 4,
|
// 'btn': '<button class="btn btn-success btn-elb"><i class="fa fa-circle-o"></i> 单选框 </button>',
|
// 'field': '<input type="radio" readonly>',
|
// 'data': _.cloneDeep(_.extend(data, {
|
// 'gcCpnAlias': '单选框',
|
// 'gcCpnType': 4,
|
// 'gcOptList': [{ 'value': '', 'selected': true }]
|
// }))
|
// },
|
{
|
'type': 5,
|
'btn': '<button class="btn btn-success btn-elb"><i class="fa fa-calendar"></i> 日期时间 </button>',
|
'field': '<div class="dateclass">' +
|
'<input type="text" readonly class="ifd_time_picker" >' +
|
'<img src="./static/img/calendar.png" class="ifd_time_picker">' +
|
'</div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '日期时间',
|
'gcCpnType': 5,
|
'gcCpnFormat': 30,
|
|
|
}))
|
},
|
{
|
'type': 6,
|
'btn': '<button class="btn btn-success btn-elb"><i class="fa fa-chevron-down"></i> 下拉框 </button>',
|
'field': '<div class="select3-element"><div class="select-container" style="width:285px"><div class="suffix"><i class="fa fa-caret-down" aria-hidden="true"></i></div></div></div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '下拉框',
|
'gcCpnType': 6,
|
'gcCpnMultiple': 0,
|
'gcOptList': [{ 'value': '', 'selected': true }]
|
}))
|
},
|
{
|
'type': 7,
|
'btn': '<button class="btn btn-success btn-elb">123 数字 </button>',
|
'field': '<input readonly/>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '123 数字',
|
'gcCpnType': 7,
|
'gcCpnFormat': 20
|
}))
|
},
|
/*
|
{
|
'type': 8,
|
'btn': '<button class="btn btn-success btn-elb"><i class="fa fa-home"></i> 地址 </button>',
|
'field': '<div>'+
|
'<div>'+
|
'<select class="addr_select" disabled>'+
|
'<option value="" selected>省/自治区/直辖市</option>'+
|
'</select>'+
|
'<select class="addr_select" disabled>'+
|
'<option value="" selected>市</option>'+
|
'</select>'+
|
'<select class="addr_select" disabled>'+
|
'<option value="" selected>区/县</option>'+
|
'</select>'+
|
'</div>'+
|
'<div class="addr_txt">'+
|
|
'</div>'+
|
'</div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '地址',
|
'gcCpnType': 8
|
}))
|
},
|
*/
|
|
{
|
'type': 9,
|
'btn': '<button class="btn btn-success btn-elb">-- 分割线 </button>',
|
'field': '<hr>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '-- 分割线',
|
'gcCpnType': 9
|
}))
|
},
|
{
|
'type': 10,
|
'btn': '<button class="btn btn-success btn-elb">子表单</button>',
|
'field': '<div class="sub_form" ></div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '子表单',
|
'gcCpnType': 10,
|
'gcCpnInCol': 2
|
|
}))
|
},
|
|
// {
|
// 'type': 11,
|
// 'btn': '<button class="btn btn-success btn-elb">城市选择</button>',
|
// 'field': '<div class="multi_level_select"><div>点击选择</div></div>',
|
// 'data': _.cloneDeep(_.extend(data, {
|
// 'gcCpnAlias': '城市选择',
|
// 'gcCpnType': 11
|
// }))
|
// },
|
|
{
|
'type': 12,
|
'btn': '<button class="btn btn-success btn-elb">人员选择</button>',
|
'field': '<div class="multi_level_select"><div>点击选择</div></div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '人员选择',
|
'gcCpnType': 12
|
}))
|
},
|
// {
|
// 'type': 13,
|
// 'btn': '<button class="btn btn-success btn-elb">部门选择</button>',
|
// 'field': '<div class="multi_level_select"><div>点击选择</div></div>',
|
// 'data': _.cloneDeep(_.extend(data, {
|
// 'gcCpnAlias': '部门选择',
|
// 'gcCpnType': 13
|
// }))
|
// },
|
{
|
'type': 14,
|
'btn': '<button class="btn btn-success btn-elb">申请单选择</button>',
|
'field': '<div class="multi_level_select"><div>点击选择</div></div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '申请单选择',
|
'gcCpnType': 14,
|
'gcCpnInCol': 2
|
}))
|
},
|
{
|
'type': 15,
|
'btn': '<button class="btn btn-success btn-elb">标签</button>',
|
'field': '<label readonly >',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '标签',
|
'gcCpnType': 15,
|
}))
|
},
|
{
|
'type': 17,
|
'btn': '<button class="btn btn-success btn-elb">支付方式子表单</button>',
|
'field': '<div class="sub_form sub_form_pay" ></div>',
|
'data': _.cloneDeep(_.extend(data, {
|
'gcCpnAlias': '支付方式子表单',
|
'gcCpnType': 17,
|
'gcCpnInCol': 2
|
}))
|
}
|
// {
|
// 'type': 16,
|
// 'btn': '<button class="btn btn-success btn-elb">组织机构</button>',
|
// 'field': '<div class="multi_level_select"><div>点击选择</div></div>',
|
// 'data': _.cloneDeep(_.extend(data, {
|
// 'gcCpnAlias': '组织机构',
|
// 'gcCpnType': 16
|
// }))
|
// }
|
]);
|
fb.add_forms('.el_form');
|
fb.add_forms('.sub_form');
|
fb.add_elements_box('.left');
|
fb.recover_form_data(edit_form_data, 'gcCpnType');
|
fb.element_appended_callback(after_el_append);
|
fb.bootstrap();
|
}
|
|
});
|
|
function edit_attrs($element) {
|
var data = $element.data('data');
|
/*
|
var $el = $(`
|
<div
|
frm-element-attr-editor
|
element="element"
|
data="data"
|
>
|
</div>
|
`);
|
$('div[name="el_attr_editor_container"]').html($el);
|
$timeout(function(){
|
$compile($el)($scope);
|
}, 0);
|
*/
|
$scope.$apply(function() {
|
$scope.element = $element;
|
$scope.data = data;
|
//$scope.$apply();
|
});
|
}
|
|
function clone_el_data(dst, src) {
|
var dst_els = dst.find('div[name="form_el_row"]');
|
var src_els = src.find('div[name="form_el_row"]');
|
if(dst_els.length) {
|
src_els.each(function(index, el) {
|
$(dst_els[index]).data('data', _.cloneDeep($(el).data('data')));
|
});
|
}
|
dst.data('data', _.cloneDeep(src.data('data')));
|
|
}
|
|
function after_el_append(element_data, element, place_holder, data) {
|
var $element = $(element);
|
var $form_el_row = $element.closest('div[name="form_el_row"]');
|
var el_data;
|
if(data) {
|
el_data = _.cloneDeep(data);
|
} else {
|
el_data = _.cloneDeep(element_data[0]['data']);
|
}
|
//el_data['gcElIden'] = new Date().getTime() + Math.random();
|
$form_el_row.data('data', el_data);
|
if(!$element.is('hr')) {
|
if(data) {
|
$form_el_row.prepend('<h8 name="el_title">' +
|
(data.gcInputMust ? '<span class="manadatory_ifd" >*</span>' : '') +
|
'<span class="process_ifd" >' + (data.gcMustCpn ? '△' : '') + '</span>' +
|
'<span class="text">' + (data.gcCpnAlias || '') +
|
'</span>' +
|
'</h8>' +
|
'<hr>' +
|
'<div name="el_desc">' +
|
(data.gcCpnDisc || '') +
|
'</div>');
|
} else {
|
$form_el_row.prepend('<h8 name="el_title">' +
|
'<span class="text">' +
|
element_data[0]['data']['gcCpnAlias'] +
|
'</span>' +
|
'</h8>' +
|
'<hr>' +
|
'<div name="el_desc"></div>');
|
}
|
}
|
|
var frm_el_click = function($icons, $form_el_row) {
|
//选项卡修改 开始
|
$icons.find('div.remove').on('click', function(event) {
|
$form_el_row.remove();
|
event.stopPropagation();
|
});
|
|
$icons.find('div.duplicate').on('click', function(event) {
|
var $clone = $form_el_row.clone();
|
$clone.removeClass('active');
|
$form_el_row.after($clone);
|
clone_el_data($clone, $form_el_row);
|
frm_el_click($clone.find('div.frm_item_icons'), $clone);
|
$clone.on('click', function() {
|
$('div[name="form_el_row"]').removeClass('active');
|
$(this).addClass('active');
|
});
|
event.stopPropagation();
|
});
|
if($($form_el_row).parent('.sub_form ').length > 0 && $($form_el_row).parent('.sub_form_pay').length == 0) { //判断此控件是否为子表单中的控件
|
$form_el_row.data('data', _.extend($form_el_row.data('data'), { 'parent_type': 1 }));
|
} else if($($form_el_row).parent('.sub_form_pay').length > 0) { //判断此控件是否为支付方式子表单中的控件
|
$form_el_row.data('data', _.extend($form_el_row.data('data'), { 'parent_type': 2 }));
|
} else {
|
$form_el_row.data('data', _.extend($form_el_row.data('data'), { 'parent_type': 0 }));
|
}
|
$form_el_row.on('click', function(event) {
|
var $scope = $route.current.scope;
|
var $el = $(this);
|
$('div[name="form_el_row"]').removeClass('active');
|
$el.addClass('active');
|
$timeout(function() {
|
$scope.element = $el;
|
$scope.data = $el.data('data');
|
}, 0);
|
event.stopPropagation();
|
event.preventDefault();
|
});
|
};
|
var $icons = $('<div class="frm_item_icons">' +
|
'<div class="frm_item_icon remove"><img src="static/img/delete.png" /></div>' +
|
'<div class="frm_item_icon duplicate"><img src="static/img/createorder.png" /></div>' +
|
'</div>');
|
|
// if($form_el_row.data('data').gcCpnType != 0){
|
$form_el_row.append($icons);
|
// }
|
|
frm_el_click($icons, $form_el_row);
|
}
|
|
}])
|
.filter("myhide", function() {
|
return function(input) {
|
if(input.value == "") {
|
return false;
|
} else {
|
return true;
|
}
|
}
|
});
|