Browse Source

[feat] 销售管理

修改销售估价列表页面:新增采购成本按钮,新增打开采购成本页面js方法
新增 采购成本前端页面
修改 根据销售估价详情ID获取销售估价详情物料价格集合后端接口:新增多个成本价格字段
销售估价实体类新增 销售估价详情物料集合
销售估价Controller层新增 新增Bom销售估价-采购后端接口;新增修改保存销售估价-采购后端接口:同时修改三个表格的数据;
销售估价详情物料新增查询所有详情物料价格后端接口
新增 物料详情子表包括form表单的数据Vo类
dev
liuxiaoxu 4 months ago
parent
commit
18aeac08b8
  1. 35
      ruoyi-admin/src/main/java/com/ruoyi/sales/controller/SalesEstimateController.java
  2. 11
      ruoyi-admin/src/main/java/com/ruoyi/sales/domain/SalesEstimate.java
  3. 40
      ruoyi-admin/src/main/java/com/ruoyi/sales/domain/VO/SalesEstimateDetailMaterialVo.java
  4. 8
      ruoyi-admin/src/main/java/com/ruoyi/sales/mapper/SalesEstimateDetailMaterialMapper.java
  5. 3
      ruoyi-admin/src/main/java/com/ruoyi/sales/service/ISalesEstimateDetailMaterialService.java
  6. 7
      ruoyi-admin/src/main/java/com/ruoyi/sales/service/ISalesEstimateService.java
  7. 43
      ruoyi-admin/src/main/java/com/ruoyi/sales/service/impl/SalesEstimateDetailMaterialServiceImpl.java
  8. 54
      ruoyi-admin/src/main/java/com/ruoyi/sales/service/impl/SalesEstimateServiceImpl.java
  9. 3
      ruoyi-admin/src/main/resources/mapper/sales/SalesEstimateDetailMaterialMapper.xml
  10. 15
      ruoyi-admin/src/main/resources/templates/sales/estimate/estimate.html
  11. 614
      ruoyi-admin/src/main/resources/templates/sales/estimate/purchaseAdd.html

35
ruoyi-admin/src/main/java/com/ruoyi/sales/controller/SalesEstimateController.java

@ -8,6 +8,7 @@ import com.ruoyi.erp.service.IErpMaterialService;
import com.ruoyi.sales.domain.SalesEstimateDetail;
import com.ruoyi.sales.domain.SalesEstimateDetailMaterial;
import com.ruoyi.sales.domain.SalesEstimateTemplate;
import com.ruoyi.sales.domain.VO.SalesEstimateDetailMaterialVo;
import com.ruoyi.sales.domain.VO.SalesEstimateDetailVo;
import com.ruoyi.sales.service.ISalesEstimateDetailMaterialService;
import com.ruoyi.sales.service.ISalesEstimateDetailService;
@ -163,12 +164,13 @@ public class SalesEstimateController extends BaseController
public TableDataInfo getEstimateDetailMaterialList(@RequestParam("estimateDetailId") Long estimateDetailId )
{
startPage();
List<SalesEstimateDetailMaterial> list = estimateDetailMaterialService.getEstimateDetailMaterialList(estimateDetailId);
List<SalesEstimateDetailMaterialVo> list = estimateDetailMaterialService.getEstimateDetailMaterialList(estimateDetailId);
return getDataTable(list);
}
/**
* 加载新增销售估价-工程 子表物料选择弹窗
*/
@ -197,6 +199,35 @@ public class SalesEstimateController extends BaseController
/**
* 新增Bom销售估价-采购
*/
@GetMapping("/purchaseAdd/{salesEstimateId}")
public String purchaseAdd(@PathVariable("salesEstimateId") Long salesEstimateId, ModelMap map)
{
SalesEstimate salesEstimate = salesEstimateService.selectSalesEstimateById(salesEstimateId);
map.put("salesEstimate", salesEstimate);
SalesEstimateDetailVo salesEstimateDetailVo = salesEstimateService.getSalesEstimateDetailVo();
map.put("salesEstimateDetailVo",salesEstimateDetailVo);
return prefix + "/purchaseAdd";
}
/**
* 修改保存销售估价-采购
*/
@RequiresPermissions("sales:estimate:purchaseAdd")
@Log(title = "销售估价", businessType = BusinessType.UPDATE)
@PostMapping("/purchaseAdd")
@ResponseBody
public AjaxResult purchaseAddSave(@RequestBody SalesEstimate salesEstimate)
{
return toAjax(salesEstimateService.purchaseAddSalesEstimate(salesEstimate));
}
/**
* 加载新增销售估价 物料选择弹窗
*/
@ -208,8 +239,6 @@ public class SalesEstimateController extends BaseController
/**
* 新增销售估价 物料选择
*/

