123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- var _this, dataObj=[], _Tok = null;
- new Vue({
- el: '#app',
- data: function() {
- return {
- tableData: [],
- nowForm:{
- deptName: "",
- email: "",
- leader: "",
- orderNum: 0,
- phone:"",
- status:"0",
- },
- dialogVisible:false,
- inpKey:"",
- defaultProps: {
- children: 'children',
- label: 'label'
- },
- parentName: {
- deptName: "请选择",
- deptId: ""
- }
- }
- },
- created() {
- _this = this;
- _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
- _this.getList();
- },
- methods: {
- getList() {
- let data1 = {
- pageNum:1,
- pageSize:100
- };
- let _opts = {
- url: baseUrl + "/system/dept/list",
- type:"GET"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1, _he)
- .then(function(res) {
- if (res.code == 200) {
- _this.tableData = _this.getTrees(res.data, 0);
- dataObj = res.data;
- }else{
- _this.$message.error(res.msg);
- }
- })
- },
- getTrees(data, parentId) {
- var tree = [];
- var temp;
- for (var i = 0; i < data.length; i++) {
- data[i].label = data[i].deptName;
- data[i].id = data[i].deptId;
- if (data[i].parentId == parentId) {
- var obj = data[i];
- temp = _this.getTrees(data, data[i].deptId);
- if (temp.length > 0) {
- obj.children = [...temp];
- }
- tree.push(obj);
- }
- }
- return tree;
- },
- Search(_key){
- let newArr = [],_ovj = dataObj;
- if(_key == ""){
- newArr = dataObj;
- }else{
- for(var i=0;i<_ovj.length;i++){
- if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
- newArr.push(_ovj[i])
- }
- }
- }
- _this.tableData = _this.getTrees(newArr, 0);
- },
- newAdd(_row){
- if(_row.deptId != undefined){
- _this.parentName = {
- deptName: _row.deptName,
- deptId: _row.deptId
- };
- }else{
- _this.parentName = {
- deptName: _this.tableData[0].deptName,
- deptId: _this.tableData[0].deptId
- };
- }
- _this.nowForm = {
- deptName: "",
- email: "",
- leader: "",
- orderNum: 0,
- phone:"",
- status:"0",
- };
- _this.dialogVisible = true;
- },
- Edit(_row){
- let data1 = {};
- let _opts = {
- url: baseUrl + "/system/dept/" + _row.deptId,
- type:"GET"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1, _he)
- .then(function(res) {
- if (res.code == 200) {
- dataObj.forEach((it,ind)=>{
- if(it.deptId == _row.parentId){
- _this.parentName = {
- deptName: it.deptName,
- deptId: it.deptId
- };
- }
- })
- _this.nowForm = res.data;
- _this.dialogVisible = true;
- }
- })
- },
- Delete(_row){
- _this.$confirm('是否确认删除编号为"'+_row.deptId+'"的数据项?', '温馨提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- let data1 = {};
- let _opts = {
- url: baseUrl + "/system/dept/"+_row.deptId,
- type:"DELETE"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1, _he)
- .then(function(res) {
- if(res.code == 200){
- _this.$message({
- type: 'success',
- message: '删除成功!'
- });
- _this.getList();
- }else{
- _this.$message.error(res.msg);
- }
- })
- }).catch(() => {
-
- });
- },
- conFirm(){
- if(_this.nowForm.parentId != 0){
- _this.nowForm.parentId = _this.parentName.deptId;
- }
- if(_this.nowForm.deptName == ""){
- _this.$message({
- type: 'warning',
- message: "请输入部门名称"
- });
- return;
- }
- if(_this.nowForm.parentId == undefined){
- _this.$message({
- type: 'warning',
- message: "请输入选择上级部门"
- });
- return;
- }
- if(_this.nowForm.phone != ""&&_this.nowForm.phone != null&&(!(/^1[3456789]\d{9}$/.test(_this.nowForm.phone)))){
- _this.$message({
- type: 'warning',
- message: '请输入正确的手机号码',
- })
- return;
- }
- if(_this.nowForm.email != ""&&_this.nowForm.email != null&&(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(_this.nowForm.email)))){
- _this.$message({
- type: 'warning',
- message: '请输入正确的邮箱格式',
- })
- return;
- }
- let data1 = JSON.stringify(_this.nowForm);
- let _opts = {
- url:baseUrl + "/system/dept",
- type: _this.nowForm.deptId == undefined?"POST":"PUT"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok,
- "Content-Type": 'application/json; charset=UTF-8'
- };
- postAxios(_opts,data1, _he)
- .then(function(res){
- if(res.code == 200){
- _this.$message({
- type: 'success',
- message: '操作成功!'
- });
- _this.getList();
- _this.dialogVisible = false;
- }else{
- _this.$message.error(res.msg);
- }
- })
- },
- nodeClick(_e){
- _this.parentName = {
- deptName: _e.deptName,
- deptId: _e.deptId
- };
- this.$refs.conSelect.blur();
- }
- }
- })
|