locationArea.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <!-- 地区定位 -->
  3. <view>
  4. <u-navbar title="选择地区" autoBack placeholder></u-navbar>
  5. <view class="card_address">
  6. <view class="add_title">{{address || '定位中...'}}</view>
  7. <view class="anew_title" @click="reposition"><u-icon name="map" size="24" color="#f9ae3d"></u-icon>重新定位
  8. </view>
  9. </view>
  10. <view style="margin-top: 20rpx;">
  11. <view class="item_city" v-for="(item,index) in areaData" @click="selectArea(item,'area')">
  12. <view class="city_title">{{item.label}}</view>
  13. <view class="item_district" v-for="(item1,index1) in item.children"
  14. @click.stop="selectArea(item1,'district')">
  15. {{item1.label}}
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. urbanArea
  24. } from '@/static/js/districtCode.js'
  25. export default {
  26. data() {
  27. return {
  28. address: '',
  29. areaData: urbanArea(), //原始数据
  30. }
  31. },
  32. mounted() {
  33. var city1 = this.$cache.getCache('city')
  34. var district2 = this.$cache.getCache('district')
  35. if (city1) {
  36. this.address = city1
  37. } else {
  38. this.address = district2
  39. }
  40. },
  41. methods: {
  42. selectArea(value, type) {
  43. this.$cache.setCache('city', '')
  44. this.$cache.setCache('district', '')
  45. if (type == 'area') {
  46. this.$cache.setCache('city', value.label)
  47. } else if (type == 'district') {
  48. this.$cache.setCache('district', value.label)
  49. }
  50. uni.$emit('selectArea');
  51. uni.redirectTo({
  52. url: '/pages/indexRouter'
  53. })
  54. },
  55. // 重新定位
  56. reposition() {
  57. uni.getLocation({
  58. type: 'gcj02', //返回可以用于uni.openLocation的经纬度
  59. geocode: true,
  60. success: (res) => {
  61. this.$cache.setCache('longitude', res)
  62. this.$cache.setCache('district', res.address.district)
  63. this.address = res.address.district
  64. uni.$emit('selectArea');
  65. uni.redirectTo({
  66. url: '/pages/indexRouter'
  67. })
  68. },
  69. });
  70. }
  71. }
  72. }
  73. </script>
  74. <style lang="scss" scoped>
  75. .card_address {
  76. padding: 30rpx 20rpx;
  77. display: flex;
  78. justify-content: space-between;
  79. align-items: center;
  80. border-bottom: 2rpx solid transparent;
  81. border-image: linear-gradient(to bottom, transparent 50%, #e7e6e4 50%) 0 0 100% 0;
  82. background-color: #fff;
  83. }
  84. .add_title {
  85. font-size: 30rpx;
  86. font-weight: 600;
  87. }
  88. .anew_title {
  89. display: flex;
  90. align-items: center;
  91. font-size: 30rpx;
  92. color: #f9ae3d;
  93. }
  94. .item_city {
  95. margin: 0rpx 20rpx;
  96. }
  97. .city_title {
  98. font-size: 30rpx;
  99. font-weight: 600;
  100. padding-top: 30rpx;
  101. padding-bottom: 30rpx;
  102. border-bottom: 2rpx solid transparent;
  103. border-image: linear-gradient(to bottom, transparent 50%, #e7e6e4 50%) 0 0 100% 0;
  104. }
  105. .item_district {
  106. font-size: 30rpx;
  107. font-weight: 600;
  108. padding: 30rpx 20rpx;
  109. border-bottom: 2rpx solid transparent;
  110. border-image: linear-gradient(to bottom, transparent 50%, #e7e6e4 50%) 0 0 100% 0;
  111. }
  112. </style>