叶松
2023-11-27 c34e1ebbabaec123d735149e47df856c4cf837c5
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
<template>
    <view class="check_add_index">
        <u-form
            ref="form"
            :model="formCheck"
            :rules="rulesCkeck"
            labelWidth="auto"
            labelPosition="left">
            <view style="overflow: auto;width: 100%;background-color: #FFFFFF;" class="upload_items items_tyle">
                <u-form-item label="问题照片">
                    <u-upload
                        :fileList="formCheck.imageList"
                        @afterRead="afterRead"
                        @delete="deleteImage"
                        name="66"
                        :previewFullImage="true"
                        :maxCount="6"
                        width="150"
                        height="150">
                        <image src="https://szpipe.thhy-tj.com/group1/M00/00/02/bx5d1GSihuWAA-kBAAAICqDtUn8566.png" mode="widthFix" style="width:64px;height: 100px;display: flex;justify-content: center;"></image>
                        <view style="text-align: center;font-size: 16px;color: #666666;">上传照片</view>
                    </u-upload>
                </u-form-item>
            </view>
            <u-form-item
                    label="隐患地点"
                    prop="dangerLocation"
                    @click="changePosition()"
                    borderBottom>
                <u-input
                    v-model="formCheck.dangerLocation"
                    placeholder="请输入隐患地点"
                    disabled
                    disabledColor="#FFFFFF"
                    border="none">
                </u-input>
            </u-form-item>
            <view class="items_tyle">
                <u-form-item
                    label="隐患标题"
                    prop="title"
                    borderBottom>
                    <u--textarea v-model="formCheck.title" placeholder="请输入隐患标题" height="100"></u--textarea>
                </u-form-item>
                <div>{{value}}</div>
            </view>
        </u-form>
        <view class="submit_bnt">
            <u-button type="primary" color="#1976FF" text="提交" @click="submitInsertForm()"></u-button>
        </view>
        <u-picker 
            :show="positionUser" 
            :columns="positionColumns" 
            keyName="dictName"
            @cancel="positionUser = false"
            @confirm="selectPosition">
        </u-picker>
    </view>
</template>
 
<script>
    import { throttle } from '../../plugins/public.js';
    import { basrUrl } from '@/api/http';
    export default{
        data(){
            return{
                value:null,
                positionUser: false,//隐患地点弹框显隐
                positionColumns: [],//所有隐患地点
                formCheck:{
                    imageList:[],//上传图片
                    positionId:'',//隐患地点
                },
                rulesCkeck: {
                    dangerLocation: [{
                        required: true,
                        message: '请输入隐患地点',
                        trigger: 'blur'
                    }],
                    title: [{
                        required: true,
                        message: '请输入隐患标题',
                        trigger: 'blur'
                    }],
                }
            }
        },
        onShow() {
            let phone = uni.getStorageSync('telphone');
            if(!phone){
                uni.navigateTo({
                    url: '../../pages/loginIndex/index'
                })
            }
        },
        onLoad(query) {
            const q = decodeURIComponent(query.q)
            this.value = q
            console.log(q,'*****')
            this.getPositionData()
        },
        methods:{
            // 获取隐患地点信息
            getPositionData() {
                let arrUser = []
                this.$api.reboSystem.getDatnmSafeType({dictType: 'danger_region',pageNum: 1,pageSize: 1000000000}).then(res=>{
                    console.log(res,'******')
                    if(res.statusMsg === 'ok'){
                        res.data.list.map(item=>{
                            arrUser.push({
                                dictName:item.dictName,
                                positionId:item.dictId
                            })
                        })
                    }else{
                        uni.$u.toast(res.statusMsg);
                    }
                })
                this.positionColumns = [arrUser]
            },
            // 打开隐患地点选择
             changePosition() {
                 this.positionUser = true;
                 this.$set(this.formCheck, 'positionId', '');
                 this.$set(this.formCheck, 'dangerLocation','');
             },
            // 确认选择隐患地点
            selectPosition({ value }) {
                 this.$set(this.formCheck, 'positionId', value[0].positionId);
                 this.$set(this.formCheck, 'dangerLocation', value[0].dictName);
                 this.positionUser = false;
            },
            //提交按钮
            submitInsertForm: throttle(function() {
                this.$refs.form.validate().then((valid) => {
                    if(valid) {
                        const params = Object.assign({}, this.formCheck);
                        params.imgEntities = this.formCheck.imageList.map(item=>{
                            return {
                                imgPath:item.data,
                            }
                        });
                        delete params.userId
                        delete params.imageList;
                        this.$api.reboSystem.addHiddenInfo(params).then((res) => {
                            if(res.success) {
                                uni.$u.toast("提交成功!");
                                uni.redirectTo({
                                    url: './hiddenReport'
                                });
                            } else {
                                uni.$u.toast(res.statusMsg);
                            }
                        })
                    }
                })
            }, 3000),
            // 读取图片后
            afterRead(event) {
                this.formCheck.imageList.push({
                    status: 'loading',
                    message: '上传中',
                })
                uni.uploadFile({
                    url: `${basrUrl}/file/file/upload`,
                    fileType: event.file.type,
                    filePath: event.file.url,
                    name: 'file',
                    success: (res) => {
                        const data = JSON.parse(res.data);
                        console.log(data,event,'名字')
                        this.$set(this.formCheck.imageList, this.formCheck.imageList.length - 1, {
                            id: this.formCheck.imageList.length + 1,
                            status: 'success',
                            message: '',
                            data: data.data,
                            url: `https://szpipe.thhy-tj.com/${data.data}`
                        })
                    },
                    fail: (error) => {
                        uni.$u.toast('上传失败!');
                    }
                })
            },
            // 删除图片
            deleteImage(event) {
                this.$nextTick(() => {
                    this.formCheck.imageList.splice(event.index, 1);
                })
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    .check_add_index{
        background-color: #F6F6F6;
        padding: 0 15px;
        position: relative;
        height: 100vh;
        overflow: hidden;
    }
    .submit_bnt {
        position: absolute;
        bottom: 5%;
        width: calc(100% - 30px);
    }
    
    
    ::v-deep .u-input__content__field-wrapper__field {
        text-align: right !important;
    }
    ::v-deep .u-form-item{
        margin: 15px 0;
        padding: 0 10px;
        background-color: #FFFFFF;
        line-height: 40px;
        border-radius: 4px;
    }
    ::v-deep .u-upload{
        flex: none !important;
        justify-content: center;
        align-items: center;
    }
    ::v-deep .u-textarea{
        background-color: #EFEFEF !important;
        color: #999999 !important;
    }
    
</style>
<style scoped>
    .items_tyle /deep/.u-form-item__body{
        flex-direction: column !important;
    }
    .upload_items /deep/.u-upload__wrap{
        flex-wrap: nowrap;
        align-items: center;
    }
</style>