Liuyi
2024-11-29 8265412eef286cc6027c8ec6085d6b059b7ab457
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
279
280
281
282
<script setup>
    import{ onLoad } from '@dcloudio/uni-app'
    import{ ref,onMounted } from 'vue'
    import{ getFacilityApi,closeFacilityApi,openFacilityApi } from '../../api/index.js'
    const facilityList = ref([])
    const facilityControl = ref({
        saleOpen:false,
        productionOpen:false,
        temperatureOpen:false,
        totalOpen:false,
    })
    let facilityCode
    let facilityOnLine
    async function getFalicityDetail(){
        await getFacilityApi(facilityId).then((res) =>{
            if(res.code == 200){
                facilityCode = res.data.facilityCode
                facilityOnLine = res.data.onLineState
                facilityList.value = []
                facilityList.value.push({name:'设备编号:',value:res.data.facilityCode})
                facilityList.value.push({name:'设备名称:',value:res.data.facilityName})
                facilityList.value.push({name:'在线状态:',value:res.data.onLineState == 1 ? '在线' : (res.data.onLineState == 0 ? '离线' : '')})
                facilityList.value.push({name:'设备供应商:',value:res.data.supplier})
                facilityList.value.push({name:'安装日期:',value:res.data.installDate})
                
                facilityControl.value.saleOpen = res.data.saleOpen == 1 ? true : false
                facilityControl.value.productionOpen = res.data.productionOpen == 1 ? true : false
                facilityControl.value.temperatureOpen = res.data.temperatureOpen == 1 ? true : false
            }
        })
    }
    function navTo(){
        uni.navigateTo({
            url:`/pagesAdmin/adminPlatform/params?id=${facilityId}`
        })
    }
    //设备开关操作相关
    //操作类型(售水开关:01开 02关,制水开关:03开 04关,温控开关:05开 06关,设备开关机:07开 08关-设备开关机代表设备完全开关机,相当于售水、制水、温控全开或全关)
    async function handelControl(status,name){
        if(facilityOnLine == 0){
            uni.showToast({
                title:'离线,无法操作',
                icon:'none'
            })
            return
        }
        let textInfo
        if(name == 'totalOnOff'){
            textInfo = status === false ?  '确认关闭设备全部状态?':'确认开启设备全部状态?'
        }else{
            textInfo = status === true ?  '确认关闭状态?':'确认开启状态?'
        }
        
        uni.showModal({
            title:'提示',
            content:textInfo,
            success:(res) =>{
                if(res.confirm){
                    
                    async function handelOpen(setStatus){
                        await openFacilityApi({data:setStatus,sn:facilityCode}).then((res) =>{
                            if(res.code == 200){
                                setTimeout(async() => {
                                    await getFalicityDetail()
                                }, 4000);
                                uni.showToast({
                                    title:'成功!三秒刷新'
                                })
                            }else{
                                uni.showToast({
                                    title:'操作失败!',
                                    icon:'none'
                                    
                                })
                            }
                        }) 
                    }
                    
                    async function handelClose(setStatus){
                        await closeFacilityApi({data:setStatus,sn:facilityCode}).then((res) =>{
                            if(res.code == 200){
                                setTimeout(async() => {
                                    await getFalicityDetail()
                                }, 4000);
                                uni.showToast({
                                    title:'成功!三秒刷新'
                                })
                            }else{
                                uni.showToast({
                                    title:'操作失败!',
                                    icon:'none'
                                })
                            }
                        }) 
                    }
                    
                    switch(name){
                        case 'saleOpen':
                        status == true ?  handelClose('02') :  handelOpen('01');
                        break;
                        case 'productionOpen':
                            status == true ?  handelClose('04') :  handelOpen('03');
                        break;
                        case 'temperatureOpen':
                            status == true ?  handelClose('06') :  handelOpen('05');
                        break;
                        case 'totalOnOff':
                            status == true ?  handelOpen('07') :  handelClose('08');
                        break;
                    }
                }
            }
        })
    }
    let facilityId
    onLoad(async(option) =>{
        console.log(14,option)
        facilityId = option.id
        await getFalicityDetail(option.id)
    })
    
