DeptMa.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="renderer" content="webkit">
  6. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  8. <meta http-equiv="pragma" content="no-cache">
  9. <meta http-equiv="Cache" content="no-cache">
  10. <meta http-equiv="cache-control" content="no-cache, must-revalidate">
  11. <meta http-equiv="expires" content="0">
  12. <meta name="viewport"
  13. content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  14. <title>部门管理</title>
  15. <link rel="stylesheet" href="../css/index.css">
  16. <link rel="stylesheet" href="../css/style.css">
  17. <script src="../js/vue.min.js"></script>
  18. <script src="../js/jquery.min.js"></script>
  19. <script src="../js/index.js"></script>
  20. <script src="../js/yz/init.js"></script>
  21. <script>
  22. checkLogin();
  23. </script>
  24. <style type="text/css">
  25. *{
  26. padding: 0;
  27. margin: 0;
  28. box-sizing: border-box;
  29. }
  30. body{
  31. padding: 10px;
  32. background-color: #040d32;
  33. }
  34. .search_ input {
  35. position: relative;
  36. width: 100%;
  37. height: 32px;
  38. line-height: 32px;
  39. border-radius: 4px;
  40. font-size: 14px;
  41. padding: 0 5px 0 25px;
  42. color: #dcdcdc;
  43. background-color: rgba(255, 255, 255, 0.2);
  44. border: 1px solid rgba(232, 232, 232, 0.3);
  45. }
  46. .search_ input::-webkit-input-placeholder {
  47. color: #dcdcdc;
  48. }
  49. .search_ .el-icon-search {
  50. position: absolute;
  51. left: 12px;
  52. top: 16px;
  53. color: #dcdcdc;
  54. }
  55. .elTable{
  56. width: 100%;
  57. border: 1px solid rgba(255, 255, 255, 0.2);
  58. }
  59. .el-table::before{
  60. height: 0;
  61. }
  62. .el-table::after{
  63. width: 0;
  64. }
  65. .el-table,.el-table__expanded-cell {
  66. color: #ddd;
  67. background-color: transparent !important;
  68. }
  69. .el-table tr,
  70. .el-table td {
  71. font-size: 14px;
  72. background-color: transparent !important;
  73. }
  74. .el-table td.el-table__cell,.el-table th.el-table__cell.is-leaf{
  75. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  76. }
  77. .el-table--border .el-table__cell{
  78. border-right: 1px solid rgba(255, 255, 255, 0.2);
  79. }
  80. .el-dialog__header{
  81. padding: 10px;
  82. }
  83. .el-dialog__title{
  84. font-size: 15px;
  85. }
  86. .el-dialog__headerbtn{
  87. top: 14px;
  88. }
  89. .el-dialog__body{
  90. padding: 10px;
  91. color: #fff;
  92. background-color: #082041;
  93. }
  94. .br{
  95. border: 1px solid rgba(255, 255, 255, 0.2);
  96. }
  97. .el-input__inner{
  98. height: 34px;
  99. line-height: 34px;
  100. }
  101. ._Form>div{
  102. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  103. }
  104. ._Form>div>div:first-child{
  105. width: 100px;
  106. height: 60px;
  107. line-height: 60px;
  108. border-right: 1px solid rgba(255, 255, 255, 0.2);
  109. }
  110. ._Form>div>div:last-child{
  111. width: calc(100% - 100px);
  112. padding: 0 10px;
  113. }
  114. .el-input__inner{
  115. color: #ececec;
  116. border-color: transparent;
  117. background-color: rgba(255, 255, 255, 0.2);
  118. }
  119. .el-input__inner::-webkit-input-placeholder {
  120. color: #a1a1a1;
  121. }
  122. .el-select .el-input__inner::-webkit-input-placeholder {
  123. color: #ececec;
  124. }
  125. ._Form .el-radio{
  126. color: #fff;
  127. }
  128. .el-radio__input.is-checked .el-radio__inner,
  129. .el-checkbox__input.is-checked .el-checkbox__inner,
  130. .el-checkbox__input.is-indeterminate .el-checkbox__inner,
  131. .el-button--success{
  132. border-color: #39b54a;
  133. background: #39b54a;
  134. }
  135. .el-radio__input.is-checked+.el-radio__label{
  136. color: #39b54a;
  137. }
  138. .el-icon-arrow-right{
  139. color: #fff;
  140. }
  141. .el-select-dropdown__item{
  142. height: auto;
  143. }
  144. .el-tree{
  145. color: #fff;
  146. background-color: transparent;
  147. }
  148. .el-select-dropdown__item.hover, .el-select-dropdown__item:hover,
  149. .el-tree-node__content:hover,.el-tree-node:focus>.el-tree-node__content{
  150. background-color: transparent;
  151. }
  152. .el-popper[x-placement^=bottom] .popper__arrow::after{
  153. border-bottom-color: #707070;
  154. }
  155. .el-select-dropdown{
  156. background-color: #707070;
  157. }
  158. </style>
  159. </head>
  160. <body>
  161. <div id="app">
  162. <div>
  163. <div class="flex align-center margin-bottom-sm">
  164. <div>
  165. <el-input placeholder="请输入关键词" v-model="inpKey" @input="_Search">
  166. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  167. </el-input>
  168. </div>
  169. <div class="tableTool">
  170. <el-button type="primary" size="small" class="margin-left-sm">查询</el-button>
  171. <el-button type="success" size="small" @click="newAdd">新增</el-button>
  172. </div>
  173. </div>
  174. <el-table
  175. :data="tableData"
  176. :header-cell-style="{background:'#082041',color:'#fff'}"
  177. class="elTable"
  178. row-key="deptId"
  179. border
  180. lazy
  181. load="load"
  182. :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
  183. <el-table-column align="center" prop="deptName" label="部门名称"> </el-table-column>
  184. <el-table-column align="center" prop="deptId" label="编号"> </el-table-column>
  185. <el-table-column align="center" prop="orderNum" label="排序"> </el-table-column>
  186. <el-table-column align="center" prop="status" label="状态">
  187. <template slot-scope="scope">
  188. <el-switch
  189. :value="scope.row.status == 0"
  190. disabled
  191. active-color="#13ce66"
  192. inactive-color="#ff4949">
  193. </el-switch>
  194. </template>
  195. </el-table-column>
  196. <el-table-column align="center" prop="createTime" label="创建时间"> </el-table-column>
  197. <el-table-column
  198. align="center"
  199. width="200"
  200. label="操作">
  201. <template slot-scope="scope">
  202. <el-button type="text" size="small" @click="newAdd(scope.row)" class="text-sray">
  203. <i class="el-icon-plus"></i>新增
  204. </el-button>
  205. <el-button type="text" size="small" @click="Edit(scope.row)" class="text-green">
  206. <i class="el-icon-edit"></i>编辑
  207. </el-button>
  208. <el-button type="text" size="small" @click="Delete(scope.row)" v-if="scope.row.parentId != 0" class="text-red">
  209. <i class="el-icon-delete"></i>删除
  210. </el-button>
  211. </template>
  212. </el-table-column>
  213. </el-table>
  214. </div>
  215. <el-dialog title="部门信息" :visible.sync="dialogVisible" width="400px">
  216. <div class="br" style="text-align: center;">
  217. <div class="_Form">
  218. <div class="flex align-center" v-if="nowForm.parentId != 0">
  219. <div><span class="text-red">*</span>上级部门</div>
  220. <div>
  221. <el-select :placeholder="parentName.deptName" ref="conSelect" style="width: 100%;">
  222. <el-option>
  223. <el-tree
  224. ref="tree"
  225. node-key="id"
  226. :data="tableData"
  227. :props="defaultProps"
  228. @node-click="nodeClick"
  229. />
  230. </el-option>
  231. </el-select>
  232. </div>
  233. </div>
  234. <div class="flex align-center">
  235. <div><span class="text-red">*</span>部门名称</div>
  236. <div><el-input v-model="nowForm.deptName" placeholder="部门名称"></el-input></div>
  237. </div>
  238. <div class="flex align-center">
  239. <div><span class="text-red">*</span>角色顺序</div>
  240. <div><el-input type="number" min="0" v-model="nowForm.orderNum" placeholder="角色顺序"></el-input></div>
  241. </div>
  242. <div class="flex align-center">
  243. <div>负责人</div>
  244. <div><el-input v-model="nowForm.leader" placeholder="负责人"></el-input></div>
  245. </div>
  246. <div class="flex align-center">
  247. <div>联系电话</div>
  248. <div><el-input v-model="nowForm.phone" placeholder="联系电话"></el-input></div>
  249. </div>
  250. <div class="flex align-center">
  251. <div>邮箱</div>
  252. <div><el-input v-model="nowForm.email" placeholder="邮箱"></el-input></div>
  253. </div>
  254. <div class="flex align-center" style="border: none;">
  255. <div>状态</div>
  256. <div class="text-left">
  257. <el-radio v-model="nowForm.status" label="0">正常</el-radio>
  258. <el-radio v-model="nowForm.status" label="1">停用</el-radio>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. <div class="padding-sm text-center">
  264. <el-button size="small" @click="dialogVisible = false;">取消</el-button>
  265. <el-button size="small" type="success" @click="conFirm">提交</el-button>
  266. </div>
  267. </el-dialog>
  268. </div>
  269. <script>
  270. var _this, dataObj=[];
  271. new Vue({
  272. el: '#app',
  273. data: function() {
  274. return {
  275. tableData: [],
  276. nowForm:{
  277. deptName: "",
  278. email: "",
  279. leader: "",
  280. orderNum: 0,
  281. phone:"",
  282. status:"0",
  283. },
  284. dialogVisible:false,
  285. inpKey:"",
  286. defaultProps: {
  287. children: 'children',
  288. label: 'label'
  289. },
  290. parentName: {
  291. deptName: "请选择",
  292. deptId: ""
  293. }
  294. }
  295. },
  296. created() {
  297. _this = this;
  298. _this.getList();
  299. },
  300. methods: {
  301. getList() {
  302. let data1 = {
  303. pageNum:1,
  304. pageSize:100
  305. };
  306. let _opts = {
  307. url: "/system/dept/list",
  308. type:"GET"
  309. };
  310. tokenAjax(_opts, data1)
  311. .then(function(res) {
  312. if (res.code == 200) {
  313. _this.tableData = _this.getTrees(res.data, 0);
  314. dataObj = res.data;
  315. }else{
  316. _this.$message.error(res.msg);
  317. }
  318. })
  319. },
  320. getTrees(data, parentId) {
  321. var tree = [];
  322. var temp;
  323. for (var i = 0; i < data.length; i++) {
  324. data[i].label = data[i].deptName;
  325. data[i].id = data[i].deptId;
  326. if (data[i].parentId == parentId) {
  327. var obj = data[i];
  328. temp = _this.getTrees(data, data[i].deptId);
  329. if (temp.length > 0) {
  330. obj.children = [...temp];
  331. }
  332. tree.push(obj);
  333. }
  334. }
  335. return tree;
  336. },
  337. _Search(_key){
  338. let newArr = [],_ovj = dataObj;
  339. if(_key == ""){
  340. newArr = dataObj;
  341. }else{
  342. for(var i=0;i<_ovj.length;i++){
  343. if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
  344. newArr.push(_ovj[i])
  345. }
  346. }
  347. }
  348. _this.tableData = _this.getTrees(newArr, 0);
  349. },
  350. newAdd(_row){
  351. if(_row.deptId != undefined){
  352. _this.parentName = {
  353. deptName: _row.deptName,
  354. deptId: _row.deptId
  355. };
  356. }else{
  357. _this.parentName = {
  358. deptName: _this.tableData[0].deptName,
  359. deptId: _this.tableData[0].deptId
  360. };
  361. }
  362. _this.nowForm = {
  363. deptName: "",
  364. email: "",
  365. leader: "",
  366. orderNum: 0,
  367. phone:"",
  368. status:"0",
  369. };
  370. _this.dialogVisible = true;
  371. },
  372. Edit(_row){
  373. let data1 = {};
  374. let _opts = {
  375. url: "/system/dept/" + _row.deptId,
  376. type:"GET"
  377. };
  378. tokenAjax(_opts, data1)
  379. .then(function(res) {
  380. if (res.code == 200) {
  381. dataObj.forEach((it,ind)=>{
  382. if(it.deptId == _row.parentId){
  383. _this.parentName = {
  384. deptName: it.deptName,
  385. deptId: it.deptId
  386. };
  387. }
  388. })
  389. _this.nowForm = res.data;
  390. _this.dialogVisible = true;
  391. }
  392. })
  393. },
  394. Delete(_row){
  395. _this.$confirm('是否确认删除编号为"'+_row.deptId+'"的数据项?', '温馨提示', {
  396. confirmButtonText: '确定',
  397. cancelButtonText: '取消',
  398. type: 'warning'
  399. }).then(() => {
  400. let data1 = {};
  401. let _opts = {
  402. url: "/system/dept/"+_row.deptId,
  403. type:"DELETE"
  404. };
  405. tokenAjax(_opts, data1)
  406. .then(function(res) {
  407. if(res.code == 200){
  408. _this.$message({
  409. type: 'success',
  410. message: '删除成功!'
  411. });
  412. _this.getList();
  413. }else{
  414. _this.$message.error(res.msg);
  415. }
  416. })
  417. }).catch(() => {
  418. });
  419. },
  420. conFirm(){
  421. if(_this.nowForm.parentId != 0){
  422. _this.nowForm.parentId = _this.parentName.deptId;
  423. }
  424. if(_this.nowForm.deptName == ""){
  425. _this.$message({
  426. type: 'warning',
  427. message: "请输入部门名称"
  428. });
  429. return;
  430. }
  431. if(_this.nowForm.parentId == undefined){
  432. _this.$message({
  433. type: 'warning',
  434. message: "请输入选择上级部门"
  435. });
  436. return;
  437. }
  438. if(_this.nowForm.phone != ""&&_this.nowForm.phone != null&&(!(/^1[3456789]\d{9}$/.test(_this.nowForm.phone)))){
  439. _this.$message({
  440. type: 'warning',
  441. message: '请输入正确的手机号码',
  442. })
  443. return;
  444. }
  445. if(_this.nowForm.email != ""&&_this.nowForm.email != null&&(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(_this.nowForm.email)))){
  446. _this.$message({
  447. type: 'warning',
  448. message: '请输入正确的邮箱格式',
  449. })
  450. return;
  451. }
  452. let data1 = _this.nowForm;
  453. let _opts = {
  454. url:"/system/dept",
  455. type: _this.nowForm.deptId == undefined?"POST":"PUT"
  456. };
  457. tokenPostAjax(_opts,data1)
  458. .then(function(res){
  459. if(res.code == 200){
  460. _this.$message({
  461. type: 'success',
  462. message: '操作成功!'
  463. });
  464. _this.getList();
  465. _this.dialogVisible = false;
  466. }else{
  467. _this.$message.error(res.msg);
  468. }
  469. })
  470. },
  471. nodeClick(_e){
  472. _this.parentName = {
  473. deptName: _e.deptName,
  474. deptId: _e.deptId
  475. };
  476. this.$refs.conSelect.blur();
  477. }
  478. }
  479. })
  480. </script>
  481. </body>
  482. </html>