fourcal/src/main/resources/static/assets/js/project_common.js

93 lines
3.2 KiB
JavaScript
Raw Normal View History

2021-11-05 09:01:26 +00:00
/**
* parse float保留两位小数四舍五入
* 空格或者非数字认为是0
2021-11-05 09:01:26 +00:00
* @param x
* @returns {*}
*/
function f2(x) {
if(!x){
return 0;
2021-11-05 09:01:26 +00:00
}
var f = parseFloat(x);
if (isNaN(f)) {
return 0;
2021-11-05 09:01:26 +00:00
}
return Math.round(x*100)/100;
}
2021-11-08 06:41:33 +00:00
/**
* 计算利润率
* @param r1
* @param r2
* @returns {*}
*/
function rate(r1,r2) {
if(!r1 || !r2 || r1==0 || r2==0){
return 0;
}
return f2(r1*100/r2);
}
function postAjax(url, data, callback) {
2021-11-03 09:53:27 +00:00
$.ajax({
url: url,
data: JSON.stringify(data),
type: "post",
dataType: "json",
contentType:"application/json",
async: false,
success: function (d) {
console.log(d);
2021-11-08 06:41:33 +00:00
callback(data, d);
2021-11-03 09:53:27 +00:00
}
});
}
2021-11-17 08:45:37 +00:00
/**
* 统计成本(含税)有一项没填就置空
*/
function calCostInclude() {
var costPurchaseDeviceTaxInclude = $("input[name='costPurchaseDeviceTaxInclude']").val();
var costPurchaseBuildTaxInclude = $("input[name='costPurchaseBuildTaxInclude']").val();
var costPurchaseServiceTaxInclude = $("input[name='costPurchaseServiceTaxInclude']").val();
var costPurchaseOtherTaxInclude = $("input[name='costPurchaseOtherTaxInclude']").val();
var costProjectManageTaxInclude = $("input[name='costProjectManageTaxInclude']").val();
var costOtherOtherTaxInclude = $("input[name='costOtherOtherTaxInclude']").val();
var costTotalTaxInclude = $("input[name='costTotalTaxInclude']");
if(costPurchaseDeviceTaxInclude && costPurchaseBuildTaxInclude && costPurchaseServiceTaxInclude && costPurchaseOtherTaxInclude && costProjectManageTaxInclude && costOtherOtherTaxInclude){
costTotalTaxInclude.val(f2(costPurchaseDeviceTaxInclude) +f2(costPurchaseBuildTaxInclude)
+f2(costPurchaseServiceTaxInclude)+f2(costPurchaseOtherTaxInclude)
+f2(costProjectManageTaxInclude)+f2(costOtherOtherTaxInclude));
}else {
costTotalTaxInclude.val("");
}
}
/**
* 统计成本(不含税)有一项没填就置空
*/
function calCostExclude() {
var costPurchaseDeviceTaxExclude = $("input[name='costPurchaseDeviceTaxExclude']").val();
var costPurchaseBuildTaxExclude = $("input[name='costPurchaseBuildTaxExclude']").val();
var costPurchaseServiceTaxExclude = $("input[name='costPurchaseServiceTaxExclude']").val();
var costPurchaseOtherTaxExclude = $("input[name='costPurchaseOtherTaxExclude']").val();
var costProjectManageTaxExclude = $("input[name='costProjectManageTaxExclude']").val();
var costOtherOtherTaxExclude = $("input[name='costOtherOtherTaxExclude']").val();
var costTotalTaxExclude = $("input[name='costTotalTaxExclude']");
if(costPurchaseDeviceTaxExclude && costPurchaseBuildTaxExclude && costPurchaseServiceTaxExclude && costPurchaseOtherTaxExclude && costProjectManageTaxExclude && costOtherOtherTaxExclude){
costTotalTaxExclude.val(f2(costPurchaseDeviceTaxExclude)+f2(costPurchaseBuildTaxExclude)
+f2(costPurchaseServiceTaxExclude)+f2(costPurchaseOtherTaxExclude)
+f2(costProjectManageTaxExclude)+f2(costOtherOtherTaxExclude));
}else {
costTotalTaxExclude.val("");
}
}