linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
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
<template>
    <view class="">
 
        <u-form labelPosition="left" :model="info" :rules="rules" ref="form" labelWidth="100"
            :labelStyle="{fontSize:'28rpx'}">
            <view class="content">
                <u-form-item label="姓名" prop="checkUserName" borderBottom required>
                    <u-input v-model="info.checkUserName" border="none" disabled disabledColor="#fff" placeholder="请输入"
                        placeholderClass="f-28 c-99" inputAlign="right"></u-input>
                </u-form-item>
                <u-form-item label="手机" prop="checkTelephone" borderBottom required>
                    <u-input v-model="info.checkTelephone" border="none" disabled disabledColor="#fff" placeholder="请输入"
                        placeholderClass="f-28 c-99" inputAlign="right"></u-input>
                </u-form-item>
                <u-form-item label="申请事由" prop="applyName" borderBottom required>
                    <u-input v-model="info.applyName" border="none" placeholder="请输入" placeholderClass="f-28 c-99"
                        inputAlign="right"></u-input>
                </u-form-item>
                <u-form-item label="申请时间" prop="applyTime" borderBottom required>
                    <u-input v-model="info.applyTime" disabled disabledColor="#ffffff" border="none" placeholder="请输入"
                        placeholderClass="f-28 c-99" inputAlign="right"></u-input>
                    <!-- <u-icon slot="right" name="arrow-right"></u-icon> -->
                </u-form-item>
                <u-form-item label="申请位置" prop="location" borderBottom ref="location" required>
                    <!-- <u-input v-model="info.location"  disabled disabledColor="#ffffff" border="none" placeholder="请选择地址" placeholderClass="f-28 c-99"
                        inputAlign="right">
                    <template slot="suffix">
                        <button class="location-btn c-main f-24"   @click="getLocation()">获取地址</button>
                    </template>    
                    </u-input> -->
                    <view class="address-row flex">
                        <view class="address-content f-28" v-if="info.location">
                            {{info.location}}
                        </view>
                        <view class="address-content f-28" style="color: #c0c4cc;" v-if="!info.location">
                            请选择位置
                        </view>
                        <view class="location-btn c-main f-24" @click="getLocation()">
                            获取地址
                        </view>
                    </view>
 
                </u-form-item>
            </view>
 
            <view class="upload bgc-ff">
                <view class="f-28 mb-20">位置图片</view>
                <view class="mt-20">
                    <u-upload :fileList="form.images" :previewFullImage="uploadConfig.previewFullImage"
                        :accept="uploadConfig.acceptImg" :multiple="uploadConfig.multiple"
                        :maxCount="uploadConfig.maxCount" :capture="uploadConfig.capture" @afterRead="afterReadImg"
                        @delete="deletePic">
                        <view class="upload-item upload-icon flex_base">
                            <u-icon name="/static/icon/upload.png" width="60rpx" height="60rpx"></u-icon>
                        </view>
                    </u-upload>
                </view>
            </view>
        </u-form>
        <button class="submit-btn" @click="sumitInfo">提交</button>
        <button class="list-btn mb-20" @click="navigatorPage">我上报的事件</button>
        <u-datetime-picker ref="datetimePicker" :show="showSelectDate" v-model="applyTime" mode="datetime"
            :formatter="formatter" @confirm="confirmDate" @cancel="showSelectDate = false"></u-datetime-picker>
    </view>
</template>
 
