he wei
2025-04-03 c6a2d2debf161b987ff91c6ac9560d10fc98c54b
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
<script setup>
  import { ref, onMounted, reactive, computed, watchEffect } from "vue"; import useElement from "@/hooks/useElement.js";
 
  import {
    addOfflineMap,
  } from '@/api/system.js';
 
  const { $loading, $message, $confirm } = useElement();
  const emit = defineEmits(["close", "success"]);
 
  import mapJson from '../../../public/mapJson/js/index.js'
  const ruleForm = ref();
 
  const params = reactive({
    StationName1: '', // 省*
    StationName2: '', // 市*
    StationName5: '', // 区县*
    dataName: '', // 数据名称
  });
 
  const rules = {
    dataName: [{
      required: true,
      message: '不能为空',
      trigger: 'blur'
    }]
  };
 
  const props = defineProps({
    list: {
      type: Array,
      required: true
    }
  });
 
  const mapList = computed(() => {
    let _list = mapJson.mapList();
    let plist = props.list;
    return _list.filter(item => {
      let isIn = false;
      for (let i = 0; i < plist.length; i++) {
        if (plist[i].name == item.value) {
          isIn = true;
          break;
        }
      }
      return !isIn;
    });
  });
 
  function submitFrom() {
    ruleForm.value.validate((valid) => {
      // 校验通过
      if (valid) {
        var tmp = {};
        tmp.province = params.StationName1;
        tmp.city = params.StationName2;
        tmp.distinct = params.StationName5;
        tmp.name = params.dataName;
        // 添加地图
        addMap(tmp);
      } else {
        $layer.msg('存在校验未通过的数据!');
        return false;
      }
    });
  };
  function addMap(tmp) {
    let loading = $loading();
    addOfflineMap(tmp).then((res) => {
      if (res.code == 1) {
        $message({
          type: 'success',
          message: '添加地图成功!'
        });
        // 触发事件
        emit('success');
      } else {
        $message({
          type: 'error',
          message: '添加地图失败!'
        });
      }
      // 关闭加载框
      loading.close();
    }).catch((err) => {
      console.log(err);
      // 关闭加载框
      loading.close();
    });
  }
  function mapChange(value) {
      let mapInfo = mapJson.getItemByValue(value, mapList.value);
      params.StationName1 = mapInfo.StationName1;
      params.StationName2 = mapInfo.StationName2;
      params.StationName5 = mapInfo.StationName5;
    }
</script>
 
<template>
  <el-form ref="ruleForm" label-position="top" :model="params" :rules="rules">
    <el-row :gutter="16">
      <el-col :span="24">
        <el-form-item label="地图字段" prop="dataName">
          <el-select v-model="params.dataName" placeholder="请选择地图" @change="mapChange" :filterable="true">
            <el-option v-for="item in mapList" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <div class="form-footer">
      <el-button type="primary" @click="submitFrom">确定</el-button>
    </div>
  </el-form>
</template>
 
<style scoped>
 
</style>