cuiqian2004
4 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
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
<template>
    <view class="pages-map-scene-rename">
        <view class="tip">{{translate('input_scene_name')}}</view>
        <view class="name-input">
            <input ref="refInputName" :focus="true" :placeholder="translate('input_scene_name')" :value="inputName"
                @input="onInputName" />
            <uni-icons class="clear" color="#ccc" type="clear" size="20" v-if="inputName"
                @click="clickClearName"></uni-icons>
        </view>
        <view class="text-button-group">
            <a-button type="primary" class="button" :disabled="loading || inputName.trim() == ''"
                @click="clickNameOK">{{translate('confirm')}} </a-button>
            <a-button type="ghost" class="button" :disabled="loading"
                @click="clickNameCancel">{{translate('cancel')}}</a-button>
        </view>
    </view>
</template>
<script>
    import {
        showToast,
        showModal,
        session,
        showError,
        showInfo
    } from "@/comm/utils.js"
    import {
        Button
    } from 'antd-mobile-vue-next'
 
    import {
        updateScene
 
    } from "@/api/vehicle.js"
    export default {
        name: "PagesMapSceneRename",
        components: {
            'a-button': Button
        },
        props: {
            ip: {
                type: String,
                default () {
                    return ''
                }
            },
            sceneName: {
                type: String,
                default () {
                    return ''
                }
            },
        },
        data() {
            return {
                loading: false,
                inputName: "",
            }
        },
 
 
        watch: {
            sceneName(val) {
                this.inputName = val
            }
        },
        methods: {
            clickNameCancel() {
                this.$emit("finish")
            },
            async clickNameOK() {
                try {
                    uni.showLoading({
                        title: this.translate("update_scene_name")
                    })
                    this.loading = true
                    const name = this.inputName.trim()
                    if (!name) {
                        showToast(this.translate("scene_name_cannot_empty"))
                        return
                    }
 
                    if (name == this.sceneName) {
                        showToast(this.translate("scene_name_not_changed"))
                        return
                    }
                    await updateScene(this.ip, this.sceneName, name)
                    showToast(this.translate("update_scene_name_success"))
                    this.$emit("finish",name)
                } catch (ex) {
                    showError(ex, this.translate('error'))
                } finally {
                    uni.hideLoading()
                    this.loading = false
                }
 
            },
 
            clickClearName() {
                this.inputName = ""
            },
            onInputName(event) {
                this.inputName = event.detail.value.trim();
 
            },
            translate(t) {
                if (typeof this.$t == "function") return this.$t(`page.${t}`)
                else return t;
            },
 
        }
    }
</script>
 
<style lang="scss" scoped>
    .pages-map-scene-rename {
        .tip {
            color: #888;
            margin: 10rpx;
            text-align: left;
        }
 
        .name-input {
            width: calc(100% - 20rpx);
            margin-bottom: 10rpx;
            background-color: #fff;
            padding: 10rpx;
            border-radius: 8rpx;
            display: flex;
            flex-direction: row;
            color: #1890FF;
 
            input {
                flex: 1;
            }
        }
 
        .text-button-group {
            display: flex;
            width: 100%;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            font-size: 30rpx !important;
 
            .button {
                margin: auto;
                margin-top: 20rpx;
                width: calc(100% - 10rpx);
            }
        }
    }
</style>