js文件拆分,防止过大

master
xxssyyyyssxx 2021-11-03 17:53:27 +08:00
parent 7ddb2aaf85
commit cd1186e843
5 changed files with 328 additions and 326 deletions

View File

@ -1,325 +0,0 @@
/**
* 一维数组变二维数组
* @param list
* @param elementsPerSubArray
* @returns {Array}
*/
function arrayToMatrix(list, elementsPerSubArray) {
var matrix = [], i, k;
for (i = 0, k = -1; i < list.length; i++) {
if (i % elementsPerSubArray === 0) {
k++;
matrix[k] = [];
}
matrix[k].push(list[i]);
}
return matrix;
}
/**
* 根据映射关系将数组变为对象
*/
function arr2Object(arr, mapArr) {
var obj = {};
for (var i = 0; i < mapArr.length; i++) {
if(!arr[i]){
//如果有空的就返回空
return null;
}
obj[mapArr[i]]=arr[i];
}
return obj;
}
/**
* 收集收入明细的数据因为动态添加的行modal无法识别所以自己来收集
* @returns {Array}
*/
function collectData(className) {
var a= [];
$("." + className).each(function (t) {
a.push($(this).val());
});
return a;
}
/**
* 绑定每一行的删除事件删除当前的一行tr
*/
function bindDeleteBtn() {
$(".am-modal-line-delete").click(function () {
//删除自己对应的tr
$(this).parent().parent().remove();
});
}
/**
* 一个收入详情的字段
*/
INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
/**
* 一个采购成本详情的字段
*/
COST_DETAIL_ARR=["type","category","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
/**
* 将页面收集到的数据转换为ajax请求的数据一维数组转换为对象数组
* @param data
* @param detailPropertyArr
* @returns {Array}
*/
function convertDetail(data,detailPropertyArr) {
var arr = arrayToMatrix(data,detailPropertyArr.length);
var details = [];
for (var i=0;i<arr.length;i++){
var obj = arr2Object(arr[i], detailPropertyArr);
if(obj){
details.push(obj);
}
}
return details;
}
function prepareAjaxData(data,detailPropertyArr,projectId){
var details = convertDetail(data, detailPropertyArr);
return {
"details":details,
"projectId":projectId
};
}
function saveDetail(url, data, callback) {
$.ajax({
url: url,
data: JSON.stringify(data),
type: "post",
dataType: "json",
contentType:"application/json",
async: false,
success: function (d) {
console.log(d);
callback(data.details);
}
});
}
/**
* 更新页面收入的数据累加
*/
function updateIncomeData(incomeDetails) {
var deviceTaxInclude = 0;
var deviceTaxExclude = 0;
var engineerTaxInclude = 0;
var engineerTaxExclude = 0;
var serviceTaxInclude = 0;
var serviceTaxExclude = 0;
incomeDetails.forEach(function (t, number, ts) {
if(t["type"] == "1"){
//设备类
deviceTaxInclude += parseFloat(t["totalTaxInclude"]);
deviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "2"){
//工程类
engineerTaxInclude += parseFloat(t["totalTaxInclude"]);
engineerTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "3"){
//服务类
serviceTaxInclude += parseFloat(t["totalTaxInclude"]);
serviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}
});
$("input[name='incomeDeviceTaxInclude']").val(deviceTaxInclude);
$("input[name='incomeDeviceTaxExclude']").val(deviceTaxExclude);
$("input[name='incomeEngineerTaxInclude']").val(engineerTaxInclude);
$("input[name='incomeEngineerTaxExclude']").val(engineerTaxExclude);
$("input[name='incomeServiceTaxInclude']").val(serviceTaxInclude);
$("input[name='incomeServiceTaxExclude']").val(serviceTaxExclude);
$("input[name='incomeTotalTaxInclude']").val(deviceTaxInclude+engineerTaxInclude+serviceTaxInclude);
$("input[name='incomeTotalTaxExclude']").val(deviceTaxExclude+engineerTaxExclude+serviceTaxExclude);
}
/**
* 绑定每个可改变的输入框修改后改变对应输入框的值
*/
function bindChangeableInput() {
//数量改变
$(".input-changeable-amount").change(function () {
var amount = parseFloat($(this).val());
//找到对应的单价和税率
var price = parseFloat($(this).parent().parent().find(".input-changeable-price").val());
var taxRate = parseFloat($(this).parent().parent().find(".input-changeable-tax-rate").val());
console.log(amount,price,taxRate);
$(this).parent().parent().find(".input-changeable-total-tax-include").val(amount*price);
$(this).parent().parent().find(".input-changeable-total-tax-exclude").val(amount*price/(1+taxRate/100));
});
//单价改变
$(".input-changeable-price").change(function () {
var price = parseFloat($(this).val());
//找到对应的数量和税率
var amount = parseFloat($(this).parent().parent().find(".input-changeable-amount").val());
var taxRate = parseFloat($(this).parent().parent().find(".input-changeable-tax-rate").val());
console.log(amount,price,taxRate);
$(this).parent().parent().find(".input-changeable-total-tax-include").val(amount*price);
$(this).parent().parent().find(".input-changeable-total-tax-exclude").val(amount*price/(1+taxRate/100));
});
//税率改变
$(".input-changeable-tax-rate").change(function () {
var taxRate = parseFloat($(this).val());
//找到对应的数量和单价
var amount = parseFloat($(this).parent().parent().find(".input-changeable-amount").val());
var price = parseFloat($(this).parent().parent().find(".input-changeable-price").val());
console.log(amount,price,taxRate);
$(this).parent().parent().find(".input-changeable-total-tax-exclude").val(amount*price/(1+taxRate/100));
});
}
/**
* 收入明细增加一行
*/
function appendTrIncome() {
var template = '<tr>\n' +
' <td>\n' +
' <select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-income">\n' +
' <option value="1">设备类</option>\n' +
' <option value="2">工程类</option>\n' +
' <option value="3">服务类</option>\n' +
' </select>\n' +
' </td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-amount"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-price"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-tax-rate"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-include" readonly></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-exclude" readonly></td>\n' +
' <td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete"><span class="am-icon-minus"></span></button></td>\n' +
' </tr>';
$("#incomeTable").append(template);
//重新绑定删除事件和input修改事件
bindDeleteBtn();
bindChangeableInput();
}
/**
* 采购成本增加一行
*/
function appendTrCost() {
var template = '<tr><td><select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">'+
'<option value="1">设备</option>'+
'<option value="2">施工</option>'+
'<option value="3">服务</option>'+
'<option value="4">其他</option>'+
'</select>'+
'</td>'+
'<td>'+
'<select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">'+
'<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>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-amount"></td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-price"></td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-tax-rate"></td>'+
'<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-modal-line-delete"><span class="am-icon-minus"></span></button></td>'+
'</tr>';
$("#costTable").append(template);
//重新绑定删除事件和input修改事件
bindDeleteBtn();
bindChangeableInput();
}
/**
* 更新页面收入的数据累加
*/
function updateCostData(details) {
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"){
//设备类
deviceTaxInclude += parseFloat(t["totalTaxInclude"]);
deviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "2"){
//施工类
buildTaxInclude += parseFloat(t["totalTaxInclude"]);
buildTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "3"){
//服务类
serviceTaxInclude += parseFloat(t["totalTaxInclude"]);
serviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "4"){
//其他类
otherTaxInclude += parseFloat(t["totalTaxInclude"]);
otherTaxExclude += parseFloat(t["totalTaxExclude"]);
}
});
$("input[name='costPurchaseDeviceTaxInclude']").val(deviceTaxInclude);
$("input[name='costPurchaseDeviceTaxExclude']").val(deviceTaxExclude);
$("input[name='costPurchaseBuildTaxInclude']").val(buildTaxInclude);
$("input[name='costPurchaseBuildTaxExclude']").val(buildTaxExclude);
$("input[name='costPurchaseServiceTaxInclude']").val(serviceTaxInclude);
$("input[name='costPurchaseServiceTaxExclude']").val(serviceTaxExclude);
$("input[name='costPurchaseOtherTaxInclude']").val(otherTaxInclude);
$("input[name='costPurchaseOtherTaxExclude']").val(otherTaxExclude);
var costOtherOtherTaxInclude = parseFloat($("input[name='costOtherOtherTaxInclude']").val());
var costOtherOtherTaxExclude = parseFloat($("input[name='costOtherOtherTaxExclude']").val());
var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val());
$("input[name='costTotalTaxInclude']").val(deviceTaxInclude+buildTaxInclude+serviceTaxInclude+otherTaxInclude+costOtherOtherTaxInclude);
$("input[name='costTotalTaxExclude']").val(deviceTaxExclude+buildTaxExclude+serviceTaxExclude+otherTaxExclude+costOtherOtherTaxExclude+costProjectManageTaxExclude);
}
function bindOtherOtherChangeable() {
$("input[name='costOtherOtherTaxInclude']").change(function () {
var costPurchaseDeviceTaxInclude = parseFloat($("input[name='costPurchaseDeviceTaxInclude']").val());
var costPurchaseBuildTaxInclude = parseFloat($("input[name='costPurchaseBuildTaxInclude']").val());
var costPurchaseServiceTaxInclude = parseFloat($("input[name='costPurchaseServiceTaxInclude']").val());
var costPurchaseOtherTaxInclude = parseFloat($("input[name='costPurchaseOtherTaxInclude']").val());
var costOtherOther = parseFloat($(this).val());
$("input[name='costTotalTaxInclude']").val(costPurchaseDeviceTaxInclude+costPurchaseBuildTaxInclude+costPurchaseServiceTaxInclude+costPurchaseOtherTaxInclude+costOtherOther);
});
$("input[name='costOtherOtherTaxExclude']").change(function () {
var costPurchaseDeviceTaxExclude = parseFloat($("input[name='costPurchaseDeviceTaxExclude']").val());
var costPurchaseBuildTaxExclude = parseFloat($("input[name='costPurchaseBuildTaxExclude']").val());
var costPurchaseServiceTaxExclude = parseFloat($("input[name='costPurchaseServiceTaxExclude']").val());
var costPurchaseOtherTaxExclude = parseFloat($("input[name='costPurchaseOtherTaxExclude']").val());
var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val());
var costOtherOther = parseFloat($(this).val());
$("input[name='costTotalTaxExclude']").val(costPurchaseDeviceTaxExclude+costPurchaseBuildTaxExclude+costPurchaseServiceTaxExclude+costPurchaseOtherTaxExclude+costProjectManageTaxExclude+costOtherOther);
});
}

