classifyManage.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class="classify-manage-wrap traing-manage">
  3. <div class="top-wrap">
  4. <el-button type="primary" @click="handleModifyClassify({})">添加分类</el-button>
  5. <el-input v-model="searchText" clearable prefix-icon="el-icon-search" placeholder="请输入分类名称"
  6. @input="getTableData" style="width:240px;"></el-input>
  7. </div>
  8. <div class="table-wrap">
  9. <el-table :data="tableData" v-loading="tableLoading" row-key="ClassifyId"
  10. :tree-props="{children:'Children',hasChildren:'hasChildren'}">
  11. <el-table-column prop="ClassifyName" label="一级分类" align="center">
  12. <template slot-scope="{row}">
  13. <span>{{row.ParentId?'':row.ClassifyName}}</span>
  14. </template>
  15. </el-table-column>
  16. <el-table-column prop="ClassifyName" label="二级分类" align="center">
  17. <template slot-scope="{row}">
  18. <span>{{row.ParentId?row.ClassifyName:''}}</span>
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="操作" align="center" width="400px">
  22. <template slot-scope="{row}">
  23. <el-button type="text" @click="handleModifyClassify(row)">编辑</el-button>
  24. <el-button type="text" @click="deleteClassify(row)">删除</el-button>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. </div>
  29. <!-- 添加分类弹窗 -->
  30. <el-dialog :title="currentClassify.ClassifyId?'编辑分类':'添加分类'" :visible.sync="isModifyDialogShow"
  31. :close-on-click-modal="false" :modal-append-to-body="false" @close="isModifyDialogShow=false" width="589px"
  32. v-dialogDrag center>
  33. <div class="dialog-container">
  34. <el-form :model="currentClassify" :rules="rules" ref="form" label-position="top">
  35. <el-form-item label="上级分类" prop="ParentId">
  36. <el-select v-model="currentClassify.ParentId" placeholder="请选择上级分类" style="width:100%;">
  37. <el-option v-for="item in currentClassify.ClassifyId
  38. ?(currentClassify.ParentId<=0?defaultList:optionList)
  39. :[...defaultList,...optionList]"
  40. :key="item.ClassifyId"
  41. :label="item.ClassifyName"
  42. :value="item.ClassifyId"/>
  43. </el-select>
  44. </el-form-item>
  45. <el-form-item label="分类名称" prop="ClassifyName">
  46. <el-input v-model="currentClassify.ClassifyName" placeholder="请输入分类名称" style="width:100%;"></el-input>
  47. </el-form-item>
  48. </el-form>
  49. </div>
  50. <div class="foot-container">
  51. <el-button @click="isModifyDialogShow=false">取 消</el-button>
  52. <el-button type="primary" @click="modifyClassify">确认</el-button>
  53. </div>
  54. </el-dialog>
  55. </div>
  56. </template>
  57. <script>
  58. import {ClassifyInterface} from '@/api/modules/trainingApi'
  59. export default {
  60. data() {
  61. return {
  62. searchText: '',
  63. tableData: [],
  64. tableLoading: false,
  65. currentClassify: {},
  66. defaultList:[{ClassifyId:-1,ClassifyName:'无'}],
  67. isModifyDialogShow: false,
  68. rules:{
  69. ParentId:[{required:true,message:'请选择上级分类'}],
  70. ClassifyName:[{required:true,message:'请输入分类名称'}]
  71. }
  72. };
  73. },
  74. watch:{
  75. isModifyDialogShow(newVal){
  76. if(newVal){
  77. this.$nextTick(()=>{
  78. this.$refs.form&&this.$refs.form.clearValidate();
  79. })
  80. }
  81. }
  82. },
  83. computed:{
  84. optionList(){
  85. const list = this.tableData.map(i=>{
  86. return {
  87. ClassifyId:i.ClassifyId,
  88. ClassifyName:i.ClassifyName
  89. }
  90. })
  91. return list
  92. },
  93. },
  94. methods: {
  95. handleModifyClassify(data) {
  96. this.currentClassify = _.cloneDeep(data)
  97. if(data.ParentId===0){
  98. this.currentClassify.ParentId = -1
  99. }
  100. this.isModifyDialogShow = true
  101. },
  102. async modifyClassify() {
  103. //params对ParentId为-1的数据做处理,转为0
  104. await this.$refs.form.validate()
  105. let res = null
  106. if(this.currentClassify.ClassifyId){
  107. res = await ClassifyInterface.editClassify({
  108. ClassifyId:this.currentClassify.ClassifyId,
  109. ParentId:this.currentClassify.ParentId===-1?0:this.currentClassify.ParentId,
  110. ClassifyName:this.currentClassify.ClassifyName
  111. })
  112. }else{
  113. res = await ClassifyInterface.addClassify({
  114. ParentId:this.currentClassify.ParentId===-1?0:this.currentClassify.ParentId,
  115. ClassifyName:this.currentClassify.ClassifyName
  116. })
  117. }
  118. if(res.Ret!==200) return
  119. this.$message.success(`${this.currentClassify.ClassifyId?'编辑':'添加'}成功`)
  120. this.getTableData()
  121. this.isModifyDialogShow = false
  122. },
  123. deleteClassify(data) {
  124. if(data.Children&&data.Children.length){
  125. this.$confirm(
  126. '该分类下已关联内容,不可删除!',
  127. '提示',
  128. {
  129. confirmButtonText: '知道了',
  130. showCancelButton:false,
  131. type: 'error',
  132. }
  133. ).then(()=>{})
  134. }else{
  135. this.$confirm(
  136. '删除后不可恢复,是否确认删除?',
  137. '提示',
  138. {
  139. confirmButtonText: '确定',
  140. cancelButtonText: '取消',
  141. type: 'warning',
  142. }
  143. ).then(()=>{
  144. ClassifyInterface.deleteClassify({
  145. ClassifyId:data.ClassifyId
  146. }).then(res=>{
  147. if(res.Ret!==200) return
  148. this.$message.success('删除成功')
  149. this.getTableData()
  150. })
  151. })
  152. }
  153. },
  154. getTableData(){
  155. ClassifyInterface.getClassifyList({
  156. Keyword:this.searchText
  157. }).then(res=>{
  158. if(res.Ret!==200) return
  159. this.tableData = res.Data&&res.Data.List||[]
  160. })
  161. },
  162. },
  163. mounted(){
  164. this.getTableData()
  165. }
  166. };
  167. </script>
  168. <style scoped lang="scss">
  169. @import "./css/manage.scss";
  170. </style>