1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <template>
- <view class="task-form-item form-item-media">
- <view class="form-lable">
- <text><text class="form-must" v-if="rule && rule.required">* </text>定位:</text>
- <view :class="['form-lable-content' , Position.length > 0 ? 'lable-content-right' : '']" v-if="!checkPage">
- <view class="lable-content-btn" @click.stop="onLocation()">
- <text class="iconfont_yige"></text>
- <text>获取当前位置</text>
- </view>
- </view>
- </view>
- <view class="form-img-video form-value">
- {{Position}}
- </view>
- </view>
- </template>
- <script>
- import {
- getLocation
- } from "@/utils/tool.js"
- export default {
- name: 'submintContent',
- model: {
- prop: ['lbsPosition'],
- event: ['onChange']
- },
- props: {
- checkPage: {
- type: Boolean,
- default: false
- },
- rule: {
- type: Object,
- default: null
- },
- lbsPosition: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- Position: ''
- }
- },
- methods: {
- onLocation() {
- try {
- getLocation().then(res => {
- console.log('getLocation = ', res)
- const {
- address
- } = res || {};
- if (address) {
- this.Position =
- `${address.province || ''}${address.city || ''}${address.district || ''}${address.street || ''}${address.poiName || ''}${address.streetNum || ''}`
- }
- }).catch(err => {
- console.log('getLocation err= ', err)
- })
- } catch (e) {
- console.log('showToast = ', e)
- uni.showToast({
- title: '定位失败',
- icon: 'none'
- })
- //TODO handle the exception
- }
- }
- },
- watch: {
- lbsPosition: {
- handler(newL, oldL) {
- this.Position = newL
- },
- immediate: true
- },
- Position: {
- handler(newL, oldL) {
- if (this.Position !== this.lbsPosition) {
- this.$emit('onChange', this.Position)
- }
- },
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '~./submint.scss';
- </style>
|