11
ruoyi-admin/src/main/java/com/ruoyi/sales/domain/SalesEstimate.java

@ -98,6 +98,9 @@ public class SalesEstimate extends BaseEntity
/** 销售估价详情集合 */
private List<SalesEstimateDetail> salesEstimateDetailList;
/** 销售估价详情物料集合 */
private List<SalesEstimateDetailMaterial> estimateDetailMaterialList;
public void setSalesEstimateId(Long salesEstimateId)
{
this.salesEstimateId = salesEstimateId;
@ -287,6 +290,14 @@ public class SalesEstimate extends BaseEntity
this.salesEstimateDetailList = salesEstimateDetailList;
}
public List<SalesEstimateDetailMaterial> getEstimateDetailMaterialList() {
return estimateDetailMaterialList;
}
public void setEstimateDetailMaterialList(List<SalesEstimateDetailMaterial> estimateDetailMaterialList) {
this.estimateDetailMaterialList = estimateDetailMaterialList;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

40
ruoyi-admin/src/main/java/com/ruoyi/sales/domain/VO/SalesEstimateDetailMaterialVo.java

@ -0,0 +1,40 @@
package com.ruoyi.sales.domain.VO;
import com.ruoyi.sales.domain.SalesEstimateDetailMaterial;
import lombok.Data;
import java.math.BigDecimal;
//物料详情子表包括form表单的数据
@Data
public class SalesEstimateDetailMaterialVo extends SalesEstimateDetailMaterial {
/** 不含税运输成本(RMB) */
private BigDecimal noTaxShippingCosts;
/** 不含税服务成本(RMB) */
private BigDecimal noTaxServiceCosts;
/** 不含税开发成本(RMB) */
private BigDecimal noTaxDevelopCosts;
/** 不含税人工成本(RMB) */
private BigDecimal noTaxLaborCosts;
/** 不含税推广成本(RMB) */
private BigDecimal noTaxPromotionalCosts;
/** 不含税业务成本(RMB) */
private BigDecimal noTaxBusinessCosts;
/** 不含税管理成本(RMB) */
private BigDecimal noTaxManagesCosts;
/** 不含税总物料成本(RMB) */
private BigDecimal noTaxMaterialCosts;
/** 不含税经营成本(RMB) */
private BigDecimal noTaxOperatingCosts;
/** 含税经营成本(RMB) */
private BigDecimal taxOperatingCosts;
}

8
ruoyi-admin/src/main/java/com/ruoyi/sales/mapper/SalesEstimateDetailMaterialMapper.java

@ -92,4 +92,12 @@ public interface SalesEstimateDetailMaterialMapper
* @return 结果
*/
List<SalesEstimateDetailMaterial> selectDetailMaterialListByEstimateDetailId(Long estimateDetailId);
/**
* 查询所有详情物料价格
*
* @return 结果
*/
List<SalesEstimateDetailMaterial> selectAllDetailMaterialList();
}

3
ruoyi-admin/src/main/java/com/ruoyi/sales/service/ISalesEstimateDetailMaterialService.java

@ -4,6 +4,7 @@ import java.util.List;
import com.ruoyi.sales.domain.SalesEstimateDetail;
import com.ruoyi.sales.domain.SalesEstimateDetailMaterial;
import com.ruoyi.sales.domain.VO.SalesEstimateDetailMaterialVo;
/**
* 销售估价详情物料价格Service接口
@ -87,5 +88,5 @@ public interface ISalesEstimateDetailMaterialService
* @param estimateDetailId 销售估价详情ID
* @return
*/
List<SalesEstimateDetailMaterial> getEstimateDetailMaterialList(Long estimateDetailId);
List<SalesEstimateDetailMaterialVo> getEstimateDetailMaterialList(Long estimateDetailId);
}

7
ruoyi-admin/src/main/java/com/ruoyi/sales/service/ISalesEstimateService.java

@ -86,4 +86,11 @@ public interface ISalesEstimateService
* @return
*/
int engineeringAddSalesEstimate(SalesEstimate salesEstimate);
/**
* 采购添加销售估价
* @param salesEstimate
* @return
*/
int purchaseAddSalesEstimate(SalesEstimate salesEstimate);
}

43
ruoyi-admin/src/main/java/com/ruoyi/sales/service/impl/SalesEstimateDetailMaterialServiceImpl.java

