|
@@ -1,55 +1,76 @@
|
|
|
<template>
|
|
|
<div class="app-container">
|
|
|
- <!-- <div class="title-container">
|
|
|
- <breadcrumb id="breadcrumb-container" class="breadcrumb-container"/>
|
|
|
- </div> -->
|
|
|
-
|
|
|
- <y-page-list-layout :page-list="pageData" :page-para="listQuery" :getList="getList">
|
|
|
- <template slot="left">
|
|
|
- <el-button type="primary" round style="float: left" @click="dialogVisible = true">新增</el-button>
|
|
|
- <el-input v-model="listQuery.itemName" placeholder="请输题目名称" clearable
|
|
|
- style="margin-left: 20px;width: 320px;float: left;">
|
|
|
- </el-input>
|
|
|
- <el-button class="filter-item" style="margin-left: 10px;float: left;" type="primary" @click="searchList" round>搜索
|
|
|
- </el-button>
|
|
|
- <el-button class="filter-item" style="float: left;" round type="warning" @click="resetSearch()">重置
|
|
|
- </el-button>
|
|
|
- </template>
|
|
|
- <parentTable v-loading="listLoading" :data="pageData.records" slot="table" style="width: 100%;"
|
|
|
- :showSummary="false">
|
|
|
- <el-table-column label="题目名称" align="center">
|
|
|
- <template slot-scope="{row}">
|
|
|
- <span>{{ row.name }}</span>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column label="创建时间" align="center">
|
|
|
- <template slot-scope="{row}">
|
|
|
- <span>{{ row.created }}</span>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </parentTable>
|
|
|
- </y-page-list-layout>
|
|
|
- <el-dialog title="新增题目" :visible.sync="dialogVisible" width="30%" center>
|
|
|
- <el-form :model="questionForm" label-width="100px" class="demo-ruleForm">
|
|
|
- <el-form-item label="题目名称" prop="name">
|
|
|
- <el-input v-model.trim="questionForm.name"></el-input>
|
|
|
+ <div class="content">
|
|
|
+ <el-tabs addable @edit="handleTabsEdit" v-model="editableTabsValue" @tab-click="clickTab" type="border-card">
|
|
|
+ <el-tab-pane :key="item.name" v-for="(item, index) in questionTypeTree" :label="item.title" :name="item.name">
|
|
|
+ <el-card shadow="always" class="tree">
|
|
|
+ <el-tree :data="item.questionTree" show-checkbox node-key="id" default-expand-all
|
|
|
+ :expand-on-click-node="false">
|
|
|
+ <span class="custom-tree-node" slot-scope="{ node, data }">
|
|
|
+ <span @click="show(node)">{{ node.label }}</span>
|
|
|
+ <span>
|
|
|
+ <el-button type="text" size="mini" @click="() => append(node, data)">
|
|
|
+ 添加
|
|
|
+ </el-button>
|
|
|
+ <el-button type="text" size="mini" @click="() => remove(node, data)">
|
|
|
+ 删除
|
|
|
+ </el-button>
|
|
|
+ </span>
|
|
|
+ </span>
|
|
|
+ </el-tree>
|
|
|
+ </el-card>
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
+ <div class="panel">
|
|
|
+ <el-card shadow="always" >
|
|
|
+ <el-form label-position="left" label-width="120px" :model="questionForm" class="form">
|
|
|
+ <el-form-item label="上级评价项:">
|
|
|
+ <el-input v-model="questionForm.parentLabel" readonly disabled></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="范围:">
|
|
|
+ <el-select v-model="questionForm.scope" placeholder="请选择评价项所属范围" style="width:100%">
|
|
|
+ <el-option label="名称" value="名称"></el-option>
|
|
|
+ <el-option label="定级因素" value="定级因素"></el-option>
|
|
|
+ <el-option label="一级因子" value="一级因子"></el-option>
|
|
|
+ <el-option label="二级因子" value="二级因子"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="评价项:">
|
|
|
+ <el-input v-model="questionForm.label"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="分值范围:">
|
|
|
+ <el-col :span="11">
|
|
|
+ <el-input v-model.number="questionForm.minScore"></el-input>
|
|
|
+ </el-col>
|
|
|
+ <el-col class="line" :span="2">--</el-col>
|
|
|
+ <el-col :span="11">
|
|
|
+ <el-input v-model.number="questionForm.maxScore"></el-input>
|
|
|
+ </el-col>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="success" @click="save">保存</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-card>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <el-dialog title="新增类型" :visible.sync="dialogVisible" width="20%" center>
|
|
|
+ <el-form label-width="100px">
|
|
|
+ <el-form-item label="类型名称">
|
|
|
+ <el-input v-model="typeName"></el-input>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
|
- <el-button type="primary" @click="addQuestion">确 定</el-button>
|
|
|
+ <el-button type="primary" @click="addType">确 定</el-button>
|
|
|
</span>
|
|
|
</el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-import YPageListLayout from '@/components/custom/YPageListLayout'
|
|
|
-
|
|
|
export default {
|
|
|
name: 'Question',
|
|
|
- components: {
|
|
|
- YPageListLayout,
|
|
|
- },
|
|
|
+
|
|
|
data() {
|
|
|
return {
|
|
|
pageData: {},
|
|
@@ -63,49 +84,74 @@ export default {
|
|
|
listQueryKey: 'keyword',
|
|
|
dialogVisible: false,
|
|
|
questionForm: {
|
|
|
- name: null
|
|
|
- }
|
|
|
+ parentId: null,
|
|
|
+ parentLabel: null,
|
|
|
+ id: null,
|
|
|
+ label: null,
|
|
|
+ scope: null,
|
|
|
+ minScore: null,
|
|
|
+ maxScore: null
|
|
|
+ },
|
|
|
+ dialogVisible: false,
|
|
|
+ typeName: null,
|
|
|
+ questionTypeTree: [
|
|
|
+
|
|
|
+ ],
|
|
|
+ editableTabsValue:null
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
- this.getList();
|
|
|
+ //this.getTableTypes();
|
|
|
+ this.getTree();
|
|
|
},
|
|
|
methods: {
|
|
|
- resetSearch() {
|
|
|
- this.$router.push({ query: {} });
|
|
|
- this.listQuery = {
|
|
|
- current: 1,
|
|
|
- size: 10,
|
|
|
- descs: 'id',
|
|
|
- }
|
|
|
- this.getList()
|
|
|
+ clickTab(e){
|
|
|
+ this.editableTabsValue = e.name;
|
|
|
},
|
|
|
- searchList() {
|
|
|
- // 重置分页
|
|
|
- this.listQuery.page = 1
|
|
|
- this.listQuery.size = 10
|
|
|
- this.getList()
|
|
|
+ addType() {
|
|
|
+ let typeName = this.typeName;
|
|
|
+ if (!typeName) {
|
|
|
+ this.$notify.error({
|
|
|
+ title: '错误',
|
|
|
+ message: '类型名称不能为空'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.$api.question.add({ "label": typeName, "scope": "类型" }).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ // this.questionTypeTree.push({
|
|
|
+ // title: typeName,
|
|
|
+ // name: typeName,
|
|
|
+ // content: typeName
|
|
|
+ // });
|
|
|
+ this.editableTabsValue = res.data+"";
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.dialogVisible = false;
|
|
|
+ this.getTree();
|
|
|
},
|
|
|
- getList() {
|
|
|
- const that = this
|
|
|
- that.listLoading = true
|
|
|
- const key = {}
|
|
|
- key[that.listQueryKey] = that.listQuery.description
|
|
|
- console.log(this.$api)
|
|
|
- this.$api.question.list(Object.assign({}, that.listQuery, key))
|
|
|
- .then((res) => {
|
|
|
- that.pageData = res.data
|
|
|
- setTimeout(() => {
|
|
|
- that.listLoading = false
|
|
|
- }, 200)
|
|
|
- })
|
|
|
- .catch(() => {
|
|
|
- that.listLoading = false
|
|
|
+ dele(id) {
|
|
|
+ if (id) {
|
|
|
+ this.$api.question.dele(id).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: '删除成功',
|
|
|
+ type: 'success'
|
|
|
+ });
|
|
|
+ this.getTree();
|
|
|
+ } else {
|
|
|
+ this.$notify.error({
|
|
|
+ title: '错误',
|
|
|
+ message: '删除失败'
|
|
|
+ });
|
|
|
+ }
|
|
|
})
|
|
|
+ }
|
|
|
},
|
|
|
- addQuestion() {
|
|
|
- let questionName = this.questionForm.name;
|
|
|
- if (questionName) {
|
|
|
+ save() {
|
|
|
+ let questionLabel = this.questionForm.label;
|
|
|
+ if (questionLabel) {
|
|
|
this.$api.question.add(this.questionForm).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
this.$notify({
|
|
@@ -113,28 +159,156 @@ export default {
|
|
|
message: '新增成功',
|
|
|
type: 'success'
|
|
|
});
|
|
|
- this.questionName = null;
|
|
|
- this.dialogVisible = false;
|
|
|
- this.getList();
|
|
|
+ this.getTree();
|
|
|
} else {
|
|
|
this.$notify.error({
|
|
|
title: '错误',
|
|
|
message: '新增失败'
|
|
|
});
|
|
|
}
|
|
|
- this.questionName = null;
|
|
|
- this.dialogVisible = false;
|
|
|
- this.getList();
|
|
|
})
|
|
|
} else {
|
|
|
this.$notify.error({
|
|
|
title: '错误',
|
|
|
- message: '题目名称不能为空'
|
|
|
+ message: '评价项名称不能为空'
|
|
|
});
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ show(node) {
|
|
|
+ this.questionForm.id = node.data.id;
|
|
|
+ this.questionForm.scope = node.data.scope;
|
|
|
+ this.questionForm.label = node.data.label;
|
|
|
+ this.questionForm.minScore = node.data.minScore;
|
|
|
+ this.questionForm.maxScore = node.data.maxScore;
|
|
|
+ this.questionForm.parentLabel = node.data.parentLabel;
|
|
|
+ this.questionForm.parentId = node.data.parentId;
|
|
|
+ },
|
|
|
+ handleTabsEdit(targetName, action) {
|
|
|
+ if (action === 'add') {
|
|
|
+ this.dialogVisible = true;
|
|
|
+ }
|
|
|
+ // if (action === 'remove') {
|
|
|
+ // let tabs = this.questionTypeTree;
|
|
|
+ // let activeName = this.editableTabsValue;
|
|
|
+ // if (activeName === targetName) {
|
|
|
+ // tabs.forEach((tab, index) => {
|
|
|
+ // if (tab.name === targetName) {
|
|
|
+ // let nextTab = tabs[index + 1] || tabs[index - 1];
|
|
|
+ // if (nextTab) {
|
|
|
+ // activeName = nextTab.name;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // this.editableTabsValue = activeName;
|
|
|
+ // this.questionTypeTree = tabs.filter(tab => tab.name !== targetName);
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ append(node, data) {
|
|
|
+ const newChild = { id: null, label: '待定义', parentLabel: node.data.label, parentId: node.data.id, children: [] };
|
|
|
+ console.log(node)
|
|
|
+ if (node.level === 5){
|
|
|
+ this.$notify.error({
|
|
|
+ title: '警告',
|
|
|
+ message: '二级因子下暂不支持添加下级'
|
|
|
+ });
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ if (!data.children) {
|
|
|
+ this.$set(data, 'children', []);
|
|
|
+ }
|
|
|
+ data.children.push(newChild);
|
|
|
+ },
|
|
|
+
|
|
|
+ remove(node, data) {
|
|
|
+ this.$confirm('请确认是否删除此评价项', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ const parent = node.parent;
|
|
|
+ console.log(node.data)
|
|
|
+ if (node.data.children!=null) {
|
|
|
+ this.$confirm('此评价项下还存在子评价项,若删除子评价项也将删除', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ const children = parent.data.children || parent.data;
|
|
|
+ const index = children.findIndex(d => d.id === data.id);
|
|
|
+ children.splice(index, 1);
|
|
|
+ this.dele(node.data.id)
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ const children = parent.data.children || parent.data;
|
|
|
+ const index = children.findIndex(d => d.id === data.id);
|
|
|
+ children.splice(index, 1);
|
|
|
+ this.dele(node.data.id)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ getTree() {
|
|
|
+ const that = this
|
|
|
+ that.questionTypeTree = [];
|
|
|
+ that.listLoading = true
|
|
|
+ this.$api.question.tree()
|
|
|
+ .then((res) => {
|
|
|
+ for (let i in res.data) {
|
|
|
+ let parentItem = {label:res.data[i].label,id:res.data[i].id,scope:res.data[i].scope,children:res.data[i].children}
|
|
|
+ let item = {
|
|
|
+ title: res.data[i].label,
|
|
|
+ name: res.data[i].id + "",
|
|
|
+ content: null,
|
|
|
+ questionTree: [parentItem]
|
|
|
+ }
|
|
|
+ that.questionTypeTree.push(item)
|
|
|
+ }
|
|
|
+ if (that.editableTabsValue==="0"){
|
|
|
+ that.editableTabsValue = that.questionTypeTree[0].name
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ that.listLoading = false
|
|
|
+ }, 200)
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ that.listLoading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
},
|
|
|
}
|
|
|
</script>
|
|
|
+<style scoped>
|
|
|
+.tree {
|
|
|
+ width: 35%;
|
|
|
+}
|
|
|
+
|
|
|
+.panel {
|
|
|
+ width: 45%;
|
|
|
+ height: 800px;
|
|
|
+ flex: 1;
|
|
|
+ position: absolute;
|
|
|
+ top: 15.2%;
|
|
|
+ left: 50%;
|
|
|
+}
|
|
|
+
|
|
|
+.custom-tree-node {
|
|
|
+ flex: 1;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+ font-size: 14px;
|
|
|
+ padding-right: 8px;
|
|
|
+}
|
|
|
|
|
|
+.form {
|
|
|
+ width: 55%;
|
|
|
+ margin-left: 23%;
|
|
|
+ margin-top: 10%;
|
|
|
+ font-size: medium;
|
|
|
+ font-weight: bold;
|
|
|
+}
|
|
|
+</style>
|
|
|
|