guoshilong
2022-10-14 d8e0af2ce345f3b40581ad05c596f965ae729c01
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
<template>
    <view class="container">
        <u-form :model="form" ref="uForm" :rules="rules">
            
            <u-form-item label="标题:" prop="title">
                <u-input v-model="form.title"/>
            </u-form-item>
            
            <u-form-item label="地址:">
                <u-input :disabled="true" v-model="form.address" placeholder="请输入地址" @click="getAddress"/>
            </u-form-item>
            
            <u-form-item label-width="20%" label="事件类型:" prop="type">
                <u-input v-model="form.typeText" type="select" @click="showType = true" placeholder="请选择事件类型"/>
            </u-form-item>
            <u-action-sheet
                v-model="showType"
                :list="typeList"
                title="请选择事件类型"
                @click="typeSelect"
            >
            </u-action-sheet>
            
<!--             <u-form-item label-width="20%" label="事件状态:" prop="state">
                <u-input v-model="form.stateText" type="select" @click="showState = true" placeholder="请选择事件状态"/>
            </u-form-item>
            <u-action-sheet
                v-model="showState"
                :list="stateList"
                title="请选择事件状态"
                @click="stateSelect"
            >
            </u-action-sheet> -->
            
<!--             <u-form-item label-width="20%" label="事件来源:">
                <u-input :disabled="true" v-model="form.sourceText" type="select" @click="showSource = true" placeholder="请选择事件来源"/>
            </u-form-item>
            <u-action-sheet
                v-model="showSource"
                :list="sourceList"
                title="请选择事件来源"
                @click="sourceSelect"
            >
            </u-action-sheet> -->
            
            <u-form-item label-position="top" label-width="25%" label="图片视频上传:">
                <evan-upload ref="evanUpload" 
                :imgLimit="4" 
                :format="format"
                :options="uploadOption" 
                @on-pre-video="onPreVideo"
                @on-upload="onUpload" 
                ></evan-upload>
            </u-form-item>
            
            <video id="myVideo" v-show="videoShow" :src="videoUrl" @fullscreenchange="fullScreenChange"></video>
            <u-form-item label-position="top" label="备注:">
                <u-input v-model="form.remark" type="textarea" />
            </u-form-item>
        </u-form>
        
        <view class="submitBtn">
            <u-button @click="submit">提交</u-button>
        </view>
        
    </view>
 
</template>
 