@ -1,10 +1,14 @@
package com.ruoyi.sales.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.sales.domain.SalesEstimateDetail;
import com.ruoyi.sales.domain.VO.SalesEstimateDetailMaterialVo;
import com.ruoyi.sales.mapper.SalesEstimateDetailMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sales.mapper.SalesEstimateDetailMaterialMapper;
@ -24,6 +28,9 @@ public class SalesEstimateDetailMaterialServiceImpl implements ISalesEstimateDet
@Autowired
private SalesEstimateDetailMaterialMapper salesEstimateDetailMaterialMapper;
@Autowired
private SalesEstimateDetailMapper salesEstimateDetailMapper;
/**
* 查询销售估价详情物料价格
*
@ -55,10 +62,42 @@ public class SalesEstimateDetailMaterialServiceImpl implements ISalesEstimateDet
* @return 销售估价详情物料价格
*/
@Override
public List<SalesEstimateDetailMaterial> getEstimateDetailMaterialList(Long estimateDetailId) {
public List<SalesEstimateDetailMaterialVo> getEstimateDetailMaterialList(Long estimateDetailId) {
// 查询物料列表
List<SalesEstimateDetailMaterial> salesEstimateDetailMaterials = salesEstimateDetailMaterialMapper.selectDetailMaterialListByEstimateDetailId(estimateDetailId);
// 查询销售估价详情的成本信息
SalesEstimateDetail salesEstimateDetail = salesEstimateDetailMapper.selectSalesEstimateDetailById(estimateDetailId);
// 创建 Vo 列表
List<SalesEstimateDetailMaterialVo> salesEstimateDetailMaterialVos = new ArrayList<>(salesEstimateDetailMaterials.size());
return salesEstimateDetailMaterialMapper.selectDetailMaterialListByEstimateDetailId(estimateDetailId);
// 遍历实体列表并构建 Vo 对象
for (SalesEstimateDetailMaterial salesEstimateDetailMaterial : salesEstimateDetailMaterials) {
SalesEstimateDetailMaterialVo vo = new SalesEstimateDetailMaterialVo();
// 手动复制公共属性,或者使用反射等工具类复制属性
BeanUtils.copyProperties(salesEstimateDetailMaterial, vo);
// 设置成本信息
setCosts(vo, salesEstimateDetail);
salesEstimateDetailMaterialVos.add(vo);
}
return salesEstimateDetailMaterialVos;
}
private void setCosts(SalesEstimateDetailMaterialVo vo, SalesEstimateDetail salesEstimateDetail) {
vo.setNoTaxMaterialCosts(salesEstimateDetail.getNoTaxMaterialCosts());
vo.setNoTaxBusinessCosts(salesEstimateDetail.getNoTaxBusinessCosts());
vo.setNoTaxDevelopCosts(salesEstimateDetail.getNoTaxDevelopCosts());
vo.setNoTaxLaborCosts(salesEstimateDetail.getNoTaxLaborCosts());
vo.setNoTaxManagesCosts(salesEstimateDetail.getNoTaxManagesCosts());
vo.setNoTaxOperatingCosts(salesEstimateDetail.getNoTaxOperatingCosts());
vo.setNoTaxPromotionalCosts(salesEstimateDetail.getNoTaxPromotionalCosts());
vo.setNoTaxServiceCosts(salesEstimateDetail.getNoTaxServiceCosts());
vo.setNoTaxShippingCosts(salesEstimateDetail.getNoTaxShippingCosts());
}
/**

54
ruoyi-admin/src/main/java/com/ruoyi/sales/service/impl/SalesEstimateServiceImpl.java

@ -8,9 +8,11 @@ import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.sales.domain.SalesEstimateDetail;
import com.ruoyi.sales.domain.SalesEstimateDetailMaterial;
import com.ruoyi.sales.domain.SalesEstimateTemplate;
import com.ruoyi.sales.domain.VO.SalesEstimateDetailVo;
import com.ruoyi.sales.mapper.SalesEstimateDetailMapper;
import com.ruoyi.sales.mapper.SalesEstimateDetailMaterialMapper;
import com.ruoyi.sales.mapper.SalesEstimateTemplateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -36,6 +38,9 @@ public class SalesEstimateServiceImpl implements ISalesEstimateService
@Autowired
private SalesEstimateDetailMapper salesEstimateDetailMapper;
@Autowired
private SalesEstimateDetailMaterialMapper estimateDetailMaterialMapper;
@Autowired
private RedisCache redisCache;
@ -218,4 +223,53 @@ public class SalesEstimateServiceImpl implements ISalesEstimateService
return salesEstimateMapper.updateSalesEstimate(salesEstimate);
}
/**
* 采购添加销售估价
*
* @param salesEstimate 销售估价
* @return 结果
*/
@Transactional(rollbackFor = Exception.class)
@Override
public int purchaseAddSalesEstimate(SalesEstimate salesEstimate) {
String loginName = ShiroUtils.getLoginName();
salesEstimate.setUpdateBy(loginName);
salesEstimate.setUpdateTime(new Date());
salesEstimate.setEstimateStatus("2");
List<SalesEstimateDetail> salesEstimateDetailList = salesEstimate.getSalesEstimateDetailList();
for (SalesEstimateDetail salesEstimateDetail : salesEstimateDetailList) {
salesEstimateDetail.setUpdateBy(loginName);
salesEstimateDetail.setUpdateTime(new Date());
int updateDetailResult = salesEstimateDetailMapper.updateSalesEstimateDetail(salesEstimateDetail);
if (updateDetailResult == 0){
throw new BusinessException("更新销售估价详情失败");
}
}
List<SalesEstimateDetailMaterial> estimateDetailMaterialList = salesEstimate.getEstimateDetailMaterialList();
boolean hasNoTaxPurchaseRmb = estimateDetailMaterialList.stream().anyMatch(item -> item.getNoTaxPurchaseRmb() == null);
if (hasNoTaxPurchaseRmb){
throw new BusinessException("存在不含税采购单价为空,请检查");
}
boolean hasTaxPurchaseRmb = estimateDetailMaterialList.stream().anyMatch(item -> item.getTaxPurchaseRmb() == null);
if (hasTaxPurchaseRmb){
throw new BusinessException("存在含税采购单价为空,请检查");
}
List<SalesEstimateDetailMaterial> tempDetailMaterialList = estimateDetailMaterialMapper.selectAllDetailMaterialList();
if (estimateDetailMaterialList.size()<tempDetailMaterialList.size()){
throw new BusinessException("请展开所有物料数据并填写采购价格");
}
for (SalesEstimateDetailMaterial salesEstimateDetailMaterial : estimateDetailMaterialList) {
salesEstimateDetailMaterial.setUpdateBy(loginName);
salesEstimateDetailMaterial.setUpdateTime(new Date());
int updateDetailMaterialResult = estimateDetailMaterialMapper.updateSalesEstimateDetailMaterial(salesEstimateDetailMaterial);
if (updateDetailMaterialResult == 0){
throw new BusinessException("更新销售估价详情物料失败");
}
}
return salesEstimateMapper.updateSalesEstimate(salesEstimate);
}
}

