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

207 lines
8.5 KiB
JavaScript
Raw Normal View History

2021-11-03 09:53:27 +00:00
/**
* 一个采购成本详情的字段
*/
COST_DETAIL_ARR=["type","category","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
2021-11-03 10:02:44 +00:00
$(function () {
$("#cost-detail").click(function () {
$('#my-prompt-cost-detail').modal({
relatedTarget: this,
onConfirm: function(e) {
//不能使用e.data因为无法获取动态添加的
var data = collectData("am-modal-prompt-input-cost");
data = prepareAjaxData(data, COST_DETAIL_ARR, $("#id").val());
2021-11-08 06:41:33 +00:00
postAjax(base+"/project/budgetEditSaveCostDetail", data, updateCostData);
2021-11-03 10:02:44 +00:00
},
onCancel: function(e) {
}
});
});
$("#costAddBtn").click(function () {
appendTrCost();
});
2021-11-06 06:45:57 +00:00
//绑定其他其他的输入框
bindOtherOtherChangeable();
2021-11-11 06:20:57 +00:00
//绑定采购明细中select联动事件
bindTypeSelectChange();
2021-11-03 10:02:44 +00:00
});
2021-11-03 09:53:27 +00:00
/**
* 采购成本增加一行
*/
function appendTrCost() {
2021-11-11 06:20:57 +00:00
var template = '<tr><td><select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost am-modal-prompt-input-cost-type">'+
2021-11-03 09:53:27 +00:00
'<option value="1">设备</option>'+
'<option value="2">施工</option>'+
'<option value="3">服务</option>'+
'<option value="4">其他</option>'+
'</select>'+
'</td>'+
'<td>'+
2021-11-11 06:20:57 +00:00
'<select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost am-modal-prompt-input-cost-category">'+
2021-11-03 09:53:27 +00:00
'<option value="1">华智产品</option>'+
'<option value="2">紫光其他产品</option>'+
'<option value="3">外购产品</option>'+
'<option value="4">外购工程</option>'+
'<option value="5">华智服务</option>'+
'<option value="6">紫光其他服务</option>'+
'<option value="7">外购服务</option>'+
'<option value="8">其他</option>'+
'</select>'+
'</td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost"></td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost""></td>'+
2021-11-08 01:55:22 +00:00
'<td><input type="number" min="0" max="99999999" step="1" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-amount"></td>'+
'<td><input type="number" min="0.00" max="99999999.99" step="0.01" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-price"></td>'+
'<td><input type="number" min="0.00" max="99.99" step="0.01" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-tax-rate"></td>'+
2021-11-03 09:53:27 +00:00
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-total-tax-include" readonly></td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-total-tax-exclude" readonly></td>'+
'<td><button type="button" class="am-btn am-btn-warning am-btn-xs am-round am-modal-line-delete"><span class="am-icon-minus"></span></button></td>'+
2021-11-03 09:53:27 +00:00
'</tr>';
$("#costTable").append(template);
//重新绑定删除事件和input修改事件
bindDeleteBtn();
2021-11-11 06:20:57 +00:00
//重新绑定
bindChangeableInput();
//绑定采购明细中select联动事件
bindTypeSelectChange();
2021-11-03 09:53:27 +00:00
}
/**
* 更新页面收入的数据累加
*/
2021-11-08 06:41:33 +00:00
function updateCostData(data, returnData) {
var details = data.details;
2021-11-03 09:53:27 +00:00
var deviceTaxInclude = 0;
var deviceTaxExclude = 0;
var buildTaxInclude = 0;
var buildTaxExclude = 0;
var serviceTaxInclude = 0;
var serviceTaxExclude = 0;
var otherTaxInclude = 0;
var otherTaxExclude = 0;
details.forEach(function (t, number, ts) {
if(t["type"] == "1"){
//设备类
2021-11-05 09:08:42 +00:00
deviceTaxInclude += f2(t["totalTaxInclude"]);
deviceTaxExclude += f2(t["totalTaxExclude"]);
2021-11-03 09:53:27 +00:00
}else if(t["type"] == "2"){
//施工类
2021-11-05 09:08:42 +00:00
buildTaxInclude += f2(t["totalTaxInclude"]);
buildTaxExclude += f2(t["totalTaxExclude"]);
2021-11-03 09:53:27 +00:00
}else if(t["type"] == "3"){
//服务类
2021-11-05 09:08:42 +00:00
serviceTaxInclude += f2(t["totalTaxInclude"]);
serviceTaxExclude += f2(t["totalTaxExclude"]);
2021-11-03 09:53:27 +00:00
}else if(t["type"] == "4"){
//其他类
2021-11-05 09:08:42 +00:00
otherTaxInclude += f2(t["totalTaxInclude"]);
otherTaxExclude += f2(t["totalTaxExclude"]);
2021-11-03 09:53:27 +00:00
}
});
2021-11-06 13:49:44 +00:00
$("input[name='costPurchaseDeviceTaxInclude']").val(f2(deviceTaxInclude));
$("input[name='costPurchaseDeviceTaxExclude']").val(f2(deviceTaxExclude));
$("input[name='costPurchaseBuildTaxInclude']").val(f2(buildTaxInclude));
$("input[name='costPurchaseBuildTaxExclude']").val(f2(buildTaxExclude));
$("input[name='costPurchaseServiceTaxInclude']").val(f2(serviceTaxInclude));
$("input[name='costPurchaseServiceTaxExclude']").val(f2(serviceTaxExclude));
$("input[name='costPurchaseOtherTaxInclude']").val(f2(otherTaxInclude));
$("input[name='costPurchaseOtherTaxExclude']").val(f2(otherTaxExclude));
2021-11-03 09:53:27 +00:00
var costOtherOtherTaxInclude = parseFloat($("input[name='costOtherOtherTaxInclude']").val());
var costOtherOtherTaxExclude = parseFloat($("input[name='costOtherOtherTaxExclude']").val());
var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val());
2021-11-06 06:45:57 +00:00
$("input[name='costTotalTaxInclude']").val(f2(deviceTaxInclude+buildTaxInclude+serviceTaxInclude+otherTaxInclude+costOtherOtherTaxInclude));
$("input[name='costTotalTaxExclude']").val(f2(deviceTaxExclude+buildTaxExclude+serviceTaxExclude+otherTaxExclude+costOtherOtherTaxExclude+costProjectManageTaxExclude));
updateProjectContributionProfitRate();
2021-11-03 09:53:27 +00:00
}
function bindOtherOtherChangeable() {
$("input[name='costOtherOtherTaxInclude']").change(function () {
2021-11-05 09:08:42 +00:00
var costPurchaseDeviceTaxInclude = f2($("input[name='costPurchaseDeviceTaxInclude']").val());
var costPurchaseBuildTaxInclude = f2($("input[name='costPurchaseBuildTaxInclude']").val());
var costPurchaseServiceTaxInclude = f2($("input[name='costPurchaseServiceTaxInclude']").val());
var costPurchaseOtherTaxInclude = f2($("input[name='costPurchaseOtherTaxInclude']").val());
2021-11-03 09:53:27 +00:00
2021-11-05 09:08:42 +00:00
var costOtherOther = f2($(this).val());
2021-11-03 09:53:27 +00:00
2021-11-06 06:45:57 +00:00
$("input[name='costTotalTaxInclude']").val(f2(costPurchaseDeviceTaxInclude+costPurchaseBuildTaxInclude+costPurchaseServiceTaxInclude+costPurchaseOtherTaxInclude+costOtherOther));
updateProjectContributionProfitRate();
2021-11-03 09:53:27 +00:00
});
$("input[name='costOtherOtherTaxExclude']").change(function () {
2021-11-05 09:08:42 +00:00
var costPurchaseDeviceTaxExclude = f2($("input[name='costPurchaseDeviceTaxExclude']").val());
var costPurchaseBuildTaxExclude = f2($("input[name='costPurchaseBuildTaxExclude']").val());
var costPurchaseServiceTaxExclude = f2($("input[name='costPurchaseServiceTaxExclude']").val());
var costPurchaseOtherTaxExclude = f2($("input[name='costPurchaseOtherTaxExclude']").val());
2021-11-03 09:53:27 +00:00
2021-11-05 09:08:42 +00:00
var costProjectManageTaxExclude = f2($("input[name='costProjectManageTaxExclude']").val());
var costOtherOther = f2($(this).val());
2021-11-03 09:53:27 +00:00
2021-11-06 06:45:57 +00:00
$("input[name='costTotalTaxExclude']").val(f2(costPurchaseDeviceTaxExclude+costPurchaseBuildTaxExclude+costPurchaseServiceTaxExclude+costPurchaseOtherTaxExclude+costProjectManageTaxExclude+costOtherOther));
updateProjectContributionProfitRate();
2021-11-03 09:53:27 +00:00
});
2021-11-11 06:20:57 +00:00
}
SELECT_DATA={
"1":[
{
"value":"1",
"name":"华智产品"
},
{
"value":"2",
"name":"紫光其他产品"
},
{
"value":"3",
"name":"外购产品"
}
],
"2":[
{
"value":"4",
"name":"外购工程"
}
],
"3":[
{
"value":"5",
"name":"华智服务"
},
{
"value":"6",
"name":"紫光其他服务"
},
{
"value":"7",
"name":"外购服务"
}
],
"4":[
{
"value":"8",
"name":"其他"
}
]
};
/**
* 大类类别联动效果
*/
function bindTypeSelectChange() {
$(".am-modal-prompt-input-cost-type").on('change',function () {
var categorySelect = $(this).parent().parent().find(".am-modal-prompt-input-cost-category");
var type = $(this).val();
categorySelect.empty();
SELECT_DATA[type].forEach(function (d) {
categorySelect.append("<option value='"+d.value+"'>"+d.name+"</option>");
})
});
}