|
@@ -26,7 +26,6 @@
|
|
|
<van-field
|
|
|
type="text"
|
|
|
v-model="teachingSchool"
|
|
|
- input-align="right"
|
|
|
label="教学点名称"
|
|
|
placeholder="请输入名称" />
|
|
|
</van-cell-group>
|
|
@@ -37,34 +36,46 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
+import AMap from 'vue-amap'
|
|
|
+AMap.initAMapApiLoader({
|
|
|
+ key: 'c7856e7c812d299cff150e74d60ea608',
|
|
|
+ plugin: ['AMap.Geolocation', 'AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.ToolBar'],
|
|
|
+ v: '1.4.4'
|
|
|
+})
|
|
|
import MHeader from '@/components/MHeader'
|
|
|
+import { schoolAdd, schoolUpdate } from '@/api/teacher'
|
|
|
export default {
|
|
|
name: 'teachingset',
|
|
|
components: { MHeader },
|
|
|
data() {
|
|
|
let self = this
|
|
|
return {
|
|
|
+ type: this.$route.query.type,
|
|
|
search_value: '', // 搜索地址
|
|
|
zoom: 12,
|
|
|
center: [114.34371, 30.55939],
|
|
|
markers: [],
|
|
|
searchResult: [], // 搜索出来的数据
|
|
|
- plugin: [{
|
|
|
+ plugin: [
|
|
|
+ {
|
|
|
pName: 'Geolocation',
|
|
|
events: {
|
|
|
init(o) {
|
|
|
- o.getCurrentPosition((status, result) => {
|
|
|
- if(result && result.position) {
|
|
|
- self.lng = result.position.lng
|
|
|
- self.lat = result.position.lat
|
|
|
- self.center = [self.lng, self.lat]
|
|
|
- self.loaded = true
|
|
|
- self.$nextTick()
|
|
|
- }
|
|
|
- })
|
|
|
+ if(self.type == 'create') {
|
|
|
+ o.getCurrentPosition((status, result) => {
|
|
|
+ if(result && result.position) {
|
|
|
+ self.lng = result.position.lng
|
|
|
+ self.lat = result.position.lat
|
|
|
+ self.center = [self.lng, self.lat]
|
|
|
+ self.loaded = true
|
|
|
+ self.$nextTick()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }, {
|
|
|
+ },
|
|
|
+ {
|
|
|
pName: 'ToolBar',
|
|
|
events: {
|
|
|
init() {
|
|
@@ -79,17 +90,72 @@ export default {
|
|
|
},
|
|
|
addressDetail: null, // 输入详情地址
|
|
|
teachingSchool: null, // 教学点
|
|
|
+ lnglat: null, // 教学点经纬度
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ document.title = '教学点设置'
|
|
|
+ let params = this.$route.query
|
|
|
+ if(params.type == 'update') {
|
|
|
+ this.addressDetail = params.address
|
|
|
+ this.teachingSchool = params.name
|
|
|
+ this.lnglat = params.longitudeLatitude
|
|
|
+ let tempLnglat = params.longitudeLatitude.split(',')
|
|
|
+ this.center = [tempLnglat[0], tempLnglat[1]]
|
|
|
+ this.markers.push({
|
|
|
+ position: [tempLnglat[0], tempLnglat[1]],
|
|
|
+ events: this.markerEvents()
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
amapEvents() {
|
|
|
return {
|
|
|
complete: () => {
|
|
|
- this.$toast('加载完成')
|
|
|
+ // this.$toast('加载完成')
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
onSubmit() { // 确定提交
|
|
|
+ if(!this.addressDetail) {
|
|
|
+ this.$toast('请选择教学地点')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if(!this.teachingSchool) {
|
|
|
+ this.$toast('请输入教学点名称')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 添加教学点
|
|
|
+ if(this.type == 'create') {
|
|
|
+ schoolAdd({
|
|
|
+ name: this.teachingSchool,
|
|
|
+ address: this.addressDetail,
|
|
|
+ longitudeLatitude: this.lnglat
|
|
|
+ }).then(res => {
|
|
|
+ let result = res.data
|
|
|
+ if(result.code == 200) {
|
|
|
+ this.$toast('添加成功')
|
|
|
+ this.$router.push('/teachingSchool')
|
|
|
+ } else {
|
|
|
+ this.$toast(result.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else if(this.type == 'update') {
|
|
|
+ schoolUpdate({
|
|
|
+ id: this.$route.query.id,
|
|
|
+ name: this.teachingSchool,
|
|
|
+ address: this.addressDetail,
|
|
|
+ longitudeLatitude: this.lnglat
|
|
|
+ }).then(res => {
|
|
|
+ let result = res.data
|
|
|
+ if(result.code == 200) {
|
|
|
+ this.$toast('修改成功')
|
|
|
+ this.$router.push('/teachingSchool')
|
|
|
+ } else {
|
|
|
+ this.$toast(result.msg)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
onSearch() {
|
|
|
if(!this.search_value) return
|
|
@@ -118,6 +184,7 @@ export default {
|
|
|
let geocoder = new AMap.Geocoder()
|
|
|
geocoder.getAddress(e.lnglat, function(status, result) {
|
|
|
if(status === 'complete' && result.regeocode) {
|
|
|
+ that.lnglat = e.lnglat.lng + ',' + e.lnglat.lat
|
|
|
that.addressDetail = result.regeocode.formattedAddress
|
|
|
} else {
|
|
|
that.$toast('请重新选择地址')
|
|
@@ -131,6 +198,9 @@ export default {
|
|
|
</script>
|
|
|
<style lang='less' scoped>
|
|
|
@import url("../../assets/commonLess/variable.less");
|
|
|
+.teachingset {
|
|
|
+ min-height: 100vh;
|
|
|
+}
|
|
|
.el-vue-amap-container {
|
|
|
height: 60vh;
|
|
|
}
|