</script>
<template>
    <view class="container">
        <navbar title = '设备详情'></navbar>
        <view class="content">
            <view class="detail-box">
                <view class="title">设备详情</view>
                <view class="detail">
                    <view class="info">
                        <view class="item" v-for="(item,index) in facilityList" :key="index">
                            <view class="item-text">{{item.name}}&nbsp;</view>
                            <view class="item-value">{{item.value}}</view>
                        </view>
                        <view @click="navTo" class="info-params"><view class="params">设备参数设置</view></view>
                    </view>
                    <view class="control">
                        <view class="switch-item">
                            <text class="switch-text">售水开关</text>
                            <view class="switch-icon" @click="handelControl(facilityControl.saleOpen,'saleOpen')">
                                <image class="icon-on-off" v-if="facilityControl.saleOpen" src="../../static/images/maintain/switch-on.png"></image>
                                <image class="icon-on-off" v-else src="../../static/images/maintain/switch-off.png"></image>
                            </view>
                        </view>
                        <view class="switch-item">
                            <text class="switch-text">制水开关</text>
                            <view class="switch-icon" @click="handelControl(facilityControl.productionOpen,'productionOpen')">
                                <image class="icon-on-off" v-if="facilityControl.productionOpen" src="../../static/images/maintain/switch-on.png"></image>
                                <image class="icon-on-off" v-else src="../../static/images/maintain/switch-off.png"></image>
                            </view>
                        </view>
                        <view class="switch-item">
                            <text class="switch-text">温控开关</text>
                            <view class="switch-icon" @click="handelControl(facilityControl.temperatureOpen,'temperatureOpen')">
                                <image class="icon-on-off" v-if="facilityControl.temperatureOpen" src="../../static/images/maintain/switch-on.png"></image>
                                <image class="icon-on-off" v-else src="../../static/images/maintain/switch-off.png"></image>
                            </view>
                        </view>
                        <view class="switch-item">
                            <text class="switch-text">总开开关</text>
                            <view class="total-control">
                                <view class="control-btn" @click="handelControl(true,'totalOnOff')">总开</view>
                                <view class="control-btn" @click="handelControl(false,'totalOnOff')">总关</view>
                            </view>
                        </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:60rpx 40rpx 100rpx;
        box-sizing: border-box;
        .detail-box{
            width:100%;
            height:1100rpx;
            background:rgba(255,255,255,0.7);
            border-radius:5rpx;
            padding:40rpx;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            align-items: center;
            .title{
                color: #575858;
            }
            .detail{
                width:100%;
                display: flex;
                flex-direction: column;
                align-items: center;
                .info{
                    width:100%;
                    display: flex;
                    flex-direction: column;
                    .info-params{
                        width:100%;
                        display: flex;
                        .params{
                            margin-top:30rpx;
                            color: #4571c3;
                            width:220rpx;
                            height:60rpx;
                            border-radius:15rpx;
                            // border:solid 1rpx #678cc3;
                            box-shadow:0 0 6rpx 1rpx  rgba(143, 182, 255, 0.3) inset;
                            text-align: center;
                            line-height:60rpx;
                            font-size:30rpx;
                            background:rgba(126, 171, 255, 0.2);
                        }
                    }
                    .item{
                        width:100%;
                        display: flex;
                        flex-wrap: nowrap;
                        margin-top:30rpx;
                        border-bottom:solid 1rpx #dbe7e8;
                        padding-bottom:10rpx;
                        .item-text{
                            color: #575858;
                        }
                        .item-value{
                            color: #4571c3;
                        }
                    }
                }
                .control{
                    height:400rpx;
                    width:100%;
                    display: flex;
                    flex-direction:column;
                    justify-content:space-evenly;
                    align-items: flex-start;
                    margin-top:20rpx;
                    .switch-item{
                        width:100%;
                        border-bottom:solid 1rpx #dbe7e8;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        .switch-text{
                            color: #697fb3;
                            font-weight:600;
                        }
                        .switch-icon{
                            .icon-on-off{
                                width:80rpx;
                                height:80rpx;
                            }
                        }
                        .total-control{
                            height: 80rpx;
                            display: flex;
                            align-items: center;
                            .control-btn{
                                width:110rpx;
                                height:50rpx;
                                background: #409eff;
                                border-radius:10rpx;
                                text-align: center;
                                line-height: 50rpx;
                                margin-left:20rpx;
                                color:#fff;
                                font-size:30rpx;
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>