angular.module('templates_center', [])
|
.factory('fileReader', ["$q", "$log", function($q, $log) { //图片转换base64
|
var onLoad = function(reader, deferred, scope) {
|
return function() {
|
scope.$apply(function() {
|
deferred.resolve(reader.result);
|
});
|
};
|
};
|
var onError = function(reader, deferred, scope) {
|
return function() {
|
scope.$apply(function() {
|
deferred.reject(reader.result);
|
});
|
};
|
};
|
var getReader = function(deferred, scope) {
|
var reader = new FileReader();
|
reader.onload = onLoad(reader, deferred, scope);
|
reader.onerror = onError(reader, deferred, scope);
|
return reader;
|
};
|
var readAsDataURL = function(file, scope) {
|
var deferred = $q.defer();
|
var reader = getReader(deferred, scope);
|
reader.readAsDataURL(file);
|
return deferred.promise;
|
};
|
return {
|
readAsDataUrl: readAsDataURL
|
};
|
}])
|
.controller('templatesCenterCtrl', ['$scope', '$compile', 'http_service', '$routeParams', 'fileReader', '$http', '$rootScope',function($scope, $compile, http_service, $routeParams, fileReader, $http,$rootScope) {
|
$scope.step = $routeParams.step;
|
$scope.img_show_flag = false;
|
$scope.temp_show_falg = false;
|
$scope.$on('$viewContentLoaded', function() {
|
$('div.split_form').height($(document).height() - 52);
|
$(window).resize(function() {
|
$('div.split_form').height($(document).height() - 52);
|
});
|
});
|
|
/*
|
$(document).off('click').on('click', function() {
|
if($('div.industry_menu_pane').is(':visible')){
|
$('div.industry_menu_pane').remove();
|
}
|
});
|
*/
|
http_service.post('indusExten/list', {}, function(res) {
|
$rootScope.search_hint(res.data.data,'arrary');
|
$scope.indus_templates = res.data.data;
|
_.each($scope.indus_templates, function(_temp) {
|
_temp.inBigIcon = "travel-web" + _temp.inBigIcon;
|
_temp.img_show_flag = false;
|
});
|
})
|
$scope.show_saved_form = function(business, type, action, templateid) {
|
$scope.business = business;
|
$scope.type = type;
|
$scope.action = action;
|
$scope.templateid = templateid;
|
var $form = $('<div saved-form business="business" type="type" unedit="1" action="action" templateid="templateid" ></div>');
|
$('div.form_container').html($form);
|
$compile($form)($scope);
|
}
|
$scope.show_saved_form_insert = function(business, type, action) {
|
$scope.business = business;
|
$scope.type = type;
|
$scope.action = action;
|
var $form = $('<div saved-form business="business" type="type" action="action" ></div>');
|
$('div.form_container').html($form);
|
$compile($form)($scope);
|
}
|
$scope.update = function(e) {
|
http_service.post('indusExten/list', {}, function(res) {
|
$rootScope.search_hint(res.data.data,'arrary');
|
$scope.indus_templates = res.data.data;
|
_.each($scope.indus_templates, function(_temp) {
|
_temp.inBigIcon = "travel-web" + _temp.inBigIcon;
|
_temp.img_show_flag = false;
|
});
|
})
|
}
|
|
$scope.show_industry_menu_pane = function(e) {
|
$("div.industry_menu_pane").remove();
|
var $element = $('<div class="industry_menu_pane"><ul><li ng-click="add_industry()">新增行业</li><li>修改行业</li><li>删除行业</li></ul></div>');
|
$('body').append($element);
|
$compile($element)($scope);
|
$element.css({
|
'top': e.pageY + 10,
|
'left': e.pageX + 10
|
});
|
e.stopPropagation();
|
}
|
|
$scope.add_industry = function(e) {
|
$("div.industry_menu_pane").html('<div class="col-md-4"><label class="col-md-2">行业名称</label><input type="text" class="col-md-3"></div>');
|
}
|
//点击空白 隐藏标识符
|
$scope.show_sign_all = function() {
|
_.each($scope.indus_templates, function(_temp) {
|
_temp.o1 = {};
|
_temp.num1 = 0;
|
_temp.o1_budget = {};
|
_temp.num1_budget = 0;
|
_.each(_temp.budgets, function(_budgets) {
|
_budgets.o1_detail = {};
|
_budgets.num1_detail = 0;
|
});
|
_temp.o1_apply = {};
|
_temp.num1_apply = 0;
|
_.each(_temp.applys, function(_apply) {
|
_apply.o1_detail = {};
|
_apply.num1_detail = 0;
|
});
|
_temp.o1_reimbursement = {};
|
_temp.num1_reimbursement = 0;
|
_.each(_temp.expends, function(_expend) {
|
_expend.o1_detail = {};
|
_expend.num1_detail = 0;
|
})
|
})
|
$scope.temp_show_falg = false;
|
// $(event).stopPropagation();
|
// $(event).preventDefault();
|
|
}
|
//显示、隐藏标识符
|
$scope.show_sign = function(template) {
|
$scope.temp_show_falg = true;
|
$scope.images = '';
|
if(template.num1 == 1) {
|
template.num1 = 0;
|
template.o1 = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
_temp.o1 = {};
|
_temp.num1 = 0;
|
if(_temp == template) {
|
_temp.num1 = 0;
|
_temp.num2 = 0;
|
_temp.num3 = 0;
|
_temp.o1 = { opacity: 1 };
|
}
|
});
|
template.num1 = 1;
|
}
|
|
// $scope.o2={};
|
// $scope.inCode=1;
|
}
|
//获取图片信息
|
$scope.img_change = function(files) {
|
$scope.imgIcon = files;
|
fileReader.readAsDataUrl($scope.imgIcon[0], $scope).then(function(res) {
|
$scope.images = res;
|
});
|
$scope.img_change_flag = true;
|
$scope.indus_templates[this.$index].img_show_flag = true;
|
}
|
//添加、修改、删除行业信息表单
|
$scope.indus_change = function(template, type) {
|
var pd = {};
|
if(type == 1) { //添加
|
if(!/\.(jpg|jpeg|png)$/.test($scope.imgIcon[0].name.toLowerCase())) {
|
$scope.$parent.twarning("图片格式必须为jpg,jpeg,png中的一种");
|
return false;
|
}
|
// else {
|
// var img = new Image();
|
// img.src = filepath;
|
// while(true) {
|
// if(img.fileSize > 0) {
|
// if(img.fileSize > 5 * 1024) {
|
// $scope.$parent.twarning("图片不大于5M。");
|
// return false;
|
// }
|
// break;
|
// }
|
//
|
// }
|
// }
|
$http({
|
method: 'post',
|
url: './travel-web/upload',
|
headers: {
|
'Content-Type': undefined
|
},
|
data: {
|
fileName: $scope.imgIcon[0],
|
problemType: '3'
|
},
|
transformRequest: function(data, headersGetter) {
|
var formData = new FormData();
|
angular.forEach(data, function(value, key) {
|
formData.append(key, value);
|
});
|
return formData;
|
}
|
}).then(function(res) {
|
|
if (res && res.data.opState === false) {
|
$scope.$parent.terro(res.data.errMsg + "(图片格式必须为jpg,jpeg,png中的一种)")
|
return false;
|
} else {
|
pd = {
|
"inName": $scope.template_title,
|
"inDesc": template.inDesc,
|
"inBigIcon": res.data.data,
|
"inSqu": template.inSqu,
|
};
|
http_service.post('indus/insert', pd, function(result) {
|
if(result.data.opState) {
|
$scope.$parent.tsuccess("添加成功!")
|
setTimeout(function() {
|
reload();
|
})
|
} else {
|
$scope.$parent.terro("添加失败")
|
reload()
|
}
|
});
|
}
|
|
}, function(err) {
|
//alert("添加失败");
|
$scope.$parent.terro("添加失败!")
|
|
});
|
// fileReader.readAsDataUrl($scope.imgIcon[0],$s cope).then(function(res){
|
// var path = res;
|
// })
|
|
|
|
|
} else if(type == 2) { //修改
|
if(!/\.(jpg|jpeg|png)$/.test($scope.imgIcon[0].name.toLowerCase())) {
|
$scope.$parent.twarning("图片格式必须为jpg,jpeg,png中的一种");
|
return false;
|
}
|
// else {
|
// var img = new Image();
|
// img.src = filepath;
|
// while(true) {
|
// if(img.fileSize > 0) {
|
// if(img.fileSize > 5 * 1024) {
|
// $scope.$parent.twarning("图片不大于5M。");
|
// return false;
|
// }
|
// break;
|
// }
|
//
|
// }
|
// }
|
if($scope.img_change_flag) {
|
$http({
|
method: 'post',
|
url: './travel-web/upload',
|
headers: {
|
'Content-Type': undefined
|
},
|
data: {
|
fileName: $scope.imgIcon[0],
|
problemType: '3'
|
},
|
transformRequest: function(data, headersGetter) {
|
var formData = new FormData();
|
angular.forEach(data, function(value, key) {
|
formData.append(key, value);
|
});
|
return formData;
|
}
|
}).then(function(res) {
|
if (res && res.data.opState === false) {
|
$scope.$parent.terro(res.data.errMsg + "(图片格式必须为jpg,jpeg,png中的一种)")
|
return false;
|
} else {
|
pd = {
|
"inName": $scope.template_title,
|
"inCode": template.inCode,
|
"inBigIcon": res.data.data
|
};
|
http_service.post('indus/update', pd, function(result) {
|
//alert("修改成功");
|
if(result.data.opState) {
|
$scope.$parent.tsuccess("修改成功!")
|
reload()
|
setTimeout("window.location.reload()")
|
} else {
|
$scope.$parent.terro("修改失败!")
|
}
|
});
|
}
|
}, function(err) {
|
//alert(false);
|
// swal({
|
// title: "错误",
|
// text:false,
|
// type: "error",
|
// confirmButtonText: "确定",
|
// })
|
$scope.$parent.terro(false)
|
|
});
|
} else {
|
pd = {
|
"inName": $scope.template_title,
|
"inCode": template.inCode
|
};
|
http_service.post('indus/update', pd, function(result) {
|
//alert("修改成功");
|
if(result.data.opState) {
|
$scope.$parent.tsuccess("修改成功!")
|
reload()
|
} else {
|
$scope.$parent.terro("修改失败!")
|
|
}
|
});
|
}
|
|
} else {
|
|
}
|
template.num1 = 0;
|
template.num2 = 0;
|
template.num3 = 0;
|
template.o1 = {};
|
}
|
//显示、隐藏预算单
|
$scope.show_sign_budget = function(template) {
|
$scope.temp_show_falg = true;
|
if(template.num1_budget == 1) {
|
template.num1_budget = 0;
|
template.o1_budget = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
if(_temp == template) {
|
_temp.num1_budget = 0;
|
_temp.o1_budget = { opacity: 1 };
|
}
|
});
|
template.num1_budget = 1;
|
}
|
|
}
|
//显示、隐藏申请单
|
$scope.show_sign_apply = function(template) {
|
$scope.temp_show_falg = true;
|
if(template.num1_apply == 1) {
|
template.num1_apply = 0;
|
template.o1_apply = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
if(_temp == template) {
|
_temp.num1_apply = 0;
|
_temp.o1_apply = { opacity: 1 };
|
}
|
});
|
template.num1_apply = 1;
|
}
|
|
}
|
//显示、隐藏报销单
|
$scope.show_sign_reimbursement = function(template) {
|
$scope.temp_show_falg = true;
|
if(template.num1_reimbursement == 1) {
|
template.num1_reimbursement = 0;
|
template.o1_reimbursement = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
if(_temp == template) {
|
_temp.num1_reimbursement = 0;
|
_temp.o1_reimbursement = { opacity: 1 };
|
}
|
});
|
template.num1_reimbursement = 1;
|
}
|
|
}
|
//显示、隐藏预算详细单
|
$scope.show_sign_budget_detail = function(template, budget) {
|
$scope.temp_show_falg = true;
|
if(budget.num1_detail == 1) {
|
budget.num1_detail = 0;
|
budget.o1_detail = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
if(_temp == template) {
|
_.each(_temp.budgets, function(_budget) {
|
if(budget == _budget) {
|
_budget.num1_detail = 0;
|
_budget.num2 = 0;
|
_budget.num3 = 0;
|
_budget.o1_detail = { opacity: 1 };
|
}
|
})
|
}
|
});
|
budget.num1_detail = 1;
|
}
|
|
}
|
//显示、隐藏申请详细单
|
$scope.show_sign_apply_budget_detail = function(template, apply) {
|
$scope.temp_show_falg = true;
|
if(apply.num1_detail == 1) {
|
apply.num1_detail = 0;
|
apply.o1_detail = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
if(_temp == template) {
|
_.each(_temp.applys, function(_apply) {
|
if(apply == _apply) {
|
_apply.num1_detail = 0;
|
_apply.num2 = 0;
|
_apply.num3 = 0;
|
_apply.o1_detail = { opacity: 1 };
|
}
|
})
|
}
|
});
|
apply.num1_detail = 1;
|
}
|
|
}
|
//显示、隐藏报销详细单
|
$scope.show_sign_extend_detail = function(template, extend) {
|
$scope.temp_show_falg = true;
|
if(extend.num1_detail == 1) {
|
extend.num1_detail = 0;
|
extend.o1_detail = {};
|
} else {
|
_.each($scope.indus_templates, function(_temp) {
|
if(_temp == template) {
|
_.each(_temp.expends, function(_extend) {
|
if(extend == _extend) {
|
_extend.num1_detail = 0;
|
_extend.num2 = 0;
|
_extend.num3 = 0;
|
_extend.o1_detail = { opacity: 1 };
|
}
|
})
|
}
|
});
|
extend.num1_detail = 1;
|
}
|
|
}
|
//设置删除弹窗按钮颜色
|
// function getBackgroundColor() {
|
// var rgb = $('#top').css('background-color');
|
// rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
|
// function hex(x) {
|
// return("0" + parseInt(x).toString(16)).slice(-2);
|
// }
|
// rgb = "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
|
// return rgb;
|
// };
|
// $scope.btncolor = getBackgroundColor();
|
|
function reload() {
|
$scope.update();
|
}
|
//删除表单模版
|
$scope.delete_form = function(form) {
|
// swal({
|
// title: "确定删除?",
|
// text: "您将无法恢复这些文件!",
|
// type: "warning",
|
// showCancelButton: true,
|
// confirmButtonColor: $scope.btncolor,
|
// confirmButtonText: "确定",
|
// cancelButtonText: "取消",
|
// closeOnConfirm: false
|
// },
|
var deletefo =true;
|
$rootScope.swalWhether({ "title": "确定删除?", 'text': "" },
|
function() {
|
if(deletefo){
|
deletefo =false;
|
http_service.post("template/delete", { "guId": form.guId }, function(res) {
|
if(res.data.opState) {
|
$rootScope.swalsuccess({ "text": "成功删除!" },
|
reload()
|
)
|
|
} else {
|
$rootScope.swalerror({ "text": "删除失败" })
|
}
|
});
|
}
|
});
|
}
|
//删除行业
|
$scope.delete_indus = function(template) {
|
var deleteind=true;
|
$rootScope.swalWhether({ "title": "确定删除?", 'text': "" },
|
function() {
|
if(deleteind){
|
deleteind=false;
|
http_service.post("indus/delete", { "inCode": template.inCode }, function(res) {
|
if(res.data.opState) {
|
$rootScope.swalsuccess({ "text": "成功删除!" },
|
reload()
|
)
|
} else {
|
$rootScope.swalerror({ "text": res.data.errMsg })
|
}
|
});
|
}
|
});
|
}
|
}]);
|