老产品前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

648 lines
18 KiB

<template>
<div>
4 years ago
4 years ago
<div class="dialog-h-content scroll-h">
4 years ago
<el-form ref="ref_form"
:inline="true"
:model="formData"
:rules="dataRule"
:disabled="formType === 'detail'"
class="form">
4 years ago
<el-form-item label="所属网格"
label-width="150px"
prop="gridId">
<el-select class="item_width_1"
v-model="formData.gridId"
placeholder="请选择"
clearable>
<el-option v-for="item in gridList"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
4 years ago
<el-form-item label="服务事项"
label-width="150px"
prop="serviceMatterList">
4 years ago
<el-checkbox-group class="item_width_1"
style="display:flex;flex-wrap:wrap"
v-model="formData.serviceMatterList">
<el-checkbox v-for="item in serviceList"
:key="item.value"
:label="item.value">{{item.label}}</el-checkbox>
</el-checkbox-group>
<!-- <el-select class="item_width_1"
4 years ago
v-model="formData.serviceMatter"
placeholder="请选择"
clearable>
<el-option v-for="item in serviceList"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
4 years ago
</el-select> -->
4 years ago
</el-form-item>
<el-form-item label="单位名称"
prop="unitIdList"
4 years ago
label-width="150px"
style="display: block">
4 years ago
<el-checkbox-group class="item_width_1"
style="display:flex;flex-wrap:wrap"
v-model="formData.unitIdList">
4 years ago
<el-checkbox v-for="item in unitList"
:key="item.value"
:label="item.value">{{item.label}}</el-checkbox>
</el-checkbox-group>
<!-- <el-select class="item_width_1"
4 years ago
v-model="formData.unitId"
placeholder="请选择"
clearable>
<el-option v-for="item in unitList"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
4 years ago
</el-select> -->
4 years ago
</el-form-item>
<el-form-item label="活动标题"
prop="title"
label-width="150px"
style="display: block">
<el-input class="item_width_1"
maxlength="50"
show-word-limit
placeholder="请输入活动标题"
v-model="formData.title">
</el-input>
</el-form-item>
<el-form-item label="活动目标"
prop="target"
label-width="150px"
style="display: block">
<el-input class="item_width_1"
type="textarea"
maxlength="100"
show-word-limit
:rows="3"
placeholder="请输入活动目标,不超过100字"
v-model="formData.target"></el-input>
</el-form-item>
<el-form-item label="活动内容"
prop="target"
label-width="150px"
style="display: block">
<div class="item_width_1">
<Tinymce class="tinymce_view "
v-if="formType!='detail'"
v-model="formData.content"
:height="250"
placeholder="在这里输入文字" />
<p v-else
class="text_p"
v-html="formData.content"></p>
</div>
</el-form-item>
<el-form-item label="服务人数"
style="display: block"
prop="peopleCount"
label-width="150px">
4 years ago
<el-input-number class="item_width_4"
4 years ago
v-model="formData.peopleCount"
:min="0"
4 years ago
:max="9999"
4 years ago
label="服务人数"></el-input-number>
</el-form-item>
<el-form-item label="活动时间"
style="display: block"
prop="activityTime"
label-width="150px">
<el-date-picker v-model="formData.activityTime"
value-format="yyyy-MM-dd HH:mm:ss"
type="datetime"
placeholder="选择时间">
</el-date-picker>
</el-form-item>
<el-form-item label="活动坐标"
prop="longitude"
label-width="150px"
style="display: block">
<div class="item_width_1">
<div class="div_map">
<div id="app">
4 years ago
</div>
<div class="div_searchmap">
<el-input class="item_width_4"
maxlength="50"
4 years ago
size="mini"
placeholder="请输入关键字"
v-model="keyWords">
</el-input>
4 years ago
<el-button style="margin-left: 10px"
type="primary"
size="mini"
@click="handleSearchMap">查询</el-button>
</div>
</div>
4 years ago
<div style="margin-top: 10px">
<span>经度</span>
<el-input class="item_width_3"
maxlength="50"
placeholder="请输入经度"
v-model="formData.longitude">
</el-input>
<span style="margin-left: 20px">纬度</span>
<el-input class="item_width_3"
maxlength="50"
placeholder="请输入纬度"
v-model="formData.latitude">
</el-input>
</div>
</div>
</el-form-item>
<el-form-item label="活动地址"
prop="address"
label-width="150px"
style="display: block">
<el-input class="item_width_1"
v-model="formData.address">
</el-input>
</el-form-item>
3 years ago
<el-form-item label="活动成果"
4 years ago
prop="result"
label-width="150px"
style="display: block">
<div class="item_width_1">
<Tinymce class="tinymce_view "
v-if="formType!='detail'"
v-model="formData.result"
:height="250"
placeholder="在这里输入文字" />
<p v-else
class="text_p"
v-html="formData.result"></p>
</div>
</el-form-item>
</el-form>
</div>
4 years ago
<div class="div_btn">
4 years ago
<el-button size="small"
@click="handleCancle"> </el-button>
<el-button size="small"
v-if="formType != 'detail'"
type="primary"
:disabled="btnDisable"
@click="handleComfirm"> </el-button>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { Loading } from 'element-ui' // 引入Loading服务
import { requestPost } from '@/js/dai/request'
import Tinymce from '@c/tinymce/index.vue'
var map
var search
var markers
var infoWindowList
var geocoder // 新建一个正逆地址解析类
let loading // 加载动画
export default {
data () {
return {
formType: 'add', //表单操作类型 add新增,edit编辑,detail详情
btnDisable: false,
keyWords: '',
activityId: '',
formData: {
4 years ago
gridId: '',
serviceMatter: '',//服务事项
4 years ago
serviceMatterList: [],
unitId: '',//单位ID
unitIdList: [],
title: '',//活动标题
target: '',//活动目标
content: '',//活动内容
activityTime: '',//活动时间
peopleCount: 0,//服务人数
result: '', //活动结果
address: '', //详细地址
longitude: 36.0722275, //经度
latitude: 120.38945519 //纬度
},
4 years ago
serviceList: [],
gridList: [],
agencyId: ''
}
},
components: { Tinymce },
mounted () {
this.initMap()
4 years ago
},
methods: {
async initForm (type, activityId) {
this.startLoading()
this.$refs.ref_form.resetFields();
4 years ago
// const { user } = this.$store.state
// this.agencyId = user.agencyId
// await this.loadGrid()
//获取服务事项
await this.loadService()
this.formType = type
if (activityId) {
this.activityId = activityId
this.formData.id = activityId
await this.loadFormData()
} else {
map.setCenter(new TMap.LatLng(36.0722275, 120.38945519))
this.setMarker(36.0722275, 120.38945519)
}
this.endLoading()
4 years ago
},
async loadGrid () {
const url = "/gov/org/customergrid/gridoption"
let params = {
agencyId: this.agencyId
}
const { data, code, msg } = await requestPost(url, params)
if (code === 0) {
this.gridList = data
} else {
this.$message.error(msg)
}
},
//获取服务事项下拉框
async loadService () {
const url = "/heart/serviceitem/dict-list"
let params = {
type: 'usable'
// parentCategoryCode: '1010'
}
const { data, code, msg } = await requestPost(url, params)
4 years ago
if (code === 0) {
this.serviceList = data
4 years ago
} else {
this.$message.error(msg)
}
4 years ago
},
//加载组织
async loadFormData () {
const url = '/heart/icpartyactivity/detail'
// const url = 'http://yapi.elinkservice.cn/mock/245/heart/icpartyactivity/detail'
let params = {
id: this.activityId
}
const { data, code, msg } = await requestPost(url, params)
if (code === 0) {
this.formData = data
4 years ago
console.log(this.formData.content)
let style_img = "style='width:50px;height:40px;' "
if (this.formData.content) {
this.formData.content = this.formData.content.replace(/<img/g, "<img style='width:200px;height:120px;'")
// let array=this.formData.content.split('<img')
}
console.log(this.formData.content)
map.setCenter(new TMap.LatLng(parseFloat(this.formData.latitude), parseFloat(this.formData.longitude)))
this.setMarker(this.formData.latitude, this.formData.longitude)
} else {
this.$message.error(msg)
}
},
async handleComfirm () {
this.btnDisable = true
setTimeout(() => {
this.btnDisable = false
}, 10000)
this.$refs['ref_form'].validate((valid, messageObj) => {
if (!valid) {
app.util.validateRule(messageObj)
this.btnDisable = false
} else {
this.addActivity()
}
})
},
async addActivity () {
let url = '/heart/icpartyactivity/save'
// let url = "http://yapi.elinkservice.cn/mock/245/heart/icpartyactivity/save"
const { data, code, msg } = await requestPost(url, this.formData)
if (code === 0) {
this.$message({
type: 'success',
message: '操作成功'
})
this.resetData()
this.$emit('dialogOk')
this.btnDisable = false
} else {
this.btnDisable = false
this.$message.error(msg)
}
},
handleCancle () {
this.resetData()
this.$emit('dialogCancle')
},
// 地图初始化函数,本例取名为init,开发者可根据实际情况定义
initMap () {
// 定义地图中心点坐标
var center = new window.TMap.LatLng(36.0722275, 120.38945519)
// 定义map变量,调用 TMap.Map() 构造函数创建地图
map = new window.TMap.Map(document.getElementById('app'), {
center: center, // 设置地图中心点坐标
zoom: 17.2, // 设置地图缩放级别
pitch: 43.5, // 设置俯仰角
rotation: 45 // 设置地图旋转角度
})
search = new window.TMap.service.Search({ pageSize: 10 })
// 新建一个地点搜索类
markers = new TMap.MultiMarker({
map: map,
geometries: []
})
infoWindowList = Array(10)
geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
// 监听地图平移结束
map.on('panend', () => {
this.handleMoveCenter()
})
this.handleMoveCenter()
this.convert()
},
setMarker (lat, lng) {
markers.setGeometries([])
markers.add([
{
id: '4',
styleId: 'marker',
position: new TMap.LatLng(lat, lng),
properties: {
title: 'marker4'
}
}
])
},
handleSearchMap () {
infoWindowList.forEach((infoWindow) => {
infoWindow.close()
})
infoWindowList.length = 0
markers.setGeometries([])
// 在地图显示范围内以给定的关键字搜索地点
search
.searchRectangle({
keyword: this.keyWords,
bounds: map.getBounds()
})
.then((result) => {
let { data } = result
if (Array.isArray(data) && data.length > 0) {
const {
location: { lat, lng }
} = data[0]
map.setCenter(new TMap.LatLng(lat, lng))
this.setMarker(lat, lng)
this.formData.latitude = lat
this.formData.longitude = lng
this.convert()
} else {
this.$message.error('未检索到相关位置坐标')
}
})
},
handleMoveCenter () {
//修改地图中心点
const center = map.getCenter()
const lat = center.getLat()
const lng = center.getLng()
this.formData.latitude = lat
this.formData.longitude = lng
this.setMarker(lat, lng)
this.convert(lat, lng)
},
convert (lat, lng) {
markers.setGeometries([]);
// var input = document.getElementById('location').value.split(',');
let location
if (lat && lng) {
location = new TMap.LatLng(lat, lng);
} else {
location = new TMap.LatLng(this.formData.latitude, this.formData.longitude);
}
// map.setCenter(location);
markers.updateGeometries([
{
id: 'main', // 点标注数据数组
position: location,
},
]);
geocoder
.getAddress({ location: location }) // 将给定的坐标位置转换为地址
.then((result) => {
this.formData.address = result.result.address
// 显示搜索到的地址
});
},
resetData () {
this.activityId = ''
this.keyWords = ''
this.formData = {
4 years ago
gridId: '',
serviceMatter: '',//服务事项
4 years ago
serviceMatterList: [],
unitId: '',//单位ID
unitIdList: [],
title: '',//活动标题
target: '',//活动目标
content: '',//活动内容
activityTime: '',//活动时间
peopleCount: 0,//服务人数
result: '', //活动结果
address: '', //详细地址
longitude: 36.0722275, //经度
latitude: 120.38945519 //纬度
}
},
// 开启加载动画
startLoading () {
loading = Loading.service({
lock: true, // 是否锁定
text: '正在加载……', // 加载中需要显示的文字
background: 'rgba(0,0,0,.7)' // 背景颜色
})
},
// 结束加载动画
endLoading () {
// clearTimeout(timer);
if (loading) {
loading.close()
}
}
},
computed: {
dataRule () {
return {
serviceMatterList: [
{ required: true, message: '服务事项不能为空', trigger: 'blur' }
],
unitIdList: [
{ required: true, message: '单位名称不能为空', trigger: 'blur' },
],
title: [
{ required: true, message: '活动标题不能为空', trigger: 'blur' }
],
target: [
{ required: true, message: '活动目标不能为空', trigger: 'blur' }
],
content: [
{ required: true, message: '活动内容不能为空', trigger: 'blur' }
],
activityTime: [
{ required: true, message: '活动时间不能为空', trigger: 'blur' }
],
result: [
{ required: true, message: '活动结果不能为空', trigger: 'blur' }
],
address: [
{ required: true, message: '详细地址不能为空', trigger: 'blur' }
],
longitude: [
{ required: true, message: '坐标不能为空', trigger: 'blur' }
]
}
},
},
props: {
unitList: {
type: Array,
default: []
},
4 years ago
gridList: {
type: Array,
default: []
},
}
}
</script>
4 years ago
<style lang="scss" scoped >
@import "@/assets/scss/modules/visual/communityManageForm.scss";
</style>
<style lang="scss" scoped>
.item_width_1 {
width: 560px;
4 years ago
/deep/.tox .tox-dialog {
z-index: 20000;
}
}
4 years ago
.tinymce_view {
4 years ago
::v-deep .tox .tox-dialog {
z-index: 2000000000;
4 years ago
}
}
.div_map {
position: relative;
}
.div_searchmap {
z-index: 5000;
position: absolute;
top: 5px;
left: 5px;
}
.tinymce_view {
height: 400px;
overflow: auto;
}
.text_p {
margin: 0;
padding: 0 10px;
border: 1px solid #d9d9d9;
border-radius: 5px;
> p {
margin: 0;
}
}
</style>