Liuyi
2024-12-20 d470e67ac1997882502b75cbfdaf359626cfaaa8
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<script setup>
    import { onLoad } from '@dcloudio/uni-app'
    import { getFacilityApi,getParameter1Api,editParameter1Api } from '../../api/index.js'
    import { ref,onMounted } from 'vue';
    
    let facilityId
    let onLineState
    let facilityCode
    onLoad(async(option) =>{
        console.log(14,option)
        facilityId = option.id
        await getFacilityById()
    })
    onMounted(async() =>{
        await handleSetting()
    })
    //获取水控机设备详情
    async function getFacilityById(){
        await getFacilityApi(facilityId).then((res) =>{
            onLineState = res.data.onLineState
            facilityCode = res.data.facilityCode
        })
    }
    //表单相关
    const formRef = ref()
    const formData = ref({})
    function initData(){
        formData.value = {
            sn: '',
            type:'',
            rateAmount: 100,
            waterYield: 100,
            pulse: 450,
            fetchWaterTime: 45,
            billingModel: 1,
            isStartKey: 1,
        }
    }
    //表单校验
    const rulesData = ref({
            rateAmount: {
                rules:[
                    {required: true, errorMessage:'请输入参数值', trigger: "blur"},
                    {pattern:/^([1-9]\d{1,2}|[1-5]\d{3}|6000)$/, errorMessage:'超出范围,请重新输入', trigger: "blur"},
                    ],
            },
            waterYield: {
                rules:[
                    {required: true, errorMessage:'请输入参数值', trigger: "blur"},
                    {pattern:/^([1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65000)$/, errorMessage:'超出范围,请重新输入', trigger: "blur"},
                    ],
            },
            pulse: {
                rules:[
                    {required: true, errorMessage:'请输入参数值', trigger: "blur"},
                    {pattern:/^([1-9]\d{0,2})$/, errorMessage:'超出范围,请重新输入', trigger: "blur"},
                    ],
            },
            fetchWaterTime: {
                rules:[
                    {required: true, errorMessage:'请输入参数值', trigger: "blur"},
                    {pattern:/^([1-9]\d{0,2}|1000)$/, errorMessage:'超出范围,请重新输入', trigger: "blur"},
                    ],
            },
            billingModel: {
                rules:[
                    {required: true, errorMessage:'请输入参数值', trigger: "blur"},
                    {pattern:/^(1|2)$/, errorMessage:'超出范围,请重新输入', trigger: "blur"},
                    ],
            },
            isStartKey: {
                rules:[
                    {required: true, errorMessage:'请输入参数值', trigger: "blur"},
                    {pattern:/^(1|2)$/, errorMessage:'超出范围,请重新输入', trigger: "blur"},
                    ],
            },
    });
    
    //参数设置按钮,请求设备参数
    async function handleSetting(){
        await getParameter1Api(facilityCode).then((res) =>{
            //参数不为空
            if(res.data != null){
                formData.value = res.data
            }else{
                //参数为空置为默认
                initData()
                formData.value.sn = facilityCode
            }
        })
    }
    //type:1:修改参数,0:恢复出厂设置
    //恢复出厂设置
    async function restore(){
        if(onLineState == 1){
            let sn = formData.value.sn
            initData()
            formData.value.type = 0
            formData.value.sn = sn
            await setParams(formData.value)
        }else{
            uni.showToast({
                title:'离线,无法操作',
                icon:'none'
            })
        }
    }
    //修改参数
    function save(){
        if(onLineState.value == 1){
            formData.value.type = 1
           formRef.value.validate().then(async() =>{
               await setParams(formData.value)
           }).catch((e) =>{
                   console.log('e',e)
           })
        }else{
           uni.showToast({
               title:'离线,无法操作',
               icon:'none'
           })
        }
    }
    
    async function setParams(formParams){
        await editParameter1Api(formParams).then((res) =>{
            if(res.code == 200){
                uni.showToast({
                    title:'成功!三秒刷新'
                })
                setTimeout(async() =>{
                    await handleSetting()
                },4000)
            }else{
                uni.showToast({
                    title:'网络错误',
                    icon:'none'
                })
            }
        })
    }
</script>
<template>
    <view>
        <view class="container">
            <navbar title = '参数设置'></navbar>
            <view class="content">
                <view class="head">
                    <text>设备参数设置</text>
                </view>
                <view class="main">
                    <view class="form-box">
                        <uni-forms ref="formRef" :modelValue="formData" :rules="rulesData">
                            <view class="devide-name">水价设置:</view>
                            <uni-group>
                                <uni-forms-item class="form-item" name="rateAmount">
                                    <text style="color:#4784c7">费率:(范围:10-6000分)</text>
                                    <uni-easyinput type="text" v-model="formData.rateAmount" placeholder="请输入参数" />
                                </uni-forms-item>
                                <uni-forms-item class="form-item" name="waterYield">
                                    <text style="color:#4784c7">水量:(范围:10-65000)</text>
                                    <uni-easyinput type="text" v-model="formData.waterYield" placeholder="请输入参数" />
                                </uni-forms-item>
                                <uni-forms-item class="form-item" name="pulse">
                                    <text style="color:#4784c7">脉冲:(范围:1-999分)</text>
                                    <uni-easyinput type="text" v-model="formData.pulse" placeholder="请输入参数" />
                                </uni-forms-item>
                                <uni-forms-item class="form-item" name="fetchWaterTime">
                                    <text style="color:#4784c7">打水时间:(范围:1-1000分)</text>
                                    <uni-easyinput type="text" v-model="formData.fetchWaterTime" placeholder="请输入参数" />
                                </uni-forms-item>
                            </uni-group>
                            
                            <view class="devide-name">系统参数:</view>
                            <uni-group>
                                <uni-forms-item class="form-item" name="billingModel">
                                    <text style="color:#4784c7">计费模式:(范围:1时间,2流量)</text>
                                    <uni-easyinput type="text" v-model="formData.billingModel" placeholder="请输入参数" />
                                </uni-forms-item>
                                <uni-forms-item class="form-item" name="isStartKey">
                                    <text style="color:#4784c7">是否启用按键:(范围:1启用,2禁用)</text>
                                    <uni-easyinput type="text" v-model="formData.isStartKey" placeholder="请输入参数" />
                                </uni-forms-item>
                            </uni-group>
                        </uni-forms>
                    </view>
                    <view class="handle-btn">
                        <view class="left" @click="restore">恢复出厂设置</view>
                        <view class="right" @click="save">保存设置</view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>
<style lang="scss" scoped>
    .container{
        width:100%;
        box-sizing: border-box;
        .content{
            height:calc(100vh - 176rpx);
            background: linear-gradient(to bottom,#8BC1FC 0%,#D2F2FE 30%,#D2F2FE 100%);
            padding:30rpx 40rpx 100rpx;
            box-sizing: border-box;
            .head{
                width:100%;
                height: 100rpx;
                background-color: rgba(255,255,255,0.6);
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 38rpx;
                color: #4784c7;
                letter-spacing: 2rpx;
                box-shadow: 0 4rpx 4rpx 1rpx rgba(71,132,199,0.6);
            }
            .main{
                width:100%;
                height:calc(100% - 100rpx);
                background-color: rgba(255,255,255,0.6);
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                margin-top:30rpx;
                padding:30rpx 40rpx; 
                box-sizing:border-box;
                .handle-btn{
                    height:60rpx;
                    width:100%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    text-align: center;
                    margin-top:50rpx;
                    .left{
                        border: 1rpx solid #99b7f0;
                        color: #409EFF;
                        background-color:#fff;
                        border-radius:15rpx;
                        line-height:60rpx;
                        margin-right:60rpx;
                        width: 215rpx;
                        font-size: 30rpx;
                    }
                    .left:hover{
                        opacity: 0.8;
                    }
                    .right{
                        background-color:#409EFF;
                        color: #fff;
                        border-radius:15rpx;
                        line-height:60rpx;
                        width: 215rpx;
                        font-size: 30rpx;
                    }
                    .right:hover{
                        opacity:0.8;
                    }
                }
                .form-box{
                    width: 580rpx;
                    height:90%;
                    overflow: scroll;
                    .devide-name{
                        width:100%;
                        color: #30b351;
                        margin:20rpx 0;
                    }
                    .form-item{
                        width:100%;
                    }
                }
            }
        }
    }
           
</style>