index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <template>
  2. <div class="app-container">
  3. <el-form class="queryParams bgWhite" :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
  4. <el-form-item label="部门名称:" prop="deptName">
  5. <el-input
  6. v-model="queryParams.deptName"
  7. placeholder="请输入部门名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="状态:" prop="status">
  14. <el-select v-model="queryParams.status" placeholder="部门状态" clearable size="small">
  15. <el-option
  16. v-for="dict in statusOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <div class="bgWhite">
  29. <el-row :gutter="10" class="mb8">
  30. <el-col :span="1.5">
  31. <el-button
  32. type="cyan"
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['system:dept:add']"
  37. >新增</el-button>
  38. <el-button
  39. type="warning"
  40. icon="el-icon-plus"
  41. size="mini"
  42. @click="isExpandAll"
  43. >展开/折叠</el-button>
  44. </el-col>
  45. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  46. </el-row>
  47. <el-table
  48. v-loading="loading"
  49. :data="deptList"
  50. ref="treeTable"
  51. row-key="deptId"
  52. default-expand-all
  53. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  54. >
  55. <el-table-column prop="deptName" label="部门名称" width="260"></el-table-column>
  56. <el-table-column prop="orderNum" label="排序" width="200"></el-table-column>
  57. <el-table-column label="状态" width="100">
  58. <template slot-scope="scope">
  59. <span class="statusTag">{{statusFormat(scope.row)}}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="创建时间" align="center" prop="createTime" width="200">
  63. <template slot-scope="scope">
  64. <span>{{ parseTime(scope.row.createTime) }}</span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  68. <template slot-scope="scope">
  69. <el-button
  70. size="mini"
  71. icon="el-icon-edit"
  72. @click="handleUpdate(scope.row)"
  73. v-hasPermi="['system:dept:edit']"
  74. >修改</el-button>
  75. <el-button
  76. size="mini"
  77. type="cyan"
  78. icon="el-icon-plus"
  79. @click="handleAdd(scope.row)"
  80. v-hasPermi="['system:dept:add']"
  81. >新增</el-button>
  82. <el-button
  83. v-if="scope.row.parentId != 0"
  84. size="mini"
  85. type="danger"
  86. icon="el-icon-delete"
  87. @click="handleDelete(scope.row)"
  88. v-hasPermi="['system:dept:remove']"
  89. >删除</el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. </div>
  94. <!-- 添加或修改部门对话框 -->
  95. <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
  96. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  97. <el-row>
  98. <el-col :span="24" v-if="form.parentId !== 0">
  99. <el-form-item label="上级部门" prop="parentId">
  100. <treeselect v-model="form.parentId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" />
  101. </el-form-item>
  102. </el-col>
  103. <el-col :span="12">
  104. <el-form-item label="部门名称" prop="deptName">
  105. <el-input v-model="form.deptName" placeholder="请输入部门名称" />
  106. </el-form-item>
  107. </el-col>
  108. <el-col :span="12">
  109. <el-form-item label="显示排序" prop="orderNum">
  110. <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="12">
  114. <el-form-item label="负责人" prop="leader">
  115. <el-input v-model="form.leader" placeholder="请输入负责人" maxlength="20" />
  116. </el-form-item>
  117. </el-col>
  118. <el-col :span="12">
  119. <el-form-item label="联系电话" prop="phone">
  120. <el-input v-model="form.phone" placeholder="请输入联系电话" maxlength="11" />
  121. </el-form-item>
  122. </el-col>
  123. <el-col :span="12">
  124. <el-form-item label="邮箱" prop="email">
  125. <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
  126. </el-form-item>
  127. </el-col>
  128. <el-col :span="12">
  129. <el-form-item label="部门状态">
  130. <el-radio-group v-model="form.status">
  131. <el-radio
  132. v-for="dict in statusOptions"
  133. :key="dict.dictValue"
  134. :label="dict.dictValue"
  135. >{{dict.dictLabel}}</el-radio>
  136. </el-radio-group>
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="12">
  140. <el-form-item label="部门编码">
  141. <el-input v-model="form.deptCode" placeholder="部门编码" />
  142. </el-form-item>
  143. </el-col>
  144. </el-row>
  145. </el-form>
  146. <div slot="footer" class="dialog-footer">
  147. <el-button type="primary" @click="submitForm">确 定</el-button>
  148. <el-button @click="cancel">取 消</el-button>
  149. </div>
  150. </el-dialog>
  151. </div>
  152. </template>
  153. <script>
  154. import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";
  155. import Treeselect from "@riophae/vue-treeselect";
  156. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  157. export default {
  158. name: "Dept",
  159. components: { Treeselect },
  160. data() {
  161. return {
  162. // 遮罩层
  163. loading: true,
  164. // 显示搜索条件
  165. showSearch: true,
  166. // 表格树数据
  167. deptList: [],
  168. // 部门树选项
  169. deptOptions: [],
  170. // 弹出层标题
  171. title: "",
  172. // 是否显示弹出层
  173. open: false,
  174. // 状态数据字典
  175. statusOptions: [],
  176. // 查询参数
  177. queryParams: {
  178. deptName: undefined,
  179. status: undefined
  180. },
  181. // 表单参数
  182. form: {},
  183. // 表单校验
  184. rules: {
  185. parentId: [
  186. { required: true, message: "上级部门不能为空", trigger: "blur" }
  187. ],
  188. deptName: [
  189. { required: true, message: "部门名称不能为空", trigger: "blur" }
  190. ],
  191. orderNum: [
  192. { required: true, message: "菜单顺序不能为空", trigger: "blur" }
  193. ],
  194. email: [
  195. {
  196. type: "email",
  197. message: "'请输入正确的邮箱地址",
  198. trigger: ["blur", "change"]
  199. }
  200. ],
  201. phone: [
  202. {
  203. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  204. message: "请输入正确的手机号码",
  205. trigger: "blur"
  206. }
  207. ]
  208. },
  209. isExpand:true,
  210. };
  211. },
  212. created() {
  213. this.getList();
  214. this.getDicts("sys_normal_disable").then(response => {
  215. this.statusOptions = response.data;
  216. });
  217. },
  218. methods: {
  219. /** 查询部门列表 */
  220. getList() {
  221. var that = this;
  222. this.loading = true;
  223. listDept(this.queryParams).then(response => {
  224. this.deptList = this.handleTree(response.data, "deptId");
  225. this.loading = false;
  226. });
  227. },
  228. /** 转换部门数据结构 */
  229. normalizer(node) {
  230. if (node.children && !node.children.length) {
  231. delete node.children;
  232. }
  233. return {
  234. id: node.deptId,
  235. label: node.deptName,
  236. children: node.children
  237. };
  238. },
  239. // 字典状态字典翻译
  240. statusFormat(row) {
  241. return this.selectDictLabel(this.statusOptions, row.status);
  242. },
  243. // 取消按钮
  244. cancel() {
  245. this.open = false;
  246. this.reset();
  247. },
  248. // 表单重置
  249. reset() {
  250. this.form = {
  251. deptId: undefined,
  252. parentId: undefined,
  253. deptName: undefined,
  254. orderNum: undefined,
  255. leader: undefined,
  256. phone: undefined,
  257. email: undefined,
  258. status: "0"
  259. };
  260. this.resetForm("form");
  261. },
  262. /** 搜索按钮操作 */
  263. handleQuery() {
  264. this.getList();
  265. },
  266. /** 重置按钮操作 */
  267. resetQuery() {
  268. this.resetForm("queryForm");
  269. this.handleQuery();
  270. },
  271. /** 新增按钮操作 */
  272. handleAdd(row) {
  273. this.reset();
  274. if (row != undefined) {
  275. this.form.parentId = row.deptId;
  276. }
  277. this.open = true;
  278. this.title = "添加部门";
  279. listDept().then(response => {
  280. this.deptOptions = this.handleTree(response.data, "deptId");
  281. });
  282. },
  283. /** 修改按钮操作 */
  284. handleUpdate(row) {
  285. this.reset();
  286. getDept(row.deptId).then(response => {
  287. this.form = response.data;
  288. this.open = true;
  289. this.title = "修改部门";
  290. });
  291. listDeptExcludeChild(row.deptId).then(response => {
  292. this.deptOptions = this.handleTree(response.data, "deptId");
  293. });
  294. },
  295. /** 提交按钮 */
  296. submitForm: function() {
  297. this.$refs["form"].validate(valid => {
  298. if (valid) {
  299. if (this.form.deptId != undefined) {
  300. updateDept(this.form).then(response => {
  301. this.msgSuccess("修改成功");
  302. this.open = false;
  303. this.getList();
  304. });
  305. } else {
  306. addDept(this.form).then(response => {
  307. this.msgSuccess("新增成功");
  308. this.open = false;
  309. this.getList();
  310. });
  311. }
  312. }
  313. });
  314. },
  315. /** 删除按钮操作 */
  316. handleDelete(row) {
  317. this.$confirm('是否确认删除名称为"' + row.deptName + '"的数据项?', "警告", {
  318. confirmButtonText: "确定",
  319. cancelButtonText: "取消",
  320. type: "warning"
  321. }).then(function() {
  322. return delDept(row.deptId);
  323. }).then(() => {
  324. this.getList();
  325. this.msgSuccess("删除成功");
  326. })
  327. },
  328. // 树形展开折叠
  329. forArr(arr, isExpand) {
  330. arr.forEach(i => {
  331. this.$refs.treeTable.toggleRowExpansion(i, isExpand)
  332. if (i.children) {
  333. this.forArr(i.children, isExpand)
  334. }
  335. })
  336. },
  337. isExpandAll(){
  338. this.isExpand = !this.isExpand;
  339. if(this.isExpand){
  340. this.forArr(this.deptList, true)
  341. }else{
  342. this.forArr(this.deptList, false)
  343. }
  344. },
  345. }
  346. };
  347. </script>
  348. <style>
  349. .el-carousel__item h3 {
  350. color: #475669;
  351. font-size: 14px;
  352. opacity: 0.75;
  353. line-height: 200px;
  354. margin: 0;
  355. }
  356. .el-carousel__item:nth-child(2n) {
  357. background-color: #99a9bf;
  358. }
  359. .el-carousel__item:nth-child(2n+1) {
  360. background-color: #d3dce6;
  361. }
  362. .statusTag{
  363. display: inline-block;
  364. height: 24px;
  365. line-height: 24px;
  366. font-size: 12px;
  367. color: #FFF;
  368. padding: 0 8px;
  369. border-radius: 12px;
  370. background: #24C9C5;
  371. }
  372. </style>