guoshilong
2023-10-27 2311b03aee9db1bebacdd2ced13c071efda6a011
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
<template>
    <view class="container">
 
        <!--上报信息-->
        <card class="card">
            <view slot="insideHead">
                <boxTitle title="上报信息"></boxTitle>
            </view>
            <view class="content" slot="content">
                <u-form :model="form" :rules="rules" ref="form">
                    <u-form-item :labelWidth="labelWidth" label="水库名称:" @click="disabled?skShow=false:skShow = true">
                        <u--input border="bottom" v-model="resName" disabled disabledColor="#ffffff"
                            placeholder="请选择水库">
                        </u--input>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
 
                    <u-form-item :labelWidth="labelWidth" label="类型:" required prop="type" @click="typeShow = true">
                        <u--input border="bottom" v-model="typeName" disabled disabledColor="#ffffff"
                            placeholder="请选择类型">
                        </u--input>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
 
                    <u-form-item :labelWidth="labelWidth" label="测点:" required @click="stationShow = true"
                        prop="stationId">
                        <u--input border="bottom" v-model="stationName" disabled disabledColor="#ffffff"
                            placeholder="请选择测点">
                        </u--input>
                        <u-icon slot="right" name="arrow-right"></u-icon>
                    </u-form-item>
 
                    <u-form-item :labelWidth="labelWidth" label="记录时间:" @click="timeVisible = true" required
                        prop="recordTime">
                        <u--input border="bottom" v-model="form.recordTime" disabled disabledColor="#ffffff"
                            placeholder="请选择记录时间">
                        </u--input>
                    </u-form-item>
 
                    <u-form-item v-if="form.type !='wy' " :labelWidth="labelWidth" label="监测值:" required prop="val">
                        <u--input border="bottom" v-model="form.val" placeholder="填写监测值">
                            <u--text :text="unit" slot="suffix" margin="0 3px 0 0"></u--text>
                        </u--input>
                    </u-form-item>
 
 
                    <u-form-item v-else :labelWidth="labelWidth" label="监测值:" required>
                        <view>
                            <u-form-item :labelWidth="85" label="水平位移X:" prop="x">
                                <u--input border="bottom" v-model="form.x" placeholder="请输入监测值">
                                    <u--text :text="unit" slot="suffix" margin="0 3px 0 0"></u--text>
                                </u--input>
                            </u-form-item>
                            <u-form-item :labelWidth="85" label="水平位移Y:" prop="y">
                                <u--input border="bottom" v-model="form.y" placeholder="请输入监测值">
                                    <u--text :text="unit" slot="suffix" margin="0 3px 0 0"></u--text>
                                </u--input>
                            </u-form-item>
                            <u-form-item :labelWidth="85" label="垂直位移:" prop="z">
                                <u--input border="bottom" v-model="form.z" placeholder="请输入监测值">
                                    <u--text :text="unit" slot="suffix" margin="0 3px 0 0"></u--text>
                                </u--input>
                            </u-form-item>
                        </view>
                    </u-form-item>
 
 
 
                    <u-form-item :labelWidth="labelWidth" label="描述:" prop="description">
                        <u-textarea confirmType="done" v-model="form.description" placeholder="请填写描述">
                        </u-textarea>
                    </u-form-item>
 
 
                </u-form>
            </view>
        </card>
 
        <view class="page-footer">
            <u-button type="primary" text="提交" @click="submit"></u-button>
        </view>
 
        <!-- 水库下拉框 -->
        <my-select v-if="skShow" :show="skShow" v-model="form.reservoirId" type="radio" popupTitle="请选择水库"
            :dataLists="skSelectList" @cancel="skShow = false" @submit="skSelect">
        </my-select>
 
        <!-- 类型下拉框 -->
        <my-select v-if="typeShow" :show="typeShow" v-model="form.type" type="radio" popupTitle="请选择测站类型"
            :dataLists="typeSelectList" @cancel="typeShow = false" @submit="typeSelect">
        </my-select>
 
        <!-- 测点下拉框 -->
        <my-select v-if="stationShow" :show="stationShow" v-model="form.stationId" type="radio" popupTitle="请选择测点"
            :dataLists="stationSelectList" @cancel="stationShow = false" @submit="stationSelect">
        </my-select>
 
        <!--时间选择-->
        <u-datetime-picker :formatter="formatter" :show="timeVisible" mode="datetime" v-model="recordTime"
            @confirm="timeConfirm" @cancel="timeVisible = false">
        </u-datetime-picker>
 
    </view>
