diff --git a/Application/Admin/View/Statement/createCpStatement.html b/Application/Admin/View/Statement/createCpStatement.html index 3a1df1843..ebca6d47e 100644 --- a/Application/Admin/View/Statement/createCpStatement.html +++ b/Application/Admin/View/Statement/createCpStatement.html @@ -644,14 +644,23 @@ var sort = $(this).data("change"); var val = $(this).val(); + var vdata = eval("DATAOBJ."+sort);//原先值 + var dom = $(this); + if(!CHECK.number.test(val)){ layer.msg('结算单中的罚款和税率必须是数字'); - $(this).val(0); + dom.val(vdata); return false; } + var str = "DATAOBJ."+sort+"='"+val+"';"; if(sort != 'fine'){ + if(val > 100 || val < 0){ + layer.msg('结算单中的税率不允许大于100和小于0'); + dom.val(vdata); + return false; + } eval(str); var index = $(this).data("index"); var td = DATAOBJ.statement_info[index]; diff --git a/Application/Admin/View/Statement/editCpStatement.html b/Application/Admin/View/Statement/editCpStatement.html index 61da150d9..588cd1514 100644 --- a/Application/Admin/View/Statement/editCpStatement.html +++ b/Application/Admin/View/Statement/editCpStatement.html @@ -456,91 +456,61 @@ } }) }, - deepCompare(x, y) { - var i, l, leftChain, rightChain; - function compare2Objects(x, y) { - var p; - if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') { - return true; - } - if (x === y) { - return true; - } - if ((typeof x === 'function' && typeof y === 'function') || - (x instanceof Date && y instanceof Date) || - (x instanceof RegExp && y instanceof RegExp) || - (x instanceof String && y instanceof String) || - (x instanceof Number && y instanceof Number)) { - return x.toString() === y.toString(); - } - if (!(x instanceof Object && y instanceof Object)) { - return false; - } - if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) { - return false; - } - if (x.constructor !== y.constructor) { - return false; - } - if (x.prototype !== y.prototype) { - return false; - } - if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) { - return false; + floatAdd(a,b){ + return Math.round(a*100+b*100)/100; + }, + floatCut(a,b){ + return Math.round(a*100-b*100)/100; + }, + CompanyKeyName:{ + id:"公司表id", + partner:"公司名称", + link_man:'联系人', + link_phone:"联系电话", + address:'邮寄地址', + company_tax_no:'公司税号', + payee_name:'名称', + bank_account:"银行账号", + opening_bank:"开户行" + }, + checkCompanyKey(type,key){ + //获取公司名 + var company = ''; + if(key == "payee_name" || key == "bank_account" || key == "opening_bank"){ + if((DATAOBJ.statement_type == 0 && type == "first_party_info") || (DATAOBJ.statement_type == 1 && type == "second_party_info")){ + company = "收款方"; } - for (p in y) { - if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) { - return false; - } else if (typeof y[p] !== typeof x[p]) { - return false; - } + if((DATAOBJ.statement_type == 0 && type == "second_party_info")|| (DATAOBJ.statement_type == 1 && type == "first_party_info")){ + company = "付款方"; } - for (p in x) { - if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) { - return false; - } else if (typeof y[p] !== typeof x[p]) { - return false; - } - switch (typeof (x[p])) { - case 'object': - case 'function': - - leftChain.push(x); - rightChain.push(y); - - if (!compare2Objects(x[p], y[p])) { - return false; - } - - leftChain.pop(); - rightChain.pop(); - break; - - default: - if (x[p] !== y[p]) { - return false; - } - break; - } + }else{ + if(type == "first_party_info"){ + company = "甲方"; + }else{ + company = "乙方"; } - - return true; } - - if (arguments.length < 1) { - return true; + //获取键名 + try { + var keyname = company+PUBLIC.CompanyKeyName[key]; + } catch (error) { + var keyname = false; } - for (i = 1, l = arguments.length; i < l; i++) { - - leftChain = []; //Todo: this can be cached - rightChain = []; - - if (!compare2Objects(arguments[0], arguments[i])) { - return false; - } + //验证 + if(DATAOBJ[type][key] ===''){ + layer.msg(keyname+"不能为空"); + return false; + } + if(key == "link_phone" && !CHECK.mobile.test(DATAOBJ[type][key])){ + layer.msg(keyname+"格式错误"); + return false; + } + if(key == "bank_account" && !CHECK.BankNo.test(DATAOBJ[type][key])){ + layer.msg(keyname+"格式错误"); + return false; } return true; - } + }, } //数据类 @@ -570,37 +540,20 @@ } //验证甲方信息 for (const key in DATAOBJ.first_party_info) { - var t = DATAOBJ.first_party_info; - if (t[key] === '') { - layer.msg('甲方信息不全,请先补全 code:' + key); - return false; - } - if (key == "link_phone" && !CHECK.mobile.test(t[key])) { - layer.msg('甲方联系人手机号格式错误'); - return false; - } - if (key == "bank_account" && !CHECK.BankNo.test(t[key])) { - layer.msg('甲方银行卡号格式错误'); - return false; + var t = DATAOBJ.first_party_info; + var flag = PUBLIC.checkCompanyKey("first_party_info",key); + if(!flag){ + return flag; } } //乙方 for (const key in DATAOBJ.second_party_info) { - var t = DATAOBJ.second_party_info; - if (!t[key] || t[key] == '') { - layer.msg('乙方信息不全,请先补全 code:' + key); - return false; - } - if (key == "link_phone" && !CHECK.mobile.test(t[key])) { - layer.msg('乙方联系人手机号格式错误'); - return false; - } - if (key == "bank_account" && !CHECK.BankNo.test(t[key])) { - layer.msg('乙方银行卡号格式错误'); - return false; + var t = DATAOBJ.second_party_info; + var flag = PUBLIC.checkCompanyKey("second_party_info",key); + if(!flag){ + return flag; } } - console.log(DATAOBJ); layer.load(2); $("#createStatement").off("click");//自我解绑 @@ -633,56 +586,67 @@ }, statementchange() { $(".statementchange").off("blur"); - $(".statementchange").on("blur", function () { - + $(".statementchange").on("blur",function(){ var sort = $(this).data("change"); var val = $(this).val(); - if (!CHECK.number.test(val)) { + var vdata = eval("DATAOBJ."+sort);//原先值 + var dom = $(this); + + if(!CHECK.number.test(val)){ layer.msg('结算单中的罚款和税率必须是数字'); - $(this).val(0); + dom.val(vdata); return false; } - var str = "DATAOBJ." + sort + "='" + val + "';"; + + var str = "DATAOBJ."+sort+"='"+val+"';"; - if (sort != 'fine') { + if(sort != 'fine'){ + if(val > 100 || val < 0){ + layer.msg('结算单中的税率不允许大于100和小于0'); + dom.val(vdata); + return false; + } eval(str); var index = $(this).data("index"); var td = DATAOBJ.statement_info[index]; - if ($(this).attr("name") == "first_ratio") { - td['second_ratio'] = 100 - val; + if( $(this).attr("name") == "first_ratio"){ + td['second_ratio'] = 100-val; } - if ($(this).attr("name") == "second_ratio") { - td['first_ratio'] = 100 - val; + if( $(this).attr("name") == "second_ratio"){ + td['first_ratio'] = 100-val; } - if (DATAOBJ.statement_type == 0) { - var ratio = td['first_ratio'] / 100; - } else { - var ratio = td['second_ratio'] / 100; + if(DATAOBJ.statement_type == 0){ + var ratio = td['first_ratio']/100; + }else{ + var ratio = td['second_ratio']/100; } - DATAOBJ.statement_count['sum_money'] -= td['sum_money']; - - td['sum_money'] = Math.floor((td['pay_amount'] * (100 - td['promote_ratio']) / 100 * ratio * (100 - td['fax_ratio']) / 100) * 100) / 100; - DATAOBJ.statement_count['sum_money'] += (td['sum_money'] - 0); - } else { - DATAOBJ.fine = Math.floor(DATAOBJ.fine * 100) / 100; - if (val > DATAOBJ.statement_count['sum_money']) { + DATAOBJ.statement_count['sum_money'] = PUBLIC.floatCut(DATAOBJ.statement_count['sum_money'],td['sum_money']); + + td['sum_money'] = Math.round((td['pay_amount']*(100-td['promote_ratio'])/100*ratio*(100-td['fax_ratio'])/100)* 100) / 100 ; + + DATAOBJ.statement_count['sum_money']=PUBLIC.floatAdd(DATAOBJ.statement_count['sum_money'],td['sum_money']); + + }else{ + DATAOBJ.fine = Math.round(DATAOBJ.fine * 100) / 100 ; + if(!CHECK.money.test(val)){ + layer.msg('罚款金额格式错误'); + $(this).val(DATAOBJ.fine); + return false; + } + if(val > DATAOBJ.statement_count['sum_money']){ layer.msg('罚款金额过大,总计不允许为负数'); $(this).val(DATAOBJ.fine); return false; } - - DATAOBJ.statement_count['sum_money'] = (DATAOBJ.statement_count['sum_money'] - 0 + DATAOBJ.fine); - DATAOBJ.statement_count['pay_amount'] = (DATAOBJ.statement_count['pay_amount'] - 0 + DATAOBJ.fine); + console.log(str); + DATAOBJ.statement_count['sum_money'] =PUBLIC.floatAdd(DATAOBJ.statement_count['sum_money'],DATAOBJ.fine); + DATAOBJ.statement_count['pay_amount'] = PUBLIC.floatAdd(DATAOBJ.statement_count['pay_amount'],DATAOBJ.fine); eval(str); - DATAOBJ.statement_count['sum_money'] = DATAOBJ.statement_count['sum_money'] - DATAOBJ.fine; - DATAOBJ.statement_count['pay_amount'] = DATAOBJ.statement_count['pay_amount'] - DATAOBJ.fine; - + DATAOBJ.statement_count['sum_money'] =PUBLIC.floatCut(DATAOBJ.statement_count['sum_money'],DATAOBJ.fine); + DATAOBJ.statement_count['pay_amount'] = PUBLIC.floatCut(DATAOBJ.statement_count['pay_amount'],DATAOBJ.fine); } - DATAOBJ.statement_count['pay_amount'] = Math.floor(DATAOBJ.statement_count['pay_amount'] * 100) / 100; - DATAOBJ.statement_count['sum_money'] = Math.floor(DATAOBJ.statement_count['sum_money'] * 100) / 100; - TPLSHOW.showStatementList(true); }) }