deptManage.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. var _this, dataObj=[], _Tok = null;
  2. new Vue({
  3. el: '#app',
  4. data: function() {
  5. return {
  6. tableData: [],
  7. nowForm:{
  8. deptName: "",
  9. email: "",
  10. leader: "",
  11. orderNum: 0,
  12. phone:"",
  13. status:"0",
  14. },
  15. dialogVisible:false,
  16. inpKey:"",
  17. defaultProps: {
  18. children: 'children',
  19. label: 'label'
  20. },
  21. parentName: {
  22. deptName: "请选择",
  23. deptId: ""
  24. }
  25. }
  26. },
  27. created() {
  28. _this = this;
  29. _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  30. _this.getList();
  31. },
  32. methods: {
  33. getList() {
  34. let data1 = {
  35. pageNum:1,
  36. pageSize:100
  37. };
  38. let _opts = {
  39. url: baseUrl + "/system/dept/list",
  40. type:"GET"
  41. };
  42. let _he = {
  43. "Authorization":"Bearer "+_Tok
  44. };
  45. getAxios(_opts, data1, _he)
  46. .then(function(res) {
  47. if (res.code == 200) {
  48. _this.tableData = _this.getTrees(res.data, 0);
  49. dataObj = res.data;
  50. }else{
  51. _this.$message.error(res.msg);
  52. }
  53. })
  54. },
  55. getTrees(data, parentId) {
  56. var tree = [];
  57. var temp;
  58. for (var i = 0; i < data.length; i++) {
  59. data[i].label = data[i].deptName;
  60. data[i].id = data[i].deptId;
  61. if (data[i].parentId == parentId) {
  62. var obj = data[i];
  63. temp = _this.getTrees(data, data[i].deptId);
  64. if (temp.length > 0) {
  65. obj.children = [...temp];
  66. }
  67. tree.push(obj);
  68. }
  69. }
  70. return tree;
  71. },
  72. Search(_key){
  73. let newArr = [],_ovj = dataObj;
  74. if(_key == ""){
  75. newArr = dataObj;
  76. }else{
  77. for(var i=0;i<_ovj.length;i++){
  78. if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
  79. newArr.push(_ovj[i])
  80. }
  81. }
  82. }
  83. _this.tableData = _this.getTrees(newArr, 0);
  84. },
  85. newAdd(_row){
  86. if(_row.deptId != undefined){
  87. _this.parentName = {
  88. deptName: _row.deptName,
  89. deptId: _row.deptId
  90. };
  91. }else{
  92. _this.parentName = {
  93. deptName: _this.tableData[0].deptName,
  94. deptId: _this.tableData[0].deptId
  95. };
  96. }
  97. _this.nowForm = {
  98. deptName: "",
  99. email: "",
  100. leader: "",
  101. orderNum: 0,
  102. phone:"",
  103. status:"0",
  104. };
  105. _this.dialogVisible = true;
  106. },
  107. Edit(_row){
  108. let data1 = {};
  109. let _opts = {
  110. url: baseUrl + "/system/dept/" + _row.deptId,
  111. type:"GET"
  112. };
  113. let _he = {
  114. "Authorization":"Bearer "+_Tok
  115. };
  116. getAxios(_opts, data1, _he)
  117. .then(function(res) {
  118. if (res.code == 200) {
  119. dataObj.forEach((it,ind)=>{
  120. if(it.deptId == _row.parentId){
  121. _this.parentName = {
  122. deptName: it.deptName,
  123. deptId: it.deptId
  124. };
  125. }
  126. })
  127. _this.nowForm = res.data;
  128. _this.dialogVisible = true;
  129. }
  130. })
  131. },
  132. Delete(_row){
  133. _this.$confirm('是否确认删除编号为"'+_row.deptId+'"的数据项?', '温馨提示', {
  134. confirmButtonText: '确定',
  135. cancelButtonText: '取消',
  136. type: 'warning'
  137. }).then(() => {
  138. let data1 = {};
  139. let _opts = {
  140. url: baseUrl + "/system/dept/"+_row.deptId,
  141. type:"DELETE"
  142. };
  143. let _he = {
  144. "Authorization":"Bearer "+_Tok
  145. };
  146. getAxios(_opts, data1, _he)
  147. .then(function(res) {
  148. if(res.code == 200){
  149. _this.$message({
  150. type: 'success',
  151. message: '删除成功!'
  152. });
  153. _this.getList();
  154. }else{
  155. _this.$message.error(res.msg);
  156. }
  157. })
  158. }).catch(() => {
  159. });
  160. },
  161. conFirm(){
  162. if(_this.nowForm.parentId != 0){
  163. _this.nowForm.parentId = _this.parentName.deptId;
  164. }
  165. if(_this.nowForm.deptName == ""){
  166. _this.$message({
  167. type: 'warning',
  168. message: "请输入部门名称"
  169. });
  170. return;
  171. }
  172. if(_this.nowForm.parentId == undefined){
  173. _this.$message({
  174. type: 'warning',
  175. message: "请输入选择上级部门"
  176. });
  177. return;
  178. }
  179. if(_this.nowForm.phone != ""&&_this.nowForm.phone != null&&(!(/^1[3456789]\d{9}$/.test(_this.nowForm.phone)))){
  180. _this.$message({
  181. type: 'warning',
  182. message: '请输入正确的手机号码',
  183. })
  184. return;
  185. }
  186. if(_this.nowForm.email != ""&&_this.nowForm.email != null&&(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(_this.nowForm.email)))){
  187. _this.$message({
  188. type: 'warning',
  189. message: '请输入正确的邮箱格式',
  190. })
  191. return;
  192. }
  193. let data1 = JSON.stringify(_this.nowForm);
  194. let _opts = {
  195. url:baseUrl + "/system/dept",
  196. type: _this.nowForm.deptId == undefined?"POST":"PUT"
  197. };
  198. let _he = {
  199. "Authorization":"Bearer "+_Tok,
  200. "Content-Type": 'application/json; charset=UTF-8'
  201. };
  202. postAxios(_opts,data1, _he)
  203. .then(function(res){
  204. if(res.code == 200){
  205. _this.$message({
  206. type: 'success',
  207. message: '操作成功!'
  208. });
  209. _this.getList();
  210. _this.dialogVisible = false;
  211. }else{
  212. _this.$message.error(res.msg);
  213. }
  214. })
  215. },
  216. nodeClick(_e){
  217. _this.parentName = {
  218. deptName: _e.deptName,
  219. deptId: _e.deptId
  220. };
  221. this.$refs.conSelect.blur();
  222. }
  223. }
  224. })