View File

@ -0,0 +1,115 @@
/**
* 一个采购成本详情的字段
*/
COST_DETAIL_ARR=["type","category","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
/**
* 采购成本增加一行
*/
function appendTrCost() {
var template = '<tr><td><select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">'+
'<option value="1">设备</option>'+
'<option value="2">施工</option>'+
'<option value="3">服务</option>'+
'<option value="4">其他</option>'+
'</select>'+
'</td>'+
'<td>'+
'<select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-cost">'+
'<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>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-amount"></td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-price"></td>'+
'<td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-cost input-changeable-tax-rate"></td>'+
'<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-modal-line-delete"><span class="am-icon-minus"></span></button></td>'+
'</tr>';
$("#costTable").append(template);
//重新绑定删除事件和input修改事件
bindDeleteBtn();
bindChangeableInput();
}
/**
* 更新页面收入的数据累加
*/
function updateCostData(details) {
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"){
//设备类
deviceTaxInclude += parseFloat(t["totalTaxInclude"]);
deviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "2"){
//施工类
buildTaxInclude += parseFloat(t["totalTaxInclude"]);
buildTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "3"){
//服务类
serviceTaxInclude += parseFloat(t["totalTaxInclude"]);
serviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "4"){
//其他类
otherTaxInclude += parseFloat(t["totalTaxInclude"]);
otherTaxExclude += parseFloat(t["totalTaxExclude"]);
}
});
$("input[name='costPurchaseDeviceTaxInclude']").val(deviceTaxInclude);
$("input[name='costPurchaseDeviceTaxExclude']").val(deviceTaxExclude);
$("input[name='costPurchaseBuildTaxInclude']").val(buildTaxInclude);
$("input[name='costPurchaseBuildTaxExclude']").val(buildTaxExclude);
$("input[name='costPurchaseServiceTaxInclude']").val(serviceTaxInclude);
$("input[name='costPurchaseServiceTaxExclude']").val(serviceTaxExclude);
$("input[name='costPurchaseOtherTaxInclude']").val(otherTaxInclude);
$("input[name='costPurchaseOtherTaxExclude']").val(otherTaxExclude);
var costOtherOtherTaxInclude = parseFloat($("input[name='costOtherOtherTaxInclude']").val());
var costOtherOtherTaxExclude = parseFloat($("input[name='costOtherOtherTaxExclude']").val());
var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val());
$("input[name='costTotalTaxInclude']").val(deviceTaxInclude+buildTaxInclude+serviceTaxInclude+otherTaxInclude+costOtherOtherTaxInclude);
$("input[name='costTotalTaxExclude']").val(deviceTaxExclude+buildTaxExclude+serviceTaxExclude+otherTaxExclude+costOtherOtherTaxExclude+costProjectManageTaxExclude);
}
function bindOtherOtherChangeable() {
$("input[name='costOtherOtherTaxInclude']").change(function () {
var costPurchaseDeviceTaxInclude = parseFloat($("input[name='costPurchaseDeviceTaxInclude']").val());
var costPurchaseBuildTaxInclude = parseFloat($("input[name='costPurchaseBuildTaxInclude']").val());
var costPurchaseServiceTaxInclude = parseFloat($("input[name='costPurchaseServiceTaxInclude']").val());
var costPurchaseOtherTaxInclude = parseFloat($("input[name='costPurchaseOtherTaxInclude']").val());
var costOtherOther = parseFloat($(this).val());
$("input[name='costTotalTaxInclude']").val(costPurchaseDeviceTaxInclude+costPurchaseBuildTaxInclude+costPurchaseServiceTaxInclude+costPurchaseOtherTaxInclude+costOtherOther);
});
$("input[name='costOtherOtherTaxExclude']").change(function () {
var costPurchaseDeviceTaxExclude = parseFloat($("input[name='costPurchaseDeviceTaxExclude']").val());
var costPurchaseBuildTaxExclude = parseFloat($("input[name='costPurchaseBuildTaxExclude']").val());
var costPurchaseServiceTaxExclude = parseFloat($("input[name='costPurchaseServiceTaxExclude']").val());
var costPurchaseOtherTaxExclude = parseFloat($("input[name='costPurchaseOtherTaxExclude']").val());
var costProjectManageTaxExclude = parseFloat($("input[name='costProjectManageTaxExclude']").val());
var costOtherOther = parseFloat($(this).val());
$("input[name='costTotalTaxExclude']").val(costPurchaseDeviceTaxExclude+costPurchaseBuildTaxExclude+costPurchaseServiceTaxExclude+costPurchaseOtherTaxExclude+costProjectManageTaxExclude+costOtherOther);
});
}

