Commit 9ac5fda2 by fengshuonan

整理字典添加条目

parent ddd35cac
...@@ -110,7 +110,7 @@ public class DictController extends BaseController { ...@@ -110,7 +110,7 @@ public class DictController extends BaseController {
if (ToolUtil.isEmpty(dictDto.getDictTypeId())) { if (ToolUtil.isEmpty(dictDto.getDictTypeId())) {
this.dictService.addDictType(dictDto); this.dictService.addDictType(dictDto);
} else { } else {
//TODO this.dictService.addDictItem(dictDto);
} }
return SUCCESS_TIP; return SUCCESS_TIP;
......
...@@ -157,16 +157,16 @@ public class Dict implements Serializable { ...@@ -157,16 +157,16 @@ public class Dict implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "Dict{" + return "Dict{" +
", dictId=" + dictId + ", dictId=" + dictId +
", pid=" + pid + ", pid=" + pid +
", name=" + name + ", name=" + name +
", code=" + code + ", code=" + code +
", description=" + description + ", description=" + description +
", sort=" + sort + ", sort=" + sort +
", createTime=" + createTime + ", createTime=" + createTime +
", updateTime=" + updateTime + ", updateTime=" + updateTime +
", createUser=" + createUser + ", createUser=" + createUser +
", updateUser=" + updateUser + ", updateUser=" + updateUser +
"}"; "}";
} }
} }
...@@ -46,6 +46,19 @@ public class DictService extends ServiceImpl<DictMapper, Dict> { ...@@ -46,6 +46,19 @@ public class DictService extends ServiceImpl<DictMapper, Dict> {
} }
/** /**
* 添加字典子类型
*/
public void addDictItem(DictDto dictDto) {
Dict dict = new Dict();
BeanUtil.copyProperties(dictDto, dict);
//字典的父级id为字典tyeId
dict.setPid(dictDto.getDictTypeId());
this.insert(dict);
}
/**
* 添加字典 * 添加字典
*/ */
@Transactional @Transactional
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<div class="container-fluid"> <div class="container-fluid">
<form id="dictForm" \@submit="submitForm"> <form id="dictForm" \@submit="submitForm">
<input value="${dictTypeId}" type="hidden" class="form-control"> <input id="dictTypeId" value="${dictTypeId}" type="hidden" class="form-control">
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
...@@ -13,15 +13,15 @@ ...@@ -13,15 +13,15 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<h5>字典名称 <span class="text-danger">*</span></h5> <h5>字典编码 <span class="text-danger">*</span></h5>
<div class="controls"> <div class="controls">
<input v-model="name" type="text" class="form-control"> <input v-model="code" type="text" class="form-control">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<h5>字典编码 <span class="text-danger">*</span></h5> <h5>字典编码对应的值 <span class="text-danger">*</span></h5>
<div class="controls"> <div class="controls">
<input v-model="code" type="text" class="form-control"> <input v-model="name" type="text" class="form-control">
</div> </div>
</div> </div>
</div> </div>
......
/** /**
* 初始化字典详情对话框 * 角色详情对话框(可用于添加和修改对话框)
*/ */
var DictInfoDlg = { var DictInfoDlg = {
count: $("#itemSize").val(), data: {
dictName: '', //字典的名称 dictTypeId: $("#dictTypeId").val(),
dictCode: '', //字典类型编码 name: "",
dictTips: '', //字典备注 code: "",
mutiString: '', //拼接字符串内容(拼接字典条目) description: "",
itemTemplate: $("#itemTemplate").html() sort: ""
};
/**
* item获取新的id
*/
DictInfoDlg.newId = function () {
if(this.count == undefined){
this.count = 0;
} }
this.count = this.count + 1;
return "dictItem" + this.count;
}; };
/** /**
...@@ -29,90 +19,58 @@ DictInfoDlg.close = function () { ...@@ -29,90 +19,58 @@ DictInfoDlg.close = function () {
}; };
/** /**
* 添加条目 * 验证表单
*/ */
DictInfoDlg.addItem = function () { DictInfoDlg.validateForm = function () {
$("#itemsArea").append(this.itemTemplate);
$("#dictItem").attr("id", this.newId());
};
/** var data = DictInfoDlg.data;
* 删除item
*/
DictInfoDlg.deleteItem = function (event) {
var obj = Feng.eventParseObject(event);
obj = obj.is('button') ? obj : obj.parent();
obj.parent().parent().remove();
};
/** if (!data.name) {
* 清除为空的item Dom return "请输入字典名称";
*/ }
DictInfoDlg.clearNullDom = function(){ if (!(data.code)) {
$("[name='dictItem']").each(function(){ return "请输入字典编码";
var num = $(this).find("[name='itemNum']").val(); }
var name = $(this).find("[name='itemName']").val();
if(num == '' || name == ''){
$(this).remove();
}
});
};
/** return true;
* 收集添加字典的数据
*/
DictInfoDlg.collectData = function () {
this.clearNullDom();
var mutiString = "";
$("[name='dictItem']").each(function(){
var code = $(this).find("[name='itemCode']").val();
var name = $(this).find("[name='itemName']").val();
var num = $(this).find("[name='itemNum']").val();
mutiString = mutiString + (code + ":" + name + ":"+ num+";");
});
this.dictName = $("#dictName").val();
this.dictCode = $("#dictCode").val();
this.dictTips = $("#dictTips").val();
this.mutiString = mutiString;
}; };
/** /**
* 提交添加字典 * 提交添加角色
*/ */
DictInfoDlg.addSubmit = function () { DictInfoDlg.addSubmit = function () {
this.collectData();
//提交信息
var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) { var ajax = new $ax(Feng.ctxPath + "/dict/add", function (data) {
Feng.success("添加成功!"); parent.Feng.success("添加成功!");
window.parent.Dict.table.refresh(); window.parent.Dict.table.refresh();
DictInfoDlg.close(); DictInfoDlg.close();
}, function (data) { }, function (data) {
Feng.error("添加失败!" + data.responseJSON.message + "!"); parent.Feng.error("添加失败!" + data.responseJSON.message + "!");
}); });
ajax.set('dictName',this.dictName); ajax.set(this.data);
ajax.set('dictCode',this.dictCode);
ajax.set('dictTips',this.dictTips);
ajax.set('dictValues',this.mutiString);
ajax.start(); ajax.start();
}; };
/** $(function () {
* 提交修改
*/ DictInfoDlg.app = new Vue({
DictInfoDlg.editSubmit = function () { el: '#dictForm',
this.collectData(); data: DictInfoDlg.data,
var ajax = new $ax(Feng.ctxPath + "/dict/update", function (data) { methods: {
Feng.success("修改成功!"); submitForm: function (e) {
window.parent.Dict.table.refresh(); e.preventDefault();
DictInfoDlg.close(); },
}, function (data) { ensure: function () {
Feng.error("修改失败!" + data.responseJSON.message + "!"); var result = DictInfoDlg.validateForm();
if (result === true) {
DictInfoDlg.addSubmit();
} else {
Feng.alert(result);
}
},
close: function () {
DictInfoDlg.close();
}
}
}); });
ajax.set('dictId',$("#dictId").val());
ajax.set('dictName',this.dictName); });
ajax.set('dictCode',this.dictCode);
ajax.set('dictTips',this.dictTips);
ajax.set('dictValues',this.mutiString);
ajax.start();
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment