Liuyi
2024-12-21 d92ab3161161f1f038680c6b52e5baf5a259f574
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<script setup>
    import { ref ,onMounted} from 'vue';
    import { searchMaintainApi,createMaintainApi } from '../../api/index.js'
    import { BASE_URL } from '../../config/baseUrl.js';
    
    const baseUrl = ref(BASE_URL)
    const maintainList = ref([])
    async function searchMaintain(){
        await searchMaintainApi({limit:10000,page:1}).then((res) =>{
            if(res.code == 200){
                maintainList.value = res.data.list
                maintainList.value.forEach((item) =>{
                    item.resultTypeView = item.resultType == 1 ? '正常' : ( item.resultType == 2 ? '异常' : '')
                })
            }
        })
    }
    //添加记录
    const popup = ref()
    const rules = ref({
        content: {
            rules:[{required: true, errorMessage:'请输入', trigger: "blur"}],
        },
        inspectUser: {
            rules:[{required: true, errorMessage:'请输入', trigger: "blur"}],
        },
        resultType: {
            rules:[{required: true, errorMessage:'请输入', trigger: "blur"}],
        },
    })
    const formRef =ref()
    const form = ref({
     url:undefined,
     content: '',
     inspectUser: '',
     resultType:1,//2:未完成,1:已完成
    })
    function openForm(){
        popup.value.open()
    }
    function radioChange(e){
        form.value.resultType = e.detail.value
        console.log('e',e,'form',form.value.resultType)
    }
    //上传图片
    function uploadImg(val){
        uni.chooseImage({
            success: async(res) =>{
                 //建立表单,请求参数传表单形式
                 let fileForm = {
                     file1:res.tempFiles,
                     path:'qingyuan'
                 }
                uni.uploadFile({
                    url:BASE_URL+ '/file/upload', 
                    filePath:res.tempFilePaths[0],
                    name: 'file',
                    formData:fileForm,
                    success: (success) => {
                        console.log('文件上传响应',success);
                        let dataObj = JSON.parse(success.data)
                        form.value.url = dataObj.data.newFileName
                        console.log('url',form.value.url)
                    },
                    fail: (err) => {
                        uni.showToast({
                            title: '上传失败,请重试',
                            duration: 2000,
                            icon:'none'
                        });
                        console.log('err',err,res.tempFilePaths[0])
                    }
                });
            }
        });
    }
    function concel(){
        form.value = { 
            url:undefined,
            content: '',
            inspectUser: '',
            resultType:1,
         }
        formRef.value.clearValidate()
        popup.value.close()
    }
    async function confirmAdd(){
        formRef.value.validate().then(async(validate)=>{
            if(form.value.url){
                let res = await createMaintainApi(form.value)
                if(res.code === 200){
                    uni.showToast({
                        title:'添加成功'
                    })
                    concel()
                    await searchMaintain()
                }else{
                    uni.showToast({
                        title:'添加失败',
                        icon:'none'
                    })
                    concel()
                }
            }else{
                uni.showToast({
                    title:'请上传图片',
                    icon:'none'
                })
            }
            
        }).catch((err)=>{})
    }
    onMounted(async() =>{
        await searchMaintain()
    })
</script>
<template>
    <view class="container">
        <navbar title = '维护记录'></navbar>
        <view class="content">
            <view v-if="maintainList.length > 0" class="main">
                <view v-for="(item,index) in maintainList" class="item">
                    <view class="item-child">
                        <text>维修人:</text>
                        <text class="value">{{item.inspectUser}}</text>
                    </view>
                    <view class="item-child-area">
                        <view>维修内容:</view>
                        <textarea class="text-area value" :maxlength='100'>{{item.content}}</textarea>
                    </view>
                    <view class="item-child">
                        <text>维修状态:</text>
                        <text class="value">{{item.resultTypeView}}</text>
                    </view>
                    <!-- <view class="item-child">
                        <text>备注:</text>
                        <text class="value remark">{{item.remark}}</text>
                    </view> -->
                    <view class="item-child">
                        <text>维修时间:</text>
                        <text class="value-time">{{item.createTimeView}}</text>
                    </view>
                    <view class="item-child-area">
                        <text>上传图片:</text>
                        <view class="item-img-box">
                            <image class="item-img" :src="baseUrl + '/upload' + item.url" mode="aspectFit"></image>
                        </view>
                    </view>
                </view>
            </view>
            <view class="nodata" v-else>
                <image class="nodata-img" src="../../static/images/other/nodata.png" mode="widthFix"></image>
            </view>
            <view @click="openForm" class="add-record">添加记录</view>
        </view>
        <!-- 新增弹窗 -->
        <uni-popup ref="popup" :is-mask-click ='false' type="center" border-radius="20px">
            <view class="dialog-box">
                <view>
                    <uni-forms ref="formRef" :model="form" :rules="rules">
                        <uni-forms-item label="维护人员:" label-width='85' name="inspectUser">
                            <uni-easyinput class="input" v-model="form.inspectUser" placeholder="请输入维护人员">></uni-easyinput> 
                        </uni-forms-item>
                        <uni-forms-item label="维护内容:" label-width='85' name="content">
                            <uni-easyinput class="input" v-model="form.content" placeholder="请输入维护内容">></uni-easyinput> 
                        </uni-forms-item>
                        <uni-forms-item label="是否完成:" label-width='85' name='resultType'>
                            <radio-group @change="radioChange">
                                <view class="radio-box">
                                    <radio :value="1" :checked="form.resultType == 1"/>
                                    <text class="radio-text">完成</text>
                                </view>
                                <view>
                                    <radio :value="2" :checked="form.resultType == 2"/>
                                    <text class="radio-text">未完成</text>
                                </view>
                            </radio-group>
                        </uni-forms-item>
                    </uni-forms>
                </view>
                <!-- 上传图片 -->
                <view class="upload-box">
                    <view class="upload-title">选择照片</view>
                    <view class="upload-img">
                            <view @click="uploadImg()" class="upload-img-item">
                                <image v-if="form.url" :src="baseUrl + '/upload' + form.url" mode="aspectFit"></image>
                                <image v-else class="default-img" src="../../static/images/other/img-add.png" alt=""></image>
                            </view>
                    </view>
                </view>
                <view class="button-box">
                    <button class="btn1" @click="concel">取消</button>
                    <button class="btn2" @click="confirmAdd">确认</button>
                </view>
            </view>
        </uni-popup>
    </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 30rpx 100rpx;
            box-sizing: border-box;
            .main{
                width:100%;
                height:calc(100% - 120rpx);
                padding:20rpx;
                box-sizing: border-box;
                background:rgba(255, 255, 255, 0.6);
                border-radius:10rpx;
                overflow: scroll;
                .item{
                    width:100%;
                    // height:500rpx;
                    border:1rpx solid rgba(77,173,225,0.3);
                    border-radius:10rpx;
                    background: rgba(255, 255, 255, 0.6);
                    margin-bottom:40rpx;
                    display: flex;
                    flex-direction: column;
                    padding:20rpx 30rpx;
                    justify-content: space-between;
                    box-sizing: border-box;
                    color: rgba(48,102,218,0.6);
                    box-shadow: 0 3rpx 5rpx 1rpx rgba(197, 199, 203, 0.6);
                    .value{
                        color: rgba(86, 86, 90, 1.0);
                    }
                    .value-time{
                        color: rgba(86, 86, 90,0.8);
                        font-size:26rpx;
                    }
                    .item-child{
                        width:100%;
                        margin-bottom:20rpx;
                        .remark{
                            margin-left:5%;
                            font-size:28rpx;
                        }
                    }
                    .item-child-area{
                        width:100%;
                        display: flex;
                        flex-direction: column;
                        margin-bottom:20rpx;
                        .text-area{
                            width:90%;
                            margin-top:20rpx;
                            margin-left:5%;
                            border:1rpx solid rgba(116, 160, 255, 0.3);
                            font-size:28rpx;
                            padding:20rpx;
                            box-sizing: border-box;
                            border-radius:10rpx;
                        }
                        .item-img-box{
                            width:220rpx;
                            height:220rpx;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            border: 1rpx dashed #8BC1FC;
                            margin-top:20rpx;
                            margin-left:10%;
                            .item-img{
                                width:200rpx;
                                height:200rpx;
                            }
                        }
                    }
                }
            }
            .nodata{
                width:100%;
                height:calc(100% - 120rpx);
                display: flex;
                justify-content: center;
                background: rgba(255,255,255,0.6);
                border-radius:10rpx;
                padding-top:150rpx;
                box-sizing: border-box;
                .nodata-img{
                    width: 520rpx;
                }
            }
            .add-record{
                margin: 40rpx auto 0;
                background-color: #5b93dc;
                width:500rpx;
                height:85rpx;
                line-height:85rpx;
                text-align: center;
                border-radius: 50rpx;
                color: #fff;
                letter-spacing:2rpx;
                font-size:38rpx;
                font-weight:500;
            }
        }
        .dialog-box{
            width:650rpx;
            // height:500rpx;
            background: #fafbfc;
            padding:40rpx;
            box-sizing: border-box;
            display: flex;
            justify-content:center;
            flex-direction: column;
            border-radius:20rpx;
            .input{
                align-items: center;
            }
            .button-box{
                width:100%;
                display: flex;
                justify-content: center;
                align-items: center;
                .btn1{
                    line-height:60rpx;
                    width:180rpx;
                    height:60rpx;
                    background: #fcfcfc;
                    color: #505354;
                }
                .btn2{
                    line-height:60rpx;
                    width:180rpx;
                    height:60rpx;
                    background: #b7cafc;
                    color: #484b4c;
                }
            }
            .upload-box{
                width:100%;
                .upload-title{
                    color: #6a717e;
                    margin-top: 10rpx;
                }
                .upload-img{
                    display: flex;
                    padding:30rpx 14rpx;
                    box-sizing: border-box;
                    .upload-img-item{
                            width: 180rpx;
                            height:180rpx;
                            border-radius:20rpx;
                            border:1rpx dashed #b7d4ff;
                            margin-bottom: 10rpx;
                            display: flex;
                            justify-content: center;
                            align-items: center;
                            image{
                                width:170rpx;
                                height:170rpx;
                            }
                            .default-img{
                                width:120rpx;
                                height:120rpx;
                            }
                    }
                }
            }
            .radio-box{
                margin-bottom:6rpx;
            }
            .radio-text{
                color: #5b93dc;
            }
        }
    }
           
</style>