</template>
 
<script>
    import mySelect from "@/components/my-components/my-select.vue"
    import card from "@/components/my-components/card.vue"
    import boxTitle from "@/subPackage/jcsb/components/boxTitle.vue"
    import {
        convertTimestampToDate
    } from "@/utils/date"
    import {
        addDb,
    } from "@/api/jcsb/dangerReport/dangerReport.js"
    import {
        reservoirList
    } from "@/api/dataCenter/reservoir/reservoir.js"
    import {
        getStationList
    } from "@/api/dataCenter/dbSafety/dbSafety"
 
    function isNumber(val) {
        let reg = /^\d+(\.\d+)?$/
        if (reg.test(val)) {
            return true
        } else {
            return false
        }
    }
 
    export default {
        components: {
            mySelect,
            card,
            boxTitle
        },
        data() {
            return {
                labelWidth: 70,
 
                resName: '',
                typeName: "",
                stationName: "",
                recordTime: "",
 
                skShow: false,
                typeShow: false,
                timeVisible: false,
                stationShow: false,
                skSelectList: [],
                typeSelectList: [{
                        value: "sy",
                        name: "渗压站",
                    },
                    {
                        value: "sl",
                        name: "渗流站",
                    },
                    {
                        value: "wy",
                        name: "变形站",
                    },
                ],
                stationSelectList: [],
 
                form: {
                    reservoirId: "",
                    type: "",
                    stationId: "",
                    val: "",
                    recordTime: "",
                    description: "",
                    x: "",
                    y: "",
                    z: "",
                },
                handleForm: {
                    toImages: [],
                    toDesinfo: "",
                    status: 1
                },
                rules: {
                    'type': {
                        required: true,
                        message: '请选择测站类型',
                        trigger: ['blur', 'change']
                    },
 
                    'stationId': {
                        required: true,
                        message: '请选择测点',
                        trigger: ['blur', 'change']
                    },
                    'recordTime': {
                        required: true,
                        message: '请选择上报时间',
                        trigger: ['blur', 'change']
                    },
                    'val': {
                        required: true,
                        message: '请输入监测值',
                        trigger: ['blur', 'change'],
                        // type: 'float',
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            return isNumber(value)
                        },
                    },
                    'x': {
                        required: true,
                        message: '请输入水平位移X监测值',
                        trigger: ['blur', 'change'],
                        // type: 'float',
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            return isNumber(value)
                        },
                    },
                    'y': {
                        required: true,
                        message: '请输入水平位移Y监测值',
                        trigger: ['blur', 'change'],
                        // type: 'float',
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            return isNumber(value)
                        },
                    },
                    'z': {
                        required: true,
                        message: '请输入垂直位移监测值',
                        trigger: ['blur', 'change'],
                        // type: 'float',
                        validator: (rule, value, callback) => {
                            // 上面有说,返回true表示校验通过,返回false表示不通过
                            return isNumber(value)
                        },
                    }
 
                },
                disabled: false,
                unit: "",
            }
        },
        watch: {},
        onLoad(option) {
            this.init()
            this.getReservoirList()
        },
        mounted() {
 
        },
        methods: {
            clearValidate() {
                this.$refs.form.clearValidate()
            },
 
            async submit() {
                const that = this
                const res = await this.$refs.form.validate()
 
                if (res) {
 
                    this.form.reservoirName = this.resName
 
                    if (this.form.type == "wy") {
                        let arr = [this.form.x, this.form.y, this.form.z]
                        this.form.val = arr.join(",")
                    }
 
                    addDb(this.form).then(res => {
                        uni.showToast({
                            icon: 'success',
                            title: '提交成功',
                            success() {
                                setTimeout(() => {
                                    that.$u.func.globalNavigator(
                                        "/pages/home/patrolIndex", "switchTab")
                                }, 1000)
                            }
                        })
                    })
                }
            },
 
            //获取测站数据
            getStation() {
 
                if (this.form.reservoirId == "" || this.form.type == "") {
                    return
                }
 
                let params = {
                    res_cd: this.form.reservoirId,
                    cd_type: this.form.type
                }
 
                this.form.stationId = ""
                this.stationName = ""
 
                getStationList(params).then(res => {
                    let data = res.data
                    this.stationSelectList = []
 
                    data.forEach(e => {
                        this.stationSelectList.push({
                            value: e.cd,
                            name: e.cd_nm
                        })
                    })
 
                })
            },
 
            timeConfirm(data) {
                let timeStamp = data.value
                let time = convertTimestampToDate(timeStamp, "yyyy-MM-dd hh:mm:ss")
                this.form.recordTime = time
                this.timeVisible = false
            },
            //时间显示格式化
            formatter(type, value) {
                if (type === 'year') {
                    return `${value}年`
                }
                if (type === 'month') {
                    return `${value}月`
                }
                if (type === 'day') {
                    return `${value}日`
                }
                if (type === 'hour') {
                    return `${value}时`
                }
                if (type === 'minute') {
                    return `${value}分`
                }
                return value
            },
 
            init() {
                this.initTime()
                let arr = this.userInfo.detail.resIds.split(",")
                var filterArr = arr.filter(function(item, index) {
                    return arr.indexOf(item) === index; // 因为indexOf 只能查找到第一个  
                });
                this.resIds = filterArr.join(",")
            },
 
            //初始化时间
            initTime() {
                this.recordTime = convertTimestampToDate(new Date)
            },
 
            // 水库下拉框数据
            async getReservoirList() {
                if (this.resIds == "") {
                    return
                }
                let params = {
                    res_cds: this.resIds.split(",").map(e => `'${e}'`).join(",")
                }
                reservoirList(100, 1, params).then(res => {
                    let data = res.data.data
                    for (let i = 0; i < data.length; i++) {
                        if (i == 0) {
                            this.resName = data[i].res_nm
                            this.form.reservoirId = data[i].res_cd
                        }
                        let skRes = {
                            value: data[i].res_cd,
                            name: data[i].res_nm
                        }
                        this.skSelectList.push(skRes)
                    }
                })
            },
 
            //水库选择
            skSelect(data) {
                this.form.reservoirId = data.value
                this.resName = data.name
                this.skShow = false
                this.getStation()
            },
 
            typeSelect(data) {
                this.form.type = data.value
                this.typeName = data.name
                this.typeShow = false
 
                if (data.value == "sy") {
                    this.unit = '(m)'
                } else if (data.value == "sl") {
                    this.unit = '(L/s)'
                } else if (data.value == "wy") {
                    this.unit = '(mm)'
                }
 
                this.clearValidate()
                this.getStation()
            },
 
            stationSelect(data) {
                this.form.stationId = data.value
                this.stationName = data.name
                this.stationShow = false
            },
 
            /** 数组去重
             * 思路:利用数组的 indexOf 下标属性来查询
             * @param arr 需要去重的数组
             * @param t 根据 t 字段(指定)进行去重
             * @returns {*[]} 已去重后的数据
             */
            deduplicate(arr, t = "") {
                const newArr = [],
                    assignList = []
                // 有指定字段
                if (t) {
                    for (let i = 0; i < arr.length; i++) {
                        if (assignList.indexOf(arr[i][t]) === -1) {
                            assignList.push(arr[i][t])
                            newArr.push(arr[i])
                        }
                    }
                }
                // 无指定字段
                else {
                    for (let i = 0; i < arr.length; i++) {
                        if (newArr.indexOf(arr[i]) === -1) newArr.push(arr[i])
                    }
                }
                return newArr
            }
        }
    }
</script>
 
<style scoped lang="scss">
    .container {
        overflow: hidden;
        // padding: 0 14rpx;
 
        .page-footer {
            position: fixed;
            bottom: 0;
            width: 100%;
        }
    }
 
    .card {
        .content {
            padding: 0 30rpx;
            border: 5rpx solid #edf6ff;
 
            .item {
                display: flex;
                align-items: center;
 
                .label {
                    width: 150rpx;
                }
 
            }
 
        }
 
        .image {
            width: 100rpx;
            height: 100rpx;
        }
    }
</style>