parent
fe898632d4
commit
ff78ab0a19
10 changed files with 1348 additions and 1136 deletions
@ -1,175 +1,206 @@ |
||||
<template> |
||||
<div> |
||||
<div> |
||||
<div> |
||||
<org-tree |
||||
:data="orgList" |
||||
<org-tree :data="orgList" |
||||
default-expand-all |
||||
ref="tree" |
||||
node-key="id" |
||||
highlight-current |
||||
:expand-on-click-node="false" |
||||
@node-click="getSingle" |
||||
:props="{children: 'children', label: 'categoryName', isLeaf: 'leaf'}" |
||||
> |
||||
<span class="custom-tree-node" slot-scope="{ node, data }"> |
||||
<span style="display: inline-block; margin-right: 20px">{{ node.label }}</span> |
||||
<span> |
||||
<el-button |
||||
v-if="node.level > 1" |
||||
type="text" |
||||
icon="el-icon-edit-outline" |
||||
@click="editType(data)"> |
||||
</el-button> |
||||
<el-button |
||||
type="text" |
||||
icon="el-icon-circle-plus-outline" |
||||
@click="addType(node, data)"> |
||||
</el-button> |
||||
<el-button |
||||
v-if="node.level > 1" |
||||
type="text" |
||||
icon="el-icon-delete" |
||||
@click="delType(data)"> |
||||
</el-button> |
||||
</span> |
||||
</span> |
||||
</org-tree> |
||||
</div> |
||||
|
||||
<el-dialog :title="Form.id ? '编辑分类' : '新增分类'" :visible.sync="typeVisible" width="24%" center @close="closeDia" :close-on-click-modal="false"> |
||||
<el-form ref="Form" :model="Form" :rules="rules"> |
||||
<el-form-item prop="categoryName"> |
||||
<el-input placeholder="请输入分类名称" v-model="Form.categoryName"></el-input> |
||||
</el-form-item> |
||||
</el-form> |
||||
<span slot="footer" class="dialog-footer"> |
||||
<el-button @click="typeVisible = false">取 消</el-button> |
||||
<el-button type="primary" @click="submit">确 定</el-button> |
||||
</span> |
||||
</el-dialog> |
||||
:props="{children: 'children', label: 'categoryName', isLeaf: 'leaf'}"> |
||||
<span class="custom-tree-node" |
||||
slot-scope="{ node, data }"> |
||||
<span style="display: inline-block; margin-right: 20px">{{ node.label }}</span> |
||||
<span> |
||||
<el-button v-if="node.level > 1" |
||||
type="text" |
||||
icon="el-icon-edit-outline" |
||||
@click="editType(data)"> |
||||
</el-button> |
||||
<el-button type="text" |
||||
icon="el-icon-circle-plus-outline" |
||||
@click="addType(node, data)"> |
||||
</el-button> |
||||
<el-button v-if="node.level > 1" |
||||
type="text" |
||||
icon="el-icon-delete" |
||||
@click="delType(data)"> |
||||
</el-button> |
||||
</span> |
||||
</span> |
||||
</org-tree> |
||||
<div :class="['school-create', {active: schoolActive}]" |
||||
@click="schoolClick">院校创建</div> |
||||
</div> |
||||
|
||||
<el-dialog :title="Form.id ? '编辑分类' : '新增分类'" |
||||
:visible.sync="typeVisible" |
||||
width="24%" |
||||
center |
||||
@close="closeDia" |
||||
:close-on-click-modal="false"> |
||||
<el-form ref="Form" |
||||
:model="Form" |
||||
:rules="rules"> |
||||
<el-form-item prop="categoryName"> |
||||
<el-input placeholder="请输入分类名称" |
||||
v-model="Form.categoryName"></el-input> |
||||
</el-form-item> |
||||
</el-form> |
||||
<span slot="footer" |
||||
class="dialog-footer"> |
||||
<el-button @click="typeVisible = false">取 消</el-button> |
||||
<el-button type="primary" |
||||
@click="submit">确 定</el-button> |
||||
</span> |
||||
</el-dialog> |
||||
</div> |
||||
</template> |
||||
<script> |
||||
import OrgTree from "@/components/org-tree/src/tree"; |
||||
export default { |
||||
props: ["Data"], |
||||
data() { |
||||
return { |
||||
systemId: this.$route.query.systemId, |
||||
orgList: [], |
||||
typeVisible: false, |
||||
Form: { |
||||
id: '', |
||||
parentId: '', |
||||
categoryName: '', |
||||
level: '' |
||||
}, |
||||
rules: { |
||||
categoryName: [ |
||||
{ required: true, message: "请输入分类名称", trigger: "blur" } |
||||
] |
||||
} |
||||
}; |
||||
}, |
||||
components: { |
||||
OrgTree |
||||
}, |
||||
mounted() { |
||||
this.getType() |
||||
}, |
||||
methods: { |
||||
getType() { |
||||
this.$post(this.api.sourceModelClassification).then(res => { |
||||
const { data } = res |
||||
this.orgList = data |
||||
data.length && this.$nextTick(() => { |
||||
const categoryId = this.$route.query.categoryId |
||||
this.$refs.tree.setCurrentKey(categoryId || data[0].id) |
||||
this.$router.push({ |
||||
path: 'backstage', |
||||
query: { |
||||
...this.$route.query, |
||||
categoryId: this.$refs.tree.getCurrentKey() |
||||
} |
||||
}).catch(err => {}) |
||||
this.$emit('getData') |
||||
}) |
||||
}).catch(res => {}) |
||||
}, |
||||
getSingle() { |
||||
props: ["Data"], |
||||
data () { |
||||
return { |
||||
systemId: this.$route.query.systemId, |
||||
orgList: [], |
||||
typeVisible: false, |
||||
Form: { |
||||
id: '', |
||||
parentId: '', |
||||
categoryName: '', |
||||
level: '' |
||||
}, |
||||
rules: { |
||||
categoryName: [ |
||||
{ required: true, message: "请输入分类名称", trigger: "blur" } |
||||
] |
||||
}, |
||||
schoolActive: 0 |
||||
}; |
||||
}, |
||||
components: { |
||||
OrgTree |
||||
}, |
||||
mounted () { |
||||
this.getType() |
||||
}, |
||||
methods: { |
||||
// 查询全部分类 |
||||
getType () { |
||||
this.$post(this.api.sourceModelClassification, { |
||||
founder: 0 |
||||
}).then(res => { |
||||
const { data } = res |
||||
this.orgList = data |
||||
data.length && this.$nextTick(() => { |
||||
const categoryId = this.$route.query.categoryId |
||||
this.$refs.tree.setCurrentKey(categoryId || data[0].id) |
||||
this.$router.push({ |
||||
path: 'backstage', |
||||
query: { |
||||
...this.$route.query, |
||||
categoryId: this.$refs.tree.getCurrentKey() |
||||
} |
||||
}).catch(err => {}) |
||||
this.$emit('initData') |
||||
}, |
||||
// 添加分类 |
||||
addType(node, data) { |
||||
this.typeVisible = true |
||||
this.Form.parentId = data ? data.id : 0 |
||||
this.Form.level = node ? node.level : 0 |
||||
}, |
||||
// 编辑分类 |
||||
editType(data) { |
||||
this.Form.id = data.id |
||||
this.Form.parentId = data ? data.parentId : 0 |
||||
this.Form.categoryName = data.categoryName |
||||
this.typeVisible = true |
||||
}, |
||||
// 保存分类 |
||||
submit() { |
||||
this.$refs['Form'].validate((valid) => { |
||||
if (valid) { |
||||
const form = this.Form |
||||
const data = { |
||||
id: form.id, |
||||
parentId: form.parentId, |
||||
categoryName: form.categoryName, |
||||
systemId: this.systemId |
||||
} |
||||
if (data.id) { |
||||
this.$post(this.api.updateSourceModelCategory, data).then(res => { |
||||
this.$message.success("编辑成功") |
||||
this.typeVisible = false |
||||
this.getType() |
||||
}).catch(res => {}) |
||||
} else { |
||||
data.level = form.level |
||||
this.$post(this.api.categorySave, data).then(res => { |
||||
this.$message.success("添加成功") |
||||
this.typeVisible = false |
||||
this.getType() |
||||
}).catch(res => {}) |
||||
} |
||||
} |
||||
}) |
||||
}, |
||||
closeDia() { |
||||
this.$refs.Form.resetFields() |
||||
this.Form = { |
||||
id: '', |
||||
parentId: '', |
||||
categoryName: '' |
||||
} |
||||
}, |
||||
// 删除分类 |
||||
delType(item) { |
||||
this.$confirm("确定要删除分类吗?", "提示", { |
||||
type: "warning" |
||||
}).then(() => { |
||||
this.$post(`${this.api.deleteSourceModelCategory}?categoryId=${item.id}`).then(res => { |
||||
this.$message.success("删除成功") |
||||
this.$emit('initData') |
||||
this.getType() |
||||
}).catch(res => {}) |
||||
}).catch(() => {}) |
||||
}).catch(err => { }) |
||||
this.$emit('getData') |
||||
}) |
||||
}).catch(res => { }) |
||||
}, |
||||
// 分类点击回调 |
||||
getSingle () { |
||||
this.schoolActive = 0 |
||||
this.$router.push({ |
||||
path: 'backstage', |
||||
query: { |
||||
...this.$route.query, |
||||
categoryId: this.$refs.tree.getCurrentKey() |
||||
} |
||||
}).catch(err => { }) |
||||
this.$emit('initData') |
||||
}, |
||||
// 院校创建点击回调 |
||||
schoolClick () { |
||||
this.schoolActive = 1 |
||||
this.$emit('initData', 1) |
||||
}, |
||||
// 添加分类 |
||||
addType (node, data) { |
||||
this.typeVisible = true |
||||
this.Form.parentId = data ? data.id : 0 |
||||
this.Form.level = node ? node.level : 0 |
||||
}, |
||||
// 编辑分类 |
||||
editType (data) { |
||||
this.Form.id = data.id |
||||
this.Form.parentId = data ? data.parentId : 0 |
||||
this.Form.categoryName = data.categoryName |
||||
this.typeVisible = true |
||||
}, |
||||
// 保存分类 |
||||
submit () { |
||||
this.$refs['Form'].validate((valid) => { |
||||
if (valid) { |
||||
const form = this.Form |
||||
const data = { |
||||
id: form.id, |
||||
parentId: form.parentId, |
||||
categoryName: form.categoryName, |
||||
systemId: this.systemId, |
||||
founder: 0 |
||||
} |
||||
if (data.id) { |
||||
this.$post(this.api.updateSourceModelCategory, data).then(res => { |
||||
this.$message.success("编辑成功") |
||||
this.typeVisible = false |
||||
this.getType() |
||||
}).catch(res => { }) |
||||
} else { |
||||
data.level = form.level |
||||
this.$post(this.api.categorySave, data).then(res => { |
||||
this.$message.success("添加成功") |
||||
this.typeVisible = false |
||||
this.getType() |
||||
}).catch(res => { }) |
||||
} |
||||
} |
||||
}) |
||||
}, |
||||
closeDia () { |
||||
this.$refs.Form.resetFields() |
||||
this.Form = { |
||||
id: '', |
||||
parentId: '', |
||||
categoryName: '' |
||||
} |
||||
}, |
||||
// 删除分类 |
||||
delType (item) { |
||||
this.$confirm("确定要删除分类吗?", "提示", { |
||||
type: "warning" |
||||
}).then(() => { |
||||
this.$post(`${this.api.deleteSourceModelCategory}?categoryId=${item.id}`).then(res => { |
||||
this.$message.success("删除成功") |
||||
this.$emit('initData') |
||||
this.getType() |
||||
}).catch(res => { }) |
||||
}).catch(() => { }) |
||||
} |
||||
} |
||||
}; |
||||
</script> |
||||
<style lang="scss" scoped> |
||||
|
||||
.school-create { |
||||
padding: 3px 5px 3px 23px; |
||||
margin-top: 5px; |
||||
font-size: 14px; |
||||
cursor: pointer; |
||||
&.active { |
||||
background-color: #f0f7ff; |
||||
} |
||||
&:hover { |
||||
background-color: #f0f7ff; |
||||
} |
||||
} |
||||
</style> |
||||
|
Loading…
Reference in new issue