236 lines
7.4 KiB
HTML
236 lines
7.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>更新字典</title>
|
|
<link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" />
|
|
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
|
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
|
</head>
|
|
<body>
|
|
<style>
|
|
.mainBox {
|
|
width: auto !important;
|
|
}
|
|
.layui-tab .layui-table-cell {
|
|
overflow:visible !important;
|
|
}
|
|
.layui-table-body ,.layui-table-box{
|
|
overflow:visible !important;
|
|
}
|
|
.layui-tab .layui-form-select dl {
|
|
max-height: 190px;
|
|
}
|
|
.layui-table-body .layui-table-col-special:last-child {
|
|
width: 100% !important;
|
|
border-right: 1px solid #eee !important;
|
|
}
|
|
xm-select {
|
|
min-height: 38px;
|
|
line-height: 38px;
|
|
}
|
|
xm-select .xm-body .xm-option .xm-option-icon {
|
|
font-size: 18px !important;
|
|
}
|
|
</style>
|
|
|
|
<form class="layui-form" action="" lay-filter="create-dict-form">
|
|
|
|
<div class="mainBox">
|
|
<div class="main-container">
|
|
|
|
<div class="layui-form-item">
|
|
<div class="layui-inline">
|
|
<label class="layui-form-label" style="width:auto">字典名</label>
|
|
<div class="layui-input-inline">
|
|
<input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入英文字母组合">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<!-- 字段属性 -->
|
|
<table id="column-table" lay-filter="column-table"></table>
|
|
|
|
<script type="text/html" id="column-toolbar">
|
|
<button type="button" class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
|
|
<i class="layui-icon layui-icon-add-1"></i>新增
|
|
</button>
|
|
<button type="button" class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
|
|
<i class="layui-icon layui-icon-delete"></i>删除
|
|
</button>
|
|
</script>
|
|
|
|
<script type="text/html" id="col-value">
|
|
<input type="text" name="value[{{ d.LAY_INDEX-1 }}][value]" placeholder="值" autocomplete="off" class="layui-input" value="{{ d.value }}">
|
|
<input type="hidden" name="value[{{ d.LAY_INDEX-1 }}][_field_id]" value="{{ d._field_id }}">
|
|
</script>
|
|
|
|
<script type="text/html" id="col-name">
|
|
<input type="text" name="value[{{ d.LAY_INDEX-1 }}][name]" placeholder="标题" autocomplete="off" class="layui-input" value="{{ d.name }}">
|
|
</script>
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="bottom">
|
|
<div class="button-container">
|
|
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
|
|
lay-filter="save">
|
|
提交
|
|
</button>
|
|
<button type="reset" class="pear-btn pear-btn-md">
|
|
重置
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<script src="/app/admin/component/layui/layui.js"></script>
|
|
<script src="/app/admin/component/pear/pear.js"></script>
|
|
<script>
|
|
|
|
const DICT_NAME = layui.url().search.name;
|
|
const UPDATE_API = '/app/admin/dict/update';
|
|
const SELECT_API = '/app/admin/dict/get/' + DICT_NAME;
|
|
|
|
// 字段设置
|
|
layui.use(['table', 'common', 'popup'], function () {
|
|
|
|
let table = layui.table;
|
|
let common = layui.common;
|
|
let $ = layui.$;
|
|
let cols = [
|
|
{
|
|
type: 'checkbox',
|
|
width: 50,
|
|
},
|
|
{
|
|
title: '值',
|
|
field: 'value',
|
|
templet: '#col-value'
|
|
},
|
|
{
|
|
title: '标题',
|
|
field: 'name',
|
|
templet: '#col-name',
|
|
}
|
|
];
|
|
|
|
$('input[name="name"]').val(DICT_NAME);
|
|
|
|
window._field_id = 0;
|
|
let data = [];
|
|
$.ajax({
|
|
url: SELECT_API,
|
|
dataType: 'json',
|
|
async: false,
|
|
success: function (res) {
|
|
data = res.data;
|
|
layui.each(data, function (k, v) {
|
|
data[k]['_field_id'] = _field_id++;
|
|
})
|
|
}
|
|
});
|
|
|
|
table.render({
|
|
elem: '#column-table',
|
|
cols: [cols],
|
|
data: data,
|
|
cellMinWidth: 40,
|
|
skin: 'line',
|
|
size: 'lg',
|
|
limit: 10000,
|
|
page: false,
|
|
toolbar: '#column-toolbar',
|
|
defaultToolbar: [],
|
|
});
|
|
|
|
table.on('toolbar(column-table)', function(obj) {
|
|
if (obj.event === 'add') {
|
|
add();
|
|
} else if (obj.event === 'batchRemove') {
|
|
batchRemove(obj);
|
|
}
|
|
});
|
|
|
|
let add = function() {
|
|
syncTableData();
|
|
let options = table.getData('column-table');
|
|
options.push({
|
|
_field_id: _field_id++,
|
|
value : '',
|
|
name: '',
|
|
});
|
|
table.reloadData('column-table', {data:options});
|
|
}
|
|
|
|
let batchRemove = function(obj) {
|
|
var checkIds = common.checkField(obj,'_field_id');
|
|
if (checkIds === "") return layui.popup.warning('未选中数据');
|
|
let data = table.getData('column-table');
|
|
let newData = [];
|
|
let deleteIds = checkIds.split(',');
|
|
layui.each(data, function (index, item) {
|
|
if (deleteIds.indexOf(item._field_id + '') === -1) {
|
|
newData.push(item);
|
|
}
|
|
});
|
|
table.reloadData('column-table', {data: newData})
|
|
}
|
|
|
|
});
|
|
|
|
layui.use(['form', 'jquery', 'popup'], function () {
|
|
//提交事件
|
|
layui.form.on('submit(save)', function () {
|
|
let data = layui.form.val('create-dict-form');
|
|
layui.jquery.ajax({
|
|
url: UPDATE_API,
|
|
type: 'POST',
|
|
dateType: 'json',
|
|
data: data,
|
|
success: function (res) {
|
|
if (res.code) {
|
|
return layui.popup.failure(res.msg);
|
|
}
|
|
return layui.popup.success('操作成功', function () {
|
|
parent.refreshTable();
|
|
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
|
});
|
|
}
|
|
});
|
|
return false;
|
|
});
|
|
});
|
|
|
|
window.syncTableData = function () {
|
|
let tableData = layui.form.val('create-dict-form');
|
|
let columnTableData = [];
|
|
let len = Object.keys(tableData).length;
|
|
let id = 0;
|
|
window._key_id = 0;
|
|
while (id < len) {
|
|
// column data
|
|
if (typeof tableData['value[' + id + '][_field_id]'] !== 'undefined') {
|
|
columnTableData.push({
|
|
_field_id: tableData['value[' + id + '][_field_id]'],
|
|
name : tableData['value[' + id + '][name]'],
|
|
value: tableData['value[' + id + '][value]'],
|
|
});
|
|
}
|
|
_key_id++;
|
|
id++;
|
|
}
|
|
layui.table.reloadData('column-table', {data: columnTableData});
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|