<template>
|
<view class="container">
|
<u-form :model="form" ref="uForm" :rules="rules">
|
|
<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="图片上传:">
|
<!-- <u-upload ref="uUpload" :header="header" :action="uploadApi" max-count="5" ></u-upload> -->
|
<evan-upload ref="evanUpload" :imgLimit="4" :options="uploadOption" @on-upload="onUpload"></evan-upload>
|
</u-form-item>
|
|
<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";
|
export default {
|
components: {'evan-upload' :evanUpload },
|
data() {
|
return {
|
form: {
|
address:"章贡区",
|
longitude:"",
|
latitude:"",
|
type:"",
|
typeText:"",
|
state:"",
|
stateText:"",
|
source:"APP",
|
sourceText:"APP",
|
picUrls:[],
|
remark:"",
|
},
|
rules:{
|
type:[{
|
required:true,
|
message:'请选择事件类型',
|
trigger:'blur'
|
}],
|
state:[{
|
required:true,
|
message:'请选择事件状态',
|
trigger:'blur'
|
}],
|
|
},
|
//换用其他写法
|
uploadApi:"http://localhost/blade-resource/oss/endpoint/put-file-attach",
|
header:{},
|
uploadOption:{
|
url:"http://localhost/blade-resource/oss/endpoint/put-file-attach",
|
header:{},
|
},
|
uploadList:[],
|
showType:false,
|
typeList:[],
|
showState:false,
|
stateList:[],
|
showSource:false,
|
sourceList:[
|
{
|
text: 'WEB',
|
value:'WEB'
|
},
|
{
|
text: 'APP',
|
value:'APP'
|
},
|
],
|
};
|
},
|
onReady() {
|
this.$refs.uForm.setRules(this.rules);
|
},
|
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,
|
geocode:true,
|
success: res=> {
|
console.log('当前位置的经度:' + res.longitude);
|
console.log('当前位置的纬度:' + res.latitude);
|
this.form.longitude = res.longitude
|
this.form.latitude = res.latitude
|
}
|
});
|
},
|
//获取数据字典
|
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) {
|
// let lists = this.$refs.uUpload.lists
|
// if(lists.length>0){
|
// lists.forEach(e=>{
|
// this.form.picUrls.push({
|
// label:e.response.data.name,
|
// value:e.response.data.link
|
// })
|
// })
|
// }else{
|
// this.form.picUrls = null
|
// }
|
if(this.uploadList.length>0){
|
this.uploadList.forEach(e=>{
|
var res = JSON.parse(e.url)
|
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
|
if(this.$refs.evanUpload.imgArr.length>0){
|
this.$refs.evanUpload.imgArr.forEach(e=>{
|
var res = JSON.parse(e.url)
|
e.thumbnail = res.data.link
|
})
|
}
|
|
if(this.$refs.evanUpload.videoArr.length>0){
|
this.$refs.evanUpload.videoArr.forEach(e=>{
|
var res = JSON.parse(e.url)
|
e.thumbnail = res.data.link
|
})
|
}
|
|
}
|
}
|
};
|
</script>
|
|
<style scoped>
|
.container{
|
padding: 20px;
|
}
|
</style>
|