地图VUE2019-08-01

<template>

  <div>

    <xzry ref="xzry" @data="huixian"></xzry>

    <el-row :gutter="20" style="height:80vh;overflow-y:scroll;overflow-x:hidden">

      <el-col :span="6">

        <el-tree style="height:70vh;" class="departmentTree" :data="departmentTreeData" :default-expand-all="true" :expand-on-click-node="false"

          @node-click="departmentTreeNodeClick">

        </el-tree>

      </el-col>

      <el-col :span="16">

        <el-form ref="editDepartmentForm" :model="departmentFormData" :rules="departmentFormRules" label-width="120px"

          label-position="right" size="small" class="departmentform" min-width="500px">

          <el-row :gutter="20">

            <el-col :span="12">

              <el-form-item label="ID:" prop="deptId" hidden>

                <el-input v-model="departmentFormData.deptId" placeholder="ID" disabled></el-input>

              </el-form-item>

              <el-form-item label="编码:" prop="deptCode">

                <el-input v-model="departmentFormData.deptCode" placeholder="编码"></el-input>

              </el-form-item>

              <el-form-item label="名称:" prop="deptName">

                <el-input v-model="departmentFormData.deptName" placeholder="名称"></el-input>

              </el-form-item>

              <el-form-item label="简称:" prop="deptSname">

                <el-input v-model="departmentFormData.deptSname" placeholder="简称"></el-input>

              </el-form-item>             

              <el-form-item label="公文名称:" prop="deptbillname">

                <el-input v-model="departmentFormData.deptBillname" placeholder="公文名称"></el-input>

              </el-form-item>

              <el-form-item label="电话:" prop="deptTel">

                <el-input v-model="departmentFormData.deptTel" placeholder="电话"></el-input>

              </el-form-item>

              <el-form-item label="经度:" prop="deptLongitude" hidden>

                <el-input placeholder="经度" v-model="departmentFormData.deptLongitude"></el-input>

              </el-form-item>

              <el-form-item label="纬度:" prop="deptLatitude" hidden>

                <el-input placeholder="纬度" v-model="departmentFormData.deptLatitude"></el-input>

              </el-form-item>

              <el-form-item label="范围:" prop="deptRange" hidden>

                <el-input placeholder="范围" v-model="departmentFormData.deptRange"></el-input>

              </el-form-item>

            </el-col>

            <el-col :span="12">

              <el-form-item label="单位/部门:" prop="deptFlag">

                <el-radio v-model="departmentFormData.deptFlag" label="1">单位</el-radio>

                <el-radio v-model="departmentFormData.deptFlag" label="0">部门</el-radio>

              </el-form-item>

              <el-form-item label="排序:" prop="deptOrder">

                <el-slider v-model="departmentFormData.deptOrder" :step="1" :max="20" show-stops>

                </el-slider>

              </el-form-item>

              <el-form-item label="地址:" prop="deptAddress">

                <el-input v-model="departmentFormData.deptAddress" placeholder="地址"></el-input>

              </el-form-item>


              <el-row :gutter="12">

                <el-col :span="6">

                  <el-form-item label="LOGO:" prop="deptLogo">

                    <img :src="'/api/upload/download?fileName='+departmentFormData.deptLogo" alt="" style="width: 80px;height: 80px">

                  </el-form-item>

                </el-col>

                <el-col :span="6">

                  <el-form-item label="" prop="deptLogo">

                    <el-upload :show-file-list="false" :file-list="fileList" :on-change="handleChange" action="/api/upload/"

                      name="file" :before-upload="beforeAvatarUpload" :on-success="handleSuccess">

                      <el-button size="small" type="warning">上传LOGO</el-button>

                      <!-- <div>只能上传jpg/png文件</div> -->

                    </el-upload>

                  </el-form-item>

                </el-col>

              </el-row>

              <el-form-item label="添加操作:">

                <el-button type="primary" @click="addSameLevelDepartment()" round v-if="$hasPermission('department:save')">添加同级</el-button>

                <el-button type="primary" @click="addSubDepartment()" round v-if="$hasPermission('department:save')">添加下级</el-button>

              </el-form-item>

              <!-- <el-button type="primary" @click="setLeader('deputygeneral')" round v-if="$hasPermission('department:save')&&departmentFormData.deptFlag=='1'">主管领导</el-button> -->

              <!-- <el-button type="primary" @click="setLeader('deputy')" round v-if="$hasPermission('department:save')&&departmentFormData.deptFlag=='0'">副负责人</el-button>

                <el-button type="primary" class="wz" @click="setLeader('deputy')" round v-if="$hasPermission('department:save')&&departmentFormData.deptFlag=='1'">副负责人</el-button> -->

              <el-form-item label="领导设置:" style="width:600px" v-show="false">

                <!-- <div v-if="departmentFormData.deptFlag=='1'" style="padding:0px 10px 10px 10px;">

                    <span>

                    <el-button type="primary" @click="setLeader('deputygeneral')" round v-if="$hasPermission('department:save')">主管领导</el-button>

                    </span>

                    <span style="padding-left:20px">{{zgld}}</span>

                  </div>    -->

                <div v-show="danwei">

                  <div style="padding:10px;">

                    <span>

                      <el-button type="primary" @click="setLeader('leadership')" round v-if="$hasPermission('department:save')">主要负责人</el-button>

                    </span>

                    <span style="padding-left:20px">{{zfzr}}</span>

                  </div>

                  <div style="padding-left:10px;">

                    <span>

                      <el-button type="primary" @click="setLeader('manager')" round v-if="$hasPermission('department:save')">分管领导</el-button>

                    </span>

                    <span style="padding-left:20px">{{fgld}}</span>

                  </div>

                  <div style="padding:10px;">

                    <span>

                      <el-button type="primary" @click="setLeader('office')" round v-if="$hasPermission('department:save')">办公室主任</el-button>

                    </span>

                    <span style="padding-left:20px">{{bangongshi}}</span>

                  </div>

                </div>

                <div v-show="bumen">

                  <div style="padding-left:10px;">

                    <span>

                      <el-button type="primary" @click="setLeader('manager')" round v-if="$hasPermission('department:save')">分管领导</el-button>

                    </span>

                    <span style="padding-left:20px">{{fgld}}</span>

                  </div>

                  <div style="padding:10px;">

                    <span>

                      <el-button type="primary" @click="setLeader('leadership')" round v-if="$hasPermission('department:save')">主要负责人</el-button>

                    </span>

                    <span style="padding-left:20px">{{zfzr}}</span>

                  </div>

                </div>

              </el-form-item>             

            </el-col>

            <el-col :span="24">

              <el-form-item label="位置">

                <div id="container" style="height:300px">您使用的浏览器版本过低,请换高版本浏览器查看。</div>

              </el-form-item>

              <el-form-item align="center">

                <el-button type="danger" @click="deleteDepartmentData()" round v-if="$hasPermission('department:save')">删除</el-button>

                <el-button type="primary" @click="saveDepartmentData('editDepartmentForm')" round v-if="$hasPermission('department:save')">立即保存</el-button>

              </el-form-item>

            </el-col>

          </el-row>

        </el-form>

      </el-col>

    </el-row>

  </div>

</template>

<script>

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

  }

};

</script>

<style scoped>

.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;

}

</style>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,875评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,569评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,475评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,459评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,537评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,563评论 1 293
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,580评论 3 414
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,326评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,773评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,086评论 2 330
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,252评论 1 343
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,921评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,566评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,190评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,435评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,129评论 2 366
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,125评论 2 352

推荐阅读更多精彩内容