surprise
2023-12-29 18377dc5d61caf3a6a0835e17015ac2601f8709d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
  <Popup
    ref="pop"
    :title="title"
    :left="left"
    :shadow="!isEdit"
    width="390px"
    @close="close(true)"
    showBtn="true"
    @yes="addData"
    @cancel="close(false)"
  >
    <el-form ref="form" :model="data" :rules="rules" label-width="105px">
      <el-form-item label="名称:">
        <el-input v-model="data.name"></el-input>
      </el-form-item>
      <el-form-item label="地址:" prop="urls">
        <el-input
          v-model="data.urls"
          :title="data.urls"
          :disabled="isEdit"
        ></el-input>
      </el-form-item>
      <el-form-item label="图层定位:">
        <el-input v-model="flyTo" placeholder="可选" :title="flyToPosition">
          <i
            slot="suffix"
            class="el-input__icon el-icon-map-location"
            title="获取当前位置"
            @click="getPosition"
          ></i>
        </el-input>
      </el-form-item>
    </el-form>
  </Popup>
</template>
 
<script>
import Popup from "@tools/Popup";
import popupTools from "./mixin/popupTools";
export default {
  name: "AddOther",
  components: {
    Popup,
  },
  mixins: [popupTools],
  data() {
    return {
      title: "添加数据",
      left: undefined,
      type: "",
      isEdit: false,
      defaultEditData: undefined,
      data: {
        name: "新增数据",
        urls: "",
      },
      // 表单验证规则
      rules: {
        urls: [{ required: true, message: "请输入服务地址", trigger: "blur" }],
      },
    };
  },
  computed: {},
  mounted() {},
  methods: {
    // 关闭弹窗
    close(isCloseBtn) {
      // 重置data值
      Object.assign(this.$data, this.$options.data());
      !isCloseBtn && this.$refs.pop.close();
    },
    // 打开弹窗
    open(type, editData) {
      this.close(true)
      this.type = type;
      this.isEdit = !!editData;
      if (this.isEdit) {
        this.title = "编辑数据";
        this.left = "calc(100% - 420px)";
 
        // 合并参数
        sgworld.Core.extend(this.data, editData, true, true);
        this.data.id = editData.id
        // 定位
        editData.flyTo && (this.flyTo = editData.flyTo.join(","));
        this.defaultEditData = editData;
      } else {
        this.title = "添加数据";
        this.data.name = type + "数据";
      }
      this.$refs.pop.open();
    },
    // 添加数据
    addData() {
      this.$refs.form.validate((valid) => {
        // 验证通过
        if (valid) {
          let data = {
            id: window.sgworld.Core.getuid(),
            sourceType: this.type,
            ...this.data,
          };
          if (this.flyTo) {
            data.flyTo = this.flyTo.split(",");
          }
 
          this.$emit("success", data, this.isEdit);
 
          this.close();
        }
      });
    },
  },
};
</script>
 
<style scoped lang="less">
.el-form {
  margin-top: 20px;
  margin-right: 10px;
  width: 380px;
 
  /deep/ .el-form-item__label {
    color: #fff;
    font-size: 18px;
  }
}
</style>