whyczyk
2021-09-30 c04569e75ef0c526f7f08169cc5724c83005d250
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
    <div class="params-container">
        <el-form
        ref="ruleForm"
        size="mini"
        label-position="top"
        :model="params"
        :rules="rules"
        class="params-dialog bg-white">
            <el-form-item label="机房名称" prop="StationName">
                <el-select
                v-model="homeName"
                placeholder="请选择"
                @change="change"
                filterable>
                    <el-option
                        v-for="item in homeList" :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="详细地址" prop="Address">
                <el-input
                    type="textarea"
                    :rows="3"
                    resize="none"
                    placeholder="请输入详细地址"
                    v-model="params.Address">
                    </el-input>
            </el-form-item>
            <div class="table-layout">
                <div class="table-row">
                    <div class="table-cell">
                        经度:{{point.lng}}
                    </div>
                    <div class="table-cell">
                        纬度:{{point.lat}}
                    </div>
                </div>
            </div>
            <div class="form-footer">
                <three-btn @click="validData">确定</three-btn>
            </div>
        </el-form>
    </div>
</template>
 
<script>
import {
    addMapStation
} from "@/assets/js/api"
 
export default {
    name: "AddPanel",
    data() {
        return {
            homeName: "",
            homeList: [],
            point: {
                lng: 0,
                lat: 0,
            },
            params: {
                StationName1: '',        // 省
                StationName2: '',        // 市
                StationName5: '',        // 区县
                StationName3: '',        // 站点名称
                StationName: '',        // 站点全称
                Address:'',                //机房物理信息
                longitude:'',                // 经度
                latitude:'',                // 纬度
                information:"",                //备注
            },
            rules: {
                StationName:[
                    {required: true, message: '请选择要添加的机房', trigger: 'change'},
                ],
                Address: [
                    {required: true, message: '详细地址不能为空', trigger: 'change'},
                ]
            }
        }
    },
    methods: {
        // 根据选择的机房更新详细地址的省-市-区县
        change(value) {
            let infos = value.split('-');
            // 解析的长度大于2
            if(infos.length>3) {
                this.params.StationName1 = infos[0];    // 省
                this.params.StationName2 = infos[1];    // 市
                this.params.StationName5 = infos[2];    // 区县
                this.params.StationName3 = infos[3];    // 机房名称
                this.params.StationName = value;        // 机房全称
                this.params.Address = infos[0]+'-'+infos[1]+'-'+infos[2]+'-';       // 省-市-区县-
            }
        },
        init() {
            this.homeName = "";     //  初始化下拉框
            this.params.StationName1 = "";    // 省
            this.params.StationName2 = "";    // 市
            this.params.StationName5 = "";    // 区县
            this.params.StationName3 = "";    // 机房名称
            this.params.StationName = "";        // 机房全称
            this.params.Address = "";       // 地址
        },
        validData() {
            this.$refs.ruleForm.validate((valid) => {
                // 校验通过
                if (valid) {
                    // 设置经纬度
                    this.params.longitude = this.point.lng;
                    this.params.latitude = this.point.lat;
                    this.$layer.confirm('确认添加机房到该位置', {icon: 3, title: '系统提示'}, (index)=>{
                        // 关闭弹出框
                        this.$layer.close(index);
                        // 添加机房到地图
                        this.addHome();
                    });
 
                }else {
                    this.$layer.msg('存在校验未通过的数据!');
                    return false;
                }
            });
        },
        addHome() {
            // 请求后台添加机房到地图
            addMapStation(this.params).then(res=>{
                let rs = JSON.parse(res.data.result);
                if(rs.code === 1) {
                    this.init();        // 初始化面板
                    this.$layer.msg('添加成功!');
                    this.$emit('handleEvent', 1);
                }else {
                    this.$layer.msg('添加失败!');
                    this.$emit('handleEvent', 0);
                }
            }).catch(error=>{
                console.log(error);
            });
        },
    }
}
</script>
 
<style scoped>
.params-container {
    width: 320px;
    background-color: #ffffff;
}
.table-layout {
    margin-top: 16px;
}
.bg-white .table-cell {
    color: #000000;
}
</style>