ll
liukangdong
2024-12-23 5c53a09ff28e5be90af9c1bc0534a4320fc5aec0
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
<template>
    <view class="main_app">
        <view class="list">
            <view class="item">
                <view class="la"><text class="red">*</text>位置类型</view>
                <view class="line sel_wrap" @click="showModal0 = true">
                    <view class="left" :class="param.areaName ? '' : 'placeholder9'">{{ param.areaName ? param.areaName : '请选择' }}
                    </view>
                    <u-icon name="arrow-right" color="#999999" size="15"></u-icon>
                </view>
            </view>
            <view class="item">
                <view class="la"><text class="red">*</text>选择区域</view>
                <view class="line sel_wrap" @click="showModal1 = true">
                    <view class="left" :class="param.projectName ? '' : 'placeholder9'">
                        {{ param.projectName ? `${param.projectName} ${param.buildingName || ''} ${param.areaType == 0 ? param.roomNum || '' : param.floorName || ''}` : '请选择' }}
                    </view>
                    <u-icon name="arrow-right" color="#999999" size="15"></u-icon>
                </view>
            </view>
            <view class="item">
                <view class="la"><text class="red">*</text>工单分类</view>
                <view class="line sel_wrap" @click="showCate1 = true">
                    <view class="left" :class="param.cateName ? '' : 'placeholder9'">
                        {{ param.cateName ? param.cateName : '请选择' }}</view>
                    <u-icon name="arrow-right" color="#999999" size="15"></u-icon>
                </view>
            </view>
            <view class="item" v-if="param.areaType == 0">
                <view class="la">上门时间</view>
                <view class="line sel_wrap" @click="showTime = true">
                    <view class="left" :class="param.getDate ? '' : 'placeholder9'">{{ param.getDate ? param.getDate : '请选择' }}
                    </view>
                    <u-icon name="arrow-right" color="#999999" size="15"></u-icon>
                </view>
            </view>
            <view class="item">
                <view class="la">描述</view>
                <view class="line">
                    <textarea v-model="param.content" placeholder="请输入" placeholder-class="placeholder9" />
                </view>
            </view>
            <view class="item">
                <view class="la">现场照片</view>
                <view class="upload_wrap">
                    <view class="upload_file" @click="showUpload = true">
                        <u-icon name="plus" color="rgb(153, 153, 153)" size="28"></u-icon>
                        <view class="mt6">图片/视频</view>
                    </view>
                    <view class="upload_file" v-for="(item, i) in fileList" :key="i">
                        <u-icon class="close" size="20" name="close-circle-fill" color="red"
                            @click="fileDel('fileList', i)"></u-icon>
                        <image v-if="item.type == 0" :src="item.fileurlFull" mode="widthFix"></image>
                        <video v-if="item.type == 1" :show-center-play-btn="false" :src="item.fileurlFull" :controls="false"></video>
                    </view>
                </view>
            </view>
        </view>
        <view class="sub_btn" @click="onSubmit">提交</view>
        <!--  -->
        <u-popup :show="showUpload" @close="showUpload = false" closeOnClickOverlay>
            <view class="sel_upload_wrap">
                <view class="btn" @click="uploadImage">选择图片</view>
                <view class="btn" @click="uploadVideo">选择视频</view>
            </view>
        </u-popup>
        <!--  -->
        <u-picker :show="showModal0" keyName="name" @cancel="showModal0 = false" @confirm='confirm0'
            :columns="areaType"></u-picker>
        <!--  -->
        <u-picker :show="showModal1" keyName="name" @cancel="showModal1 = false" @confirm='confirm1'
            :columns="projectList"></u-picker>
        <u-picker :show="showModal2" keyName="name" @cancel="showModal2 = false" @confirm='confirm2'
            :columns="buildingList"></u-picker>
        <u-picker :show="showModal3" keyName="name" @cancel="showModal3 = false" @confirm='confirm3'
            :columns="floorList"></u-picker>
        <u-picker :show="showModal4" keyName="roomNum" @cancel="showModal4 = false" @confirm='confirm4'
            :columns="roomList"></u-picker>
        <!--  -->
        <u-datetime-picker :minDate="new Date().getTime()" :show="showTime" @confirm="confirmDate"
            @cancel="showTime = false" mode="datetime"></u-datetime-picker>
 
        <u-picker :show="showCate1" keyName="name" ref="uPicker" @change="changeHandler" @cancel="showCate1 = false"
            @confirm='confirmCate1' :columns="cateList1"></u-picker>
    </view>
</template>
 
