提交 2a1ca080 编写于 作者: doc_wei's avatar doc_wei

【ERP】采购订单子单据表格拆分完成

上级 6021d7c5
//计算总价
// 计算总价
function calculatedTotalPrice() {
var allPrice = 0, taxLastMoneyPrice = 0;
$.each(initTableChooseUtil.getDataRowIndex('productList'), function(i, item) {
//获取行坐标
var rowNum = item;
//获取数量
var rkNum = parseInt(isNull($("#rkNum" + rowNum).val()) ? 0 : $("#rkNum" + rowNum).val());
//获取单价
var unitPrice = parseFloat(isNull($("#unitPrice" + rowNum).val()) ? 0 : $("#unitPrice" + rowNum).val());
//获取税率
var taxRate = parseFloat(isNull($("#taxRate" + rowNum).val()) ? 0 : $("#taxRate" + rowNum).val()) / 100;
if('rkNum' === showTdByEdit){//数量
$.each(initTableChooseUtil.getDataRowIndex('productList'), function (i, item) {
// 获取行坐标
var thisRowKey = item;
// 获取数量
var rkNum = parseInt(isNull($("#rkNum" + thisRowKey).val()) ? 0 : $("#rkNum" + thisRowKey).val());
// 获取单价
var unitPrice = parseFloat(isNull($("#unitPrice" + thisRowKey).val()) ? 0 : $("#unitPrice" + thisRowKey).val());
// 获取税率
var taxRate = parseFloat(isNull($("#taxRate" + thisRowKey).val()) ? 0 : $("#taxRate" + thisRowKey).val()) / 100;
if ('rkNum' === showTdByEdit) {//数量
//输出金额
$("#amountOfMoney" + rowNum).val((rkNum * unitPrice).toFixed(2));
$("#amountOfMoney" + thisRowKey).val((rkNum * unitPrice).toFixed(2));
//输出税额=数量*税率*单价
$("#taxMoney" + rowNum).val((rkNum * taxRate * unitPrice).toFixed(2));
$("#taxMoney" + thisRowKey).val((rkNum * taxRate * unitPrice).toFixed(2));
//输出含税单价
$("#taxUnitPrice" + rowNum).val((taxRate * unitPrice + unitPrice).toFixed(2));
$("#taxUnitPrice" + thisRowKey).val((taxRate * unitPrice + unitPrice).toFixed(2));
//输出合计价税
$("#taxLastMoney" + rowNum).val((rkNum * taxRate * unitPrice + rkNum * unitPrice).toFixed(2));
}else if('unitPrice' === showTdByEdit){//单价
$("#taxLastMoney" + thisRowKey).val((rkNum * taxRate * unitPrice + rkNum * unitPrice).toFixed(2));
} else if ('unitPrice' === showTdByEdit) {//单价
//输出金额
$("#amountOfMoney" + rowNum).val((rkNum * unitPrice).toFixed(2));
$("#amountOfMoney" + thisRowKey).val((rkNum * unitPrice).toFixed(2));
//输出税额=数量*税率*单价
$("#taxMoney" + rowNum).val((rkNum * taxRate * unitPrice).toFixed(2));
$("#taxMoney" + thisRowKey).val((rkNum * taxRate * unitPrice).toFixed(2));
//输出含税单价
$("#taxUnitPrice" + rowNum).val((taxRate * unitPrice + unitPrice).toFixed(2));
$("#taxUnitPrice" + thisRowKey).val((taxRate * unitPrice + unitPrice).toFixed(2));
//输出合计价税
$("#taxLastMoney" + rowNum).val((rkNum * taxRate * unitPrice + rkNum * unitPrice).toFixed(2));
}else if('amountOfMoney' === showTdByEdit){//金额
$("#taxLastMoney" + thisRowKey).val((rkNum * taxRate * unitPrice + rkNum * unitPrice).toFixed(2));
} else if ('amountOfMoney' === showTdByEdit) {//金额
//获取金额
var amountOfMoney = parseFloat(isNull($("#amountOfMoney" + rowNum).val()) ? 0 : $("#amountOfMoney" + rowNum).val());
var amountOfMoney = parseFloat(isNull($("#amountOfMoney" + thisRowKey).val()) ? 0 : $("#amountOfMoney" + thisRowKey).val());
//输出税额=金额*税率
$("#taxMoney" + rowNum).val((amountOfMoney * taxRate).toFixed(2));
$("#taxMoney" + thisRowKey).val((amountOfMoney * taxRate).toFixed(2));
//输出单价,含税单价,合计价税
if(rkNum != 0){
$("#unitPrice" + rowNum).val((amountOfMoney / rkNum).toFixed(2));
$("#taxUnitPrice" + rowNum).val((amountOfMoney / rkNum * taxRate + amountOfMoney / rkNum).toFixed(2));
$("#taxLastMoney" + rowNum).val((amountOfMoney * taxRate + amountOfMoney).toFixed(2));
if (rkNum != 0) {
$("#unitPrice" + thisRowKey).val((amountOfMoney / rkNum).toFixed(2));
$("#taxUnitPrice" + thisRowKey).val((amountOfMoney / rkNum * taxRate + amountOfMoney / rkNum).toFixed(2));
$("#taxLastMoney" + thisRowKey).val((amountOfMoney * taxRate + amountOfMoney).toFixed(2));
} else {
$("#unitPrice" + rowNum).val('0.00');
$("#taxUnitPrice" + rowNum).val('0.00');
$("#taxLastMoney" + rowNum).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
$("#taxUnitPrice" + thisRowKey).val('0.00');
$("#taxLastMoney" + thisRowKey).val('0.00');
}
}else if('taxRate' === showTdByEdit){//税率
} else if ('taxRate' === showTdByEdit) {//税率
//输出金额
$("#amountOfMoney" + rowNum).val((rkNum * unitPrice).toFixed(2));
$("#amountOfMoney" + thisRowKey).val((rkNum * unitPrice).toFixed(2));
//输出税额=数量*税率*单价
$("#taxMoney" + rowNum).val((rkNum * taxRate * unitPrice).toFixed(2));
$("#taxMoney" + thisRowKey).val((rkNum * taxRate * unitPrice).toFixed(2));
//输出含税单价
$("#taxUnitPrice" + rowNum).val((taxRate * unitPrice + unitPrice).toFixed(2));
$("#taxUnitPrice" + thisRowKey).val((taxRate * unitPrice + unitPrice).toFixed(2));
//输出合计价税
$("#taxLastMoney" + rowNum).val((rkNum * taxRate * unitPrice + rkNum * unitPrice).toFixed(2));
}else if('taxMoney' === showTdByEdit){//税额
$("#taxLastMoney" + thisRowKey).val((rkNum * taxRate * unitPrice + rkNum * unitPrice).toFixed(2));
} else if ('taxMoney' === showTdByEdit) {//税额
//获取税额
var taxMoney = parseFloat(isNull($("#taxMoney" + rowNum).val()) ? 0 : $("#taxMoney" + rowNum).val());
var taxMoney = parseFloat(isNull($("#taxMoney" + thisRowKey).val()) ? 0 : $("#taxMoney" + thisRowKey).val());
//输出金额
$("#amountOfMoney" + rowNum).val((rkNum * unitPrice).toFixed(2));
$("#amountOfMoney" + thisRowKey).val((rkNum * unitPrice).toFixed(2));
//获取金额
var amountOfMoney = parseFloat(isNull($("#amountOfMoney" + rowNum).val()) ? 0 : $("#amountOfMoney" + rowNum).val());
var amountOfMoney = parseFloat(isNull($("#amountOfMoney" + thisRowKey).val()) ? 0 : $("#amountOfMoney" + thisRowKey).val());
//输出含税单价,合计价税,税率
if(rkNum != 0){
if(unitPrice != 0){
$("#taxUnitPrice" + rowNum).val((taxMoney / rkNum + unitPrice).toFixed(2));
$("#taxRate" + rowNum).val((taxMoney / unitPrice / rkNum * 100).toFixed(2));
if (rkNum != 0) {
if (unitPrice != 0) {
$("#taxUnitPrice" + thisRowKey).val((taxMoney / rkNum + unitPrice).toFixed(2));
$("#taxRate" + thisRowKey).val((taxMoney / unitPrice / rkNum * 100).toFixed(2));
} else {
$("#taxUnitPrice" + rowNum).val('0.00');
$("#taxRate" + rowNum).val('0.00');
$("#unitPrice" + rowNum).val('0.00');
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxUnitPrice" + thisRowKey).val('0.00');
$("#taxRate" + thisRowKey).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
}
if(amountOfMoney != 0){
$("#taxLastMoney" + rowNum).val((amountOfMoney + taxMoney).toFixed(2));
if (amountOfMoney != 0) {
$("#taxLastMoney" + thisRowKey).val((amountOfMoney + taxMoney).toFixed(2));
} else {
$("#taxLastMoney" + rowNum).val('0.00');
$("#taxLastMoney" + thisRowKey).val('0.00');
}
} else {
$("#taxUnitPrice" + rowNum).val('0.00');
$("#taxLastMoney" + rowNum).val('0.00');
$("#taxUnitPrice" + thisRowKey).val('0.00');
$("#taxLastMoney" + thisRowKey).val('0.00');
}
}else if('taxUnitPrice' === showTdByEdit){//含税单价
} else if ('taxUnitPrice' === showTdByEdit) {//含税单价
//获取含税单价
var taxUnitPrice = parseFloat(isNull($("#taxUnitPrice" + rowNum).val()) ? 0 : $("#taxUnitPrice" + rowNum).val());
if(taxUnitPrice == 0){
$("#taxLastMoney" + rowNum).val('0.00');
$("#unitPrice" + rowNum).val('0.00');
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxMoney" + rowNum).val('0.00');
$("#taxRate" + rowNum).val('0.00');
var taxUnitPrice = parseFloat(isNull($("#taxUnitPrice" + thisRowKey).val()) ? 0 : $("#taxUnitPrice" + thisRowKey).val());
if (taxUnitPrice == 0) {
$("#taxLastMoney" + thisRowKey).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
$("#taxMoney" + thisRowKey).val('0.00');
$("#taxRate" + thisRowKey).val('0.00');
return;
}
//输出合计价税,税额,税率
if(unitPrice != 0){
if(rkNum != 0 ){
$("#taxLastMoney" + rowNum).val((taxUnitPrice * rkNum).toFixed(2));
$("#amountOfMoney" + rowNum).val((unitPrice * rowNum).toFixed(2));
if (unitPrice != 0) {
if (rkNum != 0) {
$("#taxLastMoney" + thisRowKey).val((taxUnitPrice * rkNum).toFixed(2));
$("#amountOfMoney" + thisRowKey).val((unitPrice * thisRowKey).toFixed(2));
} else {
$("#taxLastMoney" + rowNum).val('0.00');
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxLastMoney" + thisRowKey).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
}
$("#taxMoney" + rowNum).val((taxUnitPrice - unitPrice).toFixed(2));
$("#taxRate" + rowNum).val(((taxUnitPrice / unitPrice - 1) * 100).toFixed(2));
$("#taxMoney" + thisRowKey).val((taxUnitPrice - unitPrice).toFixed(2));
$("#taxRate" + thisRowKey).val(((taxUnitPrice / unitPrice - 1) * 100).toFixed(2));
} else {
$("#taxLastMoney" + rowNum).val('0.00');
$("#unitPrice" + rowNum).val('0.00');
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxMoney" + rowNum).val('0.00');
$("#taxRate" + rowNum).val('0.00');
$("#taxLastMoney" + thisRowKey).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
$("#taxMoney" + thisRowKey).val('0.00');
$("#taxRate" + thisRowKey).val('0.00');
}
}else if('taxLastMoney' === showTdByEdit){//合计价税
} else if ('taxLastMoney' === showTdByEdit) {//合计价税
//获取合计价税
var taxLastMoney = parseFloat(isNull($("#taxLastMoney" + rowNum).val()) ? 0 : $("#taxLastMoney" + rowNum).val());
if(taxLastMoney == 0){
$("#taxUnitPrice" + rowNum).val('0.00');
$("#unitPrice" + rowNum).val('0.00');
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxMoney" + rowNum).val('0.00');
$("#taxRate" + rowNum).val('0.00');
var taxLastMoney = parseFloat(isNull($("#taxLastMoney" + thisRowKey).val()) ? 0 : $("#taxLastMoney" + thisRowKey).val());
if (taxLastMoney == 0) {
$("#taxUnitPrice" + thisRowKey).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
$("#taxMoney" + thisRowKey).val('0.00');
$("#taxRate" + thisRowKey).val('0.00');
return;
}
//输出含税单价,税额,税率
if(rkNum != 0 ){
if(unitPrice != 0){
$("#taxUnitPrice" + rowNum).val((taxLastMoney / rkNum).toFixed(2));
$("#taxMoney" + rowNum).val((taxLastMoney / rkNum - unitPrice).toFixed(2));
$("#taxRate" + rowNum).val(((taxLastMoney / rkNum / unitPrice - 1 ) * 100).toFixed(2));
$("#amountOfMoney" + rowNum).val((unitPrice * rkNum).toFixed(2));
if (rkNum != 0) {
if (unitPrice != 0) {
$("#taxUnitPrice" + thisRowKey).val((taxLastMoney / rkNum).toFixed(2));
$("#taxMoney" + thisRowKey).val((taxLastMoney / rkNum - unitPrice).toFixed(2));
$("#taxRate" + thisRowKey).val(((taxLastMoney / rkNum / unitPrice - 1) * 100).toFixed(2));
$("#amountOfMoney" + thisRowKey).val((unitPrice * rkNum).toFixed(2));
} else {
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxMoney" + rowNum).val('0.00');
$("#taxUnitPrice" + rowNum).val('0.00');
$("#unitPrice" + rowNum).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
$("#taxMoney" + thisRowKey).val('0.00');
$("#taxUnitPrice" + thisRowKey).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
}
} else {
$("#taxUnitPrice" + rowNum).val('0.00');
$("#unitPrice" + rowNum).val('0.00');
$("#amountOfMoney" + rowNum).val('0.00');
$("#taxMoney" + rowNum).val('0.00');
$("#taxRate" + rowNum).val('0.00');
$("#taxUnitPrice" + thisRowKey).val('0.00');
$("#unitPrice" + thisRowKey).val('0.00');
$("#amountOfMoney" + thisRowKey).val('0.00');
$("#taxMoney" + thisRowKey).val('0.00');
$("#taxRate" + thisRowKey).val('0.00');
}
}
allPrice += parseFloat($("#amountOfMoney" + rowNum).val());
taxLastMoneyPrice += parseFloat($("#taxLastMoney" + rowNum).val());
allPrice += parseFloat($("#amountOfMoney" + thisRowKey).val());
taxLastMoneyPrice += parseFloat($("#taxLastMoney" + thisRowKey).val());
});
$("#allPrice").html(allPrice.toFixed(2));
$("#taxLastMoneyPrice").html(taxLastMoneyPrice.toFixed(2));
//优惠率计算
var discount = parseFloat(isNull($("#discount").val()) ? 0 : $("#discount").val());
//输出优惠金额
......
/**
* 根据规格加载库存
*
* @param rowNum 表格行坐标
* @param depotId 仓库id
*/
function loadTockByDepotAndMUnit(rowNum, depotId){
//获取当前选中的规格
var chooseUnitId = $("#unitId" + rowNum).val();
//当规格不为空时
if(!isNull(chooseUnitId)){
function loadTockByDepotAndMUnit(rowNum, depotId) {
// 获取当前选中的规格
var chooseUnitId = $("#mUnitId" + rowNum).val();
// 当规格不为空时
if (!isNull(chooseUnitId)) {
// 获取库存
getStockAjaxByDepotAndNormsId(chooseUnitId, depotId, function (json) {
var currentTock = 0;
if(!isNull(json.bean)){
if (!isNull(json.bean)) {
currentTock = json.bean.currentTock;
}
$("#currentTock" + rowNum).html(currentTock);
});
} else {
//否则重置库存为空
// 否则重置库存为空
$("#currentTock" + rowNum).html("");
}
}
/**
* 根据仓库id加载表格中已经选择的商品规格的库存
*
* @param depotId 仓库id
*/
function loadMaterialDepotStockByDepotId(depotId){
function loadMaterialDepotStockByDepotId(depotId) {
var rowTr = $("#useTable tr");
var normsIds = new Array();
var normsIdsNum = new Array();
$.each(rowTr, function(i, item) {
$.each(rowTr, function (i, item) {
// 获取行坐标
var rowNum = $(item).attr("trcusid").replace("tr", "");
var unitId = $("#unitId" + rowNum).val();
if(!isNull(unitId)){
if (!isNull(unitId)) {
normsIds.push(unitId);
normsIdsNum.push(rowNum);
}
});
if(normsIds.length == 0){
if (normsIds.length == 0) {
return;
}
// 获取库存
getStockAjaxByDepotAndNormsId(normsIds.join(','), depotId, function (json) {
if(normsIds.length == 1){
if (normsIds.length == 1) {
$("#currentTock" + normsIdsNum[0]).html(json.bean.currentTock);
} else {
$.each(normsIdsNum, function(i, item) {
$.each(normsIdsNum, function (i, item) {
$("#currentTock" + normsIdsNum[i]).html(json.rows[i].currentTock);
});
}
......@@ -60,8 +62,12 @@ function loadMaterialDepotStockByDepotId(depotId){
* @param depotId 仓库id,可为空
* @param callBack 回调函数
*/
function getStockAjaxByDepotAndNormsId(normsIds, depotId, callBack){
AjaxPostUtil.request({url: flowableBasePath + "material011", params: {depotId: depotId, normsIds: normsIds}, type: 'json', method: "POST", callback: function(json) {
function getStockAjaxByDepotAndNormsId(normsIds, depotId, callBack) {
var params = {
depotId: depotId,
normsIds: normsIds
};
AjaxPostUtil.request({url: flowableBasePath + "material011", params: params, type: 'json', method: "POST", callback: function(json) {
if(typeof(callBack) == "function") {
callBack(json);
}
......
......@@ -4,8 +4,6 @@ var productionMation = {};
// 根据那一列的值进行变化,默认根据数量
var showTdByEdit = 'rkNum';
// 表格的序号
var rowNum = 1;
// 兼容动态表单
var layedit, form;
......@@ -61,12 +59,12 @@ layui.config({
{id: 'taxLastMoney', title: '合计价税', formType: 'input', width: '80', className: 'change-input taxLastMoney', verify: 'required|money'},
{id: 'remark', title: '备注', formType: 'input', width: '100'}
],
deleteRowCallback: function (trId) {
allChooseProduct[trId] = undefined;
deleteRowCallback: function (trcusid) {
delete allChooseProduct[trcusid];
// 计算价格
calculatedTotalPrice();
},
addRowCallback: function (rowIndexStr) {
addRowCallback: function (trcusid) {
// 设置根据某列变化的颜色
$("." + showTdByEdit).parent().css({'background-color': '#e6e6e6'});
},
......@@ -80,26 +78,27 @@ layui.config({
// 商品规格加载变化事件
form.on('select(selectUnitProperty)', function(data) {
var thisRowValue = data.value;
var thisRowNum = data.elem.id.replace("unitId", "");//获取当前行
var thisRowKey = data.elem.id.replace("mUnitId", "").toString();
// 当前当前行选中的商品信息
if(!isNull(thisRowValue) && thisRowValue != '请选择') {
var product = allChooseProduct["tr" + thisRowNum.toString()];
$.each(product.unitList, function(j, bean) {
if(thisRowValue == bean.id){//获取规格
//获取当前行数量
var rkNum = parseInt($("#rkNum" + thisRowNum).val());
$("#unitPrice" + thisRowNum).val(bean.estimatePurchasePrice.toFixed(2));//单价
$("#amountOfMoney" + thisRowNum).val((rkNum * parseFloat(bean.estimatePurchasePrice)).toFixed(2));//金额
if (!isNull(thisRowValue)) {
var product = allChooseProduct["tr" + thisRowKey];
$.each(product.unitList, function (j, bean) {
if (thisRowValue == bean.id) {
var rkNum = parseInt($("#rkNum" + thisRowKey).val());
// 设置单价和金额
$("#unitPrice" + thisRowKey).val(bean.estimatePurchasePrice.toFixed(2));
$("#amountOfMoney" + thisRowKey).val((rkNum * parseFloat(bean.estimatePurchasePrice)).toFixed(2));
return false;
}
});
} else {
$("#unitPrice" + thisRowNum).val("0.00");//重置单价为空
$("#amountOfMoney" + thisRowNum).val("0.00");//重置金额为空
// 重置单价以及金额为空
$("#unitPrice" + thisRowKey).val("0.00");
$("#amountOfMoney" + thisRowKey).val("0.00");
}
// 加载库存
loadTockByDepotAndMUnit(thisRowNum, "");
loadTockByDepotAndMUnit(thisRowKey, "");
// 计算价格
calculatedTotalPrice();
});
......@@ -130,48 +129,31 @@ layui.config({
return false;
});
function saveData(subType, approvalId){
//获取已选商品数据
var rowTr = $("#useTable tr");
if(rowTr.length == 0) {
winui.window.msg('请选择商品.', {icon: 2, time: 2000});
return false;
}
var tableData = new Array();
var noError = false; //循环遍历表格数据时,是否有其他错误信息
$.each(rowTr, function(i, item) {
function saveData(subType, approvalId) {
var dataList = initTableChooseUtil.getDataList('productList');
var noError = false;
var tableData = [];
$.each(dataList, function(i, item) {
//获取行编号
var rowNum = $(item).attr("trcusid").replace("tr", "");
//表格数量对象
var rkNum = $("#rkNum" + rowNum);
if(parseInt(rkNum.val()) == 0) {
rkNum.addClass("layui-form-danger");
rkNum.focus();
var thisRowKey = item["trcusid"].replace("tr", "");
if (parseInt(item.rkNum) == 0) {
$("#rkNum" + thisRowKey).addClass("layui-form-danger");
$("#rkNum" + thisRowKey).focus();
winui.window.msg('数量不能为0', {icon: 2, time: 2000});
noError = true;
return false;
}
//商品对象
var product = allChooseProduct["tr" + rowNum.toString()];
if(inTableDataArrayByAssetarId(product.productId, $("#unitId" + rowNum).val(), tableData)) {
var product = allChooseProduct["tr" + thisRowKey];
if (inTableDataArrayByAssetarId(product.productId, item.mUnitId, tableData)) {
winui.window.msg('一张单中不允许出现相同单位的商品信息.', {icon: 2, time: 2000});
noError = true;
return false;
}
var row = {
materialId: product.productId,
mUnitId: $("#unitId" + rowNum).val(),
rkNum: rkNum.val(),
unitPrice: $("#unitPrice" + rowNum).val(),
taxRate: $("#taxRate" + rowNum).val(),
taxMoney: $("#taxMoney" + rowNum).val(),
taxUnitPrice: $("#taxUnitPrice" + rowNum).val(),
taxLastMoney: $("#taxLastMoney" + rowNum).val(),
remark: $("#remark" + rowNum).val()
};
tableData.push(row);
item["materialId"] = product.productId;
tableData.push(item);
});
if(noError) {
if (noError) {
return false;
}
......@@ -200,69 +182,63 @@ layui.config({
// 供应商选择
$("body").on("click", "#supplierNameSel", function (e) {
sysSupplierUtil.openSysSupplierChoosePage(function (supplierMation){
sysSupplierUtil.openSysSupplierChoosePage(function (supplierMation) {
$("#supplierName").val(supplierMation.supplierName);
});
});
//商品选择
// 商品选择
$("body").on("click", ".chooseProductBtn", function (e) {
var trId = $(this).parent().parent().attr("trcusid");
erpOrderUtil.openMaterialChooseChoosePage(function (chooseProductMation) {
//获取表格行号
var thisRowNum = trId.replace("tr", "");
//商品赋值
// 获取表格行号
var thisRowKey = trId.replace("tr", "");
// 商品赋值
allChooseProduct[trId] = chooseProductMation;
//表格商品名称赋值
$("#materialId" + thisRowNum.toString()).val(allChooseProduct[trId].productName + "(" + allChooseProduct[trId].productModel + ")");
//表格单位赋值
$("#unitId" + thisRowNum.toString()).html(getDataUseHandlebars(selOption, {rows: allChooseProduct[trId].unitList}));
// 表格商品名称赋值
$("#materialId" + thisRowKey.toString()).val(chooseProductMation.productName + "(" + chooseProductMation.productModel + ")");
// 表格单位赋值
$("#mUnitId" + thisRowKey.toString()).html(getDataUseHandlebars(selOption, {rows: chooseProductMation.unitList}));
form.render('select');
//计算价格
calculatedTotalPrice();
});
});
//生产计划单选择
// 生产计划单选择
$("body").on("click", "#productionOrderSel", function (e) {
_openNewWindows({
url: "../../tpl/erpProduction/erpProductionNoSuccessChoose.html",
title: "选择生产计划单",
pageId: "erpProductionNoSuccessChoose",
area: ['90vw', '90vh'],
callBack: function(refreshCode){
callBack: function(refreshCode) {
$("#productionOrder").val(productionMation.defaultNumber);
//移除之前填写的所有行
var checkRow = $("#useTable input[type='checkbox'][name='tableCheckRow']");
$.each(checkRow, function(i, item) {
//删除allChooseProduct已选择的商品信息
var trId = $(item).parent().parent().attr("trcusid");
allChooseProduct[trId] = undefined;
//移除界面上的信息
$(item).parent().parent().remove();
});
$.each(productionMation.norms, function(i, item){
addRow();
//将规格所属的商品信息加入到对象中存储
allChooseProduct["tr" + (rowNum - 1)] = item.product;
//单位回显
$("#unitId" + (rowNum - 1)).html(getDataUseHandlebars(selOption, {rows: item.product.unitList}));
$("#unitId" + (rowNum - 1)).val(item.normsId);
//商品回显
$("#materialId" + (rowNum - 1)).val(item.product.productName + "(" + item.product.productModel + ")");
$("#currentTock" + (rowNum - 1)).html(item.currentTock);//库存回显
$("#rkNum" + (rowNum - 1)).val(item.needNum);
$("#unitPrice" + (rowNum - 1)).val(item.unitPrice.toFixed(2));
$("#amountOfMoney" + (rowNum - 1)).val(item.allPrice.toFixed(2));
$("#taxRate" + (rowNum - 1)).val(item.taxRate.toFixed(2));
$("#taxMoney" + (rowNum - 1)).val(item.taxMoney.toFixed(2));
$("#taxUnitPrice" + (rowNum - 1)).val(item.taxUnitPrice.toFixed(2));
$("#taxLastMoney" + (rowNum - 1)).val(item.taxLastMoney.toFixed(2));
initTableChooseUtil.deleteAllRow('productList');
$.each(productionMation.norms, function(i, item) {
var params = {
"materialId": item.product.productName + "(" + item.product.productModel + ")",
"mUnitId": {
"html": getDataUseHandlebars(selOption, {rows: item.product.unitList}),
"value": item.normsId
},
"currentTock": item.currentTock,
"rkNum": item.needNum,
"unitPrice": item.unitPrice.toFixed(2),
"amountOfMoney": item.allPrice.toFixed(2),
"taxRate": item.taxRate.toFixed(2),
"taxMoney": item.taxMoney.toFixed(2),
"taxUnitPrice": item.taxUnitPrice.toFixed(2),
"taxLastMoney": item.taxLastMoney.toFixed(2)
};
var trcusid = initTableChooseUtil.resetData('productList', params);
// 将规格所属的商品信息加入到对象中存储
allChooseProduct[trcusid] = item.product;
});
//渲染
// 渲染
form.render();
//计算价格
// 计算价格
calculatedTotalPrice();
}});
});
......
......@@ -42,32 +42,7 @@
<div class="layui-form-item layui-col-xs12">
<label class="layui-form-label">列表项<i class="red">*</i></label>
<div class="layui-input-block" id="productList">
<!--<div class="winui-toolbar">
<div class="winui-tool" style="text-align: left;">
<button id="addRow" class="winui-toolbtn" type="button"><i class="fa fa-plus" aria-hidden="true"></i>新增行</button>
<button id="deleteRow" class="winui-toolbtn" type="button"><i class="fa fa-trash-o" aria-hidden="true"></i>删除行</button>
</div>
</div>
<table class="layui-table">
<thead>
<tr>
<th style="width: 30px;"></th>
<th style="width: 150px;">商品(型号)</th>
<th style="width: 50px;">单位</th>
<th style="width: 80px;">库存</th>
<th style="width: 80px;">数量</th>
<th style="width: 80px;">单价</th>
<th style="width: 80px;">金额</th>
<th style="width: 80px;">税率(%)</th>
<th style="width: 80px;">税额</th>
<th style="width: 80px;">含税单价</th>
<th style="width: 80px;">合计价税</th>
<th style="min-width: 100px;">备注</th>
</tr>
</thead>
<tbody id="useTable" class="insurance-table">
</tbody>
</table>-->
</div>
</div>
<div class="layui-form-item layui-col-xs4">
......@@ -148,27 +123,6 @@
</form>
</div>
<!-- usetableTemplate -->
<script type="text/x-handlebars-template" id="usetableTemplate">
<tr trcusid="{{trId}}">
<td><input type="checkbox" rowId="{{id}}" lay-filter="checkboxProperty" name="tableCheckRow"/></td>
<td>
<input type="text" id="{{materialId}}" name="{{materialId}}" placeholder="请选择商品" class="layui-input" readonly="readonly"/>
<i class="fa fa-plus-circle input-icon chooseProductBtn" style="top: 12px;"></i>
</td>
<td><select id="{{unitId}}" lay-filter="selectUnitProperty" lay-search win-verify="required"></select></td>
<td id="{{currentTock}}"></td>
<td><input type="text" class="layui-input change-input rkNum" value="1" id="{{rkNum}}" win-verify="required|number"/></td>
<td><input type="text" class="layui-input change-input unitPrice" id="{{unitPrice}}" win-verify="required|money"/></td>
<td><input type="text" class="layui-input change-input amountOfMoney" id="{{amountOfMoney}}" win-verify="required|money"/></td>
<td><input type="text" class="layui-input change-input taxRate" value="0.00" id="{{taxRate}}" win-verify="required|double"/></td>
<td><input type="text" class="layui-input change-input taxMoney" id="{{taxMoney}}" win-verify="required|money"/></td>
<td><input type="text" class="layui-input change-input taxUnitPrice" id="{{taxUnitPrice}}" win-verify="required|money"/></td>
<td><input type="text" class="layui-input change-input taxLastMoney" id="{{taxLastMoney}}" win-verify="required|money"/></td>
<td><input type="text" class="layui-input" id="{{remark}}"/></td>
</tr>
</script>
<script src="../../assets/lib/layui/layui.js"></script>
<script src="../../assets/lib/layui/custom.js"></script>
<script src="../../js/erpcommon/calculatePrice.js"></script>
......
......@@ -17,8 +17,8 @@ var initTableChooseUtil = {
// value: '默认值',
// valueKey: '回显时要展示数据里面的那个key',
// layFilter: '可以方便指定监听事件'}
deleteRowCallback: function () {trId}, // 删除行之后的回调函数
addRowCallback: function (rowIndexStr) {}, // 新增行之后的回调函数
deleteRowCallback: function () {trcusid}, // 删除行之后的回调函数
addRowCallback: function (trcusid) {}, // 新增行之后的回调函数
form: null, // form表单对象
}, // 表格参数数据
......@@ -67,32 +67,33 @@ var initTableChooseUtil = {
/**
* 初始化点击事件
*
* @param id
* @param tableDivId 表格外层div的id
*/
initEvent: function (id) {
initEvent: function (tableDivId) {
// 新增行
$("body").on("click", "#addRow" + id, function() {
var pointBtnBoxId = $(this).attr("id").replace("addRow", "");
initTableChooseUtil.addRow(pointBtnBoxId);
$("body").on("click", "#addRow" + tableDivId, function() {
var tableDivId = $(this).attr("id").replace("addRow", "");
initTableChooseUtil.addRow(tableDivId);
});
// 删除行
$("body").on("click", "#deleteRow" + id, function() {
var pointBtnBoxId = $(this).attr("id").replace("addRow", "");
initTableChooseUtil.deleteRow(pointBtnBoxId);
$("body").on("click", "#deleteRow" + tableDivId, function() {
var tableDivId = $(this).attr("id").replace("deleteRow", "");
initTableChooseUtil.deleteRow(tableDivId);
});
},
/**
* 新增行
*
* @param id
* @param tableDivId 表格外层div的id
*/
addRow: function (id) {
addRow: function (tableDivId) {
// 获取配置
var options = initTableChooseUtil.setting[id];
var rowIndexStr = id + options.indexRow.toString();
var tbodyStr = '<tr trcusid="tr' + rowIndexStr + '"><td><input type="checkbox" rowId="row' + rowIndexStr + '" name="tableCheckRow"/></td>';
var options = initTableChooseUtil.setting[tableDivId];
var rowIndexStr = tableDivId + options.indexRow.toString();
var trcusid = 'tr' + rowIndexStr;
var tbodyStr = '<tr trcusid="' + trcusid + '"><td><input type="checkbox" rowId="row' + rowIndexStr + '" name="tableCheckRow"/></td>';
$.each(options.cols, function (i, item) {
var tdId = item.id + rowIndexStr;
var value = isNull(item.value) ? "" : item.value;
......@@ -110,27 +111,29 @@ var initTableChooseUtil = {
}
});
tbodyStr += '</tr>';
$("#table" + id).append(tbodyStr);
$("#table" + tableDivId).append(tbodyStr);
options.form.render();
options.indexRow = options.indexRow + 1;
initTableChooseUtil.setting[id] = options;
if(typeof(initTableChooseUtil.addRowCallback) == "function") {
initTableChooseUtil.addRowCallback(rowIndexStr);
initTableChooseUtil.setting[tableDivId] = options;
if(typeof(options.addRowCallback) == "function") {
options.addRowCallback(trcusid);
}
return trcusid;
},
/**
* 删除行
*
* @param id
* @param tableDivId 表格外层div的id
*/
deleteRow: function (id) {
var checkRow = $("#table" + id + " input[type='checkbox'][name='tableCheckRow']:checked");
deleteRow: function (tableDivId) {
var checkRow = $("#table" + tableDivId + " input[type='checkbox'][name='tableCheckRow']:checked");
if (checkRow.length > 0) {
var options = initTableChooseUtil.setting[tableDivId];
$.each(checkRow, function (i, item) {
var trId = $(item).parent().parent().attr("trcusid");
if (typeof (initTableChooseUtil.deleteRowCallback) == "function") {
initTableChooseUtil.deleteRowCallback(trId);
var trcusid = $(item).parent().parent().attr("trcusid");
if (typeof (options.deleteRowCallback) == "function") {
options.deleteRowCallback(trcusid);
}
// 移除界面上的信息
$(item).parent().parent().remove();
......@@ -140,20 +143,40 @@ var initTableChooseUtil = {
}
},
/**
* 删除所有行
*
* @param tableDivId 表格外层div的id
*/
deleteAllRow: function (tableDivId) {
var trRow = $("#table" + tableDivId + " tr");
var options = initTableChooseUtil.setting[tableDivId];
$.each(trRow, function (i, item) {
var trId = $(item).attr("trcusid");
if (typeof (options.deleteRowCallback) == "function") {
options.deleteRowCallback(trId);
}
// 移除界面上的信息
$(item).remove();
});
},
/**
* 获取数据
*
* @param id
* @param tableDivId 表格外层div的id
*/
getDataList: function (id) {
getDataList: function (tableDivId) {
// 获取配置
var options = initTableChooseUtil.setting[id];
var options = initTableChooseUtil.setting[tableDivId];
var result = [];
var rowTr = $("#table" + id + " tr");
var rowTr = $("#table" + tableDivId + " tr");
$.each(rowTr, function (i, item) {
var trId = $(item).attr("trcusid");
var rowIndexStr = trId.replace("tr", "");
var row = {};
var trcusid = $(item).attr("trcusid");
var rowIndexStr = trcusid.replace("tr", "");
var row = {
"trcusid": trcusid
};
$.each(options.cols, function (j, bean) {
var tdId = bean.id + rowIndexStr;
var value = "";
......@@ -174,18 +197,75 @@ var initTableChooseUtil = {
/**
* 获取指定表格每一行的rowIndex
*
* @param id
* @param tableDivId 表格外层div的id
*/
getDataRowIndex: function (id) {
getDataRowIndex: function (tableDivId) {
// 获取配置
var result = [];
var rowTr = $("#table" + id + " tr");
var rowTr = $("#table" + tableDivId + " tr");
$.each(rowTr, function (i, item) {
var trId = $(item).attr("trcusid");
var rowIndexStr = trId.replace("tr", "");
result.push(rowIndexStr);
var trcusid = $(item).attr("trcusid");
var thisRowKey = trcusid.replace("tr", "");
result.push(thisRowKey);
});
return result;
},
/**
* 重置数据
*
* @param tableDivId 表格外层div的id
* @param data 数据集合[]
*/
resetDataList: function (tableDivId, data) {
// 清空数据
initTableChooseUtil.deleteAllRow(tableDivId);
// 获取配置
var options = initTableChooseUtil.setting[tableDivId];
$.each(data, function (i, item) {
var trcusid = initTableChooseUtil.addRow(tableDivId);
initTableChooseUtil.setCols(options.cols, item, trcusid);
});
},
/**
* 重置单条数据
*
* @param tableDivId 表格外层div的id
* @param data 数据对象{}
*/
resetData: function (tableDivId, data) {
// 获取配置
var options = initTableChooseUtil.setting[tableDivId];
var trcusid = initTableChooseUtil.addRow(tableDivId);
initTableChooseUtil.setCols(options.cols, data, trcusid);
return trcusid;
},
/**
* 设置每一列的值
*
* @param cols 列集合
* @param data 数据对象{}
* @param trcusid 行id
*/
setCols: function (cols, data, trcusid) {
var rowIndexStr = trcusid.replace("tr", "");
$.each(cols, function (j, bean) {
var value = data[bean.id];
var tdId = bean.id + rowIndexStr;
var formType = bean.formType;
if (formType == 'input') {
$("#" + tdId).val(value);
} else if (formType == 'chooseInput') {
$("#" + tdId).val(value);
} else if (formType == 'select') {
$("#" + tdId).html(value["html"]);
$("#" + tdId).val(value["value"]);
} else if (formType == 'detail') {
$("#" + tdId).html(value);
}
});
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册