@ -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;
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 = "收款方";
}
if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
return false ;
if((DATAOBJ.statement_type == 0 & & type == "second_party_info")|| (DATAOBJ.statement_type == 1 & & type == "first_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 ;
}else{
if(type == "first_party_info") {
company = "甲方" ;
}else{
company = "乙方" ;
}
}
for (p in x) {
if (y.hasOwnProper ty(p) !== x.hasOwnP ropert y(p)) {
return false ;
} else if (typeof y[p] !== typeof x[p] ) {
return false;
//获取键名
try {
var keyname = company+PUBLIC.CompanyKeyName[key] ;
} catch (error ) {
var keyname = false;
}
switch (typeof (x[p])) {
case 'object':
case 'function':
leftChain.push(x);
rightChain.push(y);
if (!compare2Objects(x[p], y[p])) {
//验证
if(DATAOBJ[type][key] ===''){
layer.msg(keyname+"不能为空");
return false;
}
leftChain.pop();
rightChain.pop();
break;
default:
if (x[p] !== y[p]) {
if(key == "link_phone" & & !CHECK.mobile.test(DATAOBJ[type][key])){
layer.msg(keyname+"格式错误");
return false;
}
break;
}
}
return true;
}
if (arguments.length < 1 ) {
return true;
}
for (i = 1, l = arguments.length; i < l ; i + + ) {
leftChain = []; //Todo: this can be cached
rightChain = [];
if (!compare2Objects(arguments[0], arguments[i])) {
if(key == "bank_account" & & !CHECK.BankNo.test(DATAOBJ[type][key])){
layer.msg(keyname+"格式错误");
return false;
}
}
return true;
}
},
}
//数据类
@ -571,36 +541,19 @@
//验证甲方信息
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 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 ;
var flag = PUBLIC.checkCompanyKey("second_party_info",key);
if(!flag){
return flag;
}
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;
}
}
console.log(DATAOBJ);
layer.load(2);
$("#createStatement").off("click");//自我解绑
@ -634,17 +587,25 @@
statementchange() {
$(".statementchange").off("blur");
$(".statementchange").on("blur",function(){
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];
@ -661,28 +622,31 @@
}else{
var ratio = td['second_ratio']/100;
}
DATAOBJ.statement_count['sum_money'] -= td['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']);
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;
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);
})
}