View File

@ -0,0 +1,70 @@
/**
* 一个收入详情的字段
*/
INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"];
/**
* 更新页面收入的数据累加
*/
function updateIncomeData(incomeDetails) {
var deviceTaxInclude = 0;
var deviceTaxExclude = 0;
var engineerTaxInclude = 0;
var engineerTaxExclude = 0;
var serviceTaxInclude = 0;
var serviceTaxExclude = 0;
incomeDetails.forEach(function (t, number, ts) {
if(t["type"] == "1"){
//设备类
deviceTaxInclude += parseFloat(t["totalTaxInclude"]);
deviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "2"){
//工程类
engineerTaxInclude += parseFloat(t["totalTaxInclude"]);
engineerTaxExclude += parseFloat(t["totalTaxExclude"]);
}else if(t["type"] == "3"){
//服务类
serviceTaxInclude += parseFloat(t["totalTaxInclude"]);
serviceTaxExclude += parseFloat(t["totalTaxExclude"]);
}
});
$("input[name='incomeDeviceTaxInclude']").val(deviceTaxInclude);
$("input[name='incomeDeviceTaxExclude']").val(deviceTaxExclude);
$("input[name='incomeEngineerTaxInclude']").val(engineerTaxInclude);
$("input[name='incomeEngineerTaxExclude']").val(engineerTaxExclude);
$("input[name='incomeServiceTaxInclude']").val(serviceTaxInclude);
$("input[name='incomeServiceTaxExclude']").val(serviceTaxExclude);
$("input[name='incomeTotalTaxInclude']").val(deviceTaxInclude+engineerTaxInclude+serviceTaxInclude);
$("input[name='incomeTotalTaxExclude']").val(deviceTaxExclude+engineerTaxExclude+serviceTaxExclude);
}
/**
* 收入明细增加一行
*/
function appendTrIncome() {
var template = '<tr>\n' +
' <td>\n' +
' <select style="width: auto" class="am-modal-prompt-input am-modal-prompt-input-income">\n' +
' <option value="1">设备类</option>\n' +
' <option value="2">工程类</option>\n' +
' <option value="3">服务类</option>\n' +
' </select>\n' +
' </td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-amount"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-price"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-tax-rate"></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-include" readonly></td>\n' +
' <td><input type="text" class="am-modal-prompt-input am-modal-prompt-input-income input-changeable-total-tax-exclude" readonly></td>\n' +
' <td><button type="button" class="am-btn am-btn-warning am-btn-xs am-modal-line-delete"><span class="am-icon-minus"></span></button></td>\n' +
' </tr>';
$("#incomeTable").append(template);
//重新绑定删除事件和input修改事件
bindDeleteBtn();
bindChangeableInput();
}

