index.vue 8.4 KB

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