代码生成模板支持主子表
This commit is contained in:
@ -308,7 +308,7 @@ function createMenuItem(dataUrl, menuName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//日志打印封装处理
|
||||
// 日志打印封装处理
|
||||
var log = {
|
||||
log: function(msg) {
|
||||
console.log(msg);
|
||||
@ -324,7 +324,7 @@ var log = {
|
||||
}
|
||||
};
|
||||
|
||||
//本地缓存处理
|
||||
// 本地缓存处理
|
||||
var storage = {
|
||||
set: function(key, value) {
|
||||
window.localStorage.setItem(key, value);
|
||||
@ -340,6 +340,52 @@ var storage = {
|
||||
}
|
||||
};
|
||||
|
||||
// 主子表操作封装处理
|
||||
var sub = {
|
||||
editColumn: function() {
|
||||
var count = $("#" + table.options.id).bootstrapTable('getData').length;
|
||||
var params = new Array();
|
||||
for (var dataIndex = 0; dataIndex <= count; dataIndex++) {
|
||||
var columns = $('#' + table.options.id + ' tr[data-index="' + dataIndex + '"] td');
|
||||
var obj = new Object();
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
var inputValue = $(columns[i]).find('input');
|
||||
var selectValue = $(columns[i]).find('select');
|
||||
var key = table.options.columns[i].field;
|
||||
if ($.common.isNotEmpty(inputValue.val())) {
|
||||
obj[key] = inputValue.val();
|
||||
} else if ($.common.isNotEmpty(selectValue.val())) {
|
||||
obj[key] = selectValue.val();
|
||||
} else {
|
||||
obj[key] = "";
|
||||
}
|
||||
}
|
||||
params.push({ index: dataIndex, row: obj });
|
||||
}
|
||||
$("#" + table.options.id).bootstrapTable("updateRow", params);
|
||||
},
|
||||
delColumn: function(column) {
|
||||
var subColumn = $.common.isEmpty(column) ? "index" : column;
|
||||
var ids = $.table.selectColumns(subColumn);
|
||||
if (ids.length == 0) {
|
||||
$.modal.alertWarning("请至少选择一条记录");
|
||||
return;
|
||||
}
|
||||
$("#" + table.options.id).bootstrapTable('remove', { field: subColumn, values: ids });
|
||||
if($.common.equals("index", subColumn))
|
||||
{
|
||||
sub.resetIndex();
|
||||
}
|
||||
},
|
||||
resetIndex: function(msg) {
|
||||
var count = $("#" + table.options.id).bootstrapTable('getData').length;
|
||||
for (var index = 0; index <= count; index++) {
|
||||
// 重置序号
|
||||
$("#" + table.options.id).bootstrapTable('updateRow', { index: index, row: { index: parseInt(index + 1) } })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** 设置全局ajax处理 */
|
||||
$.ajaxSetup({
|
||||
complete: function(XMLHttpRequest, textStatus) {
|
||||
|
@ -1523,6 +1523,20 @@ var table = {
|
||||
});
|
||||
return json;
|
||||
},
|
||||
// 数据字典转下拉框
|
||||
dictToSelect: function(datas, value, name) {
|
||||
var actions = [];
|
||||
actions.push($.common.sprintf("<select class='form-control' name='%s'>", name));
|
||||
$.each(datas, function(index, dict) {
|
||||
actions.push($.common.sprintf("<option value='%s'", dict.dictValue));
|
||||
if (dict.dictValue == ('' + value)) {
|
||||
actions.push(' selected');
|
||||
}
|
||||
actions.push($.common.sprintf(">%s</option>", dict.dictLabel));
|
||||
});
|
||||
actions.push('</select>');
|
||||
return actions.join('');
|
||||
},
|
||||
// 获取obj对象长度
|
||||
getLength: function(obj) {
|
||||
var count = 0;
|
||||
|
@ -63,8 +63,8 @@
|
||||
<h4 class="form-header h4">商品数据</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<button type="button" class="btn btn-white btn-sm" onclick="return addColumn()"><i class="fa fa-plus"> 增加</i></button>
|
||||
<button type="button" class="btn btn-white btn-sm" onclick="return delColumn()"><i class="fa fa-minus"> 删除</i></button>
|
||||
<button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
|
||||
<button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
|
||||
<div class="col-sm-12 select-table table-striped">
|
||||
<table id="bootstrap-table"></table>
|
||||
</div>
|
||||
@ -150,28 +150,9 @@
|
||||
autoclose: true
|
||||
});
|
||||
|
||||
function addColumn(){
|
||||
function addColumn() {
|
||||
var count = $("#" + table.options.id).bootstrapTable('getData').length;
|
||||
|
||||
var params = new Array();
|
||||
for (var dataIndex = 0; dataIndex <= count; dataIndex++) {
|
||||
var columns = $('#' + table.options.id + ' tr[data-index="' + dataIndex + '"] td');
|
||||
var obj = new Object();
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
var inputValue = $(columns[i]).find('input');
|
||||
var selectValue = $(columns[i]).find('select');
|
||||
var key = table.options.columns[i].field;
|
||||
if ($.common.isNotEmpty(inputValue.val())) {
|
||||
obj[key] = inputValue.val();
|
||||
} else if ($.common.isNotEmpty(selectValue.val())) {
|
||||
obj[key] = selectValue.val();
|
||||
} else {
|
||||
obj[key] = "";
|
||||
}
|
||||
}
|
||||
params.push({ index: dataIndex, row: obj });
|
||||
}
|
||||
$("#" + table.options.id).bootstrapTable("updateRow", params);
|
||||
sub.editColumn();
|
||||
|
||||
$("#" + table.options.id).bootstrapTable('insertRow', {
|
||||
index: count,
|
||||
@ -182,35 +163,14 @@
|
||||
price: "",
|
||||
type: "",
|
||||
}
|
||||
})
|
||||
resetIndex();
|
||||
}
|
||||
|
||||
function delColumn(){
|
||||
var ids = $.table.selectColumns("index");
|
||||
if (ids.length == 0) {
|
||||
$.modal.alertWarning("请至少选择一条记录");
|
||||
return;
|
||||
}
|
||||
$("#" + table.options.id).bootstrapTable('remove', {
|
||||
field: 'index',
|
||||
values: ids
|
||||
})
|
||||
resetIndex();
|
||||
}
|
||||
|
||||
function resetIndex() {
|
||||
var count = $("#" + table.options.id).bootstrapTable('getData').length;
|
||||
for (var index = 0; index <= count; index++) {
|
||||
// 重置序号
|
||||
$("#" + table.options.id).bootstrapTable('updateRow', { index: index, row: { index: parseInt(index + 1) } })
|
||||
}
|
||||
});
|
||||
sub.resetIndex();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!-- 查询方式 -->
|
||||
<!-- 商品类型 -->
|
||||
<script id="goodsTypeTpl" type="text/x-jquery-tmpl">
|
||||
<div>
|
||||
<select class='form-control' name='goods[${index}].type'>
|
||||
|
Reference in New Issue
Block a user