<script>
    import {
        uploadUrl,
        ywProjectPost,
        ywBuildingPost,
        ywFloorPost,
        ywRoomPost,
        ywWorkorderCreate,
        getCategoryPost
    } from '@/api'
    import dayjs from 'dayjs';
    export default {
        data() {
            return {
                param: {
                    areaName: '室内装修',
                    areaType: 0
                },
                showUpload: false,
                fileList: [],
 
                showModal0: false,
                showModal1: false,
                showModal2: false,
                showModal3: false,
                showModal4: false,
                showTime: false,
                showCate1: false,
                showCate2: false,
                areaType: [
                    [{
                            name: '室内维修',
                            id: 0
                        },
                        {
                            name: '公共维修',
                            id: 1
                        }
                    ]
                ],
                cateList1: [],
                cateList2: [],
                projectList: [],
                buildingList: [],
                floorList: [],
                roomList: [],
            };
        },
        onLoad() {
            this.getProject()
            this.getCate()
        },
        methods: {
            onSubmit() {
                const {
                    param,
                    fileList
                } = this
                if (!param.projectId) return this.showToast('请选择完整的区域')
                if (!param.buildingId) return this.showToast('请选择完整的区域')
                if (!param.floorName && !param.roomNum) return this.showToast('请选择完整的区域')
                if (!param.cateName) return this.showToast('请选择工单分类')
                ywWorkorderCreate({
                    ...param,
                    // roomId: '',
                    fileList
                }).then(res => {
                    this.showToast('提交成功')
                    uni.redirectTo({
                        url: '/pages/workOrder/list'
                    })
                })
            },
            changeHandler(e) {
                const {
                    columnIndex,
                    value,
                    values, // values为当前变化列的数组内容
                    index,
                    // 微信小程序无法将picker实例传出来,只能通过ref操作
                    picker = this.$refs.uPicker
                } = e
                // 当第一列值发生变化时,变化第二列(后一列)对应的选项
                console.log(index);
                console.log(index);
                if (columnIndex === 0) {
                    // picker为选择器this实例,变化第二列对应的选项
                    picker.setColumnValues(1, this.cateList1[0][index].childCategoryList)
                }
            },
            confirmCate1(e) {
                console.log(e.value[1]);
                if(e.value.length == 2){
                    this.$set(this.param, 'cateId', e.value[1].id)
                    this.$set(this.param, 'cateName', e.value[1].name)
                    this.showCate1 = false
                }
                
            },
            confirm0(e) {
                const item = e.value[0]
                this.$set(this.param, 'areaType', item.id)
                this.$set(this.param, 'areaName', item.name)
                this.showModal0 = false
                this.param = {
                    areaType: item.id,
                    areaName: item.name,
                }
            },
            confirm1(e) {
                const item = e.value[0]
                this.showModal1 = false
                this.$set(this.param, 'projectName', item.name)
                this.$set(this.param, 'projectId', item.id)
                this.getBuilding(item.id)
                this.showModal2 = true
            },
            confirm2(e) {
                const item = e.value[0]
                this.showModal2 = false
                this.$set(this.param, 'buildingName', item.name)
                this.$set(this.param, 'buildingId', item.id)
                if (this.param.areaType == 0) {
                    this.getRoom(item.id)
                    this.showModal4 = true
                } else {
                    this.getFloor(item.id)
                    this.showModal3 = true
                }
            },
            confirm3(e) {
                const item = e.value[0]
                this.showModal3 = false
                this.$set(this.param, 'floorName', item.name)
                this.$set(this.param, 'floorId', item.id)
            },
            confirm4(e) {
                const item = e.value[0]
                this.showModal4 = false
                this.$set(this.param, 'roomNum', item.roomNum)
                this.$set(this.param, 'roomId', item.id)
            },
            confirmDate(e) {
                this.$set(this.param, 'getDate', dayjs(e.value).format('YYYY-MM-DD HH:mm:ss'));
                this.showTime = false
            },
            getCate() {
                getCategoryPost({
                    capacity: 9999,
                    page: 1,
                    model: {
                        type: 3
                    }
                }).then(res => {
 
                    let temp = res.data.records || []
                    if (temp && temp.length > 0) {
                        this.cateList1 = [temp, temp[0].childCategoryList || []]
                    } else {
                        this.cateList1 = [temp, []]
                    }
                    console.log(this.cateList1);
                })
            },
            getProject() {
                ywProjectPost().then(res => {
                    this.projectList = [res.data || []]
                })
            },
            getBuilding(projectId) {
                ywBuildingPost({
                    projectId
                }).then(res => {
                    this.buildingList = [res.data || []]
                })
            },
            getFloor(buildingId) {
                ywFloorPost({
                    buildingId
                }).then(res => {
                    this.floorList = [res.data || []]
                })
            },
            getRoom(buildingId) {
                ywRoomPost({
                    buildingId
                }).then(res => {
                    this.roomList = [res.data || []]
                })
            },
            fileDel(str, i) {
                this[str].splice(i, 1);
            },
            uploadImage() {
                this.showUpload = false;
                let token = uni.getStorageSync('token') || '';
                uni.chooseImage({
                    count: 6,
                    success: chooseImageRes => {
                        uni.showLoading({
                            title: '上传中',
                            mask: true
                        });
                        const tempFilePaths = chooseImageRes.tempFilePaths;
                        let imgs = tempFilePaths.map((value, index) => {
                            return {
                                name: 'file',
                                uri: value
                            };
                        });
                        uni.uploadFile({
                            url: `${uploadUrl}`,
                            files: imgs,
                            name: 'file',
                            formData: {
                                folder: 'YW_WORKORDER_FILE'
                            },
                            header: {
                                Dm_user_token: token
                            },
                            success: uploadFileRes => {
                                let res = JSON.parse(uploadFileRes.data);
                                if (res.data && res.data.length > 0) {
                                    res.data.forEach(i => {
                                        i.type = 0;
                                        i.fileurl = i.imgaddr;
                                        i.fileurlFull = i.url;
                                        this.fileList.push(i);
                                    });
                                }
                            },
                            fail(err) {
                                console.log('err', err);
                            },
                            complete() {
                                uni.hideLoading();
                                // if (i === chooseImageRes.tempFilePaths.length - 1) {
                                //   uni.hideLoading()
                                // }
                            }
                        });
                    }
                });
            },
            uploadVideo() {
                this.showUpload = false;
                let token = uni.getStorageSync('token') || '';
                uni.chooseVideo({
                    success: chooseImageRes => {
                        uni.showLoading({
                            title: '上传中',
                            mask: true
                        });
                        uni.uploadFile({
                            url: `${uploadUrl}`,
                            filePath: chooseImageRes.tempFilePath,
                            header: {
                                Dm_user_token: token
                            },
                            name: 'file',
                            formData: {
                                folder: 'YW_WORKORDER_FILE'
                            },
                            success: uploadFileRes => {
                                let res = JSON.parse(uploadFileRes.data);
                                if (res.data && res.data.length > 0) {
                                    res.data.forEach(i => {
                                        i.type = 1;
                                        i.fileurl = i.imgaddr;
                                        i.fileurlFull = i.url;
                                        this.fileList.push(i);
                                    });
                                }
                            },
                            complete() {
                                uni.hideLoading();
                            }
                        });
                    }
                });
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .list {
 
        .item {
            .la {
                margin-top: 30rpx;
            }
 
            .line {
 
                textarea {
                    box-sizing: border-box;
                    width: 690rpx;
                    min-height: 160rpx;
                    background-color: #f7f7f7;
                    font-size: 28rpx;
                    color: #333333;
                    padding: 24rpx;
                    border-radius: 8rpx;
                    margin-bottom: 30rpx;
                    margin-top: 20rpx;
                }
            }
 
            .sel_wrap {
                height: 90rpx;
                display: flex;
                justify-content: space-between;
                align-items: center;
                border-bottom: 1rpx solid #E5E5E5;
            }
 
            .upload_wrap {
                display: flex;
                flex-wrap: wrap;
                margin-bottom: 30rpx;
            }
 
            .upload_file {
                margin-top: 24rpx;
                width: 156rpx;
                height: 156rpx;
                margin-right: 20rpx;
                border: 2rpx solid #e5e5e5;
                background: #f7f7f7;
                color: #666666;
                font-size: 22rpx;
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                position: relative;
 
                &:nth-of-type(4n) {
                    margin-right: 0;
                }
 
                .close {
                    position: absolute;
                    right: -20rpx;
                    top: -20rpx;
                    z-index: 9999;
                    background-color: #fff;
                    border-radius: 50%;
                    overflow: hidden;
                }
 
                image {
                    width: 100%;
                    height: 100%;
                }
 
                video {
                    width: 100%;
                    height: 100%;
                }
            }
 
        }
    }
 
    .sub_btn {
        // position: fixed;
        // bottom: 68rpx;
        // left: 40rpx;
        width: 670rpx;
        height: 88rpx;
        margin-top: 80rpx;
        background: $primaryColor;
        box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0, 104, 255, 0.3);
        border-radius: 44rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 500;
        font-size: 32rpx;
        color: #FFFFFF;
    }
 
    .sel_upload_wrap {
        width: 100%;
        border-top: 1px solid #666666;
        box-shadow: 0 1 1 #333333;
 
        .btn {
            height: 90rpx;
            line-height: 90rpx;
            text-align: center;
        }
    }
</style>