View File

@ -0,0 +1,140 @@
/**
* 一维数组变二维数组
* @param list
* @param elementsPerSubArray
* @returns {Array}
*/
function arrayToMatrix(list, elementsPerSubArray) {
var matrix = [], i, k;
for (i = 0, k = -1; i < list.length; i++) {
if (i % elementsPerSubArray === 0) {
k++;
matrix[k] = [];
}
matrix[k].push(list[i]);
}
return matrix;
}
/**
* 根据映射关系将数组变为对象
*/
function arr2Object(arr, mapArr) {
var obj = {};
for (var i = 0; i < mapArr.length; i++) {
if(!arr[i]){
//如果有空的就返回空
return null;
}
obj[mapArr[i]]=arr[i];
}
return obj;
}
/**
* 收集收入明细的数据因为动态添加的行modal无法识别所以自己来收集
* @returns {Array}
*/
function collectData(className) {
var a= [];
$("." + className).each(function (t) {
a.push($(this).val());
});
return a;
}
/**
* 绑定每一行的删除事件删除当前的一行tr
*/
function bindDeleteBtn() {
$(".am-modal-line-delete").click(function () {
//删除自己对应的tr
$(this).parent().parent().remove();
});
}
/**
* 将页面收集到的数据转换为ajax请求的数据一维数组转换为对象数组
* @param data
* @param detailPropertyArr
* @returns {Array}
*/
function convertDetail(data,detailPropertyArr) {
var arr = arrayToMatrix(data,detailPropertyArr.length);
var details = [];
for (var i=0;i<arr.length;i++){
var obj = arr2Object(arr[i], detailPropertyArr);
if(obj){
details.push(obj);
}
}
return details;
}
function prepareAjaxData(data,detailPropertyArr,projectId){
var details = convertDetail(data, detailPropertyArr);
return {
"details":details,
"projectId":projectId
};
}
function saveDetail(url, data, callback) {
$.ajax({
url: url,
data: JSON.stringify(data),
type: "post",
dataType: "json",
contentType:"application/json",
async: false,
success: function (d) {
console.log(d);
callback(data.details);
}
});
}
/**
* 绑定每个可改变的输入框修改后改变对应输入框的值
*/
function bindChangeableInput() {
//数量改变
$(".input-changeable-amount").change(function () {
var amount = parseFloat($(this).val());
//找到对应的单价和税率
var price = parseFloat($(this).parent().parent().find(".input-changeable-price").val());
var taxRate = parseFloat($(this).parent().parent().find(".input-changeable-tax-rate").val());
console.log(amount,price,taxRate);
$(this).parent().parent().find(".input-changeable-total-tax-include").val(amount*price);
$(this).parent().parent().find(".input-changeable-total-tax-exclude").val(amount*price/(1+taxRate/100));
});
//单价改变
$(".input-changeable-price").change(function () {
var price = parseFloat($(this).val());
//找到对应的数量和税率
var amount = parseFloat($(this).parent().parent().find(".input-changeable-amount").val());
var taxRate = parseFloat($(this).parent().parent().find(".input-changeable-tax-rate").val());
console.log(amount,price,taxRate);
$(this).parent().parent().find(".input-changeable-total-tax-include").val(amount*price);
$(this).parent().parent().find(".input-changeable-total-tax-exclude").val(amount*price/(1+taxRate/100));
});
//税率改变
$(".input-changeable-tax-rate").change(function () {
var taxRate = parseFloat($(this).val());
//找到对应的数量和单价
var amount = parseFloat($(this).parent().parent().find(".input-changeable-amount").val());
var price = parseFloat($(this).parent().parent().find(".input-changeable-price").val());
console.log(amount,price,taxRate);
$(this).parent().parent().find(".input-changeable-total-tax-exclude").val(amount*price/(1+taxRate/100));
});
}

View File

@ -542,7 +542,9 @@
</div>
</div>
<script src="${base}/assets/js/project_budget.js"></script>
<script src="${base}/assets/js/project_common.js"></script>
<script src="${base}/assets/js/project_budget_income.js"></script>
<script src="${base}/assets/js/project_budget_cost.js"></script>
<script>
$(function () {