<script>
import {clientId,clientSecret} from '@/common/setting'
import {add} from "@/api/eventgm/eventgm.js"
import {getDicList} from "@/api/dict/dict.js"
import evanUpload from "@/components/evan-upload/evan-upload.vue";
import {devUrl} from '@/common/setting'
export default {
    components: {'evan-upload' :evanUpload },
    data() {
        return {
            form: {
                title:"",
                address:"章贡区",
                longitude:"116.4",
                latitude:"39.9",
                type:"",
                typeText:"",
                state:"",
                stateText:"",
                source:"APP",
                sourceText:"APP",
                picUrls:[],
                remark:"",
                taskinfoId:null,
            },
            rules:{
                type:[{
                    required:true,
                    message:'请选择事件类型',
                    trigger:'blur'
                }],
                state:[{
                    required:true,
                    message:'请选择事件状态',
                    trigger:'blur'
                }],
                title:[{
                    required:true,
                    message:'请输入标题',
                    trigger:'blur'
                }]
                
            },
            uploadOption:{
                // url:"http://localhost/blade-resource/oss/endpoint/put-file-attach",
                url:devUrl+"/blade-resource/oss/endpoint/put-file-attach",
                header:{},
            },
            fileSuffix: 'fileType',
            uploadList:[],
            videoUrl:"",
            videoShow:false,
            videoContext:null,
            showType:false,
            typeList:[],
            showState:false,
            stateList:[],
            showSource:false,
            sourceList:[
                {
                    text: 'WEB',
                    value:'WEB'
                },
                {
                    text: 'APP',
                    value:'APP'
                },
            ],
            
        };
    },
    onReady() {
        this.$refs.uForm.setRules(this.rules);
        this.videoContext = uni.createVideoContext("myVideo",this)
    },
    onLoad(option) {
        if(option.id){
            this.form.taskinfoId = option.id
        }
    },
    created() {
        this.getType()
        this.getState()
        this.getHeader()
    },
    methods:{
        //获取头部
        getHeader(){
            let accessToken = uni.getStorageSync('accessToken');
            var myHeader = {}
            if (accessToken) {
                myHeader['Blade-Auth'] = 'bearer ' + accessToken;
            }
            // 客户端认证参数
            myHeader['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
            this.header = myHeader
            this.uploadOption.header = myHeader
        },
        getAddress(){
            uni.getLocation({
                type: 'wgs84',
                isHighAccuracy:true,
                accuracy:'best',
                geocode:true,
                success: res=> {
                    console.log(res)
                    console.log('当前位置的经度:' + res.longitude);
                    console.log('当前位置的纬度:' + res.latitude);
                    this.form.longitude = res.longitude
                    this.form.latitude = res.latitude
                    
                    //#ifdef APP-PLUS
                    //根据经纬度获取地址信息
                    var point = new plus.maps.Point(res.longitude, res.latitude);
                    plus.maps.Map.reverseGeocode(
                        point,
                        {},
                        (successRes)=>{
                            this.form.address = successRes.address
                        }
                    )
                    //#endif
                }
            });
        },
        //获取数据字典
        getType(){
            getDicList("EVENT_TYPE").then(res=>{
                if(res.code == 200){
                    res.data.forEach(e=>{
                        this.typeList.push({
                            text:e.dictValue,
                            key:e.dictKey
                        })
                    })
                }
            })
        },
        getState(){
            getDicList("EVENT_STATE").then(res=>{
                if(res.code == 200){
                    res.data.forEach(e=>{
                        this.stateList.push({
                            text:e.dictValue,
                            key:e.dictKey
                        })
                    })
                    this.form.state = this.stateList[0].key
                }
            })
        },
        //选择事件
        typeSelect(index){
            this.form.typeText = this.typeList[index].text
            this.form.type = this.typeList[index].key
        },
        stateSelect(index){
            this.form.stateText = this.stateList[index].text
            this.form.state = this.stateList[index].key
        },
        sourceSelect(index){
            this.form.sourceText = this.sourceList[index].text
            this.form.source = this.sourceList[index].value
        },
        //表单提交
        submit(){
            this.$refs.uForm.validate(valid => {
                if (valid) {
                    if(this.uploadList.length>0){
                        this.uploadList.forEach(e=>{
                            var res = JSON.parse(e.res)
                            this.form.picUrls.push({
                                label:res.data.name,
                                value:res.data.link
                            })
                        })
                    }else{
                        this.form.picUrls = null
                    }
                    add(this.form).then(res=>{
                        if(res.code ==200){
                            uni.redirectTo({
                                url:"/pages/taskinfo/list"
                            })
                        }
                    })
                } 
            });
        },
        onUpload(res){
            this.uploadList = res.data
        },
        //对返回的数据进行处理
        format(res){
            var myRes = JSON.parse(res.url)
            var fileType = myRes.data.originalName.split(".")[1]
            var thumbnail = myRes.data.link
            var url = res.url
            res = {}
            res.fileType = fileType
            res.thumbnail = thumbnail
            res.url = thumbnail
            res.res = url
            res.imgCoverKey = thumbnail
            return res
        },
        //视频预览
        onPreVideo(video){
            this.videoUrl = video.url
            this.videoShow = true
            this.videoContext.requestFullScreen({direction:0})
        },
        //退出全屏
        fullScreenChange(e){
            if(!e.detail.fullScreen){
                //隐藏视频
                this.videoShow = false
            }
        },
    }
};
</script>
 
<style scoped>
    .container{
        padding: 20px;
    }
</style>