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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
    <view class="pages-map-pallet-size">
        <view class="tip">{{translate("pallet_size")}}</view>
        <view class="row">
            <view class="width-50">
                <text class="attr">{{translate("length")}}:</text>
                <input class=" val " type="number" :value="palletLength" @blur="onBlurPalletLength"
                    @confirm="onConfirmPalletLength" :maxlength="10" :placeholder="translate('input_please')" />
                cm
            </view>
            <view class="width-50">
                <text class="attr">{{translate("width")}}:</text>
                <input class=" val " type="number" :value="palletWidth" @blur="onBlurPalletWidth"
                    @confirm="onConfirmPalletWidth" :maxlength="10" :placeholder="translate('input_please')" />
 
                cm
            </view>
        </view>
    </view>
</template>
<script>
    import {
        showToast,
        showModal,
        session,
        showError,
        showInfo
    } from "@/comm/utils.js"
    import {
        Button
    } from 'antd-mobile-vue-next'
 
    import {
        savePalletSize,
        getPalletSize,
 
    } from "@/api/vehicle.js"
    export default {
        name: "PagesMapPalletSize",
        components: {
            'a-button': Button
        },
        props: {
            ip: {
                type: String,
                default () {
                    return ''
                }
            },
        },
        data() {
            return {
                palletLength: "200",
                palletWidth: "1000"
            }
        },
        computed: {
 
        },
 
        mounted() {
            this.loadData()
 
        },
        methods: {
            async loadData() {
                try {
                    const res = await getPalletSize(this.ip)
                    this.palletLength = res?.length ? Math.floor(res.length * 100) : "200"
                    this.palletWidth = res?.width ? Math.floor(res.width * 100) : "1000"
                } catch (ex) {
 
                    showError(ex, this.translate('error'))
                }
            },
 
            validateNumber(input) {
                // 常用正则模式
                const patterns = {
                    integer: /^-?\d+$/, // 整数,包括负数 [citation:6]
                    positiveInt: /^[1-9]\d*$/, // 正整数 [citation:7]
                    decimal: /^-?\d*\.?\d+$/, // 小数 (支持像 ".1" 这样的格式)
                    decimalFixed: /^-?\d*\.?\d{0,3}$/, // 最多两位小数 [citation:5][citation:8]
                };
                // 选择需要的模式进行测试,例如使用 decimal
                return patterns.integer.test(input);
            },
            async savePalletSize() {
                try {
                    if (!this.validateNumber(this.palletLength)) {
                        console.log("input_content_only_numbers_or_signs")
                        showError(this.translate("input_content_only_numbers_or_signs"))
                        return
                    }
                    if (!this.validateNumber(this.palletWidth)) {
                        console.log("input_content_only_numbers_or_signs")
                        showError(this.translate("input_content_only_numbers_or_signs"))
                        return
                    }
                    const len = Number(this.palletLength) / 100
                    const width = Number(this.palletWidth) / 100
                    await savePalletSize(this.ip, len, width)
                    console.log("modify_success_restart_device", this.palletLength, this.palletWidth)
                    showToast(this.translate("modify_success_restart_device"))
                } catch (ex) {
                    showError(ex, this.translate('error'))
                }
            },
            onBlurPalletLength(event) {
                this.palletLength = event.detail.value
                this.savePalletSize()
            },
            onConfirmPalletLength(event) {
                this.palletLength = event.detail.value
                this.savePalletSize()
            },
 
            onBlurPalletWidth(event) {
                this.palletWidth = event.detail.value
 
                this.savePalletSize()
 
            },
            onConfirmPalletWidth(event) {
                this.palletWidth = event.detail.value
                this.savePalletSize()
            },
            translate(t) {
                if (typeof this.$t == "function") return this.$t(`page.${t}`)
                else return t;
            },
 
        }
    }
</script>
 
<style lang="scss" scoped>
    .pages-map-pallet-size {
        .tip {
            color: #888;
            margin: 10rpx;
            text-align: left;
        }
 
        .row {
            margin: 5px;
            display: flex;
            flex-direction: row;
 
            .width-50 {
                width: calc(50% - 10rpx);
                display: flex;
                flex-direction: row;
                padding-left: 10rpx;
            }
 
            .attr {
                padding-right: 10rpx;
            }
 
            .val {
                flex: 1;
                padding-left: 10rpx;
                color: #2d8cf0;
                background-color: #fff;
                border-bottom: 1px solid #ccc;
 
            }
        }
 
 
 
 
    }
</style>