index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <!--专业管理-->
  2. <template>
  3. <div class="app-container major-page">
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px">
  5. <el-form-item label="关键字" prop="majorName">
  6. <el-input
  7. v-model="queryParams.searchValue"
  8. placeholder="专业名称/专业代码"
  9. clearable
  10. size="small"
  11. />
  12. </el-form-item>
  13. <el-form-item style="float: right;">
  14. <el-col :span="1.5">
  15. <p class="add-button-one-90"
  16. @click="handleAdd"
  17. v-hasPermi="['system:major:add']"
  18. >新增</p>
  19. </el-col>
  20. </el-form-item>
  21. <el-form-item>
  22. <p class="inquire-button-one" @click="handleQuery">查询</p>
  23. <p class="reset-button-one" @click="resetQuery">重置</p>
  24. </el-form-item>
  25. </el-form>
  26. <el-table v-loading="loading" border :data="majorList" @selection-change="handleSelectionChange">
  27. <el-table-column type="selection" width="55" align="center" />
  28. <el-table-column label="学院名称" align="center" prop="deptName" />
  29. <el-table-column label="专业代码" align="center" prop="majorCode" />
  30. <el-table-column label="主键ID" align="center" prop="id" v-if="false"/>
  31. <el-table-column label="专业名称" align="center" prop="majorName" />
  32. <!-- <el-table-column label="组织结构(学院id)" align="center" prop="deptId" />-->
  33. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" v-if="tableButtonType">
  34. <template slot-scope="scope">
  35. <div class="table-button-box">
  36. <p class="table-button-null"></p>
  37. <p class="table-button-p"
  38. @click="handleUpdate(scope.row)"
  39. v-hasPermiAnd="['system:major:query','system:major:edit']"
  40. >修改</p>
  41. <p class="table-button-p"
  42. @click="handleDelete(scope.row)"
  43. v-hasPermi="['system:major:remove']"
  44. >删除</p>
  45. <p class="table-button-null"></p>
  46. </div>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. <pagination
  51. v-show="total>0"
  52. :total="total"
  53. :page.sync="queryParams.pageNum"
  54. :limit.sync="queryParams.pageSize"
  55. @pagination="getList"
  56. />
  57. <!-- 添加或修改major对话框 -->
  58. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  59. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  60. <el-form-item label="专业名称" prop="majorName">
  61. <el-input v-model="form.majorName" type="textarea" placeholder="请输入专业名称" />
  62. </el-form-item>
  63. <el-form-item label="专业代码" prop="majorCode">
  64. <el-input v-model="form.majorCode" type="textarea" placeholder="请输入专业代码" />
  65. </el-form-item>
  66. <el-form-item label="学院选择" prop="deptId">
  67. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" @select="deptSelect" placeholder="请选择学院" />
  68. </el-form-item>
  69. </el-form>
  70. <div slot="footer" class="dialog-footer">
  71. <el-button type="primary" @click="submitForm">确 定</el-button>
  72. <el-button @click="cancel">取 消</el-button>
  73. </div>
  74. </el-dialog>
  75. </div>
  76. </template>
  77. <script>
  78. import { listMajor, getMajor, delMajor, addMajor, updateMajor } from "@/api/system/major";
  79. import { treeselect } from "@/api/system/dept";
  80. import Treeselect from "@riophae/vue-treeselect";
  81. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  82. export default {
  83. name: "Major",
  84. components: { Treeselect },
  85. data() {
  86. return {
  87. tableButtonType:this.hasPermiDom(['system:major:query','system:major:edit','system:major:remove']),
  88. // 遮罩层
  89. loading: true,
  90. // 选中数组
  91. ids: [],
  92. // 非单个禁用
  93. single: true,
  94. // 非多个禁用
  95. multiple: true,
  96. // 显示搜索条件
  97. showSearch: true,
  98. // 总条数
  99. total: 0,
  100. // 部门树选项
  101. deptOptions: undefined,
  102. // major表格数据
  103. majorList: [],
  104. // 弹出层标题
  105. title: "",
  106. // 是否显示弹出层
  107. open: false,
  108. // 查询参数
  109. queryParams: {
  110. pageNum: 1,
  111. pageSize:20,
  112. searchValue: null,
  113. majorName: null,
  114. majorCode: null,
  115. deptId: null,
  116. deptName: null,
  117. },
  118. // 表单参数
  119. form: {},
  120. // 表单校验
  121. rules: {
  122. majorName:[
  123. {required: true, message: '请输入专业名称', trigger: 'change'},
  124. { required: true, message: "请输入专业名称", validator: this.spaceJudgment, trigger: "blur" }
  125. ],
  126. majorCode:[
  127. {required: true, message: '请输入专业代码', trigger: 'change'},
  128. { required: true, message: "请输入专业代码", validator: this.spaceJudgment, trigger: "blur" }
  129. ],
  130. deptId:[
  131. {required: true, message: '请选择学院', trigger: 'change'},
  132. ],
  133. }
  134. };
  135. },
  136. created() {
  137. this.getList();
  138. },
  139. methods: {
  140. /** 查询major列表 */
  141. getList() {
  142. this.loading = true;
  143. listMajor(this.queryParams).then( response => {
  144. this.majorList = response.rows;
  145. this.total = response.total;
  146. this.loading = false;
  147. });
  148. },
  149. /** 查询部门下拉树结构 */
  150. getTreeselect() {
  151. treeselect().then(response => {
  152. console.log(response.data);
  153. this.deptOptions = response.data;
  154. });
  155. },
  156. // 取消按钮
  157. cancel() {
  158. this.open = false;
  159. this.reset();
  160. },
  161. // 表单重置
  162. reset() {
  163. this.form = {
  164. id: null,
  165. majorName: null,
  166. majorCode: null,
  167. deptId: null,
  168. deptName: null,
  169. createTime: null
  170. };
  171. this.resetForm("form");
  172. },
  173. /** 搜索按钮操作 */
  174. handleQuery() {
  175. this.queryParams.pageNum = 1;
  176. this.getList();
  177. },
  178. /** 重置按钮操作 */
  179. resetQuery() {
  180. // this.resetForm("queryForm");
  181. this.$set(this,'queryParams',{
  182. pageNum: 1,
  183. pageSize:20,
  184. majorName:"",
  185. });
  186. this.handleQuery();
  187. },
  188. // 多选框选中数据
  189. handleSelectionChange(selection) {
  190. this.ids = selection.map(item => item.id)
  191. this.single = selection.length!==1
  192. this.multiple = !selection.length
  193. },
  194. /** 新增按钮操作 */
  195. handleAdd() {
  196. this.reset();
  197. this.getTreeselect();
  198. this.open = true;
  199. this.title = "添加专业";
  200. },
  201. /** 修改按钮操作 */
  202. handleUpdate(row) {
  203. this.reset();
  204. this.getTreeselect();
  205. const id = row.id || this.ids
  206. getMajor(id).then( response => {
  207. this.form = response.data;
  208. this.open = true;
  209. this.title = "修改专业";
  210. });
  211. },
  212. deptSelect(item){
  213. this.form.deptName=item.label
  214. },
  215. /** 提交按钮 */
  216. submitForm() {
  217. this.$refs["form"].validate(valid => {
  218. if (valid) {
  219. if (this.form.id != null) {
  220. updateMajor(this.form).then( response => {
  221. this.msgSuccess("修改成功");
  222. this.open = false;
  223. this.getList();
  224. });
  225. } else {
  226. addMajor(this.form).then( response => {
  227. this.msgSuccess("新增成功");
  228. this.open = false;
  229. this.getList();
  230. });
  231. }
  232. }
  233. });
  234. },
  235. /** 删除按钮操作 */
  236. handleDelete(row) {
  237. const ids = row.id || this.ids;
  238. this.$confirm('是否确认删除?', "警告", {
  239. confirmButtonText: "确定",
  240. cancelButtonText: "取消",
  241. type: "warning"
  242. }).then(function() {
  243. return delMajor(ids);
  244. }).then(() => {
  245. this.getList();
  246. this.msgSuccess("删除成功");
  247. }).catch(() => {});
  248. },
  249. /** 导出按钮操作 */
  250. handleExport() {
  251. this.download('system/major/export', {
  252. ...this.queryParams
  253. }, `system_major.xlsx`)
  254. }
  255. }
  256. };
  257. </script>
  258. <style lang="scss" scoped>
  259. .major-page{
  260. display: flex!important;
  261. flex-direction: column;
  262. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  263. padding:20px 20px 20px!important;
  264. .button-box{
  265. width:190px;
  266. display: flex;
  267. margin:0 auto;
  268. }
  269. }
  270. </style>