Commit c2d9aa73 authored by 骆瑛's avatar 骆瑛

修改数据字典编辑新增重复

parent cd65df1b
...@@ -23,4 +23,7 @@ export default { ...@@ -23,4 +23,7 @@ export default {
getallanditems() { getallanditems() {
return api.get(u('getallanditems')) return api.get(u('getallanditems'))
}, },
list(paras) {
return api.post(u('list'), paras)
},
} }
\ No newline at end of file
...@@ -260,10 +260,12 @@ export default { ...@@ -260,10 +260,12 @@ export default {
}, },
async loadDictionary() { async loadDictionary() {
let r = await api.getallanditems(); let r = await api.getallanditems();
this.dictionaryItems = r.result.filter((u) => { if (r.result.length > 0) {
return u.items && u.items.length > 0; this.dictionaryItems = r.result.filter((u) => {
}); return u.items && u.items.length > 0;
this.completeList = this.dictionaryItems; });
this.completeList = this.dictionaryItems;
}
}, },
handleSearch(v) { handleSearch(v) {
if (v == "") { if (v == "") {
...@@ -281,30 +283,17 @@ export default { ...@@ -281,30 +283,17 @@ export default {
}, },
introduceBtn() { introduceBtn() {
if (this.dictionaryId != "") { if (this.dictionaryId != "") {
// console.log(this.dictionaryId);
let p = this.completeList.filter((v) => { let p = this.completeList.filter((v) => {
return v.code == this.dictionaryId; return v.code == this.dictionaryId;
}); });
if (p.items && p.items.length > 0) { if (p[0].items && p[0].items.length > 0) {
p.items.map((u) => { p[0].items.map((u) => {
delete u.id; delete u.id;
delete u.upId; delete u.upId;
this.entity.items.push(u); this.entity.items.push(u);
}); });
this.completeValue = "";
} }
this.completeList.map((item, index) => {
if (item.code == this.dictionaryId) {
// this.replceList.push(item);
// item.items.map((element) => {
// this.parentList.push(element);
// });
this.completeList.splice(index, 1);
}
// this.parentList.forEach((u) => {
// u.parentCode = this.dictionaryId;
// });
});
// console.log(this.parentList);
} }
}, },
changeName(row, index) { changeName(row, index) {
...@@ -325,32 +314,6 @@ export default { ...@@ -325,32 +314,6 @@ export default {
}, },
remove(row, index) { remove(row, index) {
this.entity.items.splice(index, 1); this.entity.items.splice(index, 1);
// console.log(this.replceList);
// if (this.parentList.length > 0) {
// var nameCode = "";
// this.parentList.map((p) => {
// this.entity.items.map((r, index) => {
// if (p.parentCode != r.code) {
// nameCode = r.code;
// }
// console.log(r);
// });
// });
// }
// this.parentList.map((team, index) => {
// if (team.parentCode == nameCode) {
// this.parentList.splice(index, 1);
// }
// });
// debugger;
// this.replceList.map((k) => {
// if (nameCode == k.code) {
// console.log(k);
// this.completeList.push(k);
// }
// });
// }
// console.log(this.completeList);
}, },
async setColor(col, name, i, row) { async setColor(col, name, i, row) {
if (name == "color") { if (name == "color") {
...@@ -374,14 +337,12 @@ export default { ...@@ -374,14 +337,12 @@ export default {
return (flag = true); return (flag = true);
} }
}); });
if (this.entity.items.length >= 2) { for (var i = 0; i < this.entity.items.length - 1; i++) {
for (let a = 0; a < this.entity.items.length; a++) { for (var j = i + 1; j < this.entity.items.length; j++) {
for (let b = 1; b <= this.entity.items.length; b++) { if (this.entity.items[i].code === this.entity.items[j].code) {
if (this.entity.items[a].code == this.entity.items[b].code) { this.$Message.error("编码不能重复!");
this.$Message.error("编码不能重复!"); flag = true;
flag = true; return;
return;
}
} }
} }
} }
......
...@@ -13,7 +13,14 @@ ...@@ -13,7 +13,14 @@
<Row class="rowTitle100"> <Row class="rowTitle100">
<FormItem label="名称" prop="name"> <FormItem label="名称" prop="name">
<Input v-model="entity.name"> <Input v-model="entity.name">
<ColorPicker v-model="entity.color" slot="prepend" transfer size="small" transfer recommend /> <ColorPicker
v-model="entity.color"
slot="prepend"
transfer
size="small"
transfer
recommend
/>
</Input> </Input>
</FormItem> </FormItem>
</Row> </Row>
...@@ -23,8 +30,8 @@ ...@@ -23,8 +30,8 @@
</FormItem> </FormItem>
</Row> </Row>
<Row class="rowTitle100"> <Row class="rowTitle100">
<FormItem label="图标" prop="icon"> <FormItem label="图标" prop="icon">
<InputIcon v-model="entity.icon"></InputIcon> <InputIcon v-model="entity.icon"></InputIcon>
</FormItem> </FormItem>
</Row> </Row>
<FormItem label="状态" prop="number"> <FormItem label="状态" prop="number">
...@@ -51,55 +58,85 @@ ...@@ -51,55 +58,85 @@
</Form> </Form>
</template> </template>
<script> <script>
import api from "../api.js";
export default { export default {
name: 'Edit', name: "Edit",
data() { data() {
const changeCode = (rule, value, callback) => {
if (value === "") {
callback(new Error("请填写编码"));
} else {
if (this.entity.upId) {
let par = {
conditions: [
{
fieldName: "upId",
conditionalType: "Equal",
fieldValue: this.entity.upId,
},
{
fieldName: "code",
conditionalType: "Equal",
fieldValue: this.entity.code,
},
],
};
let flag = false;
api.list(par).then((r) => {
if (r.result.length >= 1) {
callback(new Error("编码不可重复"));
}else{
callback();
}
});
}
}
};
return { return {
entity: { entity: {
color:"" color: "",
}, },
rules: { rules: {
name: [{ required: true, message: '必填', trigger: 'blur' }], name: [{ required: true, message: "必填", trigger: "blur" }],
code: [{ required: true, message: '必填', trigger: 'blur' }] code: [{ validator: changeCode, trigger: "blur" }],
} },
} };
}, },
props: { props: {
v: Object v: Object,
}, },
mounted(){ mounted() {
this.entity = this.v this.entity = this.$u.clone(this.v);
if(!this.entity.color){ if (!this.entity.color) {
this.entity.color=""; this.entity.color = "";
} }
}, },
methods: { methods: {
handleSubmit() { handleSubmit() {
this.$refs.form.validate((v) => { this.$refs.form.validate((v) => {
if (v) { if (v) {
var url2 = `${systemUrl}/Dictionary/createorupdate` var url2 = `${systemUrl}/Dictionary/createorupdate`;
this.$api.post(url2, { Dictionary: this.entity }).then((r) => { this.$api.post(url2, { Dictionary: this.entity }).then((r) => {
if (r.success) { if (r.success) {
this.$Message.success('保存成功') this.$Message.success("保存成功");
this.$emit('on-ok') this.$emit("on-ok");
} }
}) });
} }
}) });
}, },
handleClose() { handleClose() {
this.$emit('on-close') this.$emit("on-close");
} },
}, },
watch: { watch: {
v(v) { v(v) {
this.entity = this.v // this.entity = this.v;
if(!this.entity.color){ // if (!this.entity.color) {
this.entity.color=""; // this.entity.color = "";
} // }
console.info(this.entity) // console.info(this.entity);
} },
} },
} };
</script> </script>
...@@ -358,6 +358,7 @@ export default { ...@@ -358,6 +358,7 @@ export default {
// }, // },
//右键点击事件 //右键点击事件
contextmenu: (e, v, a) => { contextmenu: (e, v, a) => {
debugger;
e.preventDefault(); e.preventDefault();
this.$refs.contentMenu.$refs.reference = event.target; this.$refs.contentMenu.$refs.reference = event.target;
this.$refs.contentMenu.currentVisible = !this.$refs this.$refs.contentMenu.currentVisible = !this.$refs
...@@ -549,6 +550,7 @@ export default { ...@@ -549,6 +550,7 @@ export default {
this.data.pop(); this.data.pop();
}, },
save() { save() {
console.log(this.node);
if (this.cur.name == "") { if (this.cur.name == "") {
this.$Message.error("名称不能为空"); this.$Message.error("名称不能为空");
return; return;
...@@ -557,21 +559,40 @@ export default { ...@@ -557,21 +559,40 @@ export default {
this.$Message.error("值不能为空"); this.$Message.error("值不能为空");
return; return;
} }
for (let a = 0; a < this.data.length; a++) { if (this.node) {
for (let b = 1; b < this.data.length; b++) { let par = {
if (this.data[a].code == this.data[b].code) { conditions: [
this.$Message.error("编码不能重复"); {
return; fieldName: "upId",
conditionalType: "Equal",
fieldValue: this.node.id,
},
],
};
let flag = false;
api.list(par).then((r) => {
console.log(r.result);
if (r.result.length > 0) {
r.result.map((z) => { console.log(z.code, this.cur.code)
if (z.code == this.cur.code) {
this.$Message.error("编码不能重复!");
flag = true
return ;
}
});
if (flag == false) {
api.save(this.cur).then((r) => {
if (r.success) {
this.$Message.success("添加成功");
this.load();
}
});
}
} }
} });
} }
api.save(this.cur).then((r) => {
// console.warn(r);
if (r.success) {
this.$Message.success("添加成功");
this.load();
}
});
}, },
}, },
}; };
......
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