master
parent
f6f0231de4
commit
ef8522d1e1
21 changed files with 718 additions and 121 deletions
@ -0,0 +1,237 @@ |
||||
<template> |
||||
<div> |
||||
<el-card shadow="hover" class="m-b-20"> |
||||
<div> |
||||
<div class="p-title m-b-20">筛选</div> |
||||
|
||||
<div class="flex"> |
||||
<div> |
||||
<el-input placeholder="请输入分类名称" prefix-icon="el-icon-search" v-model="keyword" clearable></el-input> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</el-card> |
||||
|
||||
<el-card shadow="hover"> |
||||
<div class="flex j-between m-b-20"> |
||||
<div class="p-title">分类管理</div> |
||||
|
||||
<div> |
||||
<el-button type="primary" size="small" round @click="addFirst" v-auth>添加一级分类</el-button> |
||||
</div> |
||||
</div> |
||||
<el-table :data="listData" class="table" stripe header-align="center" row-key="cid" :tree-props="treeProps" :indent="9"> |
||||
<el-table-column prop="typeName" label="分类名称"> |
||||
<template slot-scope="scope"> |
||||
<span style="display: inline-block;width: 23px;" v-if="!scope.row.secondColumn.length"></span>{{scope.row.typeName}} |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column label="操作" width="200"> |
||||
<template slot-scope="scope"> |
||||
<el-button type="text" v-if="scope.row.parentId == 0" @click="addSecond(scope.row)" v-auth>添加</el-button> |
||||
<el-button type="text" @click="editType(scope.row)" v-auth>编辑</el-button> |
||||
<el-button type="text" @click="handleDelete(scope.row)" v-auth>删除</el-button> |
||||
</template> |
||||
</el-table-column> |
||||
</el-table> |
||||
<div class="pagination"> |
||||
<el-pagination background @current-change="handleCurrentChange" :current-page="page" layout="total, prev, pager, next" :total="total"> |
||||
</el-pagination> |
||||
</div> |
||||
</el-card> |
||||
|
||||
<el-dialog :title="isAddFirst ? '添加一级分类' : '编辑一级分类'" :visible.sync="firstVisible" width="24%" center @close="closeFirst" :close-on-click-modal="false"> |
||||
<el-form> |
||||
<el-form-item> |
||||
<el-input placeholder="请输入题库分类名称" v-model="firstName" maxlength="15"></el-input> |
||||
</el-form-item> |
||||
</el-form> |
||||
<span slot="footer" class="dialog-footer"> |
||||
<el-button @click="firstVisible = false">取消</el-button> |
||||
<el-button type="primary" @click="firstSubmit">确定</el-button> |
||||
</span> |
||||
</el-dialog> |
||||
|
||||
<el-dialog :title="isAddSecond ? '添加二级分类' : '编辑二级分类'" :visible.sync="secondVisible" width="24%" center @close="closeSecond" :close-on-click-modal="false"> |
||||
<el-form> |
||||
<el-form-item> |
||||
<el-input placeholder="请输入题库分类名称" v-model="secondName" maxlength="15"></el-input> |
||||
</el-form-item> |
||||
</el-form> |
||||
<span slot="footer" class="dialog-footer"> |
||||
<el-button @click="secondVisible = false">取消</el-button> |
||||
<el-button type="primary" @click="secondSubmit">确定</el-button> |
||||
</span> |
||||
</el-dialog> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import { mapState } from 'vuex' |
||||
export default { |
||||
data() { |
||||
return { |
||||
treeProps: {children: 'secondColumn', hasChildren: 'hasChildren'}, |
||||
listData: [], |
||||
keyword: '', |
||||
page: 1, |
||||
pageSize: 10, |
||||
total: 0, |
||||
searchTimer: null, |
||||
firstVisible: false, |
||||
firstId: '', |
||||
firstName: '', |
||||
secondVisible: false, |
||||
secondName: '', |
||||
secondId: '', |
||||
curRow: {}, |
||||
isAddFirst: false, |
||||
isAddSecond: false, |
||||
}; |
||||
}, |
||||
computed: { |
||||
...mapState('user', [ |
||||
'userId','clientId' |
||||
]) |
||||
}, |
||||
mounted() { |
||||
this.getData() |
||||
}, |
||||
watch: { |
||||
keyword: function(val) { |
||||
clearTimeout(this.searchTimer) |
||||
this.searchTimer = setTimeout(() => { |
||||
this.getData() |
||||
},500) |
||||
} |
||||
}, |
||||
methods: { |
||||
getData() { |
||||
let data = { |
||||
pageNum: this.page, |
||||
pageSize: this.pageSize, |
||||
keyword: this.keyword, |
||||
schoolId: this.clientId, |
||||
source: 2 |
||||
} |
||||
this.$post(this.api.listByPage,data) |
||||
.then(res => { |
||||
this.listData = res.data.list.list |
||||
this.total = res.data.list.totalCount |
||||
}).catch(err => {}) |
||||
}, |
||||
handleCurrentChange(val) { |
||||
this.page = val |
||||
this.getData() |
||||
}, |
||||
handleDelete(row) { |
||||
this.$confirm('确定要删除吗?', '提示', { |
||||
type: 'warning' |
||||
}) |
||||
.then(() => { |
||||
this.$post(`${this.api.deleteById}?cid=${row.cid}`).then(res => { |
||||
this.$message.success('删除成功') |
||||
this.getData() |
||||
}).catch(res => {}) |
||||
}) |
||||
.catch(() => {}) |
||||
}, |
||||
addFirst(){ |
||||
this.isAddFirst = true |
||||
this.firstVisible = true |
||||
}, |
||||
firstSubmit(){ |
||||
if(!this.firstName) return this.$message.warning('请填写题库分类名称') |
||||
let data = { |
||||
userId: this.userId, |
||||
typeName: this.firstName, |
||||
schoolId: this.clientId, |
||||
source: 2 |
||||
} |
||||
if(this.curRow.cid){ |
||||
data.cid = this.curRow.cid |
||||
this.$post(this.api.modifyLevel, data).then(res => { |
||||
if(res.success){ |
||||
this.$message.success('修改成功'); |
||||
this.firstVisible = false |
||||
this.getData() |
||||
} |
||||
}).catch(err => {}) |
||||
}else{ |
||||
this.$post(this.api.AddOneLevel, data).then(res => { |
||||
if(res.success){ |
||||
this.$message.success('添加成功'); |
||||
this.firstVisible = false |
||||
this.getData() |
||||
} |
||||
}).catch(err => {}) |
||||
} |
||||
}, |
||||
addSecond(row){ |
||||
this.isAddSecond = true |
||||
this.curRow = row |
||||
this.secondVisible = true |
||||
}, |
||||
closeFirst(){ |
||||
this.curRow = {} |
||||
this.firstName = '' |
||||
}, |
||||
closeSecond(){ |
||||
this.curRow = {} |
||||
this.secondName = '' |
||||
}, |
||||
editType(row){ |
||||
this.curRow = row |
||||
if(row.parentId == 0){ |
||||
this.isAddFirst = false |
||||
this.firstVisible = true |
||||
this.firstName = row.typeName |
||||
}else{ |
||||
this.isAddSecond = false |
||||
this.secondVisible = true |
||||
this.secondName = row.typeName |
||||
} |
||||
}, |
||||
secondSubmit(){ |
||||
if(!this.secondName) return this.$message.warning('请填写题库分类名称') |
||||
|
||||
let data = { |
||||
typeName: this.secondName, |
||||
userId: this.userId, |
||||
schoolId: this.clientId, |
||||
source: 2 |
||||
} |
||||
if(this.curRow.parentId == 0){ |
||||
data.parentId = this.curRow.cid |
||||
this.$post(this.api.AddSecondLevel, data).then(res => { |
||||
this.$message.success('添加成功'); |
||||
this.secondVisible = false |
||||
this.getData() |
||||
}).catch(err => {}) |
||||
}else{ |
||||
data.cid = this.curRow.cid |
||||
this.$post(this.api.modifyLevel, data).then(res => { |
||||
this.$message.success('修改成功'); |
||||
this.secondVisible = false |
||||
this.getData() |
||||
}).catch(err => {}) |
||||
} |
||||
}, |
||||
delData(row) { |
||||
this.$confirm('确定要删除吗?', '提示', { |
||||
type: 'warning' |
||||
}) |
||||
.then(() => { |
||||
this.$del(`${this.api.deleteColumn}/${row.id}`).then(res => { |
||||
this.$message.success('删除成功'); |
||||
this.getData() |
||||
}).catch(res => {}) |
||||
}).catch(() => {}) |
||||
}, |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style lang="scss" scoped> |
||||
|
||||
</style> |
Loading…
Reference in new issue