mapControl.vue 4.3 KB
<template>
  <div>
    <el-drawer
      @mousedown.prevent
      @selectstart.prevent
      @dblclick.prevent
      title="管制区域"
      :visible.sync="control"
      :direction="direction"
      :before-close="handleClose"
      class="no-select"
    >
      <div class="demo-input-suffix">
        <map-table ref="mapTable"></map-table>
        <br />
        <el-form ref="form" :model="form" label-width="80px">
          <el-row>
            <el-col :span="23">
              <el-form-item label="管制名称">
                <el-input v-model="form.name"></el-input>
              </el-form-item>
              <el-form-item label="管制点位">
                <div>
                  <el-tag
                    v-for="(item, index) in form.point"
                    :key="index"
                    closable
                    :disable-transitions="true"
                    :hit="true"
                    @close="handlePointDel(item)"
                    >{{ item }}</el-tag
                  >
                </div>
                <!-- <el-input
                  v-model="form.point"
                  type="textarea"
                  :rows="10"
                ></el-input> -->
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="drawer__footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleOk">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { formatTime, openConfirm, showMsg } from "@/utils/index.js";
import mapTable from "./mapTable.vue";

export default {
  name: "mapControl",
  components: {
    mapTable,
  },
  props: {},
  data() {
    return {
      //画布
      graph: null,
      control: false,
      direction: "rtl",
      form: {},

      tableCol: [
        {
          label: "序号",
          prop: "id",
          width: 60,
        },
        {
          label: "管制名称",
          prop: "name",
          width: 80,
        },
        {
          label: "管制节点",
          prop: "point",
        },
      ],
      tableData: [
        {
          id: 1,
          name: "A",
          point: "400280,440280",
        },
        {
          id: 2,
          name: "B",
          point: "200160,280160",
        },
      ],
    };
  },
  mounted() {},
  methods: {
    //管制点位删除
    handlePointDel(item) {
      this.form.point.splice(this.form.point.indexOf(item), 1);
    },
    //管制区域
    controlEdit(node) {
      this.form = {
        name: "",
        point: [],
      };
      this.graph.getSelectedCells().forEach((cell) => {
        if (cell.shape == "Point") {
          this.form.point.push(cell.data.code);
        }
      });
      this.control = true;
      this.$nextTick(() => {
        this.$refs.mapTable.isDelete = true;
        this.$refs.mapTable.tableCol = this.tableCol;
        this.$refs.mapTable.tableData = this.tableData;
      });
    },

    //管制区域确定
    handleOk() {
      if (this.form.name == "") {
        showMsg("管制名称不能为空,请输入!", false);
        return;
      } else {
        var isRe = false;
        for (let i = 0; i < this.tableData.length; i++) {
          if (this.form.name == this.tableData[i].name) {
            this.tableData[i].point = this.form.point.join(",");
            isRe = true;
          }
        }
        if (!isRe) {
          this.tableData.push({
            id: this.tableData.length + 1,
            name: this.form.name,
            point: this.form.point.join(","),
          });
        }
        this.$refs.mapTable.tableData = this.tableData;
        // this.graph.getNodes().forEach((item) => {
        //   if (item.shape == "Point") {
        //     item.data.control = this.getControlData();
        //   }
        // });
        this.control = false;
      }
    },

    //获取管制区域数据
    getControlData() {
      // for (let i = 0; i < this.tableData.length; i++) {
      //   this.tableData[i].point = this.tableData[i].point.split(",");
      // }
      return this.tableData;
    },

    handleClose(done) {
      this.control = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.drawer__footer {
  position: absolute;
  bottom: 10px;
  right: 10px;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
</style>