You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
4.4 KiB
JavaScript

layui.define(['index', 'api'], function (exports) {
var $ = layui.$, admin = layui.admin;
var obj = {
addTr: function (listTableCols) {
var html = ``;
for (var key in listTableCols) {
if (listTableCols.hasOwnProperty(key)) {
var element = listTableCols[key];
if (element.toolbar) {
html += `<td data-field="${element.field}" align="${element.align ? element.align : 'left'}" data-off="true" class="layui-table-col-special">
<div class="layui-table-cell">
<span class="cell-opr save-cell" lay-event="add" data-tips="新增" onmouseover="showToolTips(this)"></span>
<span class="cell-opr delete-cell" lay-event="cancel" data-tips="取消" onmouseover="showToolTips(this)"></span>
</div></td>`;
} else {
if (element.hide) {
html += ``;
} else {
html += `<td data-field="${element.field}" data-key="333-0-${key}" align="${element.align ? element.align : 'left'}" class="add-${element.field}">
<div class="layui-table-cell">
<input type="text" name="${element.field}" required lay-verify="required" data-tips="请填写${element.title}" value="" autocomplete="off" class="layui-input ${element.field}">
</div>
</td>`;
}
}
}
}
return html;
},
addFormFiled: function (listTableCols) {
var addField = {};
for (const key in listTableCols) {
if (listTableCols.hasOwnProperty(key)) {
const element = listTableCols[key];
if (!element.toolbar) {
if (element.hide) {
} else {
var id = $(`.layui-table .add-${element.field} .${element.field}`);
if (!$(id).val()) {
showToolTips($(id));
return false
}
addField[element.field] = $(id).val();
}
}
}
}
return addField;
},
editTr: function (listTableCols, data) {
var html = ``;
for (var key in listTableCols) {
if (listTableCols.hasOwnProperty(key)) {
var element = listTableCols[key];
if (element.toolbar) {
html += `<td data-field="${element.field}" align="${element.align ? element.align : 'left'}" data-off="true" class="layui-table-col-special">
<div class="layui-table-cell">
<span class="cell-opr save-cell" lay-event="save" data-tips="编辑" onmouseover="showToolTips(this)"></span>
<span class="cell-opr delete-cell" lay-event="cancel" data-tips="取消" onmouseover="showToolTips(this)"></span>
</div></td>`;
} else {
if (element.hide) {
html += `
<input type="text" name="${element.field}" data-key="222-0-${key}" class="display-none" required lay-verify="required" value="${data[element.field]}" class="edit-${element.field}">
`;
} else {
html += `<td data-field="${element.field}" data-key="222-0-${key}" align="${element.align ? element.align : 'left'}" class="edit-${element.field}">
<div class="layui-table-cell">
<input type="text" name="${element.field}" required lay-verify="required" data-tips="请填写${element.title}" value="${data[element.field]}" autocomplete="off" class="layui-input ${element.field}">
</div>
</td>`;
}
}
}
}
return html;
},
editFormFiled: function (listTableCols, data) {
var editField = {};
var id = data.id;
for (var key in listTableCols) {
if (listTableCols.hasOwnProperty(key)) {
var element = listTableCols[key];
if (!element.toolbar) {
if (element.hide) {
editField[element.field] = data[element.field];
} else {
var id = $(`.layui-table .edit-${element.field} .${element.field}`);
if (!$(id).val()) {
showToolTips($(id));
return false
}
editField[element.field] = $(id).val();
}
}
}
}
return editField;
}
}
exports('dynamicTr', obj);
});