@node-click="departmentTreeNodeClick">
label-position="right" size="small" class="departmentform" min-width="500px"> name="file" :before-upload="beforeAvatarUpload" :on-success="handleSuccess"> {{zfzr}} {{fgld}} {{bangongshi}}
{{fgld}}
{{zfzr}}
import { MP } from "@/utils/map";
import fetch from "@/utils/fetch.js";
import { Message } from "element-ui";
import Tree from "@/views/sys/tree";
import xzry from "@/template/selectpeople/xzry";
export default {
data() {
return {
danwei: false,
bumen: false,
//办公室主任
bangongshi: "",
//主管领导
zgld: "",
//分管领导
fgld: "",
//主负责人
zfzr: "",
text: [],
fileList: [],
deptLongitude: null,
deptLatitude: null,
departmentTreeData: [],
departmentFormData: {
deptLongitude: null,
deptLatitude: null
},
isVisiable: false,
type: "",
selectId: [],
//数据验证
departmentFormRules: {
deptCode: [
{ required: true, message: "请输入编号" },
{ min: 1, max: 11, message: "长度不能大于11位" }
],
deptName: [
{ required: true, message: "请输入名称" },
{ min: 2, max: 200, message: "长度2到200字符" }
],
deptSname: [
{ required: true, message: "请输入简称" },
{ min: 2, max: 200, message: "长度2到200字符" }
],
deptBillname: [{ min: 1, max: 200, message: "长度为1到200个字符" }],
deptAddress: [{ min: 1, max: 200, message: "长度为1到200个字符" }],
deptFlag: [{ required: true, message: "请选择你的标记" }],
},
m: null,
};
},
created: function() {
this.getDepartmentTreeList();
this.handleOpen();
this.leaderShow();
},
methods: {
leaderShow() {},
f() {
this.$refs.xzry.init();
},
huixian(data) {
if (this.departmentFormData.deptFlag == "1") {
this.text = data;
this.callback();
} else {
if (data.length > 1) {
Message({
message: "选择人员数大于1,请重新选择",
type: "error",
duration: 3 * 1000
});
} else {
this.text = data;
this.callback();
}
}
},
handleOpen() {
var that = this;
this.$nextTick(() => {
MP("R8b2KReUQd2osuCG4ORGqftcxvLXpNlG").then(BMap => {
this.m = new BMap.Map("container");
var point = new BMap.Point(125.349631, 43.869385);
var markers = new BMap.Marker(point);
this.m.addOverlay(markers);
markers.setAnimation(BMAP_ANIMATION_BOUNCE);
this.m.centerAndZoom("长春", 10);
this.m.enableScrollWheelZoom();
this.m.addEventListener("click", function(e) {
that.m.clearOverlays();
var marker = new BMap.Marker(
new BMap.Point(e.point.lng, e.point.lat)
);
that.m.addOverlay(marker);
marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
that.departmentFormData.deptLongitude = e.point.lng;
that.departmentFormData.deptLatitude = e.point.lat;
});
});
});
},
handleSuccess(res) {
if (res.code == "0") {
this.departmentFormData.deptLogo = res.data.dir;
}
},
beforeAvatarUpload(file) {
// 类型验证
const extension = file.type.toString().split("/")[0] == "image";
// 大小验证
const isLt2M = file.size / 1024 / 1024 < 10;
if (!extension) {
this.$message.error("上传模板只能是图片!");
}
if (!isLt2M) {
this.$message.error("上传缩略图大小不能超过 10MB!");
}
return extension && isLt2M;
},
handleChange(file, fileList) {},
//获取部门数据
getDepartmentTreeList() {
//获取数据
fetch
.get("/api/department")
.then(res => {
if (res.code == "0") {
this.departmentTreeData = this.toTree(
res.data,
0,
"deptId",
"deptName",
"deptPid"
);
} else {
Message({
message: res.msg,
type: "error",
duration: 5 * 1000
});
}
})
.catch(error => {
console.log(error);
});
},
//获取部门详细信息
departmentTreeNodeClick(data) {
this.zgld = "";
this.fgld = "";
this.zfzr = "";
this.bangongshi = "";
fetch
.get("/api/department/" + data.deptId)
.then(res => {
if (res.code == "0") {
this.departmentFormData = res.data;
if (res.data.deptPid == 1) {
this.danwei = true;
this.bumen = false;
} else {
this.bumen = true;
this.danwei = false;
}
// this.getleaders(data.deptId);
this.mapup();
} else {
Message({
message: res.msg,
type: "error",
duration: 5 * 1000
});
}
})
.catch(error => {
console.log("555", error);
});
},
getleaders(deptId) {
this.fgld = "";
fetch.get("/api/departmentmanager/getdept/" + deptId).then(res1 => {
if (res1.code == "0") {
if (res1.data != null) {
res1.data.forEach(element => {
if (element.managerType == "deputygeneral") {
this.zgld = element.userName;
} else if (element.managerType == "manager") {
this.fgld += element.userName + ",";
} else if (element.managerType == "leadership") {
this.zfzr = element.userName;
} else if (element.managerType == "office") {
this.bangongshi = element.userName;
}
});
if (this.fgld != "") {
// console.log(this.fgld)
this.fgld = this.fgld.substring(0, this.fgld.length - 1);
}
}
}
});
},
mapup() {
var xy = this.departmentFormData;
if (
xy.deptLongitude != null &&
xy.deptLatitude != null &&
xy.deptRange != null
) {
var po = new BMap.Point(xy.deptLongitude, xy.deptLatitude);
var markers = new BMap.Marker(po);
this.m.clearOverlays();
this.m.addOverlay(markers);
markers.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
this.m.centerAndZoom(po, 16);
this.m.enableScrollWheelZoom();
} else {
this.m.clearOverlays();
this.m.centerAndZoom("吉林市", 12);
this.m.enableScrollWheelZoom();
}
},
//更新信息
saveDepartmentData(editDepartmentForm) {
this.$refs[editDepartmentForm].validate(valid => {
if (valid) {
fetch
.post("/api/department/save", {
deptId: this.departmentFormData.deptId,
deptCode: this.departmentFormData.deptCode,
deptName: this.departmentFormData.deptName,
deptSname: this.departmentFormData.deptSname,
deptPid: this.departmentFormData.deptPid,
deptFlag: this.departmentFormData.deptFlag,
deptAddress: this.departmentFormData.deptAddress,
deptBillname: this.departmentFormData.deptBillname,
deptOrder: this.departmentFormData.deptOrder,
deptZt: this.departmentFormData.deptZt,
deptTel: this.departmentFormData.deptTel,
deptLogo: this.departmentFormData.deptLogo,
deptLongitude: this.departmentFormData.deptLongitude,
deptLatitude: this.departmentFormData.deptLatitude,
deptRange: this.departmentFormData.deptRange
})
.then(res => {
if (res.code == "0") {
Message({
message: "操作成功",
type: "success",
duration: 3 * 1000
});
//成功后刷新数据
this.getDepartmentTreeList();
//成功清除form中数据
this.$refs[editDepartmentForm].resetFields();
} else {
Message({
message: res.msg,
type: "error",
duration: 5 * 1000
});
}
})
.catch(error => {
console.log(error);
});
}
});
},
//添加下级部门
addSubDepartment() {
//父ID等于deptId
this.departmentFormData.deptPid = this.departmentFormData.deptId;
//状态默认为1
this.departmentFormData.deptZt = 1;
//id调整为0 新增
this.departmentFormData.deptId = 0;
//默认选择部门
this.departmentFormData.deptFlag = "0";
//清空信息
this.departmentFormData.deptName = null;
this.departmentFormData.deptSname = null;
this.departmentFormData.deptOrder = null;
this.departmentFormData.deptAddress = null;
this.departmentFormData.deptBillname = null;
this.departmentFormData.deptCode = null;
this.departmentFormData.deptTel = null;
this.departmentFormData.deptLongitude = null;
this.departmentFormData.deptLatitude = null;
},
//添加同级部门
addSameLevelDepartment() {
//id默认为0
this.departmentFormData.deptId = 0;
//同级父ID不变
this.departmentFormDatadeptPid = this.departmentFormData.deptPid;
//状态默认为1
this.departmentFormData.deptZt = 1;
//默认选择部门
this.departmentFormData.deptFlag = "0";
//清空信息
this.departmentFormData.deptName = null;
this.departmentFormData.deptSname = null;
this.departmentFormData.deptOrder = null;
this.departmentFormData.deptAddress = null;
this.departmentFormData.deptBillname = null;
this.departmentFormData.deptCode = null;
this.departmentFormData.deptTel = null;
this.departmentFormData.deptLongitude = null;
this.departmentFormData.deptLatitude = null;
},
//删除
deleteDepartmentData() {
this.departmentFormData.deptZt = "0";
this.$confirm("是否确定删除此信息", "提示", {
type: "warning",
confirmButtonText: "确定",
cancelButtonText: "取消"
})
.then(() => {
fetch
.get(
"/api/department/findChildList/" + this.departmentFormData.deptId
)
.then(res => {
if (res.data.length != 0) {
alert("该组织存在下级部门,不能删除");
} else {
this.saveDepartmentData("editDepartmentForm");
}
});
})
.catch(error => {
console.log(error);
});
},
setLeader(type) {
// console.log("999",this.departmentFormData)
this.selectId = [];
console.log(this.departmentFormData.deptCode);
if (this.notNull(this.departmentFormData.deptCode)) {
fetch
.post("/api/departmentmanager/getuser", {
deptId: this.departmentFormData.deptId,
type: type
})
.then(res => {
// console.log(888,res);
res.data.forEach(element => {
this.selectId.push("u_" + element.userId);
});
this.$refs.xzry.init(this.departmentFormData.deptId);
// this.isVisiable = !this.isVisiable;
// this.$nextTick(() => {
// this.$refs.Tree.init();
// });
this.type = type;
})
.catch(err => {
console.log("444", err);
});
// fetch
// .post("/api/department/getleader", {
// bmId: this.departmentFormData.deptId,
// type: type
// })
// .then(res => {
// res.data.forEach(element => {
// this.selectId.push("u_" + element.userId);
// });
// this.isVisiable = !this.isVisiable;
// this.$nextTick(() => {
// this.$refs.Tree.init()
// })
// this.type = type;
// })
// .catch(err => {
// });
} else {
Message({
message: "请先选择一个单位或部门",
type: "error",
duration: 5 * 1000
});
}
},
callback() {
var ids = [];
for (var i in this.text) {
if (this.text[i].userId != "" && this.text[i].userId != undefined) {
ids.push(this.text[i].userId);
}
}
// console.log("IDS",ids.join())
// var ids = this.$refs.Tree._setCheckedNodes();
// console.log("sdf",this.text)
fetch
.post("/api/departmentmanager/save", {
ids: ids.join(),
deptId: this.departmentFormData.deptId,
type: this.type
})
.then(res => {
if (res.code == "0") {
Message({
message: res.msg,
type: "success",
duration: 3 * 1000
});
this.isVisiable = !this.isVisiable;
this.getleaders(this.departmentFormData.deptId);
} else {
this.isVisiable = !this.isVisiable;
this.departmentTreeNodeClick(this.departmentFormData);
Message({
message: "删除成功",
type: "error",
duration: 3 * 1000
});
}
})
.catch(error => {
console.log(error);
});
},
scLogo() {}
},
components: {
Tree,
xzry
}
};
.departmentTree {
color: #373f4a;
height: 380px;
overflow: auto;
background: #e5e9f2;
border: 1px solid #e0dddd;
}
.departmentform {
margin: 40px 0px 0px 20px;
}
.savebutton {
margin: 40px 0px 0px 0px;
}
.wz {
margin: 5px 5px 0px 0px;
}