index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!--学习分类-->
  2. <template>
  3. <div class="el-category">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
  5. <el-form-item style="float: right;">
  6. <el-col :span="1.5" style="margin-bottom:20px;">
  7. <p class="add-button-one-90"
  8. @click="handleAdd"
  9. v-hasPermi="['exam:el_category:add']"
  10. ><i class="el-icon-plus"></i>新增</p>
  11. </el-col>
  12. </el-form-item>
  13. <el-form-item class="button-box">
  14. <p class="reset-button-one" @click="backPage"><i class="el-icon-arrow-left"></i>返回</p>
  15. </el-form-item>
  16. </el-form>
  17. <el-table
  18. v-loading="loading"
  19. :data="el_categoryList"
  20. row-key="id"
  21. default-expand-all
  22. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  23. >
  24. <el-table-column prop="title" label="分类名称"/>
  25. <el-table-column label="操作" width="320" v-if="tableButtonType">
  26. <template slot-scope="scope">
  27. <div class="button-box">
  28. <p
  29. v-show="scope.row.level<3"
  30. class="table-min-button"
  31. style="margin-right: 10px"
  32. @click="handleAdd(scope.row)"
  33. v-hasPermi="['exam:el_category:add']"
  34. >新增
  35. </p>
  36. <p
  37. class="table-min-button"
  38. style="margin-right: 10px"
  39. @click="handleUpdate(scope.row)"
  40. v-hasPermi="['exam:el_category:edit']"
  41. >编辑
  42. </p>
  43. <p
  44. class="table-min-button"
  45. @click="handleDelete(scope.row)"
  46. v-hasPermi="['exam:el_category:remove']"
  47. >删除
  48. </p>
  49. </div>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <!-- 添加或修改学习分类对话框 -->
  54. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  55. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  56. <el-form-item label="分类名称" prop="title">
  57. <el-input v-model="form.title" placeholder="请输入分类名称" maxLength="50"/>
  58. </el-form-item>
  59. </el-form>
  60. <div slot="footer" class="dialog-footer">
  61. <el-button type="primary" @click="submitForm">确 定</el-button>
  62. <el-button @click="cancel">取 消</el-button>
  63. </div>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script>
  68. import { listEl_category, getEl_category, delEl_category, addEl_category, updateEl_category } from "@/api/exam/el_category";
  69. export default {
  70. name: "El_category",
  71. props:{
  72. pageData:{},
  73. },
  74. data() {
  75. return {
  76. tableButtonType:this.hasPermiDom(['exam:el_category:add','exam:el_category:edit','exam:el_category:remove']),
  77. // 遮罩层
  78. loading: true,
  79. // 选中数组
  80. ids: [],
  81. // 非单个禁用
  82. single: true,
  83. // 非多个禁用
  84. multiple: true,
  85. // 显示搜索条件
  86. showSearch: true,
  87. // 学习分类表格数据
  88. el_categoryList: [],
  89. // 弹出层标题
  90. title: "",
  91. // 是否显示弹出层
  92. open: false,
  93. // 查询参数
  94. queryParams: {
  95. title: null,
  96. parentId: null,
  97. level: null,
  98. type: null,
  99. userId: null,
  100. deptId: null,
  101. deptName: null,
  102. },
  103. // 表单参数
  104. form: {},
  105. // 表单校验
  106. rules: {
  107. title: [
  108. { required: true, message: "分类名称不能为空", trigger: "blur" },
  109. { required: true, message: "分类名称不能为空", validator: this.spaceJudgment, trigger: "blur" }
  110. ],
  111. },
  112. };
  113. },
  114. created() {
  115. this.getList();
  116. },
  117. methods: {
  118. //返回按钮
  119. backPage(){
  120. console.log(this.pageData.type)
  121. if(this.pageData.type==1){//1资源管理2课程管理
  122. this.$parent.clickPage(1,'');
  123. }else if(this.pageData.type==2){
  124. this.$parent.goPageEdit(4,'');
  125. }
  126. },
  127. /** 查询学习分类列表 */
  128. getList() {
  129. this.loading = true;
  130. listEl_category(this.queryParams, this.pageData.type).then( response => {
  131. console.log(response)
  132. this.$set(this,'el_categoryList',response.data);
  133. // this.el_categoryList = response.data;
  134. this.loading = false;
  135. });
  136. },
  137. // 取消按钮
  138. cancel() {
  139. this.open = false;
  140. this.reset();
  141. },
  142. // 表单重置
  143. reset() {
  144. this.form = {
  145. id: null,
  146. title: null,
  147. parentId: null,
  148. level: null,
  149. type: null,
  150. userId: null,
  151. createBy: null,
  152. updateBy: null,
  153. deptId: null,
  154. deptName: null,
  155. createTime: null,
  156. updateTime: null,
  157. remark: null
  158. };
  159. this.resetForm("form");
  160. },
  161. /** 搜索按钮操作 */
  162. handleQuery() {
  163. this.getList();
  164. },
  165. /** 重置按钮操作 */
  166. resetQuery() {
  167. this.resetForm("queryForm");
  168. this.handleQuery();
  169. },
  170. // 多选框选中数据
  171. handleSelectionChange(selection) {
  172. this.ids = selection.map(item => item.id)
  173. this.single = selection.length!==1
  174. this.multiple = !selection.length
  175. },
  176. /** 新增按钮操作 */
  177. handleAdd(data) {
  178. this.reset();
  179. if(data.id){
  180. this.form.id = data.id;
  181. this.form.level = data.level;
  182. }
  183. this.open = true;
  184. this.title = "添加分类";
  185. },
  186. /** 修改按钮操作 */
  187. handleUpdate(row) {
  188. this.reset();
  189. this.title = "编辑分类";
  190. this.form = JSON.parse(JSON.stringify(row));
  191. this.form.edit = true;
  192. this.open = true;
  193. },
  194. /** 提交按钮 */
  195. submitForm() {
  196. this.$refs["form"].validate(valid => {
  197. if (valid) {
  198. if (this.form.edit) {
  199. let obj = {
  200. id:this.form.id,
  201. title:this.form.title,
  202. parentId:this.form.parentId,
  203. type:this.form.type,
  204. };
  205. updateEl_category(obj).then( response => {
  206. this.msgSuccess("修改成功");
  207. this.open = false;
  208. this.getList();
  209. });
  210. } else {
  211. let obj = {
  212. title:this.form.title,
  213. type:this.pageData.type,//type 1资源 2课程
  214. };
  215. if(!this.form.id){
  216. obj.parentId = 0;
  217. obj.level = 1;
  218. }else{
  219. obj.level = this.form.level+1;
  220. obj.parentId = this.form.id;
  221. }
  222. addEl_category(obj).then( response => {
  223. this.msgSuccess("新增成功");
  224. this.open = false;
  225. this.getList();
  226. });
  227. }
  228. }
  229. });
  230. },
  231. /** 删除按钮操作 */
  232. handleDelete(row) {
  233. const ids = row.id || this.ids;
  234. this.$confirm('是否确认删除?', "警告", {
  235. confirmButtonText: "确定",
  236. cancelButtonText: "取消",
  237. type: "warning"
  238. }).then(function() {
  239. return delEl_category(ids);
  240. }).then(() => {
  241. this.getList();
  242. this.msgSuccess("删除成功");
  243. }).catch(() => {});
  244. },
  245. /** 导出按钮操作 */
  246. handleExport() {
  247. this.download('exam/el_category/export', {
  248. ...this.queryParams
  249. }, `exam_el_category.xlsx`)
  250. }
  251. }
  252. };
  253. </script>
  254. <style scoped lang="scss">
  255. .el-category {
  256. flex:1;
  257. display: flex!important;
  258. flex-direction: column;
  259. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  260. padding:20px!important;
  261. .button-box{
  262. width:300px;
  263. display: flex;
  264. }
  265. }
  266. </style>