diff --git a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java index b43cba5..7e19219 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProjectController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProjectController.java @@ -20,10 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.datetime.DateFormatter; import org.springframework.stereotype.Controller; import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import top.jfunc.common.utils.CollectionUtil; import javax.servlet.http.HttpServletResponse; @@ -177,22 +174,21 @@ public class ProjectController extends BaseController{ * 保存收入明细 */ @RequestMapping("/budgetEditSaveIncomeDetail") + @ResponseBody public ResponseMsg budgetEditSaveIncomeDetail(@RequestBody String body) { JSONObject jsonObject = JSON.parseObject(body); JSONArray incomeDetails = jsonObject.getJSONArray("incomeDetails"); - if(CollectionUtil.isNotEmpty(incomeDetails)){ - List incomeDetailList = new ArrayList<>(incomeDetails.size()); - for (int i = 0; i < incomeDetails.size(); i++) { - ProjectBudgetIncomeDetail incomeDetail = incomeDetails.getObject(i, ProjectBudgetIncomeDetail.class); - incomeDetailList.add(incomeDetail); - } - - Project project = projectService.getProject(jsonObject.getInteger("projectId")); - - projectBudgetService.clearBudgetIncomeDetail(project); - projectBudgetService.saveBudgetIncomeDetail(project, incomeDetailList); - + List incomeDetailList = new ArrayList<>(incomeDetails.size()); + for (int i = 0; i < incomeDetails.size(); i++) { + ProjectBudgetIncomeDetail incomeDetail = incomeDetails.getObject(i, ProjectBudgetIncomeDetail.class); + incomeDetailList.add(incomeDetail); } + + Project project = projectService.getProject(jsonObject.getInteger("projectId")); + + projectBudgetService.clearBudgetIncomeDetail(project); + projectBudgetService.saveBudgetIncomeDetail(project, incomeDetailList); + return ResponseMsg.buildSuccessMsg("成功"); } /** @@ -202,19 +198,17 @@ public class ProjectController extends BaseController{ public ResponseMsg budgetEditSaveCostDetail(@RequestBody String body) { JSONObject jsonObject = JSON.parseObject(body); JSONArray costDetails = jsonObject.getJSONArray("costDetails"); - if(CollectionUtil.isNotEmpty(costDetails)){ - List costDetailList = new ArrayList<>(costDetails.size()); - for (int i = 0; i < costDetails.size(); i++) { - ProjectBudgetCostDetail costDetail = costDetails.getObject(i, ProjectBudgetCostDetail.class); - costDetailList.add(costDetail); - } - - Project project = projectService.getProject(jsonObject.getInteger("projectId")); - - projectBudgetService.clearBudgetCostDetail(project); - projectBudgetService.saveBudgetCostDetail(project, costDetailList); - + List costDetailList = new ArrayList<>(costDetails.size()); + for (int i = 0; i < costDetails.size(); i++) { + ProjectBudgetCostDetail costDetail = costDetails.getObject(i, ProjectBudgetCostDetail.class); + costDetailList.add(costDetail); } + + Project project = projectService.getProject(jsonObject.getInteger("projectId")); + + projectBudgetService.clearBudgetCostDetail(project); + projectBudgetService.saveBudgetCostDetail(project, costDetailList); + return ResponseMsg.buildSuccessMsg("成功"); } /** @@ -224,19 +218,17 @@ public class ProjectController extends BaseController{ public ResponseMsg budgetEditSaveCostProjectManageDetail(@RequestBody String body) { JSONObject jsonObject = JSON.parseObject(body); JSONArray costDetails = jsonObject.getJSONArray("costProjectManageDetails"); - if(CollectionUtil.isNotEmpty(costDetails)){ - List costDetailList = new ArrayList<>(costDetails.size()); - for (int i = 0; i < costDetails.size(); i++) { - ProjectBudgetCostProjectManageDetail costDetail = costDetails.getObject(i, ProjectBudgetCostProjectManageDetail.class); - costDetailList.add(costDetail); - } - - Project project = projectService.getProject(jsonObject.getInteger("projectId")); - - projectBudgetService.clearBudgetCostProjectManageDetail(project); - projectBudgetService.saveBudgetCostProjectManageDetail(project, costDetailList); - + List costDetailList = new ArrayList<>(costDetails.size()); + for (int i = 0; i < costDetails.size(); i++) { + ProjectBudgetCostProjectManageDetail costDetail = costDetails.getObject(i, ProjectBudgetCostProjectManageDetail.class); + costDetailList.add(costDetail); } + + Project project = projectService.getProject(jsonObject.getInteger("projectId")); + + projectBudgetService.clearBudgetCostProjectManageDetail(project); + projectBudgetService.saveBudgetCostProjectManageDetail(project, costDetailList); + return ResponseMsg.buildSuccessMsg("成功"); } @InitBinder diff --git a/src/main/resources/static/assets/js/project_budget.js b/src/main/resources/static/assets/js/project_budget.js index 41675e0..14842e9 100644 --- a/src/main/resources/static/assets/js/project_budget.js +++ b/src/main/resources/static/assets/js/project_budget.js @@ -25,6 +25,10 @@ function arrayToMatrix(list, elementsPerSubArray) { 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; @@ -33,8 +37,89 @@ function arr2Object(arr, mapArr) { /** * 一个收入详情的字段 */ -INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate"]; -INCOME_DETAIL_PROP_LENGTH=8; +INCOME_DETAIL_ARR=["type","name","unit","amount","price","taxRate","totalTaxInclude","totalTaxExclude"]; + +/** + * 保存收入明细数据 + */ +function saveIncomeDetail(url, data, projectId) { + if(Array.isArray(data) && data.length != 0){ + var incomeDetails = convertIncomeDetail(data); + var da = { + "incomeDetails":incomeDetails, + "projectId":projectId + }; + console.log(da); + $.ajax({ + url: url, + data: JSON.stringify(da), + type: "post", + dataType: "json", + contentType:"application/json", + async: false, + success: function (d) { + console.log(d); + updateIncomeData(incomeDetails); + } + }); + } +} + +/** + * 更新页面收入的数据【累加】 + */ +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); +} + + +/** + * 将页面收集到的数据转换为ajax请求的数据【一维数组转换为对象数组】 + * @param data + * @returns {Array} + */ +function convertIncomeDetail(data) { + var arr = arrayToMatrix(data,INCOME_DETAIL_ARR.length); + + var incomeDetails = []; + for (var i=0;i 收入 设备类 - - + + 收入 工程类 - - + + 收入 服务类 - - + + 合计 - - + + @@ -441,31 +441,14 @@ - + - - <#-- - - - - - - - - - - - --> - +