angular.module('travel_expense', ['ngDraggable']) .directive('dropDownSelector', ['$rootScope', 'http_service', function($rootScope, http_service) { return { restrict: 'EACM', scope: { 'filterlist': '=', 'refreshdata': '&' }, templateUrl: './static/templates/drop_down_selector.html', link: function($scope, element, attrs) { $(document).off('click').on('click', function() { if($('div.drop_down_sel').is(':visible')) { $('div.drop_down_sel').remove(); } }); $(element).on('click', function(e) { $scope.save(); e.stopPropagation(); }) // $scope.listfilter = function(list){ // var arr = []; // _.each(list,function(_list){ // if(_list.gc_cpn_type != 10){ // arr.push(_list); // } // }); // return arr; // } $scope.save = function() { var cfg_list = _.filter($scope.filterlist, function(o) { return o.selected; }); var cfg = []; _.each(cfg_list, function(cfg_item) { cfg.push(_.pick(cfg_item, ['sfCfgType', 'sfFieldName'])); }); http_service.post('showFieldCfg/update', { "child": cfg }, function(res) { if(res.status === 200) { $scope.refreshdata(); } else { //alert('查询内容更新失败。'); $scope.$parent.terro("查询内容更新失败!") } }); } } } }]) .directive('detailPopup', ['$rootScope', 'http_service', '$timeout', function($rootScope, http_service, $timeout) { return { restrict: 'EACM', scope: { type: "=", billid: "@", edit: '=', iscreate: "@" }, templateUrl: './static/templates/travel_expense_detail_popup.html?v=12292330', link: function($scope, element, attrs) { $scope.init_btn_flag = true; $rootScope.form_id = undefined;//初始化表单ID $rootScope.lock_key = undefined;//初始化钥匙 $scope.save_btn_flag = true; $rootScope.startTime = undefined; $rootScope.endTime = undefined; $rootScope.sumMoney_budget = undefined; $scope.couldNumber = undefined; $scope.exCouldNumber = undefined; $scope.bill_commit_permission = "bill_commit_detail"; $scope.rectification_show = false; $scope.restart_review_show = false; $scope.commitflag_bill = true; //提交按钮根据票据状态判断 初始值为true //若无票据上传权限 则无票据上传按钮 // if(app_userinfo.expendAllPermiss){ // $scope.bill_commit_flag = true; // }else{ // $scope.bill_commit_flag = false; // } //打开查看图片新页面并且传值 $scope.show_pic = function() { if($scope.exCouldNumber) { http_service.post("expend/get/order/pic", { 'orderCode': $scope.exCouldNumber }, function(res) { var pic_data = res.data.data; if(pic_data == undefined || pic_data.length == 0) { $rootScope.twarning("无票据图片"); return false; } // var pic_data = [{ 'picUrl':'http://localhost:8070/static/img/pic.png','picName':"aaaa"},{ 'picUrl':'http://localhost:8070/static/img/continue.png','picName':"bbbb"},{ 'picUrl':'http://localhost:8070/static/img/pic.png','picName':"aaaa"},{ 'picUrl':'http://localhost:8070/static/img/continue.png','picName':"bbbb"},{ 'picUrl':'http://localhost:8070/static/img/pic.png','picName':"aaaa"},{ 'picUrl':'http://localhost:8070/static/img/continue.png','picName':"bbbb"},{ 'picUrl':'http://localhost:8070/static/img/pic.png','picName':"aaaa"},{ 'picUrl':'http://localhost:8070/static/img/continue.png','picName':"bbbb"}]; pic_data = JSON.stringify(pic_data); $("#pic").attr('value', pic_data); window.open('./static/templates/pic.html'); }) } } $scope.restart_review = function() { if($scope.exCouldNumber) { http_service.post("expend/order/backrule", { 'orderCode': $scope.exCouldNumber }, function(res) { res.data.opState; if (res.data.opState) { $scope.$parent.tsuccess("单据已进入重新审单流程,请耐心等待!"); $scope.restart_review_show = false; $rootScope.reflect_bill(); } else { $scope.$parent.terro("订单来源必须是差旅费或费用云!"); $rootScope.reflect_bill(); } }) } } $scope.rectification = function(){ if($scope.exCouldNumber != undefined){ $rootScope.swalWhether({ "title": "确认重新纠偏?", 'text': "重新纠偏将删除行程,可能造成数据损失,请谨慎操作!" }, function(res) { if(res == true){ http_service.post("expend/backCorrect",{'orderCode':$scope.exCouldNumber},function(res){ if(res.data.opState == true){ $scope.edit = false; $scope.editflag = false; $rootScope.change_orderstatus("自动审单中"); swal.close(); } }); } }); } } var re_account_flag = true; $scope.re_account = function() { if(re_account_flag) { re_account_flag = false; http_service.post("flow/expend/add/order", { "tId": $scope.re_account_exid }, function(res) { if(res.data.opState) { $scope.$parent.tsuccess("重新记账成功"); $scope.re_account_show = false; if($rootScope.reflect_bill) { //刷新详情页面 $rootScope.reflect_bill(); } } else { $scope.$parent.terro("重新记账失败"); re_account_flag = true; if($rootScope.reflect_bill) { //刷新详情页面 $rootScope.reflect_bill(); } } }); } } if($scope.iscreate) { $scope.btnflag = true; } else { $scope.btnflag = false; } var update_url = ''; if($scope.type === 10) { update_url = 'budget/update'; } else if($scope.type === 20) { update_url = 'apply/update'; } else if($scope.type === 30) { update_url = 'expend/update'; } function get_bill_data(form, data,cd_num,cd_type) { var flag = !!data; var bill_data = data || { 'child': [], 'fchild':[] }; if(!flag) { var children = form.child; if(children && children.length) { var num = 0; var pay_num = 0; _.each(children, function(cd) { var col_name = cd['gcColName']; var _children = cd['child']; if(col_name) { var item_cus = $('*[gcColName="' + col_name + '"]'); if(item_cus.is(':radio')) { bill_data[col_name] = $('*[gcColName="' + col_name + '"]:checked').val(); } else if(item_cus.attr("class") == "getDateTime ng-scope flatpickr-input") { bill_data[col_name] = cd['render_value']; } else if(item_cus.attr("class") == "select-container") { bill_data[col_name] = $('*[gcColName="' + col_name + '"]:last').attr('value'); } else if(item_cus.attr("choose_budget")) { //判断是否为预算选择控件 bill_data[col_name] = $rootScope.budget_selected; bill_data['buNumber'] = $rootScope.budget_selected; } else if(item_cus.attr("choose_apply")) { //判断是否为申请选择控件 bill_data[col_name] = $rootScope.expend_number_info; bill_data['apNumber'] = $rootScope.expend_number_info; } else if(item_cus.attr("user_selected")) { //判断是否为人员选择控件 $rootScope.userId = $('*[gcColName="' + col_name + '"]').attr("user_selected"); bill_data[col_name] = $('*[gcColName="' + col_name + '"]').attr("user_selected"); } else if(item_cus.attr("org_selected")) { //判断是否为组织机构选择控件 bill_data[col_name] = $('*[gcColName="' + col_name + '"]').attr("org_selected"); } else if(item_cus.attr("selected_city")) { bill_data[col_name] = $('*[gcColName="' + col_name + '"]').attr("selected_city"); } else { bill_data[col_name] = $('*[gcColName="' + col_name + '"]').val(); } } if(_children && _children.length) { if(cd.gcCpnType == 10){ get_bill_data(cd, bill_data,num,1); num++; }else if(cd.gcCpnType == 17){ get_bill_data(cd, bill_data,pay_num,2); pay_num++; } } }); } } else { var children = form.child; var num; if(data.child == undefined) { num = 0; } else { num = data.child.length; } if(children && children.length) { var sub_form = { 'child': [] }; if(form.billInfos != undefined){// 存储票据信息 sub_form['billInfos'] = form.billInfos_str; } _.each(children, function(cd) { var col_name = cd['gcColName']; var _children = cd['child']; var type = cd['gcCpnType']; if(type === 12) { sub_form[col_name] = $('*[gcColName="' + col_name + '"]:eq(' + cd_num + ')').attr("user_selected"); // var budget_list = form['budget_list']; // var user_id, _budget_list = []; // _.each(budget_list, function(budget) { // sub_form['child'].push({ // "an_user_id": budget.userId, // "child": _.map(budget.child, function(cld) { // return { // "jp_cd_code": cld['jp_cd_code'], // "jp_amount": cld['jp_amount'] // } // }) // }); // }); } else { if(col_name) { if(cd.gcCpnType == 6) { sub_form[col_name] = $('*[gcColName="' + col_name + '"]:eq(' + cd_num + ')').attr('value'); } else { sub_form[col_name] = $('*[gcColname="' + col_name + '"]:eq(' + cd_num + ')').val(); } } } }); if(form.ej_id) { sub_form["ej_id"] = form.ej_id; } // if(form.budget_list&&form.budget_list.length!=0){ // var budget_list = form.budget_list[0].child; // sub_form['child'].push({ // "an_user_id":$rootScope.userId, // "child": _.map(budget_list, function(cld) { // return { // "jp_cd_code": cld['jp_cd_code'], // "jp_amount": cld['jp_amount'] // } // }) // }); // } } if(cd_type == 1){ bill_data['child'].push(sub_form); }else if(cd_type == 2){ bill_data['fchild'].push(sub_form); } } var new_jour_arr = $rootScope.new_jour; if (bill_data.child && new_jour_arr) { if (bill_data.child.length == new_jour_arr.length) { for (var i=0; i < bill_data.child.length; i++) { bill_data.child[i].billInfos = new_jour_arr[i].jour.billInfos_str; } } } return bill_data; } $scope.cancel = function() { $(element).remove(); $scope.close_lock(); }; $scope.close_lock = function(){ $rootScope.close_lock = true; $rootScope.formula_num = 0; $rootScope.formula_num_id = [];//页面关闭 则将前端公式计数清零 if($rootScope.update_speical != undefined){//系统变量公式监听初始化 $rootScope.update_speical(); } $rootScope.update_speical = undefined; if($rootScope.update_speical_formula != undefined){//前端公式监听初始化 $rootScope.update_speical_formula(); } $rootScope.update_speical_formula = undefined; var key_data = { "id":$rootScope.form_id, "type":$scope.type, "key":$rootScope.lock_key != undefined?$rootScope.lock_key:"" } http_service.post("form/closeForm",key_data,function(res){}) } //校验数字 function numbercheck(form, child_item) { var val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').val(); if(val != "") { if(textcheck(form, val, child_item)) { //文本长度校验 var reg0 = new RegExp("^([-]){0,1}([0-9]){1,}([.]){0,1}([0-9]){0,}$"); //校验是否为数字 var reg1 = new RegExp("^-?\\d+$"); //校验是否为整数 var reg2 = new RegExp("^-?\\d+(.[0-9]{0," + form.gcDmlLeng + "})?$"); //校验是否为n位小数 if(!reg0.test(val)) { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("请输入数字"); return false; } else { if(form.gcCpnFormat == 20) { //当条件为整数时 if(!reg1.test(val)) { //不为整数 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("必须为整数"); return false; } else if(val.length > form.gcElLeng) { //长度超过限制 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("长度不能超过" + form.gcElLeng + ""); return false; } else { return true; } } else { //当条件为允许小数时 if(form.gcDmlLeng == undefined || _.trim(form.gcDmlLeng) == ''){ return true; }else if(!reg2.test(val)) { //超过n位小数 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("小数位数不能超过" + form.gcDmlLeng + "位"); return false; } else if(val.length > form.gcElLeng) { //长度超过限制 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("长度不能超过" + form.gcElLeng + ""); return false; } else { return true; } } } } } else { return true; } } //判断并显示校验信息 function showcheck(form, sValue, nValue, child_item) { if(nValue != undefined) { if(form.gcInputMust == 1) { //判断是否必填 必填 var val; if(form.gcCpnType == 6) { val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').attr("value"); } else if(form.gcCpnType == 12) { val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').attr("user_selected"); } else if(form.gcCpnType == 0) { val = $rootScope.budget_selected } else if(form.gcCpnType == 14) { val = $rootScope.expend_number_info; } else { val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == "" || _.isNull(val)) { if(form.gcCpnType == 5) { $("" + form.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcCpnAlias + "不能为空"); } return false; } else { switch(form.gcCheckOp) { case "<": if(sValue < nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "<=": if(sValue <= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">": if(sValue > nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">=": if(sValue >= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "==": if(sValue == nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:last').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcErrorMsg + ""); } return false; } break; case "<>": if(sValue != nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; } } } else { //判断是否必填 可为空 switch(form.gcCheckOp) { case "<": if(sValue < nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "<=": if(sValue <= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]::eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">": if(sValue > nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">=": if(sValue >= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "==": if(sValue == nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "<>": if(sValue != nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; } } } } //文本长度校验 function textcheck(form, value, child_item) { if(value.length <= form.gcElLeng) { return true; } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("长度不能超过" + form.gcElLeng + ""); return false; } } //获取占用预算控件内的日期 function get_date() { // $scope.str = "【预算部门】销售部、媒体部【预算日期】2017-01-01~2017-03-31【预算金额】RMB:30,000元【可用余额】RMB:25,000元"; // $scope.str =$('.apply_control_input:last').val(); var arr = []; if(check_budget()) { $scope.datestart = $rootScope.startTime; $scope.dateend = $rootScope.endTime; if($scope.datestart == undefined || $scope.dateend == undefined) { return false; } else { arr = [$scope.datestart, $scope.dateend]; } } return arr; } //判断是否为部门预算并判断是否为预算单 function check_budget() { if($scope.type != 10) { if($scope.type == 20) { return true; } else { return false; } } else { return true; } } //转化日期格式 function replace_date(date) { var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? '0' + m : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; return y + '-' + m + '-' + d; } function addDate(dd, dadd) { var a = $rootScope.getNewDate(dd) a = a.valueOf() a = a + dadd * 24 * 60 * 60 * 1000 a = $rootScope.getNewDate(a) return a; } //验证申请单 出发日期+出差天数 是否在预算起始于截至日期范围内 function applyDateCheck(form) { var budget_date = get_date(); if(budget_date) { if(budget_date.length == 0) { return false; } var start = $rootScope.getNewDate(budget_date[0].replace(/-/g, "/")); var end = $rootScope.getNewDate(budget_date[1].replace(/-/g, "/")); var mdCode_arr = []; _.each(filed, function(_filed) { switch(_filed.busCode) { case "FromDate": mdCode_arr.push(_filed.mdCode); break; case "travelDays": mdCode_arr.push(_filed.mdCode); break; } }); var item_form = []; _.each(mdCode_arr, function(_mdCode_arr) { if(form && form.child !== undefined) { _.each(form.child, function(_form) { if(_form.gcMeCode == _mdCode_arr) { item_form.push(_form); } }) } }); if(item_form && item_form.length > 0) { if(item_form[0].render_value) { var fromDate = $rootScope.getNewDate(item_form[0].render_value.replace(/-/g, "/")); if(fromDate < start || fromDate > end) { $("" + item_form[0].gcCpnAlias + "不在选择的预算时间范围内").appendTo($('*[gccolname="' + item_form[0].gcColName + '"]:last').closest(".timeinfo")); } if(item_form[1].render_value) { var travelDays = addDate(item_form[0].render_value, item_form[1].render_value); if(travelDays < start || travelDays > end) { $('*[gccolname="' + item_form[1].gcColName + '"]:last').after("" + item_form[0].gcCpnAlias + ' 和 ' + item_form[1].gcCpnAlias + "不在上级预算可用余额范围内"); } } } } } } //根据占用预算控件内的日期校验时间 function datecheck(sDate, form) { var datearr = get_date(); var checkflag = false; _.each(filed, function(_filed) { switch(_filed.busCode) { case "beginCalendar": if(_filed.mdCode == form.gcMeCode) { checkflag = true; } break; case "endCalendar": if(_filed.mdCode == form.gcMeCode) { checkflag = true; } break; } }) if(datearr != false && checkflag) { datearr[0] = datearr[0].slice(0, 10); datearr[1] = datearr[1].slice(0, 10); var start = $rootScope.getNewDate(datearr[0].replace(/-/g, "/")); var end = $rootScope.getNewDate(datearr[1].replace(/-/g, "/")); if(start <= sDate && sDate <= end) { return true; } else { $("" + form.gcCpnAlias + "不在选择的预算时间范围内").appendTo($('*[gccolname="' + form.gcColName + '"]:last').closest(".timeinfo")); return false; } } else { return true; } } //申请时间校验 function check_applyDate() { var datearr = get_date(); var checkflag = false; var apply_date_code, sDate, err_str; _.each(filed, function(_filed) { switch(_filed.busCode) { case "applyDate": apply_date_code = _filed.mdCode; break; } }); _.each($scope.form_data.child, function(form) { if(form.gcMeCode == apply_date_code && form.gcMeCode != undefined) { sDate = $rootScope.getNewDate($('*[gccolname="' + form.gcColName + '"]').val().replace(/-/g, "/")); checkflag = true; err_str = form.gcCpnAlias + "不在选择的预算时间范围内"; } }); if(datearr != false && checkflag && sDate) { var start = $rootScope.getNewDate(datearr[0].replace(/-/g, "/")); var end = $rootScope.getNewDate(datearr[1].replace(/-/g, "/")); if(start <= sDate && sDate <= end) { return true; } else { $rootScope.terro(err_str); return false; } } else { return true; } } //验证预算金额、申请金额 是否在上级预算范围内 function check_sumMoney() { if(check_budget() == false) { return false; } var mdCode_arr = []; _.each(filed, function(_filed) { switch(_filed.busCode) { case "budgetMoney": mdCode_arr.push(_filed.mdCode); break; case "applyMoney": mdCode_arr.push(_filed.mdCode); break; } }); _.each($scope.form_data.child, function(form) { _.each(mdCode_arr, function(code) { if(form.gcMeCode == code) { if(form.render_value != undefined && form.render_value !== "") { if(form.render_value > $rootScope.sumMoney_budget && $rootScope.sumMoney_budget != undefined) { $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcCpnAlias + "不在上级预算可用余额范围内"); } } } }) }) } //日期加天数 function addDate(dd, dadd) { var a = $rootScope.getNewDate(dd); a = a.valueOf(); a = a + dadd * 24 * 60 * 60 * 1000; a = $rootScope.getNewDate(a); return a; } //跨行程验证 开始时间 function check_data_cross(type) { if($scope.type == 10) { return false; } if($scope.form_data == undefined){ return false; } var jour_data = []; _.each($scope.form_data.child, function(form) { if(form.gcCpnType == 10) { jour_data.push(form); } }); var form_date = []; var businessDays = []; var leaveDate = []; var form_date_code, businessDays_code, leaveDate_code; _.each(filed, function(_filed) { switch(_filed.busCode) { case "FromDate": form_date_code = _filed.mdCode; break; case "travelDays": businessDays_code = _filed.mdCode; break; case "journeyEndDate": leaveDate_code = _filed.mdCode; break; } }) if(jour_data.length > 1) { //当有一个以上行程才验证 _.each(jour_data, function(_jour, i) { _.each(_jour.child, function(cd) { switch(cd.gcMeCode) { case form_date_code: if(type) { form_date.push({ "value": cd.render_value, "item": cd }); } else { form_date.push({ "value": $('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').val(), "item": cd }); } break; case businessDays_code: if(type) { businessDays.push(cd.render_value); } else { businessDays.push($('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').val()); } break; case leaveDate_code: if(type) { leaveDate.push(cd.render_value); } else { leaveDate.push($('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').val()); } break; } }); }); _.each(form_date, function(fdate, k) { if($scope.type == 20) { if(k > 0 && fdate.value != "" && fdate.value && form_date[k - 1].value != "" && form_date[k - 1].value && businessDays[k - 1] != "" && businessDays) { var sDate = $rootScope.getNewDate(fdate.value); var nDate = addDate(form_date[k - 1].value, businessDays[k - 1]); if(sDate < nDate) { if(type) { $timeout(function() { $('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').attr('color', 'red'); $("" + fdate.item.gcCpnAlias + "与上一行程未衔接").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); }, 1) } else { $("" + fdate.item.gcCpnAlias + "与上一行程未衔接").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } else if((sDate - nDate) != 0) { if(type) { $timeout(function() { $('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').attr('color', 'red'); $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); }, 1) } else { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } } } else if($scope.type == 30) { if(k > 0 && fdate.value != "" && fdate.value && leaveDate[k - 1] != "" && leaveDate[k - 1]) { var sDate = $rootScope.getNewDate(fdate.value); var nDate = $rootScope.getNewDate(leaveDate[k - 1]); if(sDate < nDate) { if(type) { $("" + fdate.item.gcCpnAlias + "不可小于上一行程离开日期").appendTo($('span[value="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } else { $("" + fdate.item.gcCpnAlias + "不可小于上一行程离开日期").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } else if((sDate - nDate) != 0) { if(type) { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('span[value="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } else { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } } } }) } } $rootScope.check_data_cross = function() { check_data_cross(true); } //跨行程 验证 出发地 function check_land_cross() { if($scope.type == 10) { return false; } if($scope.form_data == undefined){ return false; } var jour_data = []; _.each($scope.form_data.child, function(form) { if(form.gcCpnType == 10) { jour_data.push(form); } }); var from_land = []; var to_land = []; var from_land_code, to_land_code; _.each(filed, function(_filed) { switch(_filed.busCode) { case "journey_from": from_land_code = _filed.mdCode; break; case "journey_to": to_land_code = _filed.mdCode; break; } }); if(jour_data.length > 1) { //当有一个以上行程才验证 _.each(jour_data, function(_jour, i) { _.each(_jour.child, function(cd) { switch(cd.gcMeCode) { case from_land_code: from_land.push({ "value": $('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').attr('value'), "item": cd }); break; case to_land_code: to_land.push($('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').attr('value')); break; } }); }); _.each(from_land, function(fland, k) { if(k > 0 && fland.value != "" && fland.value && to_land[k - 1] != "" && to_land[k - 1]) { var sLand = fland.value; var nLand = to_land[k - 1]; if(sLand != nLand) { // $('*[gccolname="' + fland.item.gcColName + '"]:eq(' + k + ')').after("" + fland.item.gcCpnAlias + "与上一行程的到达地不同"); $('*[gccolname="' + fland.item.gcColName + '"]:eq(' + k + ')').closest('.select').append("" + fland.item.gcCpnAlias + "与上一行程的到达地不同"); } } }) } } //数据校验 $rootScope.checkdata = function() { $scope.checkdata(); } $scope.checkdata = function() { var child_item = -1; //子表单索引 var child_item_pay = -1;//支付方式子表单索引 var form = $scope.form_data; $(".errinfo").remove(); $(".errinfo_point").remove(); check_sumMoney(); check_data_cross(false); check_land_cross() if($scope.type == 20) { applyDateCheck(form); } _.each(form.child, function(_form) { if(_form.gcCpnType !== 10 && _form.gcCpnType !== 17) { //判断是否为子表单 否 if(_form.gcShowFlag != 0){//被隐藏的控件 不验证 if(_form.gcCheckOp !== "" && _form.gcCheckOp != undefined) { //判断是否有校验规则 有 if(_form.gcCheckCpnCode == "-1") { //判断是否根据固定值进行校验 是 if(_form.gcCpnType == 5) { //判断是否为日期、时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); if(datecheck(sDtate, _form)) { var nDate = $rootScope.getNewDate(_form.gcCheckValue.replace(/-/g, "/")); showcheck(_form, sDtate, nDate, 0); } } else { if(_form.gcCpnType == 7) { //判断是否为数字 是 var numberflag = numbercheck(_form, 0); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + _form.gcColName + '"]').val()); var nValue = parseFloat(_form.gcCheckValue); showcheck(_form, sValue, nValue, 0); } } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); if(textcheck(_form, sValue, 0)) { var nValue = _form.gcCheckValue; showcheck(_form, sValue, nValue, 0); } } else { var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); var nValue = _form.gcCheckValue; showcheck(_form, sValue, nValue, 0); } } } else { //判断是否根据固定值进行校验 否 if(_form.gcCpnType == 5) { //判断是否为日期时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); var nDate; if(datecheck(sDtate, _form)) { _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nDate = $rootScope.getNewDate($('*[gccolname="' + _formchild.gcColName + '"]').val().replace(/-/g, "/")); } }); showcheck(_form, sDtate, nDate, 0); } } else { //判断是否为日期时间 否 if(_form.gcCpnType == 7) { //判断是否为数字 var numberflag = numbercheck(_form, 0); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + _form.gcColName + '"]').val()); var nValue; _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nValue = parseFloat($('*[gccolname="' + _formchild.gcColName + '"]').val()); } }); showcheck(_form, sValue, nValue, 0); } } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); var nValue; if(textcheck(_form, sValue, 0)) { _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]').val(); } }); showcheck(_form, sValue, nValue, 0); } } else { var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); var nValue; _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]').val(); } }); showcheck(_form, sValue, nValue, 0); } } } } else { //判断是否有校验规则 没有 if(_form.gcInputMust == 1) { //判断是否必填 必填 var val; if(_form.gcCpnType == 6) { val = $('*[gccolname="' + _form.gcColName + '"]:last').attr("value"); } else if(_form.gcCpnType == 12) { val = $('*[gccolname="' + _form.gcColName + '"]:last').attr("user_selected"); } else if(_form.gcCpnType == 0) { val = $rootScope.budget_selected; } else if(_form.gcCpnType == 14) { val = $rootScope.expend_number_info; } else { val = $('*[gccolname="' + _form.gcColName + '"]:last').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == "" || _.isNull(val)) { if(_form.gcCpnType == 5) { $("" + _form.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + _form.gcColName + '"]:last').closest(".timeinfo")); } else { $('*[gccolname="' + _form.gcColName + '"]:last').after("" + _form.gcCpnAlias + "不能为空"); } } else { if(_form.gcCpnType == 7) { //判断是否为数字 是 numbercheck(_form, 0); } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); textcheck(_form, sValue, 0); } else if(_form.gcCpnType == 5) { //判断是否为时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); datecheck(sDtate, _form); } } } else { //判断是否必填 可为空 if(_form.gcCpnType == 7) { //判断是否为数字 是 numbercheck(_form, 0); } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val().trim(val);; textcheck(_form, sValue, 0); } else if(_form.gcCpnType == 5) { //判断是否为时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); datecheck(sDtate, _form); } } } } } else if(_form.gcCpnType == 10) { //判断是否为子表单 是 child_item++; _.each(_form.child, function(cd) { if(cd.gcShowFlag != 0){//被隐藏的控件 不验证 if(cd.gcCheckOp !== "" && cd.gcCheckOp != undefined) { //判断是否有校验规则 有 if(cd.gcCheckCpnCode == "-1") { //判断是否根据固定值进行校验 是 if(cd.gcCpnType == 5) { //判断是否为日期、时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val().replace(/-/g, "/")); var nDate = $rootScope.getNewDate(cd.gcCheckValue.replace(/-/g, "/")); showcheck(cd, sDtate, nDate, child_item); } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 var numberflag = numbercheck(cd, child_item); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val()); var nValue = parseFloat(cd.gcCheckValue); showcheck(cd, sValue, nValue, child_item); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); if(textcheck(cd, sValue, child_item)) { var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue, child_item); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue, child_item); } } } else { //判断是否根据固定值进行校验 否 if(cd.gcCpnType == 5) { //判断是否为日期时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val().replace(/-/g, "/")); var nDate; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nDate = $rootScope.getNewDate($('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val().replace(/-/g, "/")) } }); showcheck(cd, sDtate, nDate, child_item); } else { //判断是否为日期时间 否 if(cd.gcCpnType == 7) { //判断是否为数字 var numberflag = numbercheck(cd, child_item); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val()); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = parseFloat($('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val()); } }); showcheck(cd, sValue, nValue, child_item); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); var nValue; if(textcheck(cd, sValue, child_item)) { _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val(); } }); showcheck(cd, sValue, nValue, child_item); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val(); } }); showcheck(cd, sValue, nValue, child_item); } } } } else { //判断是否有校验规则 没有 if(cd.gcInputMust == 1) { //判断是否必填 必填 var val; if(cd.gcCpnType == 6) { val = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').attr("value"); }else if(cd.gcCpnType == 12) { val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item+')').attr("user_selected"); } else { val = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == "" || _.isNull(val)) { if(cd.gcCpnType == 5) { $("" + cd.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + cd.gcColName + '"]:eq(' + ((child_item + 1) * 2 - 1) + ')').closest(".timeinfo")); } else { $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').after("" + cd.gcCpnAlias + "不能为空"); } } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd, child_item); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); textcheck(cd, sValue, child_item); } } } else { //判断是否必填 可为空 if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd, child_item); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); textcheck(cd, sValue, child_item); } } } } }) }else if(_form.gcCpnType == 17){//判断是否为支付方式子表单 是 child_item_pay++; _.each(_form.child, function(cd) { if(cd.gcShowFlag != 0){//被隐藏的控件 不验证 if(cd.gcCheckOp !== "" && cd.gcCheckOp != undefined) { //判断是否有校验规则 有 if(cd.gcCheckCpnCode == "-1") { //判断是否根据固定值进行校验 是 if(cd.gcCpnType == 5) { //判断是否为日期、时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val().replace(/-/g, "/")); var nDate = $rootScope.getNewDate(cd.gcCheckValue.replace(/-/g, "/")); showcheck(cd, sDtate, nDate,child_item_pay); } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 var numberflag = numbercheck(cd,child_item_pay); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val()); var nValue = parseFloat(cd.gcCheckValue); showcheck(cd, sValue, nValue,child_item_pay); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); if(textcheck(cd, sValue,child_item_pay)) { var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue,child_item_pay); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue,child_item_pay); } } } else { //判断是否根据固定值进行校验 否 if(cd.gcCpnType == 5) { //判断是否为日期时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val().replace(/-/g, "/")); var nDate; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nDate = $rootScope.getNewDate($('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val().replace(/-/g, "/")) } }); showcheck(cd, sDtate, nDate,child_item_pay); } else { //判断是否为日期时间 否 if(cd.gcCpnType == 7) { //判断是否为数字 var numberflag = numbercheck(cd,child_item_pay); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val()); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = parseFloat($('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val()); } }); showcheck(cd, sValue, nValue,child_item_pay); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); var nValue; if(textcheck(cd, sValue,child_item_pay)) { _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val(); } }); showcheck(cd, sValue, nValue,child_item_pay); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val(); } }); showcheck(cd, sValue, nValue,child_item_pay); } } } } else { //判断是否有校验规则 没有 if(cd.gcInputMust == 1) { //判断是否必填 必填 var val; if(cd.gcCpnType == 6){ val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').attr("value"); }else if(cd.gcCpnType == 12) { val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').attr("user_selected"); } else{ val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == ""|| _.isNull(val)) { if(cd.gcCpnType == 5) { $("" + cd.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + cd.gcColName + '"]:eq('+((child_item_pay+1)*2-1)+')').closest(".timeinfo")); } else { $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').after("" + cd.gcCpnAlias + "不能为空"); } } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd,child_item_pay); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); textcheck(cd, sValue,child_item_pay); } } } else { //判断是否必填 可为空 if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd,child_item_pay); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); textcheck(cd, sValue,child_item_pay); } } } } }) } }) } //保存发送请求 function save_post(form_data, bill_type, auto_flag, auto_data,version) { var auto_post_flag = true; if(auto_flag) { var data = auto_data; } else { var data = get_bill_data(form_data); } var allcost = 0; if($scope.form_data == undefined){ is_click = true; return false; } _.each($scope.form_data.child, function(cost) { if(cost.gcCpnType == 10) { if(cost.budget_list != undefined) { if(cost.budget_list.length != 0) { _.each(cost.budget_list, function(spell) { allcost += parseFloat(spell.jp_amount); }); } } } }); data = _.extend(data, { "total": allcost }); if($scope.type == 10) { data['bu_temp_id'] = form_data.guId; data['bu_id'] = form_data.ap_id; } else if($scope.type == 20) { data['ap_temp_id'] = form_data.guId; data['ap_id'] = form_data.ap_id; } else if($scope.type == 30) { data['ex_temp_id'] = form_data.guId; if(auto_flag){// 自动 更新 对比 报销单ID if(auto_data.ex_id != undefined && form_data.ap_id != undefined && auto_data.ex_id != form_data.ap_id){ auto_post_flag = false; } }else{// 非自动 更新不对比 data['ex_id'] = form_data.ap_id; } } // 报销单——订单编号字段 if($scope.couldNumber) { data['couldNumber'] = $scope.couldNumber; } // 报销单——公司代码字段 if(getCookie("csc_comp_code")) { data['ex_company'] = getCookie("csc_comp_code"); } var post_url; if(auto_flag) { //自动更新时 接口不同 post_url = 'expend/update/special'; } else { post_url = update_url; } if($rootScope.get_all_err_data){ var form_err = $rootScope.get_all_err_data();// 保存错误 信息 if(form_err != undefined){ _.extend(data,{'errInfo':JSON.stringify(form_err)}); } } if(!auto_flag || (auto_flag && auto_post_flag)){ if(version != undefined){//添加版本号 _.extend(data,{"version":version}); } if($rootScope.lock_key != undefined){//添加钥匙 _.extend(data,{"key":$rootScope.lock_key}); } http_service.post(post_url, data, function(res) { if(!auto_flag) { is_click = true; $scope.couldNumber = undefined; if(res.status === 200) { //alert('成功更新'+bill_type+'。'); // $scope.$parent.refreshdata(); if(res.data.opState) { $scope.$parent.tsuccess("成功更新" + bill_type + "") $scope.$parent.refreshdata(); $(element).remove(); } else { // $scope.$parent.terro("更新失败") if(res.data.errMsg != undefined){ $rootScope.twarning(res.data.errMsg); }else{ $scope.$parent.terro("更新失败") } } } else { //alert('更新'+bill_type+'失败。'); $scope.$parent.terro("更新" + bill_type + "失败"); // $rootScope.twarning(res.data.errMsg); } $(element).remove(); } }); }else{ is_click = true; } } //详情页自动计算并计算完公式后自动更新 $rootScope.save_post = function(auto_data) { save_post($scope.form_data, "报销单", true, auto_data) } //修改确定 var is_click = true; $scope.create_bill = function() { var form_data = $scope.form_data; var bill_type = ""; if($scope.type == 10) { bill_type = "预算单"; } else if($scope.type == 20) { bill_type = "申请单"; } else if($scope.type == 30) { bill_type = "报销单"; } $timeout(function() { if(is_click == false) { return false; } is_click = false; if($scope.type != 10) {// 申请单、报销单 详情保存时 计算费用 $rootScope.query_journel_budget($scope.type, function(version) { $timeout(function(){ create_bill_save(form_data,bill_type,version); }); }, false); } else { create_bill_save(form_data,bill_type); } // $scope.checkdata(); // if($(".errinfo").length == 0 && check_applyDate()) { // if($scope.type == 10 && $rootScope.budget_selected != "") { // http_service.post("budget/search/balance", { "buNumber": $rootScope.budget_selected }, function(result) { // var budgetMoney_code; // var save_flag = true; // _.each(filed, function(_filed) { // if(_filed.busCode == "budgetMoney") { // budgetMoney_code = _filed.mdCode; // } // }) // _.each($scope.form_data, function(form) { // if(form.gcMeCode == budgetMoney_code) { // if(form.render_value > result.data.data) { // save_flag = false; // is_click = true; // $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcCpnAlias + "不在上级预算可用余额范围内"); // } // } // }) // if(save_flag) { // save_post(form_data, bill_type, false); // } // }); // } else { // // 判断如果有错误提示 弹出确认框 // if($(".errinfo_point").length > 0) { // $rootScope.swalWhether({ "title": "确认保存?", 'text': "

提示:" + bill_type + "数据不符合标准

点击取消可查看

" }, function(res) { // if(!res) { // is_click = true; // return false; // } else { // swal.close(); // save_post(form_data, bill_type, false); // } // }); // } else { // save_post(form_data, bill_type, false); // } // } // // } else { // is_click = true; // } }, 10); }; //详情保存 function create_bill_save(form_data,bill_type,version){ $scope.checkdata(); if($(".errinfo").length == 0 && check_applyDate()) { if($scope.type == 10 && $rootScope.budget_selected != "") { http_service.post("budget/search/balance", { "buNumber": $rootScope.budget_selected }, function(result) { var budgetMoney_code; var save_flag = true; _.each(filed, function(_filed) { if(_filed.busCode == "budgetMoney") { budgetMoney_code = _filed.mdCode; } }) _.each($scope.form_data, function(form) { if(form.gcMeCode == budgetMoney_code) { if(form.render_value > result.data.data) { save_flag = false; is_click = true; $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcCpnAlias + "不在上级预算可用余额范围内"); } } }) if(save_flag) { save_post(form_data, bill_type, false,"",version); } }); } else { // 判断如果有错误提示 弹出确认框 if($(".errinfo_point").length > 0) { $rootScope.swalWhether({ "title": "确认保存?", 'text': "

提示:" + bill_type + "数据不符合标准

点击取消可查看

" }, function(res) { if(!res) { is_click = true; return false; } else { swal.close(); save_post(form_data, bill_type, false,"",version); } }); } else { save_post(form_data, bill_type, false,"",version); } } } else { $rootScope.terro("存在未通过校验规则的控件,请检查",true); is_click = true; } } //显示iframe页面 function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if(c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ""; } var tokens = getCookie('token'); var compid = getCookie("csc_compid"); var tenantId = getCookie("tenantId"); $scope.iframe_src = iframe_url + "views/order_create_visit.html?token="+tokens+"&compid="+compid+"&tenantId="+tenantId; // $scope.iframe_src = "./static/templates/iframe_test.html"; $scope.show_iframe = function() { $scope.iframe_show = true; var thisHeight = $(".bill_create_pop").height(); $('#iframeId').height(thisHeight); // var iframeHeight=document.getElementById("iframeId").contentWindow.document.body.offsetHeight; } $scope.close_iframe = function() { $scope.iframe_show = false; } window.addEventListener("message", function(event) { if(event.data != undefined && event.data.indexOf('=') != -1) { var arr = event.data.split('='); // 报销单 上传票据后 接收订单号 $scope.couldNumber = arr[1]; // if (arr[1]) { // $scope.tsuccess("票据上传成功!"); // } else { // $scope.terro("票据上传失败!"); // } $scope.exCouldNumber = $scope.couldNumber; if($(".tool_icon").length != 0) { //接收到订单号后 更新报销单 http_service.post("expend/update/cloudNumber", { "ex_id": $rootScope.billid, "couldNumber": $scope.couldNumber }, function(res) { if(res.status === 200) { if(res.data.opState) { // $scope.$parent.tsuccess("成功更新" + bill_type + ""); if($rootScope.reflect_bill) { $rootScope.reflect_bill(); } $scope.$parent.refreshdata(); if($rootScope.refres_table_data){//审核成功后刷新列表 修改后 $rootScope.refres_table_data(); } if($rootScope.refer_data_all) { //审核成功后刷新列表 $rootScope.refer_data_all(); } if($rootScope.refer_data_budget) { //审核成功后刷新列表 $rootScope.refer_data_budget(); } if($rootScope.refer_data_apply) { //审核成功后刷新列表 $rootScope.refer_data_apply(); } if($rootScope.refer_data_expend) { //审核成功后刷新列表 $rootScope.refer_data_expend(); } } else { $scope.$parent.terro("更新失败") } } }) } } $timeout(function() { $scope.iframe_show = false; }, 1) }, false); //关闭iframe页面并获取iframe页面的值 window.getdata_iframe = function(couldNumber) { $timeout(function() { $scope.iframe_show = false; }, 1) } //判断是否可以编辑和删除 switch($scope.type) { case 10: $scope.editurl = 'flow/budget/can/edit'; break; case 20: $scope.editurl = 'flow/apply/can/edit'; break; case 30: $scope.editurl = 'flow/expend/can/edit'; break; } //获取流程状态详情 http_service.post($scope.editurl, { "tId": $rootScope.billid }, function(response) { //获取预算,申请,报销记录 switch($scope.type) { case 10: $scope.url = 'flow/budget/log'; $scope.typeword = '预算流程'; break; case 20: $scope.url = 'flow/apply/log'; $scope.typeword = '申请流程'; break; case 30: $scope.url = 'flow/expend/log'; $scope.typeword = '报销流程'; break; } http_service.post($scope.url, { "tId": $rootScope.billid }, function(res) { $scope.res = res.data.data; $scope.response = response.data.data; $scope.editflag = $scope.response.edit; $scope.deleteflag = $scope.response.edit; $scope.commitflag = $scope.response.submit; $scope.check = $scope.response.submit && $scope.response.edit ? "提交" : "审核"; $scope.backflag = $scope.response.back; $scope.data = $scope.response.data; $scope.expendAllPermiss = app_userinfo.expendAllPermiss; if($scope.res && $scope.res.length > 0) { var flow_data = $scope.res[$scope.res.length - 1]; if(flow_data.flStepCode == undefined) { flow_data = $scope.res[$scope.res.length - 2]; } if(flow_data.flStepCode == 20) { $scope.flow_back = true; } } //流程表单提交按钮响应事件 $scope.commit_bill = function() { if( !$scope.save_btn_flag || !$scope.init_btn_flag){// 计算完费用且显示完全后才可提交 return false; } var cost_err; if($scope.cost_err != undefined) { if($scope.cost_err.length != 0) { cost_err = "警告!费用不符合标准" } else { cost_err = ""; } } else if($('.errinfo').length > 0 || $('.errinfo_point').length > 0 || $('.is_red').length > 0 || $('.nobill_red').length > 0) { cost_err = "警告!存在不符合标准信息"; } else { cost_err = ""; } if($scope.check == "提交") { if($scope.type == 30) { //报销单中必须有行程且报销金额大于0才可提交 var expendMoney_code; var jour_flag = false; var money_flag = true; _.each(filed, function(_filed) { if(_filed.busCode == "expendMoney") { expendMoney_code = _filed.mdCode; } }); _.each($scope.form_data.child, function(form) { if(form.gcMeCode == expendMoney_code) { var val = form.render_value; if(val && val > 0) { money_flag = true } else { money_flag = false; } } if(form.gcCpnType == 10) { jour_flag = true; } }); if(!jour_flag) { $rootScope.terro("必须有行程才可提交"); return false; } if(!money_flag) { $rootScope.terro("报销金额大于0才可提交"); return false; } } var approval = true; $scope.checkdata(); //提交前校验规则 if($('.errinfo').length > 0) { return false; } $rootScope.swalWhether({ "title": "确认" + $scope.check + "?", 'text': cost_err }, function() { if(approval) { approval = false; $scope.param = _.extend({ "tId": $rootScope.billid }, $scope.data); //判断表单类型 switch($scope.type) { case 10: $scope.submiturl = 'flow/budget/submit'; break; case 20: $scope.submiturl = 'flow/apply/submit'; break; case 30: $scope.submiturl = 'flow/expend/submit'; break; } if($rootScope.get_all_err_data){ var form_err = $rootScope.get_all_err_data();// 保存错误 信息 if(form_err != undefined){ _.extend($scope.param,{'errInfo':JSON.stringify(form_err)}); } } if($rootScope.lock != undefined){//提交时 传锁头 _.extend($scope.param,{'lock':$rootScope.lock}); } http_service.post($scope.submiturl, $scope.param, function(response) { if(response.data.opState) { $rootScope.swalsuccess({ "text": "流程表单" + $scope.check + "成功!" }) $(element).remove(); if($scope.$parent.refreshdata) { $scope.$parent.refreshdata(); } if($rootScope.refres_table_data){//提交成功后刷新列表 修改后 $rootScope.refres_table_data(); } if($rootScope.refer_data_all) { //提交成功后刷新列表 $rootScope.refer_data_all(); } if($rootScope.refer_data_budget) { //提交成功后刷新列表 $rootScope.refer_data_budget(); } if($rootScope.refer_data_apply) { //提交成功后刷新列表 $rootScope.refer_data_apply(); } if($rootScope.refer_data_expend) { //提交成功后刷新列表 $rootScope.refer_data_expend(); } } else { // $rootScope.swalerror({ "text": "流程表单" + $scope.check + "失败!" }) $rootScope.swalerror({ "text": response.data.errMsg }); } //$scope.$parent.tsuccess() http_service.post($scope.editurl, { "tId": $rootScope.billid }, function(result) { $scope.response = result.data.data; $scope.editflag = $scope.response.edit; $scope.deleteflag = $scope.response.edit; $scope.commitflag = $scope.response.submit; $scope.check = $scope.response.submit && $scope.response.edit ? "提交" : "审核"; $scope.backflag = $scope.response.back; }); }) } }); } else { $scope.audit_commit_show = true; $scope.back_commit_show = false; } }; //关闭审核弹窗 $scope.audit_commit_close = function() { $scope.audit_commit_show = false; $("#audit_commit_content_textarea").val(""); } //审核确定 var audit_commit_wait = true; $scope.audit_commit = function() { if(audit_commit_wait) { audit_commit_wait = false; $scope.param = _.extend({ "tId": $rootScope.billid, "info": $("#audit_commit_content_textarea").val() }, $scope.data); var form_err = $rootScope.get_all_err_data();// 保存错误 信息 if(form_err != undefined){ _.extend($scope.param,{'errInfo':JSON.stringify(form_err)}); } //判断表单类型 switch($scope.type) { case 10: $scope.submiturl = 'flow/budget/submit'; break; case 20: $scope.submiturl = 'flow/apply/submit'; break; case 30: $scope.submiturl = 'flow/expend/submit'; break; } http_service.post($scope.submiturl, $scope.param, function(response) { audit_commit_wait = true; if(response.data.opState) { $rootScope.swalsuccess({ "text": "流程表单" + $scope.check + "成功!" }) $(element).remove(); if($rootScope.refres_table_data){//审核成功后刷新列表 修改后 $rootScope.refres_table_data(); } if($rootScope.refer_data_all) { //审核成功后刷新列表 $rootScope.refer_data_all(); } if($rootScope.refer_data_budget) { //审核成功后刷新列表 $rootScope.refer_data_budget(); } if($rootScope.refer_data_apply) { //审核成功后刷新列表 $rootScope.refer_data_apply(); } if($rootScope.refer_data_expend) { //审核成功后刷新列表 $rootScope.refer_data_expend(); } } else { // $rootScope.swalerror({ "text": "流程表单" + $scope.check + "失败!" }) $rootScope.swalerror({ "text": response.data.errMsg }); } //$scope.$parent.tsuccess() http_service.post($scope.editurl, { "tId": $rootScope.billid }, function(result) { $scope.response = result.data.data; $scope.editflag = $scope.response.edit; $scope.deleteflag = $scope.response.edit; $scope.commitflag = $scope.response.submit; $scope.check = $scope.response.submit && $scope.response.edit ? "提交" : "审核"; $scope.backflag = $scope.response.back; }); }) } } //流程表单退回按钮响应事件 $scope.back_bill = function() { $scope.audit_commit_show = false; $scope.back_commit_show = true; // var disagree = true; //// $rootScope.swalWhether({ "title": "确认退回表单?", 'text': "" }, //// function() { // if(disagree){ // disagree = false; // $scope.param = _.extend({ // "tId": $rootScope.billid // }, $scope.data); // http_service.post('flow/budget/back', $scope.param, function(response) { // if(response.data.opState) { // $rootScope.swalsuccess({ "text": "退回成功!" }) // } else { // $rootScope.swalerror({ 'text': "退回失败!" }, // function() { // childDel(); // }) // } // http_service.post($scope.editurl, { // "tId": $rootScope.billid // }, function(result) { // $scope.response = result.data.data; // $scope.editflag = $scope.response.edit; // $scope.deleteflag = $scope.response.edit; // $scope.commitflag = $scope.response.submit; // $scope.check = $scope.response.submit && $scope.response.edit ? "提交" : "审核"; // $scope.backflag = $scope.response.back; // }); // $(element).remove(); // }) // // swal({ // // title: "完成", // // text: "流程表单成功退回!", // // type: "success", // // confirmButtonText: "确定", // // }); // // // // $(element).remove(); // } // }) }; //退回确定 var back_commit_wait = true; $scope.back_commit = function() { if(back_commit_wait) { back_commit_wait = false; $scope.param = _.extend({ "tId": $rootScope.billid, "info": $("#back_commit_content_textarea").val() }, $scope.data); var back_url; switch($scope.type) { case 10: back_url = "flow/budget/back"; break; case 20: back_url = 'flow/apply/back'; break; case 30: back_url = 'flow/expend/back'; break; } http_service.post(back_url, $scope.param, function(response) { back_commit_wait = true; if(response.data.opState) { $rootScope.swalsuccess({ "text": "退回成功!" }) if($rootScope.refres_table_data){//退回成功后刷新列表 修改后 $rootScope.refres_table_data(); } if($rootScope.refer_data_all) { //退回成功后刷新列表 $rootScope.refer_data_all(); } if($rootScope.refer_data_budget) { //退回成功后刷新列表 $rootScope.refer_data_budget(); } if($rootScope.refer_data_apply) { //退回成功后刷新列表 $rootScope.refer_data_apply(); } if($rootScope.refer_data_expend) { //退回成功后刷新列表 $rootScope.refer_data_expend(); } } else { // $rootScope.swalerror({ 'text': "退回失败!" }, // function() { // childDel(); // }) $rootScope.swalerror({ 'text': response.data.errMsg }, function() { childDel(); }) } http_service.post($scope.editurl, { "tId": $rootScope.billid }, function(result) { $scope.response = result.data.data; $scope.editflag = $scope.response.edit; $scope.deleteflag = $scope.response.edit; $scope.commitflag = $scope.response.submit; $scope.check = $scope.response.submit && $scope.response.edit ? "提交" : "审核"; $scope.backflag = $scope.response.back; }); $(element).remove(); }) } } //关闭退回弹窗 $scope.back_commit_close = function() { $("#back_commit_content_textarea").val(""); $scope.back_commit_show = false; } //判断是否有流程记录 $scope.flowflag = $scope.response.flowStart; //显示流程状态详情 $scope.flowstatus = function() { //存储流程信息 $scope.flowDetail = []; $scope.flow_status_show = $scope.flowflag; } }) }) //删除按钮响应事件 $scope.rm_bill = function() { function childDel() { var form_data = $scope.form_data; var ap_id = form_data.ap_id; var del_url = ''; if($scope.type == 10) { del_url = "budget/deletebudgets"; var data = { "child": [{ "buId": ap_id, "key":$rootScope.lock_key != undefined?$rootScope.lock_key:"" }], "insP": 1 //单个删除 用于后端权限判断 }; } else if($scope.type == 20) { del_url = "apply/deleteApplys"; var data = { "child": [{ "apId": ap_id, "key":$rootScope.lock_key != undefined?$rootScope.lock_key:"" }], "insP": 1 //单个删除 用于后端权限判断 }; } else if($scope.type == 30) { del_url = "expend/deleteExpends"; var data = { "child": [{ "exId": ap_id, "key":$rootScope.lock_key != undefined?$rootScope.lock_key:"" }], "insP": 1 //单个删除 用于后端权限判断 }; } http_service.post(del_url, data, function(res) { if(res.status == 200) { $(element).remove(); $scope.$parent.refreshdata(); // swal({ // title: "完成", // text: "成功删除!", // type: "success", // confirmButtonText: "确定", // }) if(res.data.opState) { $rootScope.swalsuccess({ "text": "成功删除!" }) } else { if(res.data.errMsg != undefined){ $rootScope.swalerror({ "text": res.data.errMsg }) }else{ $rootScope.swalerror({ "text": "删除失败!" }) } } } }); }; var deleteall = true; $rootScope.swalWhether({ "title": "确定删除?", 'text': "" }, function() { if(deleteall) { deleteall = false; childDel(); } }); }; //删除单项项结束 $(element).find('.close').on('click', function() { $(element).remove(); }); var edit_bill_flag = true; $scope.edit_bill = function() { if( !$scope.save_btn_flag){// 计算完费用后才可编辑 return false; } if(!edit_bill_flag){ return false; } var lock_key_url; if($scope.type == "10"){//编辑验证锁 lock_key_url = "budget/edit"; }else if($scope.type == "20"){ lock_key_url = "apply/edit"; }else if($scope.type == "30"){ lock_key_url = "expend/edit"; } lock_data = { "type":$scope.type, "id":$rootScope.form_id }; if($rootScope.lock != undefined){ _.extend(lock_data,{"lock":$rootScope.lock}); } http_service.post(lock_key_url,lock_data,function(res){ edit_bill_flag = true; if(res.data.opState == true){ $rootScope.lock_key = res.data.data; $scope.edit = true; $scope.bill_commit_permission = "bill_commit_update"; $timeout(function() { $scope.btnflag = true; }, 10) }else{ $rootScope.twarning(res.data.errMsg); } }); } } } }]) .directive('billCreator', ['$rootScope', 'http_service', '$timeout', function($rootScope, http_service, $timeout) { return { restrict: 'EACM', templateUrl: './static/templates/bill_create_popup.html?v=10211439', link: function($scope, element, attrs) { $scope.save_btn_flag = true; $scope.init_btn_flag = false; $rootScope.startTime = undefined; $rootScope.endTime = undefined; $rootScope.sumMoney_budget = undefined; $scope.couldNumber = undefined; $scope.exCouldNumber = undefined; $scope.edit = true; //若无票据上传权限 则无票据上传按钮 // if(app_userinfo.expendAllPermiss){ // $scope.bill_commit_flag = true; // }else{ // $scope.bill_commit_flag = false; // } function select_arr(select_arr) { var str = ''; if(select_arr && $.isArray(select_arr)) { for(var i = 0; i < select_arr.length; i++) { if(str != '') { str = str + ',' } str = str + select_arr[i]; } return str; } else { return select_arr; } } function get_bill_data(form, data,cd_num,cd_type) { var flag = !!data; var bill_data = data || { 'child': [], 'fchild':[] }; if(!flag) { var children = form.child; if(children && children.length) { var num = 0; var pay_num = 0; _.each(children, function(cd) { var col_name = cd['gcColName']; var _children = cd['child']; if(col_name) { var item_cus = $('*[gcColName="' + col_name + '"]'); if(item_cus.is(':radio')) { bill_data[col_name] = $('*[gcColName="' + col_name + '"]:checked').val(); } else if(item_cus.attr("class") == "getDateTime ng-scope flatpickr-input") { bill_data[col_name] = cd['render_value']; } else if(item_cus.attr("class") == "select-container") { bill_data[col_name] = select_arr(cd['render_value']); } else if(item_cus.attr("choose_budget")) { //判断是否为预算选择控件 bill_data[col_name] = $rootScope.budget_selected; bill_data['buNumber'] = $rootScope.budget_selected; } else if(item_cus.attr("choose_apply")) { //判断是否为申请选择控件 bill_data[col_name] = $rootScope.expend_number_info; bill_data['apNumber'] = $rootScope.expend_number_info; } else if(item_cus.attr("user_selected")) { //判断是否为人员选择控件 $rootScope.userId = $('*[gcColName="' + col_name + '"]').attr("user_selected"); bill_data[col_name] = $('*[gcColName="' + col_name + '"]').attr("user_selected"); } else if(item_cus.attr("org_selected")) { //判断是否为组织机构选择控件 bill_data[col_name] = $('*[gcColName="' + col_name + '"]').attr("org_selected"); } else if(item_cus.attr("selected_city")) { bill_data[col_name] = $('*[gcColName="' + col_name + '"]').attr("selected_city"); } else { bill_data[col_name] = $('*[gcColName="' + col_name + '"]').val(); } } if(_children && _children.length) { if(cd.gcCpnType == 10){ get_bill_data(cd, bill_data,num,1); num++; }else if(cd.gcCpnType == 17){ get_bill_data(cd, bill_data,pay_num,2); pay_num++; } } }); } } else{ var children = form.child; if(children && children.length) { var sub_form = { 'child': [] }; _.each(children, function(cd) { var col_name = cd['gcColName']; var _children = cd['child']; var type = cd['gcCpnType']; if(type === 12) { sub_form[col_name] = $('*[gcColName="' + col_name + '"]:eq(' + cd_num + ')').attr("user_selected"); // var budget_list = form['budget_list']; // var user_id, _budget_list = []; // _.each(budget_list, function(budget) { // sub_form['child'].push({ // "an_user_id": budget.userId, // "child": _.map(budget.child, function(cld) { // return { // "jp_cd_code": cld['jp_cd_code'], // "jp_amount": cld['jp_amount'] // } // }) // }); // }); } else { if(col_name) { if(cd.gcCpnType == 6) { sub_form[col_name] = $('*[gcColName="' + col_name + '"]:eq(' + cd_num + ')').attr('value'); } else { sub_form[col_name] = $('*[gcColname="' + col_name + '"]:eq(' + cd_num + ')').val(); } } } }); // if(form.budget_list&&form.budget_list.length!=0){ // var budget_list = form.budget_list[0].child; // sub_form['child'].push({ // "an_user_id":$rootScope.userId, // "child": _.map(budget_list, function(cld) { // return { // "jp_cd_code": cld['jp_cd_code'], // "jp_amount": cld['jp_amount'] // } // }) // }); // } } if(cd_type == 1){ bill_data['child'].push(sub_form); }else if(cd_type == 2){ bill_data['fchild'].push(sub_form); } } return bill_data; } $scope.cancel = function() { $(element).remove(); }; //校验数字 function numbercheck(form, child_item) { var val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').val(); if(val != "") { if(textcheck(form, val, child_item)) { //文本长度校验 var reg0 = new RegExp("^([-]){0,1}([0-9]){1,}([.]){0,1}([0-9]){0,}$"); //校验是否为数字 var reg1 = new RegExp("^-?\\d+$"); //校验是否为整数 var reg2 = new RegExp("^-?\\d+(.[0-9]{0," + form.gcDmlLeng + "})?$"); //校验是否为n位小数 if(!reg0.test(val)) { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("请输入数字"); return false; } else { if(form.gcCpnFormat == 20) { //当条件为整数时 if(!reg1.test(val)) { //不为整数 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("必须为整数"); return false; } else if(val.length > form.gcElLeng) { //长度超过限制 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("长度不能超过" + form.gcElLeng + ""); return false; } else { return true; } } else { //当条件为允许小数时 if(form.gcDmlLeng == undefined || _.trim(form.gcDmlLeng) == ''){ return true; }else if(!reg2.test(val)) { //超过n位小数 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("小数位数不能超过" + form.gcDmlLeng + "位"); return false; } else if(val.length > form.gcElLeng) { //长度超过限制 $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("长度不能超过" + form.gcElLeng + ""); return false; } else { return true; } } } } } else { return true; } } //判断并显示校验信息 function showcheck(form, sValue, nValue, child_item) { if(nValue != undefined) { if(form.gcInputMust == 1) { //判断是否必填 必填 var val; if(form.gcCpnType == 6) { val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').attr("value"); } else if(form.gcCpnType == 12) { val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').attr("user_selected"); } else if(form.gcCpnType == 0) { val = $rootScope.budget_selected } else if(form.gcCpnType == 14) { val = $rootScope.expend_number_info; } else { val = $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == "" || _.isNull(val)) { if(form.gcCpnType == 5) { $("" + form.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcCpnAlias + "不能为空"); } return false; } else { switch(form.gcCheckOp) { case "<": if(sValue < nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "<=": if(sValue <= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">": if(sValue > nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">=": if(sValue >= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "==": if(sValue == nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:last').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcErrorMsg + ""); } return false; } break; case "<>": if(sValue != nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; } } } else { //判断是否必填 可为空 switch(form.gcCheckOp) { case "<": if(sValue < nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "<=": if(sValue <= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]::eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">": if(sValue > nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case ">=": if(sValue >= nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "==": if(sValue == nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; case "<>": if(sValue != nValue) { if(form.gcCpnType == 5) { $("" + form.gcErrorMsg + "").appendTo($('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').closest(".timeinfo")); } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("" + form.gcErrorMsg + ""); } return false; } break; } } } } //文本长度校验 function textcheck(form, value, child_item) { if(value.length <= form.gcElLeng) { return true; } else { $('*[gccolname="' + form.gcColName + '"]:eq(' + child_item + ')').after("长度不能超过" + form.gcElLeng + ""); return false; } } //获取占用预算控件内的日期 function get_date() { // $scope.str = "【预算部门】销售部、媒体部【预算日期】2017-01-01~2017-03-31【预算金额】RMB:30,000元【可用余额】RMB:25,000元"; // $scope.str =$('.apply_control_input:last').val(); var arr = []; if(check_budget()) { $scope.datestart = $rootScope.startTime; $scope.dateend = $rootScope.endTime; if($scope.datestart == undefined || $scope.dateend == undefined) { return false; } else { arr = [$scope.datestart, $scope.dateend]; } } return arr; } //判断是否为部门预算并判断是否为预算单 function check_budget() { if($scope.type != 10) { if($scope.type == 20) { return true; } else { return false; } } else { return true; } } function addDate(dd, dadd) { var a = $rootScope.getNewDate(dd) a = a.valueOf() a = a + dadd * 24 * 60 * 60 * 1000 a = $rootScope.getNewDate(a) return a; } //验证申请单 出发日期+出差天数 是否在预算起始于截至日期范围内 function applyDateCheck(form) { var budget_date = get_date(); if(budget_date) { if(budget_date.length == 0) { return false; } var start = $rootScope.getNewDate(budget_date[0].replace(/-/g, "/")); var end = $rootScope.getNewDate(budget_date[1].replace(/-/g, "/")); var mdCode_arr = []; _.each(filed, function(_filed) { switch(_filed.busCode) { case "FromDate": mdCode_arr.push(_filed.mdCode); break; case "travelDays": mdCode_arr.push(_filed.mdCode); break; } }); var item_form = []; _.each(mdCode_arr, function(_mdCode_arr) { if(form && form.child !== undefined) { _.each(form.child, function(_form) { if(_form.gcMeCode == _mdCode_arr) { item_form.push(_form); } }) } }); if(item_form && item_form.length > 0) { if(item_form[0].render_value) { var fromDate = $rootScope.getNewDate(item_form[0].render_value.replace(/-/g, "/")); if(fromDate < start || fromDate > end) { $("" + item_form[0].gcCpnAlias + "不在选择的预算时间范围内").appendTo($('*[gccolname="' + item_form[0].gcColName + '"]:last').closest(".timeinfo")); } if(item_form[1].render_value) { var travelDays = addDate(item_form[0].render_value, item_form[1].render_value); if(travelDays < start || travelDays > end) { $('*[gccolname="' + item_form[1].gcColName + '"]:last').after("" + item_form[0].gcCpnAlias + ' 和 ' + item_form[1].gcCpnAlias + "不在上级预算可用余额范围内"); } } } } } } //根据占用预算控件内的日期校验时间 function datecheck(sDate, form) { var datearr = get_date(); var checkflag = false; _.each(filed, function(_filed) { switch(_filed.busCode) { case "beginCalendar": if(_filed.mdCode == form.gcMeCode) { checkflag = true; } break; case "endCalendar": if(_filed.mdCode == form.gcMeCode) { checkflag = true; } break; } }) if(datearr != false && checkflag) { var start = $rootScope.getNewDate(datearr[0].replace(/-/g, "/")); var end = $rootScope.getNewDate(datearr[1].replace(/-/g, "/")); if(start <= sDate && sDate <= end) { return true; } else { $("" + form.gcCpnAlias + "不在选择的预算时间范围内").appendTo($('*[gccolname="' + form.gcColName + '"]:last').closest(".timeinfo")); return false; } } else { return true; } } //申请时间校验 function check_applyDate() { var datearr = get_date(); var checkflag = false; var apply_date_code, sDate, err_str; _.each(filed, function(_filed) { switch(_filed.busCode) { case "applyDate": apply_date_code = _filed.mdCode; break; } }); _.each($scope.form_data.child, function(form) { if(form.gcMeCode == apply_date_code && form.gcMeCode != undefined) { sDate = $rootScope.getNewDate($('*[gccolname="' + form.gcColName + '"]').val().replace(/-/g, "/")); checkflag = true; err_str = form.gcCpnAlias + "不在选择的预算时间范围内"; } }); if(datearr != false && checkflag && sDate) { var start = $rootScope.getNewDate(datearr[0].replace(/-/g, "/")); var end = $rootScope.getNewDate(datearr[1].replace(/-/g, "/")); if(start <= sDate && sDate <= end) { return true; } else { $rootScope.terro(err_str); return false; } } else { return true; } } //验证预算金额、申请金额 是否在上级预算范围内 function check_sumMoney() { if(check_budget() == false) { return false; } var mdCode_arr = []; _.each(filed, function(_filed) { switch(_filed.busCode) { case "budgetMoney": mdCode_arr.push(_filed.mdCode); break; case "applyMoney": mdCode_arr.push(_filed.mdCode); break; } }); if($scope.form_data) { _.each($scope.form_data.child, function(form) { _.each(mdCode_arr, function(code) { if(form.gcMeCode == code) { if(form.render_value != undefined && form.render_value !== "") { if(form.render_value > $rootScope.sumMoney_budget && $rootScope.sumMoney_budget != undefined) { $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcCpnAlias + "不在上级预算可用余额范围内"); } } } }) }) } } //日期加天数 function addDate(dd, dadd) { var a = $rootScope.getNewDate(dd); a = a.valueOf(); a = a + dadd * 24 * 60 * 60 * 1000; a = $rootScope.getNewDate(a); return a; } //跨行程验证 开始时间 function check_data_cross(type) { if($scope.type == 10) { return false; } var jour_data = []; if($scope.form_data == undefined) { return false; } _.each($scope.form_data.child, function(form) { if(form.gcCpnType == 10) { jour_data.push(form); } }); var form_date = []; var businessDays = []; var leaveDate = []; var form_date_code, businessDays_code, leaveDate_code; _.each(filed, function(_filed) { switch(_filed.busCode) { case "FromDate": form_date_code = _filed.mdCode; break; case "travelDays": businessDays_code = _filed.mdCode; break; case "journeyEndDate": leaveDate_code = _filed.mdCode; break; } }) if(jour_data.length > 1) { //当有一个以上行程才验证 _.each(jour_data, function(_jour, i) { _.each(_jour.child, function(cd) { switch(cd.gcMeCode) { case form_date_code: form_date.push({ "value": $('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').val(), "item": cd }); break; case businessDays_code: businessDays.push($('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').val()); break; case leaveDate_code: leaveDate.push($('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').val()); break; } }); }); _.each(form_date, function(fdate, k) { if($scope.type == 20) { if(k > 0 && fdate.value != "" && fdate.value && form_date[k - 1].value != "" && form_date[k - 1].value && businessDays[k - 1] != "" && businessDays) { var sDate = $rootScope.getNewDate(fdate.value); var nDate = addDate(form_date[k - 1].value, businessDays[k - 1]); if(sDate < nDate) { if(type) { $("" + fdate.item.gcCpnAlias + "与上一行程未衔接").appendTo($('*[gccolname_date="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } else { $("" + fdate.item.gcCpnAlias + "与上一行程未衔接").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } else if((sDate - nDate) != 0) { if(type) { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('*[gccolname_date="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } else { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } } } else if($scope.type == 30) { if(k > 0 && fdate.value != "" && fdate.value && leaveDate[k - 1] != "" && leaveDate[k - 1]) { var sDate = $rootScope.getNewDate(fdate.value); var nDate = $rootScope.getNewDate(leaveDate[k - 1]); if(sDate < nDate) { if(type) { $("" + fdate.item.gcCpnAlias + "不可小于上一行程离开日期").appendTo($('*[gccolname_date="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } else { $("" + fdate.item.gcCpnAlias + "不可小于上一行程离开日期").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } else if((sDate - nDate) != 0) { if(type) { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('span[value="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } else { $("" + fdate.item.gcCpnAlias + "与上一行程不连续").appendTo($('*[gccolname="' + fdate.item.gcColName + '"]:eq(' + k + ')').closest(".timeinfo")); } } } } }) } } //跨行程 验证 出发地 function check_land_cross() { if($scope.type == 10) { return false; } var jour_data = []; if($scope.form_data == undefined) { return false; } _.each($scope.form_data.child, function(form) { if(form.gcCpnType == 10) { jour_data.push(form); } }); var from_land = []; var to_land = []; var from_land_code, to_land_code; _.each(filed, function(_filed) { switch(_filed.busCode) { case "journey_from": from_land_code = _filed.mdCode; break; case "journey_to": to_land_code = _filed.mdCode; break; } }); if(jour_data.length > 1) { //当有一个以上行程才验证 _.each(jour_data, function(_jour, i) { _.each(_jour.child, function(cd) { switch(cd.gcMeCode) { case from_land_code: from_land.push({ "value": $('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').attr('value'), "item": cd }); break; case to_land_code: to_land.push($('*[gccolname="' + cd.gcColName + '"]:eq(' + i + ')').attr('value')); break; } }); }); _.each(from_land, function(fland, k) { if(k > 0 && fland.value != "" && fland.value && to_land[k - 1] != "" && to_land[k - 1]) { var sLand = fland.value; var nLand = to_land[k - 1]; if(sLand != nLand) { $('*[gccolname="' + fland.item.gcColName + '"]:eq(' + k + ')').after("" + fland.item.gcCpnAlias + "与上一行程的到达地不同"); } } }) } } //数据校验 $rootScope.checkdata = function() { $scope.checkdata(); } $scope.checkdata = function() { var child_item = -1; //子表单索引 var child_item_pay = -1//支付方式子表单索引 var form = $scope.form_data; $(".errinfo").remove(); $(".errinfo_point").remove(); check_sumMoney(); check_data_cross(false); check_land_cross(); if($scope.type == 20) { applyDateCheck(form); } if(form == undefined) { return false; } _.each(form.child, function(_form) { if(_form.gcCpnType !== 10 && _form.gcCpnType !== 17) {//判断是否为子表单 否 if(_form.gcShowFlag != 0){//被隐藏的控件 不验证 if(_form.gcCheckOp !== "" && _form.gcCheckOp != undefined) { //判断是否有校验规则 有 if(_form.gcCheckCpnCode == "-1") { //判断是否根据固定值进行校验 是 if(_form.gcCpnType == 5) { //判断是否为日期、时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); if(datecheck(sDtate, _form)) { var nDate = $rootScope.getNewDate(_form.gcCheckValue.replace(/-/g, "/")); showcheck(_form, sDtate, nDate, 0); } } else { if(_form.gcCpnType == 7) { //判断是否为数字 是 var numberflag = numbercheck(_form, 0); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + _form.gcColName + '"]').val()); var nValue = parseFloat(_form.gcCheckValue); showcheck(_form, sValue, nValue, 0); } } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); if(textcheck(_form, sValue, 0)) { var nValue = _form.gcCheckValue; showcheck(_form, sValue, nValue, 0); } } else { var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); var nValue = _form.gcCheckValue; showcheck(_form, sValue, nValue, 0); } } } else { //判断是否根据固定值进行校验 否 if(_form.gcCpnType == 5) { //判断是否为日期时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); var nDate; if(datecheck(sDtate, _form)) { _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nDate = $rootScope.getNewDate($('*[gccolname="' + _formchild.gcColName + '"]').val().replace(/-/g, "/")); } }); showcheck(_form, sDtate, nDate, 0); } } else { //判断是否为日期时间 否 if(_form.gcCpnType == 7) { //判断是否为数字 var numberflag = numbercheck(_form, 0); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + _form.gcColName + '"]').val()); var nValue; _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nValue = parseFloat($('*[gccolname="' + _formchild.gcColName + '"]').val()); } }); showcheck(_form, sValue, nValue, 0); } } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); var nValue; if(textcheck(_form, sValue, 0)) { _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]').val(); } }); showcheck(_form, sValue, nValue, 0); } } else { var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); var nValue; _.each(form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == _form.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]').val(); } }); showcheck(_form, sValue, nValue, 0); } } } } else { //判断是否有校验规则 没有 if(_form.gcInputMust == 1) { //判断是否必填 必填 var val; if(_form.gcCpnType == 6) { val = $('*[gccolname="' + _form.gcColName + '"]:last').attr("value"); } else if(_form.gcCpnType == 12) { val = $('*[gccolname="' + _form.gcColName + '"]:last').attr("user_selected"); } else if(_form.gcCpnType == 0) { val = $rootScope.budget_selected; } else if(_form.gcCpnType == 14) { val = $rootScope.expend_number_info; } else { val = $('*[gccolname="' + _form.gcColName + '"]:last').val(); } // // if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == "" || val == undefined || _.isNull(val)) { if(_form.gcCpnType == 5) { $("" + _form.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + _form.gcColName + '"]:last').closest(".timeinfo")); } else { $('*[gccolname="' + _form.gcColName + '"]:last').after("" + _form.gcCpnAlias + "不能为空"); } } else { if(_form.gcCpnType == 7) { //判断是否为数字 是 numbercheck(_form, 0); } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); textcheck(_form, sValue, 0); } else if(_form.gcCpnType == 5) { //判断是否为时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); datecheck(sDtate, _form); } } } else { //判断是否必填 可为空 if(_form.gcCpnType == 7) { //判断是否为数字 是 numbercheck(_form, 0); } else if(_form.gcCpnType == 1 || _form.gcCpnType == 2) { //判断是否为文本 var sValue = $('*[gccolname="' + _form.gcColName + '"]').val(); textcheck(_form, sValue, 0); } else if(_form.gcCpnType == 5) { //判断是否为时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + _form.gcColName + '"]').val().replace(/-/g, "/")); datecheck(sDtate, _form); } } } } } else if(_form.gcCpnType == 10) { //判断是否为子表单 是 child_item++; _.each(_form.child, function(cd) { if(cd.gcShowFlag != 0){//被隐藏的控件 不验证 if(cd.gcCheckOp !== "" && cd.gcCheckOp != undefined) { //判断是否有校验规则 有 if(cd.gcCheckCpnCode == "-1") { //判断是否根据固定值进行校验 是 if(cd.gcCpnType == 5) { //判断是否为日期、时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val().replace(/-/g, "/")); var nDate = $rootScope.getNewDate(cd.gcCheckValue.replace(/-/g, "/")); showcheck(cd, sDtate, nDate, child_item); } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 var numberflag = numbercheck(cd, child_item); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val()); var nValue = parseFloat(cd.gcCheckValue); showcheck(cd, sValue, nValue, child_item); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); if(textcheck(cd, sValue, child_item)) { var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue, child_item); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue, child_item); } } } else { //判断是否根据固定值进行校验 否 if(cd.gcCpnType == 5) { //判断是否为日期时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val().replace(/-/g, "/")); var nDate; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nDate = $rootScope.getNewDate($('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val().replace(/-/g, "/")) } }); showcheck(cd, sDtate, nDate, child_item); } else { //判断是否为日期时间 否 if(cd.gcCpnType == 7) { //判断是否为数字 var numberflag = numbercheck(cd, child_item); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val()); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = parseFloat($('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val()); } }); showcheck(cd, sValue, nValue, child_item); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); var nValue; if(textcheck(cd, sValue, child_item)) { _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val(); } }); showcheck(cd, sValue, nValue, child_item); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq(' + child_item + ')').val(); } }); showcheck(cd, sValue, nValue, child_item); } } } } else{ //判断是否有校验规则 没有 if(cd.gcInputMust == 1) { //判断是否必填 必填 var val; if(cd.gcCpnType == 6) { val = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').attr("value"); }else if(cd.gcCpnType == 12) { val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item+')').attr("user_selected"); } else { val = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } if(val == "" || _.isNull(val)) { if(cd.gcCpnType == 5) { $("" + cd.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + cd.gcColName + '"]:eq(' + ((child_item + 1) * 2 - 1) + ')').closest(".timeinfo")); } else { $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').after("" + cd.gcCpnAlias + "不能为空"); } } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd, child_item); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); textcheck(cd, sValue, child_item); } } } else { //判断是否必填 可为空 if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd, child_item); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq(' + child_item + ')').val(); textcheck(cd, sValue, child_item); } } } } }) }else if(_form.gcCpnType == 17){//判断是否为支付方式子表单 child_item_pay++; _.each(_form.child, function(cd) { if(cd.gcShowFlag != 0){//被隐藏的控件 不验证 if(cd.gcCheckOp !== "" && cd.gcCheckOp != undefined) { //判断是否有校验规则 有 if(cd.gcCheckCpnCode == "-1") { //判断是否根据固定值进行校验 是 if(cd.gcCpnType == 5) { //判断是否为日期、时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val().replace(/-/g, "/")); var nDate = $rootScope.getNewDate(cd.gcCheckValue.replace(/-/g, "/")); showcheck(cd, sDtate, nDate,child_item_pay); } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 var numberflag = numbercheck(cd,child_item_pay); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val()); var nValue = parseFloat(cd.gcCheckValue); showcheck(cd, sValue, nValue,child_item_pay); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); if(textcheck(cd, sValue,child_item_pay)) { var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue,child_item_pay); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); var nValue = cd.gcCheckValue; showcheck(cd, sValue, nValue,child_item_pay); } } } else { //判断是否根据固定值进行校验 否 if(cd.gcCpnType == 5) { //判断是否为日期时间 是 var sDtate = $rootScope.getNewDate($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val().replace(/-/g, "/")); var nDate; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nDate = $rootScope.getNewDate($('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val().replace(/-/g, "/")) } }); showcheck(cd, sDtate, nDate,child_item_pay); } else { //判断是否为日期时间 否 if(cd.gcCpnType == 7) { //判断是否为数字 var numberflag = numbercheck(cd,child_item_pay); if(numberflag) { var sValue = parseFloat($('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val()); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = parseFloat($('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val()); } }); showcheck(cd, sValue, nValue,child_item_pay); } } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { //判断是否为文本 是 var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); var nValue; if(textcheck(cd, sValue,child_item_pay)) { _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val(); } }); showcheck(cd, sValue, nValue,child_item_pay); } } else { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); var nValue; _.each(_form.child, function(_formchild) { //找到与之比较的控件 if(_formchild.gcMeCode == cd.gcCheckCpnCode) { nValue = $('*[gccolname="' + _formchild.gcColName + '"]:eq('+child_item_pay+')').val(); } }); showcheck(cd, sValue, nValue,child_item_pay); } } } } else { //判断是否有校验规则 没有 if(cd.gcInputMust == 1) { //判断是否必填 必填 var val; // // if(cd.gcCpnType == 6){ val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').attr("value"); }else if(cd.gcCpnType == 12) { val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').attr("user_selected"); } else{ val = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); } if(_.isNull(val) == false){ val = val.replace(/\s/gi,''); } // if(val == "" || _.isNull(val)) { if(cd.gcCpnType == 5) { $("" + cd.gcCpnAlias + "不能为空").appendTo($('*[gccolname="' + cd.gcColName + '"]:eq('+((child_item_pay+1)*2-1)+')').closest(".timeinfo")); } else { $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').after("" + cd.gcCpnAlias + "不能为空"); } } else { if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd,child_item_pay); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); textcheck(cd, sValue,child_item_pay); } } } else { //判断是否必填 可为空 if(cd.gcCpnType == 7) { //判断是否为数字 是 numbercheck(cd,child_item_pay); } else if(cd.gcCpnType == 1 || cd.gcCpnType == 2) { var sValue = $('*[gccolname="' + cd.gcColName + '"]:eq('+child_item_pay+')').val(); textcheck(cd, sValue,child_item_pay); } } } } }) } }) } //保存发送请求 function save_post(form_data) { var data = get_bill_data(form_data); if($scope.type == 10) { data['bu_temp_id'] = form_data.guId; } else if($scope.type == 20) { data['ap_temp_id'] = form_data.guId; } else if($scope.type == 30) { data['ex_temp_id'] = form_data.guId; // 报销单——订单编号字段 if($scope.couldNumber) { data['couldNumber'] = $scope.couldNumber; } // 报销单——公司代码字段 if(getCookie("csc_comp_code")) { data['ex_company'] = getCookie("csc_comp_code"); } // if($rootScope.expend_number_info) { // data['apNumber'] = $rootScope.expend_number_info; // } } http_service.post($scope.bill_data_create_url, data, function(res) { $scope.is_click = true; $scope.couldNumber = undefined; var bill_type = ""; if($scope.type == 10) { bill_type = "预算单"; } else if($scope.type == 20) { bill_type = "申请单"; } else if($scope.type == 30) { bill_type = "报销单"; } if(res.status === 200) { //alert('成功保存'+bill_type+'。'); if(res.data.opState) { $scope.$parent.tsuccess("成功保存" + bill_type + "。") $scope.refreshdata() $(element).remove(); } else { $scope.$parent.terro("保存" + bill_type + "失败。") } } else { //alert('保存'+bill_type+'失败。'); $scope.$parent.terro("保存" + bill_type + "失败") } $(element).remove(); }) } //新建保存 function create_bill_save(form_data) { $scope.checkdata(); if(check_applyDate() == false) { $scope.is_click = true; return false; } if($(".errinfo").length == 0) { if($scope.type == 10 && $rootScope.budget_selected != "") { http_service.post("budget/search/balance", { "buNumber": $rootScope.budget_selected }, function(res) { var budgetMoney_code; var save_flag = true; _.each(filed, function(_filed) { if(_filed.busCode == "budgetMoney") { budgetMoney_code = _filed.mdCode; } }) _.each($scope.form_data, function(form) { if(form.gcMeCode == budgetMoney_code) { if(form.render_value > res.data.data) { save_flag = false; is_click = true; $('*[gccolname="' + form.gcColName + '"]:last').after("" + form.gcCpnAlias + "不在上级预算可用余额范围内"); } } }) if(save_flag) { save_post(form_data); } }) } else { var bill_type = ""; if($scope.type == 10) { bill_type = "预算单"; } else if($scope.type == 20) { bill_type = "申请单"; } else if($scope.type == 30) { bill_type = "报销单"; } // 判断如果有错误提示 弹出确认框 if($(".errinfo_point").length > 0) { $rootScope.swalWhether({ "title": "确认保存?", 'text': "

提示:" + bill_type + "数据不符合标准

点击取消可查看

" }, function(res) { if(!res) { $scope.is_click = true; return false; } else { swal.close(); save_post(form_data); } }); } else { save_post(form_data); } } } else { $rootScope.terro("存在未通过校验规则的控件,请检查",true); $scope.is_click = true; } } //新建确定 $scope.is_click = true; $scope.create_bill = function() { var form_data = $scope.form_data; $timeout(function() { if($scope.is_click == false) { return false; } $scope.is_click = false; if($scope.type != 10) {// 申请单、报销单 新建保存时 计算费用 $rootScope.query_journel_budget($scope.type, function(version) { $timeout(function(){ create_bill_save(form_data); },10) }, false); } else { create_bill_save(form_data); } }, 10); } //document.domain = "";//iframe 同顶级域名的不同二级域名之间的调用解决办法 //显示iframe页面 function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if(c.indexOf(name) == 0) return c.substring(name.length, c.length); } return ""; } var tokens = getCookie('token'); var compid = getCookie("csc_compid"); var tenantId = getCookie("tenantId"); $scope.iframe_src = iframe_url + "views/order_create_visit.html?token="+tokens+"&compid="+compid+"&tenantId="+tenantId; // $scope.iframe_src = "./static/templates/iframe_test.html"; $scope.show_iframe = function() { $scope.iframe_show = true; var thisHeight = $(".bill_create_pop").height(); $('#iframeId').height(thisHeight); // var iframeHeight=document.getElementById("iframeId").contentWindow.document.body.offsetHeight; } $scope.close_iframe = function() { $scope.iframe_show = false; } // TODO window.addEventListener("message", function(event) { if(event.data != undefined && event.data.indexOf('=') != -1) { var arr = event.data.split('='); // 报销单 上传票据后 接收订单号 $scope.couldNumber = arr[1]; // if (arr[1]) { // $scope.tsuccess("票据上传成功!"); // } else { // $scope.terro("票据上传失败!"); // } $scope.exCouldNumber = $scope.couldNumber; } $timeout(function() { $scope.iframe_show = false; }, 1) }, false); //关闭iframe页面并获取iframe页面的值 window.getdata_iframe = function(couldNumber) { $timeout(function() { $scope.iframe_show = false; }, 1) } //关闭iframe页面并获取iframe页面的值 // window.close_iframe = function() { // $timeout(function() { // $scope.iframe_show = false; // }, 1) // // } } } }]) //点击查看表详情 .directive('clickDetailTd', ['$rootScope', '$compile', function($rootScope, $compile) { return function(scope, element, attrs) { $(element).css({ 'cursor': 'pointer' }); $(element).on('click', function() { var billid = $(element).find('input[type="checkbox"]').attr('bind_value'); $rootScope.billid = billid; $('#detailPopup').remove(); //默认不可编辑 scope.edit = false; var $el = $('
'); $('body').append($el); $compile($el)(scope); }); } }]) //上级预算管控:点击选择弹出预算单列表 .directive('clickBudgetDetail', [function() { return { restrict: "EACM", templateUrl: './static/templates/completed_order.html' } }]) .directive('clickDetailTdAll', ['$rootScope', '$compile', 'http_service', function($rootScope, $compile, http_service) { return { scope: { index: "@", type: "@", mold: "@" // editurl:"@" }, link: function(scope, element, attrs) { $(element).css({ 'cursor': 'pointer' }); $(element).on('click', function() { var urls = "flow/" + scope.mold + "/wait/handle"; // http_service.post(urls, {}, function(res) { var billid = scope.$parent.data[scope.index].id; // if(res.data.data[scope.index].bu_id) { // billid = res.data.data[scope.index].bu_id; // } else if(res.data.data[scope.index].ap_id) { // billid = res.data.data[scope.index].ap_id; // } else { // billid = res.data.data[scope.index].ex_id; // } $rootScope.billid = billid; $('#detailPopup').remove(); scope.edit = false; var $el = $('
'); $('body').append($el); $compile($el)(scope); // }); }); } } }]) .controller('travelExpenseCtrl', ['$scope', '$routeParams', '$route', '$compile', 'http_service', '$rootScope', function($scope, $routeParams, $route, $compile, http_service, $rootScope) { $scope.type = $routeParams.type; if($rootScope.my_form_type == undefined){ $rootScope.my_form_type = 1; } switch($scope.type){ case "1": $scope.my_form = '我的预算单'; $scope.my_check_form = '我审核的预算单'; break; case "2": $scope.my_form = '我的申请单'; $scope.my_check_form = '我审核的申请单'; break; case "3": $scope.my_form = '我的报销单'; $scope.my_check_form = '我审核的报销单'; break; } $scope.toggle_form = function(type){ $rootScope.my_form_type = type; $scope.refreshdata(); } var get_headers = function(cfg, form_list) { var headers = []; var headers_label_key = []; if(form_list) { _.each(form_list.child, function(form_item) { _.each(cfg, function(cfg_item) { if(form_item['gcColName'] === cfg_item) { headers_label_key.push({ 'label': form_item['gcCpnAlias'], 'gcColName': cfg_item }); headers.push(form_item['gcCpnAlias']); } }); if(form_item.child) { if(form_item.child.length > 0) { _.each(cfg, function(_cfg_item) { _.each(form_item.child, function(_form_item) { if(_form_item['gcColName'] === _cfg_item) { headers_label_key.push({ 'label': _form_item['gcCpnAlias'], 'gcColName': _cfg_item }); headers.push(_form_item['gcCpnAlias']); } }) }); } } }); } return { 'headers': headers, 'headers_label_key': headers_label_key }; }, get_search_items = function(cfg, form_list, cfgType) { var search_items = []; if(form_list) { _.each(form_list.child, function(form_item) { // 如果控件非分割线时 if(form_item['gcCpnType'] !== 9 && form_item['gcCpnType'] !== 10 &&form_item['gcCpnType'] !== 0 && form_item['gcCpnType'] !== 14 && form_item['gcCpnType'] != 17 && form_item['gcShowFlag'] != 0) { var item = { 'gc_cpn_alias': form_item['gcCpnAlias'], 'sfCfgType': cfgType, 'sfFieldName': form_item['gcColName'], 'gc_cpn_type': form_item['gcCpnType'], 'gcMeCode': form_item['gcMeCode'], // 关联查询页下拉框 'gcCpnMultiple': form_item['gcCpnMultiple'], // 关联查询页下拉框 'selected': true }; item.selected = _.includes(cfg, form_item['gcColName']); search_items.push(item); if(form_item.child) { if(form_item.child.length > 0) { _.each(form_item.child, function(form_item) { var _item = { 'sfCfgType': cfgType, 'gc_cpn_alias': form_item['gcCpnAlias'], 'sfFieldName': form_item['gcColName'], 'gc_cpn_type': form_item['gcCpnType'], 'gcMeCode': form_item['gcMeCode'], // 关联查询页下拉框 'gcCpnMultiple': form_item['gcCpnMultiple'], // 关联查询页下拉框 'selected': true } _item.selected = _.includes(cfg, form_item['gcColName']); search_items.push(_item); }); } } } }); } return { 'search_items': search_items }; }, get_data = function(headers_label_key, bill_data) { var data = []; _.each(bill_data, function(data_item, i) { var _data = []; var len = headers_label_key.length; _.each(headers_label_key, function(cfg_item, n) { _data.push(_.get(data_item, cfg_item.gcColName)); if(n === len - 1) { var doc_id = _.get(data_item, 'bu_id') || _.get(data_item, 'ap_id') || _.get(data_item, 'ex_id'); _data.push(doc_id); } }); if($rootScope.my_form_type == 2){ var id = $scope.doc_id(_data); var wait_data = _.slice(_data,0,(_data.length-1)); switch(parseInt(_.get(data_item,"flowStart"))){ case 10: wait_data.push("已审核"); break; case 20: wait_data.push("驳回"); break; case 30: wait_data.push("已通过"); break; case 50: wait_data.push("待审核"); break; } wait_data.push(id); _data = wait_data; } data.push(_data); }); return data; }, search_select = function() { var search_list = []; _.each($scope.searchlist, function(n, key) { if(n.selected == true && (n.valueLeft || n.valueRight)) { search_list.push({ "sfFieldName": n.sfFieldName, "gc_cpn_type": n.gc_cpn_type, "valueLeft": n.valueLeft, "valueRight": n.valueRight }); } }); if($rootScope.my_form_type == 1){ if($scope.searchlist.length == 0){ var data = _.assign({ 'num_per_page': $scope.num_per_page }, { 'page_num': $scope.page_num }); }else{ var data = _.assign({ 'num_per_page': $scope.num_per_page }, { 'page_num': $scope.page_num }, { 'search': search_list }); } } else { if($scope.searchlist.length == 0){ var data = _.assign({ 'num_per_page': $scope.num_per_page }, { 'page_num': $scope.page_num },{ 'flowStart':$rootScope.my_status }); }else{ var data = _.assign({ 'num_per_page': $scope.num_per_page }, { 'page_num': $scope.page_num }, { 'search': search_list },{ 'flowStart':$rootScope.my_status }); } } return data; }, list_lock = function(list_data,type){//列表单据固化 var errInfo = ''; if(type === 10) { errInfo = 'buErrInfo'; } else if(type === 20) { errInfo = 'apErrInfo'; } else if(type === 30) { errInfo = 'exErrInfo'; } _.each(list_data,function(ldata){ if(ldata.canDel == 0 && ldata[errInfo] != undefined && ldata[errInfo] != ''){ var errInfo_data = JSON.parse(ldata[errInfo]).form_err_data; var new_data = {}; _.each(errInfo_data,function(itemdata){ if(itemdata.gcColName != undefined && itemdata.gcColName != ''){ if(itemdata.old_users_selected != undefined){ new_data[itemdata.gcColName] = itemdata.old_users_selected[0].personName; }else if(itemdata.select_value != undefined){ new_data[itemdata.gcColName] = itemdata.select_value; }else if(itemdata.render_value != undefined){ new_data[itemdata.gcColName] = itemdata.render_value; } } }); _.extend(ldata,new_data); } }); return list_data; }, search_data = function(cfgColumnType, tempType) { $scope.wait = true; var url = ''; $scope.bill_data_create_url = ''; $scope.bill_data_update_url = ''; if($rootScope.my_form_type == 1){ if(tempType === 10) { url = 'budget/search/myData'; $scope.bill_data_create_url = 'budget/insert'; $scope.bill_data_update_url = 'budget/update'; } else if(tempType === 20) { url = 'apply/search/myData'; $scope.bill_data_create_url = 'apply/insert'; $scope.bill_data_update_url = 'apply/update'; } else if(tempType === 30) { url = 'expend/search/myData'; $scope.bill_data_create_url = 'expend/insert'; $scope.bill_data_update_url = 'expend/update'; } }else{ if(tempType === 10) { url = 'budget/search/waitHandle'; $scope.bill_data_create_url = 'budget/insert'; $scope.bill_data_update_url = 'budget/update'; } else if(tempType === 20) { url = 'apply/search/waitHandle'; $scope.bill_data_create_url = 'apply/insert'; $scope.bill_data_update_url = 'apply/update'; } else if(tempType === 30) { url = 'expend/search/waitHandle'; $scope.bill_data_create_url = 'expend/insert'; $scope.bill_data_update_url = 'expend/update'; } } http_service.post(url, search_select(), function(res) { var bill_data = list_lock(res.data.data,tempType);//列表单据固化 // var bill_data = res.data.data; $rootScope.search_hint(res.data.data, 'arrary', "无列表数据"); $scope.handle_data = res.data.data; $scope.rows = res.data.rows; var headers = []; http_service.post('showFieldCfg/list', { "sfCfgType": cfgColumnType }, function(res) { var cfg; if(res.data.data) { if(res.data.data.length == 0) { cfg = []; if($scope.form_list_first.data.data != undefined && $scope.form_list_first.data.data.child.length > 0) { _.each($scope.form_list_first.data.data.child, function(form_list) { if(form_list.gcCpnType != 9 && form_list.gcCpnType != 10 && form_list.gcCpnType != 0 && form_list.gcCpnType != 14 && form_list.gcCpnType != 17 && form_list.gcShowFlag != 0) { cfg.push(form_list.gcColName); } }) } } else { cfg = _.map(res.data.data, function(res) { return res['sfFieldName']; }); } } // var cfg= []; // _.each($scope.showFieldCfg_data.data.data, function(res) { // if(res['sfCfgType'] == cfgColumnType){ // cfg.push(res['sfFieldName']); // } // // }); // http_service.post('form/list', { // "guTempType": tempType // }, function(res) { if(!$scope.form_list_first.data.opState) { return false; } $scope.wait = false; var form_list = $scope.form_list_first.data.data; headers = get_headers(cfg, form_list); $scope.data = get_data(headers.headers_label_key, bill_data); $scope.id_list = {}; $scope.budget_data = { headers: headers.headers_label_key, data: $scope.data }; // }); }); }); }; //实现排序方法 $scope.content_ordering = function() { } //判断是否显示删除复选框 $scope.delete_checkbox = function(data_list) { if(data_list == undefined){ return false; } var form_type; var delteflag = false; switch($scope.type) { case 10: form_type = "bu_id"; break; case 20: form_type = "ap_id"; break; case 30: form_type = "ex_id"; break; } var doc_id = $scope.doc_id(data_list); _.each($scope.handle_data, function(handle) { if(handle[form_type] == doc_id && handle.canDel == 1 && handle.ins_p == app_userinfo.userId) { delteflag = true; } }); return delteflag; } $scope.doc_id = function(data_list) { return _.slice(data_list, data_list.length - 1, data_list.length)[0]; } $scope.sub_data = function(data_list) { return _.slice(data_list, 0, data_list.length - 1); } $scope.select_bill = function(event) { event.stopPropagation(); } // pager $scope.num_per_page = "20"; $scope.page_num = "1"; $scope.math_ceil = function(v) { if(!v) { return ''; } return Math.ceil(v); } $scope.pre_page = function() { if($scope.page_num > 1) { $scope.page_num = $scope.page_num - 1; } search_data(cfgColumnType, tempType); // $scope.budget_data['data'] = _.slice($scope.data, $scope.num_per_page * ($scope.page_num - 1), $scope.num_per_page * $scope.page_num - 1); } $scope.next_page = function() { if($scope.page_num < Math.ceil($scope.rows / $scope.num_per_page)) { $scope.page_num = (parseInt($scope.page_num) + 1).toString(); } search_data(cfgColumnType, tempType); // $scope.budget_data['data'] = _.slice($scope.data, $scope.num_per_page * ($scope.page_num - 1), $scope.num_per_page * $scope.page_num - 1); } $scope.change_page_num = function() { $scope.page_num = 1; search_data(cfgColumnType, tempType); // $scope.budget_data['data'] = _.slice($scope.data, $scope.num_per_page * ($scope.page_num - 1), $scope.num_per_page * $scope.page_num - 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.change_keycode = function(pageNumber){ if(check_number(pageNumber)){ $scope.page_num = parseInt(pageNumber); if($scope.page_num > Math.ceil($scope.rows/$scope.num_per_page)){ $scope.page_num = Math.ceil($scope.rows/$scope.num_per_page); }else if($scope.page_num < 1){ $scope.page_num = 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.page_num = pageNum; }else{ $scope.page_num = 1; } } $scope.change_page = function() { if($scope.page_num > Math.ceil($scope.rows / $scope.num_per_page)) { $scope.page_num = Math.ceil($scope.rows / $scope.num_per_page); } else if($scope.page_num < 1) { $scope.page_num = 1; }else if(_.isNaN($scope.page_num)){ $scope.page_num = 1; } search_data(cfgColumnType, tempType); } $scope.data = []; var cfgSearchType, tempType, cfgColumnType; switch($scope.type) { case "1": tempType = 10; $scope.type = 10; cfgSearchType = 11; cfgColumnType = 12; break; case "2": tempType = 20; $scope.type = 20; cfgSearchType = 21; cfgColumnType = 22; break; case "3": tempType = 30; $scope.type = 30; cfgSearchType = 31; cfgColumnType = 32; break; } // search_data(cfgColumnType, tempType); //按回车键则查询 $scope.search_keydown = function(event) { if(event.keyCode == 13) { $scope.refreshdata(); } } $rootScope.refres_table_data = function(){ $scope.refreshdata(); } $scope.refreshdata = function() { search_data(cfgColumnType, tempType); }; //由于设置高度产生滚动条,注释之 //$scope.$on('$viewContentLoaded', function() { // $('div.split_form').height($(document).height() - 52); // $(window).resize(function(){ // $('div.split_form').height($(document).height() - 52); // }); //}); _.extend($scope, { "searchlist": [], "visiblecolumns": [] }); http_service.post('form/list', { "guTempType": tempType, "cache_id": tempType }, function(result) { $scope.form_list_first = result; http_service.post('showFieldCfg/list/type', { "type": $scope.type }, function(res) { $scope.showFieldCfg_data = res; search_data(cfgColumnType, tempType); var cfg_search = []; var cfg_show = []; _.each(res.data.data, function(res) { if(res['sfCfgType'] == cfgSearchType) { cfg_search.push(res['sfFieldName']); } if(res['sfCfgType'] == cfgColumnType) { cfg_show.push(res['sfFieldName']); } }); if(!result.data.opState) { return false; } var form_list = result.data.data; var search_items_search = get_search_items(cfg_search, form_list, cfgSearchType); $scope.searchlist = search_items_search.search_items; var search_items_show = get_search_items(cfg_show, form_list, cfgColumnType); $scope.visiblecolumns = search_items_show.search_items; }); // http_service.post('showFieldCfg/list',{ // "sfCfgType": cfgSearchType // },function(res){ // var cfg = _.map(res.data.data, function(res) { // return res['sfFieldName']; // }); // if(!result.data.opState){ // return false; // } // var form_list = result.data.data; // var search_items = get_search_items(cfg, form_list, cfgSearchType); // $scope.searchlist = search_items.search_items; // }); // // http_service.post('showFieldCfg/list',{ // "sfCfgType": cfgColumnType // },function(res){ // var cfg = _.map(res.data.data, function(res) { // return res['sfFieldName']; // }); // if(!result.data.opState){ // return false; // } // var form_list = result.data.data; // var search_items = get_search_items(cfg, form_list, cfgColumnType); // $scope.visiblecolumns = search_items.search_items; // }); }, true); // http_service.post('showFieldCfg/list', { // "sfCfgType": cfgSearchType // }, function(res) { // var cfg = _.map(res.data.data, function(res) { // return res['sfFieldName']; // }); // http_service.post('form/list', { // "guTempType": tempType // }, function(res) { // if(!res.data.opState){ // return false; // } // var form_list = res.data.data; // var search_items = get_search_items(cfg, form_list, cfgSearchType); // $scope.searchlist = search_items.search_items; // }); // }); // // http_service.post('showFieldCfg/list', { // "sfCfgType": cfgColumnType // }, function(res) { // var cfg = _.map(res.data.data, function(res) { // return res['sfFieldName']; // }); // http_service.post('form/list', { // "guTempType": tempType // }, function(res) { // if(!res.data.opState){ // return false; // } // var form_list = res.data.data; // var search_items = get_search_items(cfg, form_list, cfgColumnType); // $scope.visiblecolumns = search_items.search_items; // }); // }); $scope.show_search_dropdown = function(e) { $('div.drop_down_sel').remove(); var $element = $(''); $('body').append($element); $compile($element)($scope); $element.css({ 'top': e.pageY + 5, 'right': 80 }); e.stopPropagation(); }; $scope.searchcol = function() { http_service.post('showFieldCfg/list', { "flowStart": 100 }, function(res) { if(res.data.data.length == 0) { return false; } }) } $scope.selectli = function() { alert(1); for(i in $("input[name='status']")) { if($("input[name='status']")[i].checked) { $scope.status = $("input[name='status']")[i].val(); } } } $scope.showstatus = function(e) { $('div.drop_down_sel').remove(); var $element = $(''); $('body').append($element); $compile($element)($scope); $element.css({ 'top': e.pageY + 5, 'right': 80 }); e.stopPropagation(); }; $scope.show_conent_dropdown = function(e) { $('div.drop_down_sel').remove(); var $element = $(''); $('body').append($element); $compile($element)($scope); $element.css({ 'top': e.pageY + 5, 'right': 80 }); e.stopPropagation(); }; $scope.new = function() { var bill_creator = $('
'); $('body').append(bill_creator); $compile(bill_creator)($scope); }; $scope.delete_batch = function() { if(!$('input[type="checkbox"]:checked').length) { //$scope.swalwarning({"text": "请选择要删除的内容!"}) $scope.$parent.twarning("请选择要删除的内容") return; } function childDel() { var del_url = ''; if(tempType === 10) { del_url = 'budget/deletebudgets'; } else if(tempType === 20) { del_url = 'apply/deleteApplys'; } else if(tempType === 30) { del_url = 'expend/deleteExpends'; } var data = { "child": [] }; $('input[type="checkbox"]:checked').each(function() { var id = $(this).attr('bind_value'); if(tempType === 10) { data['child'].push({ 'buId': parseInt(id) }); } else if(tempType === 20) { data['child'].push({ 'apId': parseInt(id) }); } else if(tempType === 30) { data['child'].push({ 'exId': parseInt(id) }); }; }); http_service.post(del_url, data, function(res) { if(res.status != 200) { var msg = ''; if(tempType === 10) { msg = '批量删除预算订单失败。'; } else if(tempType === 20) { msg = '批量删除申请订单失败。'; } else if(tempType === 30) { msg = '批量删除报销订单失败.'; } $('input[type="checkbox"]:checked').prop() $rootScope.swalerror({ "text": msg }) //alert(msg); } else { if(Math.ceil(($scope.rows - res.data.rows) / $scope.num_per_page) < $scope.page_num) { $scope.page_num = 1; } search_data(cfgColumnType, tempType); //swal("删除", "成功删除", "success"); if(res.data.opState) { $rootScope.swalsuccess({ "text": "成功删除!" }) } else { $rootScope.swalerror({ "text": "操作失败!" }) } $('input[type="checkbox"]').prop("checked", false); } }); } var deletecon = true; $rootScope.swalWhether({ "title": "确定删除?", "text": "" }, function() { if(deletecon) { deletecon = false; childDel(); } }); }; // 取消 列表页总金额查询 // var sum_url; // if(tempType == 10) { // sum_url = 'budget/countPro'; // } else if(tempType == 20) { // sum_url = 'apply/countPro'; // } else if(tempType == 30) { // sum_url = 'expend/countPro'; // } // http_service.post(sum_url, {}, function(res) { // if(res.data.opState) { // $scope.sum_money = res.data.data.sum; // } // }) $scope.import = function() { }; $scope.export = function() { }; }]);