3
ruoyi-admin/src/main/resources/mapper/sales/SalesEstimateDetailMaterialMapper.xml

@ -45,6 +45,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectSalesEstimateDetailMaterialVo"/>
where estimate_detail_id = #{estimateDetailId}
</select>
<select id="selectAllDetailMaterialList" resultMap="SalesEstimateDetailMaterialResult">
<include refid="selectSalesEstimateDetailMaterialVo"/>
</select>
<insert id="insertSalesEstimateDetailMaterial" parameterType="SalesEstimateDetailMaterial" useGeneratedKeys="true" keyProperty="estimateDetailMaterialId">
insert into sales_estimate_detail_material

15
ruoyi-admin/src/main/resources/templates/sales/estimate/estimate.html

@ -68,6 +68,7 @@
var cancelFlag = [[${@permission.hasPermi('sales:estimate:cancel')}]];
var restoreFlag = [[${@permission.hasPermi('sales:estimate:restore')}]];
var engineeringAddFlag = [[${@permission.hasPermi('sales:estimate:engineeringAdd')}]];
var purchaseAddFlag = [[${@permission.hasPermi('sales:estimate:purchaseAdd')}]];
var estimateStatusDatas = [[${@dict.getType('estimate_status')}]];
var commonCurrencyDatas = [[${@dict.getType('sys_common_currency')}]];
@ -167,15 +168,13 @@
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.salesEstimateId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.salesEstimateId + '\')"><i class="fa fa-remove"></i>删除</a> ');
if(row.estimateStatus == '0'){
actions.push('<a class="btn btn-success btn-xs ' + engineeringAddFlag + '" href="javascript:void(0)" onclick="engineeringAdd(\'' + row.salesEstimateId + '\')"><i class="fa fa-edit"></i>添加BOM</a> ');
}
if(row.delFlag == '0'){
actions.push('<a class="btn btn-danger btn-xs ' + cancelFlag + '" href="javascript:void(0)" onclick="$.operate.cancel(\'' + row.id + '\')"><i class="fa fa-remove"></i>作废</a> ');
}else{
actions.push('<a class="btn btn-success btn-xs ' + restoreFlag + '" href="javascript:void(0)" onclick="$.operate.restore(\'' + row.id + '\')"><i class="fa fa-window-restore"></i>恢复</a> ');
if(row.estimateStatus == '1'){
actions.push('<a class="btn btn-success btn-xs ' + purchaseAddFlag + '" href="javascript:void(0)" onclick="purchaseAdd(\'' + row.salesEstimateId + '\')"><i class="fa fa-edit"></i>采购成本</a> ');
}
return actions.join('');
}
}]
@ -195,6 +194,12 @@
var url = prefix + "/engineeringAdd/" + salesEstimateId;
$.modal.open("添加BOM", url);
}
//采购 添加BOM
function purchaseAdd(salesEstimateId){
var url = prefix + "/purchaseAdd/" + salesEstimateId;
$.modal.open("采购成本", url);
}
</script>
</body>
</html>