<script>
    import uploadMixin from "@/mixin/uploadMixin";
    import {
        saveBailReporting,
        getBailReportingDetail,
        updateBailReporting
    } from "@/api/reporting/reporting";
    export default {
        mixins: [uploadMixin],
        data() {
            return {
                form: {
                    images: []
                },
                info: {
                    checkUserName: "",
                    checkTelephone: "",
                    applyName: "",
                    applyTime: '',
                    location: "",
                    houseCode: "",
                    districtName: "",
                    checkUserId: "",
                    reportType: 1
                },
                rules: {
                    checkUserName: [{
                        type: 'string',
                        required: true,
                        message: '请输入姓名',
                        trigger: ['blur', 'change']
                    }],
                    checkTelephone: [{
                            type: 'number',
                            required: true,
                            message: '请输入手机',
                            trigger: ['blur', 'change']
                        },
                        {
 
                            validator: (rule, value, callback) => {
                                return uni.$u.test.mobile(value);
                            },
                            message: '手机号码不正确',
                            trigger: ['change', 'blur']
 
                        }
 
                    ],
                    applyName: [{
                        type: 'string',
                        required: true,
                        message: '请输入事由',
                        trigger: ['blur', 'change']
                    }],
                    applyTime: [{
                        type: 'string',
                        required: true,
                        message: '请输入选择时间',
                        trigger: ['blur', 'change']
                    }],
                    location: [{
                        type: 'string',
                        required: true,
                        message: '请输入位置',
                        trigger: ['blur', 'change']
                    }]
                },
                showSelectDate: false,
                applyTime: Number(new Date()),
                status: "",
                isEdit: false
            }
        },
        onLoad(option) {
 
            if (option.id) {
                this.isEdit = true;
                this.getDetail(option.id)
            }
 
            let siteInfo = uni.getStorageSync("siteInfo");
            let userInfo = uni.getStorageSync("userInfo");
            this.$set(this.info, "houseCode", siteInfo.houseCode);
            this.$set(this.info, "districtName", siteInfo.name);
            this.$set(this.info, "checkUserName", userInfo.real_name);
            this.$set(this.info, "checkTelephone", userInfo.phone);
            this.$set(this.info, "checkUserId", userInfo.user_id);
            this.$set(this.info, "applyTime", uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd hh:MM:ss'))
        },
 
        onReady() {
            // 微信小程序需要用此写法
            this.$refs.datetimePicker.setFormatter(this.formatter)
        },
 
        methods: {
 
 
            getDetail(id) {
                getBailReportingDetail({
                    taskId: id
                }).then(res => {
                    if (res.code == 200) {
                        for (let i in this.info) {
                            this.info[i] = res.data[i]
                        }
                        this.info.reportType = 1;
                        this.status = data.confirmFlag;
                        if (res.data.applyTime) {
                            this.applyTime = Number(new Date(res.data.applyTime))
                        }
                        this.form.images = this.$setImageUrl(data.locationImageUrls, 2);
                        this.info.locationImageUrls = data.locationImageUrls;
                        this.info.id = data.id;
                        this.info.taskId = data.taskId;
                    }
                })
            },
 
 
            getLocation() {
                uni.chooseLocation({
                    success: (res) => {
                        this.$set(this.info, "location", res.address);
                    }
                })
            },
 
 
            formatter(type, value) {
                if (type === 'year') {
                    return `${value}年`
                }
                if (type === 'month') {
                    return `${value}月`
                }
                if (type === 'day') {
                    return `${value}日`
                }
                return value
            },
 
            confirmDate(e) {
                this.showSelectDate = false;
                this.info.applyTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss')
            },
 
            checkImages() {
                if (this.form.images.length) {
                    this.$set(this.info, "locationImageUrls", this.setImages())
                }
            },
 
            setImages() {
                let urls = [];
                for (let i of this.form.images) {
                    urls.push(i.name);
                }
                return urls.join(",")
            },
 
            sumitInfo() {
                this.$refs.form.validate().then(valid => {
                    this.checkImages();
                    if (this.isEdit) {
                        this.info.status = 1;
                        this.updateRequest()
                    } else {
                        this.addRequest()
                    }
                })
            },
 
 
            addRequest() {
                saveBailReporting(this.info).then(res => {
                    uni.showToast({
                        icon: 'success',
                        title: '提交成功'
                    })
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 300)
                })
            },
 
            updateRequest() {
                // this.info.applyTime = Number(new Date(res.data.applyTime));
                updateBailReporting(this.info).then(res => {
                    uni.showToast({
                        icon: 'success',
                        title: '保存成功'
                    })
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 300)
                })
            },
 
            navigatorPage() {
                this.$u.func.globalNavigator('bailList', "navTo")
            }
        }
    }
</script>
 
<style lang="less">
    page {
        background-color: #F5F5F5;
    }
 
    .content {
        margin: 20rpx 30rpx;
        padding: 0 30rpx;
        background-color: #fff;
    }
 
    /deep/.u-radio-group--row {
        justify-content: flex-end;
    }
 
    .site-box {
        padding: 30rpx;
        margin: 20rpx 30rpx;
        border-radius: 4rpx;
 
        .c-aa {
            color: #aaa;
        }
 
        .address {
            width: 60%;
            margin-left: 25rpx;
        }
    }
 
    .upload-item {
        width: 140rpx;
        height: 140rpx;
        border: 1px solid #EEEEEE;
    }
 
    .upload {
        margin: 0 30rpx;
        padding: 30rpx;
 
 
    }
 
    .submit-btn {
        width: 690rpx;
        height: 78rpx;
        line-height: 78rpx;
        background: linear-gradient(163deg, #01BDFC 0%, #017BFC 100%);
        border-radius: 8rpx 8rpx 8rpx 8rpx;
        font-size: 32rpx;
        color: #fff;
        margin-top: 50rpx;
    }
 
    .list-btn {
        width: 690rpx;
        height: 78rpx;
        line-height: 78rpx;
        background: linear-gradient(163deg, #c7d7dc 0%, #c3cdd8 100%);
        border-radius: 8rpx 8rpx 8rpx 8rpx;
        font-size: 32rpx;
        color: #fff;
        margin-top: 50rpx;
    }
 
    .address-row {
        flex: 1;
        justify-content: flex-end;
        align-items: center;
    }
 
    .address-content {
        width: calc(100% - 116rpx - 20rpx);
        margin-right: 20rpx;
        text-align: right;
    }
 
    .location-btn {
        width: 116rpx;
        height: 46rpx;
        line-height: 46rpx;
        border-radius: 4rpx;
        border: 1px solid currentColor;
        padding: 0;
        background-color: #fff;
        text-align: center;
    }
</style>