|
|
@ -90,6 +90,9 @@ |
|
|
|
<script th:inline="javascript"> |
|
|
|
var prefix = ctx + "system/baseExpense" |
|
|
|
$("#form-baseExpense-add").validate({focusCleanup: true}); |
|
|
|
var costTypeDatas = [[${@category.getChildByCode('costType')}]]; |
|
|
|
var $table = $("#bootstrap-sub-table-expense"); |
|
|
|
var costTypes; |
|
|
|
$(function() { |
|
|
|
$.ajax({ |
|
|
|
url: prefix + "/getId", |
|
|
@ -103,8 +106,9 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
var $table = $("#bootstrap-sub-table-expense"); |
|
|
|
// 假设此函数返回供应商列表 |
|
|
|
|
|
|
|
}); |
|
|
|
//获取子表信息 |
|
|
|
$(function() { |
|
|
|
var options = { |
|
|
@ -114,15 +118,23 @@ |
|
|
|
model: "报销单数据", |
|
|
|
columns: [ |
|
|
|
{checkbox: true}, |
|
|
|
{title: '主键',field: '',visible: false, |
|
|
|
{title: '主键',field: 'index',align: 'center',visible: false, |
|
|
|
formatter: function (value, row, index) { |
|
|
|
return index; |
|
|
|
} |
|
|
|
}, |
|
|
|
{title: '报销单分项子表',field: 'expenseChildId',visible: false}, |
|
|
|
{title: '关联报销单号',field: 'quoteId',visible: false}, |
|
|
|
{title: '成本类型',field: 'costType',}, |
|
|
|
{title: '成本小类',field: 'costSmallType',}, |
|
|
|
{title: '成本类型',field: 'costType', |
|
|
|
formatter:function (value, row, index) { |
|
|
|
return costTypeFormatter(value,row,index); |
|
|
|
} |
|
|
|
}, |
|
|
|
{title: '成本小类',field:'costSmallType', |
|
|
|
formatter:function(value, row, index){ |
|
|
|
return getCostSmallType(value,row,index) |
|
|
|
} |
|
|
|
}, |
|
|
|
{title: '用途',field: 'purpose',editable:{type:'text',options:{maxlength:100}}}, |
|
|
|
{title: '金额',field: 'amounts',editable: {type:'text',options:{maxlength:100}}}, |
|
|
|
{title: '报销时间',field: 'expenseTime',editable:{type:'date'}}, |
|
|
@ -132,7 +144,7 @@ |
|
|
|
{title: '操作', align: 'center', |
|
|
|
formatter: function (value, row, index) { |
|
|
|
var actions = []; |
|
|
|
actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="removeRow(\'' + row.index + '\')"><i class="fa fa-remove"></i>删除</a> '); |
|
|
|
actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="removeRow(\'' + index + '\')"><i class="fa fa-remove"></i>删除</a> '); |
|
|
|
return actions.join(''); |
|
|
|
} |
|
|
|
} |
|
|
@ -145,31 +157,87 @@ |
|
|
|
index:1, |
|
|
|
row: { |
|
|
|
expenseChildId:'', |
|
|
|
costType: "<select name='costType' class='form-control'>"+ "<option value=''>所有</option>" + "</select>", |
|
|
|
costSmallType:"<select name='costSmallType' class='form-control'>"+ "\"<option value=''>所有</option>\"" +"</select>", |
|
|
|
purpose:'<input name="purpose" class="form-control" type="text">' , |
|
|
|
amounts: '<input name="amounts" class="form-control" type="text">', |
|
|
|
expenseTime: '<div class="input-group date">\n' + |
|
|
|
'<input name="expenseTime" class="form-control" placeholder="yyyy-MM-dd" type="date"></div>', |
|
|
|
evectionCode:'<input name="evectionCode" class="form-control" type="text">' , |
|
|
|
purcahseCode:'<input name="purcahseCode" class="form-control" type="text">', |
|
|
|
outsourceCode: '<input name="outsourceCode" class="form-control" type="text">', |
|
|
|
costType: "", |
|
|
|
costSmallType:"", |
|
|
|
purpose:'' , |
|
|
|
amounts: '', |
|
|
|
expenseTime: '', |
|
|
|
evectionCode:'' , |
|
|
|
purcahseCode:'', |
|
|
|
outsourceCode: '', |
|
|
|
} |
|
|
|
}) |
|
|
|
layer.close(index); |
|
|
|
} |
|
|
|
/* 删除指定表格行 */ |
|
|
|
function removeRow(id){ |
|
|
|
$table.bootstrapTable('remove', { |
|
|
|
field: 'id', |
|
|
|
values: id |
|
|
|
}) |
|
|
|
} |
|
|
|
function removeRow(index){$table.bootstrapTable('remove', {field: 'index',values: index})}; |
|
|
|
function submitHandler() { |
|
|
|
if ($.validate.form()) { |
|
|
|
$.operate.save(prefix + "/add", $('#form-baseExpense-add').serialize()); |
|
|
|
var formData = $('#form-baseExpense-add').serializeArray(); |
|
|
|
var tableData = $table.bootstrapTable('getData'); |
|
|
|
var rows = tableData.length; |
|
|
|
if(rows==0){ |
|
|
|
$.modal.alertWarning("子表数据不能为空!"); |
|
|
|
}else{ |
|
|
|
formData.push({"name": "expenseAccountChildList", "value": tableData}); |
|
|
|
var jsonData = $.common.formDataToJson(formData); |
|
|
|
$.operate.saveJson(prefix + "/add", jsonData); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 列中获取成本类型的下拉改变数据 |
|
|
|
function onCostTypeChange(selectElement, rowIndex) { |
|
|
|
var newSupplierId = $(selectElement).val(); |
|
|
|
var tableData = $table.bootstrapTable('getData'); |
|
|
|
var newRow = tableData[rowIndex]; // 获取当前行数据 |
|
|
|
newRow.costType = newSupplierId; // 更新供应商ID |
|
|
|
// 重新渲染成本小类的设备名称列 |
|
|
|
// 更新行数据 |
|
|
|
$table.bootstrapTable('updateRow', {index: rowIndex, row: newRow}); |
|
|
|
} |
|
|
|
|
|
|
|
// 自定义供应商名称列的格式化函数 |
|
|
|
function costTypeFormatter(value, row, index) { |
|
|
|
var selectHtml = '<select class="form-control" onchange="onCostTypeChange(this, ' + index + ')">'; |
|
|
|
costTypeDatas.forEach(function (child) { |
|
|
|
selectHtml += '<option value="' + child.code + '"' + (value === child.code ? ' selected' : '') + '>' + child.name + '</option>'; |
|
|
|
}); |
|
|
|
selectHtml += '</select>'; |
|
|
|
return selectHtml; |
|
|
|
} |
|
|
|
|
|
|
|
// 自定义设备名称列的格式化函数,依赖于供应商列的选择 |
|
|
|
function getCostSmallType(value, row, index) { |
|
|
|
var selectHtml = '<select class="form-control" onchange="onCostSmallTypeChange(this, ' + index + ')">'; |
|
|
|
// 假设此函数根据供应商ID返回设备列表 |
|
|
|
var costSamllTypes = []; |
|
|
|
$.ajax({ |
|
|
|
url: ctx + 'system/category/getChildCode', |
|
|
|
type: 'post', |
|
|
|
data: {code: row.costType}, |
|
|
|
async: false, |
|
|
|
success: function (result) { |
|
|
|
console.log(result); |
|
|
|
costSamllTypes = result; |
|
|
|
} |
|
|
|
}); |
|
|
|
if (costSamllTypes) { |
|
|
|
costSamllTypes.forEach(function (child) { |
|
|
|
selectHtml += '<option value="' + child.code + '"' + (value === child.code ? ' selected' : '') + '>' + child.name + '</option>'; |
|
|
|
}); |
|
|
|
selectHtml += '</select>'; |
|
|
|
return selectHtml; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function onCostSmallTypeChange(selectElement, rowIndex) { |
|
|
|
var newCostSmallType = $(selectElement).val(); |
|
|
|
var tableData = $table.bootstrapTable('getData'); |
|
|
|
var newRow = tableData[rowIndex]; // 获取当前行数据 |
|
|
|
newRow.costSmallType = newCostSmallType; |
|
|
|
// 重新渲染当前行的设备名称列 |
|
|
|
// 更新行数据 |
|
|
|
$table.bootstrapTable('updateRow', {index: rowIndex, row: newRow}); |
|
|
|
} |
|
|
|
</script> |
|
|
|
</body> |
|
|
|
</html> |