614
ruoyi-admin/src/main/resources/templates/sales/estimate/purchaseAdd.html

@ -0,0 +1,614 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('工程新增销售估价')" />
<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-estimate-add" th:object="${salesEstimate}">
<input name="salesEstimateId" th:field="*{salesEstimateId}" type="hidden">
<div class="form-group">
<label class="col-sm-4 control-label">业务员:</label>
<div class="col-sm-8">
<input name="businessMembers" id="businessMembers" th:field="*{businessMembers}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">定价日期:</label>
<div class="col-sm-8">
<div class="input-group date">
<input name="pricingDate" th:value="${#dates.format(salesEstimate.pricingDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">客户ID:</label>
<div class="col-sm-8">
<input name="enterpriseCode" th:field="*{enterpriseCode}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">客户名称:</label>
<div class="col-sm-8">
<input name="enterpriseName" th:field="*{enterpriseName}" class="form-control" type="text" readonly>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label is-required">估价币种:</label>
<div class="col-sm-8">
<select name="commonCurrency" id="commonCurrency_add" class="form-control m-b" th:with="type=${@dict.getType('sys_common_currency')}" disabled>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" required></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label is-required">美元汇率:</label>
<div class="col-sm-8">
<div class="input-group">
<input name="usdRate" th:field="*{usdRate}" id="usdRate_add" class="form-control" type="text" required readonly>
<span class="input-group-addon">%</span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">备注信息:</label>
<div class="col-sm-8">
<input name="remark" th:field="*{remark}" class="form-control" type="text">
</div>
</div>
<div class="container">
<h4 class="form-header h4">计算</h4>
<div class="col-xs-12 form-row">
<label class=" col-sm-2">物料合计:</label><input class="col-sm-4" name="materialSum" id="materialSum_add" type="number" readonly/>
<label class=" col-sm-2">数量合计:</label><input class="col-sm-4" name="enterpriseSum" id="enterpriseSum_add" type="number" readonly/>
</div>
<div class="col-xs-12 form-row">
<label class="col-sm-2"> 不含税单价(RMB):</label><input placeholder="RMB" class="col-sm-4" name="noTaxRmb" id="noTaxRmb_add" type="number" readonly/>
<label class="col-sm-2"> 不含税总价(RMB):</label><input placeholder="RMB" class="col-sm-4" name="allNoTaxRmb" id="allNoTaxRmb_add" type="number" readonly/>
</div>
<div class="col-xs-12 form-row">
<label class="col-sm-2"> 含税单价(RMB):</label><input placeholder="RMB" class="col-sm-4" name="taxRmb" id="taxRmb_add" type="number" readonly/>
<label class="col-sm-2"> 含税总价(RMB):</label><input placeholder="RMB" class="col-sm-4" name="allTaxRmb" id="allTaxRmb_add" type="number" readonly/>
</div>
<div class="col-xs-12">
<label class="col-sm-2">不含税单价(USD):</label><input placeholder="美元" class="col-sm-4" name="noTaxDollar" id="noTaxDollar_add" type="number" readonly/>
<label class="col-sm-2">不含税总价(USD):</label><input placeholder="美元" class="col-sm-4" name="allNoTaxDollar" id="allNoTaxDollar_add" type="number" readonly/>
</div>
<div class="col-xs-12 form-row">
<label class="col-sm-2">含税单价(USD):</label><input placeholder="美元" class="col-sm-4" name="taxDollar" id="taxDollar_add" type="number" readonly/>
<label class="col-sm-2">含税总价(USD):</label><input placeholder="美元" class="col-sm-4" name="allTaxDollar" id="allTaxDollar_add" type="number" readonly/>
</div>
</div>
</form>
<div class="container">
<div class="row">
<div class="col-sm-12 select-table table-striped">
<table id="bootstrap-table"></table>
</div>
</div>
</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include::bootstrap-table-editable-js"/>
<script th:inline="javascript">
var prefix = ctx + "sales/estimate"
var materialGearPositionDatas = [[${@dict.getType('material_gear_position')}]];
var materialTypeDatas = [[${@category.getChildByCode('materialType')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var salesEstimateDetailVo = [[${salesEstimateDetailVo}]];
var salesEstimate = [[${salesEstimate}]];
$("#form-estimate-add").validate({
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
// 获取表单数据
const estimateData = $("#form-estimate-add").serializeArray().reduce((obj, item) => {
obj[item.name] = item.value;
return obj;
}, {});
//设置一个标志来跟踪任何错误
var hasError = false;
// 销售估价物料
var estimateMaterialTable = $('#bootstrap-table').bootstrapTable('getData');
// 将表数据转换成与estimateData格式一致的数组
var estimateMaterialDataList = estimateMaterialTable.map(function(item) {
// 根据实际字段名调整
return {
"estimateDetailId": item.estimateDetailId,
"noTaxDevelopCosts": null, // 初始化为 null 或 0
"noTaxShippingCosts": null,
"noTaxServiceCosts": null,
// ...其他字段
};
});
$('.form-inline[data-index]').each(function () {
var index = $(this).data('index'); // 获取数据索引
var noTaxDevelopCosts = $('#noTaxDevelopCosts' + index).val();
var noTaxShippingCosts = $('#noTaxShippingCosts' + index).val();
var noTaxServiceCosts = $('#noTaxServiceCosts' + index).val();
// 检查成本值是否为空或仅为0
if (!noTaxDevelopCosts && noTaxDevelopCosts !== '0') {
$.modal.alertWarning("开发成本不能为空,请填写第 " + (parseInt(index) + 1) + " 行的开发成本");
hasError = true;
return; // 退出循环,阻止进一步处理
}
if (!noTaxShippingCosts && noTaxShippingCosts !== '0') {
$.modal.alertWarning("运输成本不能为空,请填写第 " + (parseInt(index) + 1) + " 行的运输成本");
hasError = true;
return; // 退出循环,阻止进一步处理
}
if (!noTaxServiceCosts && noTaxServiceCosts !== '0') {
$.modal.alertWarning("服务成本不能为空,请填写第 " + (parseInt(index) + 1) + " 行的服务成本");
hasError = true;
return; // 退出循环,阻止进一步处理
}
// 更新 estimateMaterialDataList 中对应的记录
estimateMaterialDataList[index].noTaxDevelopCosts = noTaxDevelopCosts;
estimateMaterialDataList[index].noTaxShippingCosts = noTaxShippingCosts;
estimateMaterialDataList[index].noTaxServiceCosts = noTaxServiceCosts;
});
if (hasError) {
return; // 存在错误,阻止提交
}
// 在需要收集所有子表数据的地方调用此函数
var allSubData = getAllSubTablesData();
// 将表数据转换成与complaintNoticeData格式一致的数组
var childDataList = allSubData.map(function(item) {
// 根据实际字段名调整
return {
"estimateDetailMaterialId":item.estimateDetailMaterialId,
"noTaxPurchaseRmb": item.noTaxPurchaseRmb,
"taxPurchaseRmb": item.taxPurchaseRmb,
// ..其他字段
};
});
const combinedData = Object.assign({}, estimateData, {
salesEstimateDetailList: estimateMaterialDataList,
estimateDetailMaterialList: childDataList,
// ...其他字段
});
// 合并表单数据和表格数据
console.log(combinedData)
// 使用 JSON.stringify() 序列化数据
const jsonData = JSON.stringify(combinedData);
// 发送 AJAX 请求到后端接口
$.operate.saveJson(prefix + "/purchaseAdd", jsonData);
}
}
$("input[name='pricingDate']").datetimepicker({
format: "yyyy-mm-dd",
minView: "month",
autoclose: true
});
$(function() {
var options = {
url: prefix + "/getEstimateDetailList",
id:'bootstrap-table',
queryParams:queryParams,
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
modalName: "销售估价详情",
detailView: true,
onExpandRow : function(index, row, $detail) {
initChildTable(index, row, $detail);
},
columns: [
{
checkbox: true
},
{
title: '销售估价详情ID',
field: 'estimateDetailId',
visible: false
},
{
title: '料号',
field: 'materialNo',
},
{
title: '物料名称',
field: 'materialName',
},
{
title: '物料类型',
field: 'materialType',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
title: '图片地址',
field: 'materialPhotoUrl',
},
{
title: '物料单位',
field: 'materialUnit',
},
{
title: '物料品牌',
field: 'materialBrand',
},
{
title: '物料描述',
field: 'materialDescribe',
},
{
title: '加工方式',
field: 'materialProcessMethod',
formatter: function(value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
title: '料号档位',
field: 'materialGearPosition',
formatter: function(value, row, index) {
return $.table.selectDictLabel(materialGearPositionDatas, value);
}
},
{
title: '物料数量',
field: 'materialNum',
},
{
title: '不含税单价',
field: 'noTaxRmb',
},
{
title: '含税单价',
field: 'taxRmb',
},
{
title: '不含税总价',
field: 'allNoTaxRmb',
},
{
title: '含税总价',
field: 'allTaxRmb',
},
{
title: '含税单价',
field: 'taxDollar',
},
{
title: '不含税单价',
field: 'noTaxDollar',
},
{
title: '含税总价',
field: 'allTaxDollar',
},
{
title: '不含税总价',
field: 'allNoTaxDollar',
},
{
title: '入库部门',
field: 'warehouseDept',
visible:false
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="removeMaterialRow(\'' + row.materialNo + '\')"><i class="fa fa-remove"></i>删除</a> ');
return actions.join('');
}
}],
onEditableSave:function(field, row, oldValue, $el){
// 确保getTotalAmount函数存在且正确引用
getTotalAmount();
},
};
$.table.init(options);
});
initChildTable = function(index, row, $detail) {
var parentRow = row;
var childTableId = 'child_table_'+index;
$detail.html('<table id="'+childTableId+'"></table>');
$('#'+childTableId).bootstrapTable({
url: prefix + "/getEstimateDetailMaterialList",
method: 'post',
sidePagination: "server",
contentType: "application/x-www-form-urlencoded",
queryParams : {
estimateDetailId:parentRow.estimateDetailId
},
columns: [
{
title: '销售估价详情物料ID',
field: 'estimateDetailMaterialId',
visible: false
},
{
title: '销售估价详情ID',
field: 'estimateDetailId',
visible: false
},
{
title: '不含税开发成本',
field: 'noTaxDevelopCosts',
visible: false
},
{
title: '不含税运输成本',
field: 'noTaxShippingCosts',
visible: false
},
{
title: '不含税服务成本',
field: 'noTaxServiceCosts',
visible: false
},
{
title: '物料名称',
field: 'materialName',
},
{
title: '物料类型',
field: 'materialType',
formatter: function(value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{
title: '物料单位',
field: 'materialUnit',
},
{
title: '物料描述',
field: 'materialDescribe',
},
{
title: '用量',
field: 'useNum',
},
{
title: '不含税采购单价(RMB)',
field: 'noTaxPurchaseRmb',
editable: {
type: 'text',
title: '不含税单价',
validate: function (value, row, index) {
if (!value) {
return '不含税采购单价不能为空';
}
}
}
},
{
title: '含税采购单价(RMB)',
field: 'taxPurchaseRmb',
editable: {
type: 'text',
title: '含税单价',
validate: function (value, row, index) {
if (!value) {
return '含税采购单价不能为空';
}
}
}
},
{
title: '操作',
align: 'center',
formatter: function (value, row, index) {
return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="deleteRow(\'' + row.shippingDeviceId + '\')"><i class="fa fa-remove"></i>删除</a>';
}
}
],
onLoadSuccess: function(data) {
// 初始化成本数据为一个空对象
var costs = {};
// 如果 data 是一个对象,将其转换为单元素数组
if (typeof data === 'object' && !Array.isArray(data)) {
data = [data];
}
// 检查数据是否有效
if (data.length > 0 && data[0].rows && data[0].rows.length > 0) {
// 使用第一条数据
var firstRow = data[0].rows[0];
costs.noTaxDevelopCosts = firstRow.noTaxDevelopCosts || '';
costs.noTaxShippingCosts = firstRow.noTaxShippingCosts || '';
costs.noTaxServiceCosts = firstRow.noTaxServiceCosts || '';
} else {
// 如果没有数据,设置所有成本字段为空字符串
costs.noTaxDevelopCosts = '';
costs.noTaxShippingCosts = '';
costs.noTaxServiceCosts = '';
}
// 动态生成 form 表单
var formHtml = '<form class="form-inline" data-index="' + index + '">';
formHtml += '<h3>运输、服务、开发成本</h3>';
formHtml += '<div class="form-group">';
formHtml += '<label for="noTaxDevelopCosts' + index + '">不含税开发成本(RMB):</label>';
formHtml += '<input type="text" class="form-control" id="noTaxDevelopCosts' + index + '" name="noTaxDevelopCosts' + index + '" value="' + costs.noTaxDevelopCosts + '">';
formHtml += '</div>';
formHtml += '<div class="form-group">';
formHtml += '<label for="noTaxShippingCosts' + index + '">不含税运输成本(RMB):</label>';
formHtml += '<input type="text" class="form-control" id="noTaxShippingCosts' + index + '" name="noTaxShippingCosts' + index + '" value="' + costs.noTaxShippingCosts + '">';
formHtml += '</div>';
formHtml += '<div class="form-group">';
formHtml += '<label for="noTaxServiceCosts' + index + '">不含税服务成本(RMB):</label>';
formHtml += '<input type="text" class="form-control" id="noTaxServiceCosts' + index + '" name="noTaxServiceCosts' + index + '" value="' + costs.noTaxServiceCosts + '">';
formHtml += '</div>';
formHtml += '</form>';
// 将 form 表单添加到子表下面
$detail.append(formHtml);
}
});
};
function queryParams(params) {
var curParams = {
// 传递参数查询参数
salesEstimateCode: salesEstimate.salesEstimateCode
};
return curParams;
}
// 逻辑删除前端的一行数据
function removeMaterialRow(materialNo){
$("#bootstrap-table").bootstrapTable('remove', {
field: 'materialNo',
values: materialNo
})
getTotalAmount();
}
//form计算模块
function getTotalAmount(){
let getData = $('#bootstrap-table').bootstrapTable('getData');
var materialSum = 0;
var enterpriseSum = 0;
var noTaxRmb = 0;
var taxRmb = 0;
var allNoTaxRmb = 0;
var allTaxRmb = 0;
var noTaxDollar = 0;
var taxDollar = 0;
var allNoTaxDollar = 0;
var allTaxDollar = 0;
materialSum = getData.length;
enterpriseSum = getData.reduce((sum, item) => sum + (parseInt(item.materialNum) || 0), 0);
for(var i=0;i<getData.length;i++){
noTaxRmb += parseFloat(getData[i].noTaxRmb) || 0;
taxRmb += parseFloat(getData[i].taxRmb) || 0;
allNoTaxRmb += parseFloat(getData[i].allNoTaxRmb) || 0;
allTaxRmb += parseFloat(getData[i].allTaxRmb) || 0;
noTaxDollar += parseFloat(getData[i].noTaxDollar) || 0;
taxDollar += parseFloat(getData[i].taxDollar) || 0;
allNoTaxDollar += parseFloat(getData[i].allNoTaxDollar) || 0;
allTaxDollar += parseFloat(getData[i].allTaxDollar) || 0;
}
noTaxRmb = noTaxRmb.toFixed(2);
taxRmb = taxRmb.toFixed(2);
allNoTaxRmb = allNoTaxRmb.toFixed(2);
allTaxRmb = allTaxRmb.toFixed(2);
noTaxDollar = noTaxDollar.toFixed(2);
taxDollar = taxDollar.toFixed(2);
allNoTaxDollar = allNoTaxDollar.toFixed(2);
allTaxDollar = allTaxDollar.toFixed(2);
$("input[name='materialSum']").val(materialSum);
$("input[name='enterpriseSum']").val(enterpriseSum);
$("input[name='noTaxRmb']").val(noTaxRmb);
$("input[name='taxRmb']").val(taxRmb);
$("input[name='allNoTaxRmb']").val(allNoTaxRmb);
$("input[name='allTaxRmb']").val(allTaxRmb);
$("input[name='noTaxDollar']").val(noTaxDollar);
$("input[name='taxDollar']").val(taxDollar);
$("input[name='allNoTaxDollar']").val(allNoTaxDollar);
$("input[name='allTaxDollar']").val(allTaxDollar);
}
function getAllSubTablesData() {
var allSubData = [];
// 获取所有被展开的行
var parentLength = $("#bootstrap-table").bootstrapTable("getData").length;
for (let i = 0; i < parentLength; i++) {
var childTableId = "child_table_" + i;
var sonData = $('#' + childTableId).bootstrapTable("getData");
// 确保 sonData 是一个数组
if (!Array.isArray(sonData)) {
sonData = []; // 如果 sonData 不是数组,将其转换为空数组
}
// 循环获取子表中存在的行数据,每个行数据转换添加到allSubData数组中
sonData.forEach(function (item) {
item.tableId = childTableId;
allSubData.push(item);
});
}
return allSubData;
}
// $(function() {
// $('#bootstrap-table').on('load-success.bs.table', function(e, data) {
// // 页面加载成功后,遍历所有行并初始化子表
// $('#bootstrap-table').bootstrapTable('getSelections').forEach(function(row) {
// var $detail = $('#bootstrap-table').bootstrapTable('getRowDetail', row.fieldId);
// var estimateDetailId = row.estimateDetailId;
// if ($detail.length) {
// // 预加载子表数据
// $detail.bootstrapTable({
// url: prefix + "/getEstimateDetailMaterialList" + "?estimateDetailId=" + estimateDetailId,
// // 隐藏子表
// initHidden: true,
// onLoadSuccess: function() {
// // 隐藏子表
// $detail.hide();
// },
// // 子表其他配置
// });
// }
// });
// });
//
// // 重写 onExpandRow 方法
// $('#bootstrap-table').bootstrapTable({
// onExpandRow: function(index, row, $detail) {
// // 展开行时显示子表
// $detail.show();
// },
// // 其他主表配置
// });
// });
</script>
</body>
</html>
Loading…
Cancel
Save