location.vue 7.96 KB
Newer Older
786817560's avatar
786817560 committed
1 2 3 4
<!--
   * @Descrip""/>User Settings Edit
 * @Author: your name
 * @Date: 2019-10-11 09:39:51
786817560's avatar
786817560 committed
5
 * @LastEditTime: 2019-11-25 10:01:44
786817560's avatar
786817560 committed
6 7 8 9 10 11 12 13 14 15
 * @LastEditors: Please set LastEditors
   -->
<template>
  <h-view id="location" class="public-style" title="定位">
    <h-header :proportion="[5,1,1]" class="bar-custom">
      <div slot="left" class="h-header-btn">
        <img src="@/assets/userBind/arrow.png" @click="$routeGo()">
        <span>选择地区</span>
      </div>
    </h-header>
786817560's avatar
786817560 committed
16
    <section>
李晓兵's avatar
李晓兵 committed
17 18 19
      <section class="location-wrap">
        <div class="current-location">
          <div class="img-box">
786817560's avatar
786817560 committed
20
            <img src="@/assets/homePage/locationImage.png" alt="">
786817560's avatar
786817560 committed
21

李晓兵's avatar
李晓兵 committed
22 23
          </div>
          <p>当前位置</p>
786817560's avatar
786817560 committed
24
        </div>
李晓兵's avatar
李晓兵 committed
25 26 27 28 29 30 31 32
        <list-item>
          <item :proportion="[5,2]">
            <section slot="name" class="place">{{ places }}</section>
            <section slot="content" class="relocation">
              <div>
                <img src="@/assets/homePage/relocation.png" alt="">
                <p @click="relocation">重新定位</p>
              </div>
786817560's avatar
786817560 committed
33

李晓兵's avatar
李晓兵 committed
34
            </section>
786817560's avatar
786817560 committed
35 36
          </item>
        </list-item>
李晓兵's avatar
李晓兵 committed
37 38 39 40 41 42 43 44 45
        <div class="current-location">
          <p class="select-location" @click="switchCity">选择位置</p>
        </div>
        <div class="provinces">
          <p :class="{styles:!flag}" @click="changeStyle(1)">{{ province }}</p>
          <p :class="{styles:flag}" @click="changeStyle(2)">{{ city }}</p>
        </div>
      </section>
      <!-- 省份 -->
李晓兵's avatar
李晓兵 committed
46
      <section v-show="province_flag" ref="pro" class="pro-wrapper">
李晓兵's avatar
李晓兵 committed
47 48 49 50 51 52 53 54
        <div class="pro-content">
          <list-item :item-height="40">
            <item v-for="(item,index) in lists" :key="index" :proportion="[5,2]">
              <section slot="name" @click="selectProvince(item)">{{ item.province_name }}</section>
            </item>
          </list-item>
        </div>
      </section>
李晓兵's avatar
李晓兵 committed
55 56 57 58 59 60 61 62 63 64
      <!-- 城市 -->
      <section v-show="!province_flag" ref="city" class="pro-wrapper">
        <div class="city-content">
          <list-item :item-height="40">
            <item v-for="(item,index) in cityList" :key="index" :proportion="[5,2]">
              <section slot="name" @click="selectCity(item.city_name)">{{ item.city_name }}</section>
            </item>
          </list-item>
        </div>
      </section>
786817560's avatar
786817560 committed
65
  </section></h-view>
786817560's avatar
786817560 committed
66 67
</template>
<script>
李晓兵's avatar
李晓兵 committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
import BScroll from 'better-scroll'
export default {
  name: 'Location',
  data () {
    return {
      flag: false,
      province_flag: true,
      province: '请选择省',
      city: '请选择市',
      places: '',
      lists: [],
      cityList: [],
    }
  },
  computed: {},
  watch: {},
  created () {
    // 判断是否是初次进入,不是就显示手动绑定的位置
    if (window.localStorage.getItem('province')) {
      this.places = window.localStorage.getItem('province') + '-' + window.localStorage.getItem('city')
    } else {
      this.places = this.$route.params.province + '-' + this.$route.params.city
    }
    this.selectLocation()
  },
  methods:
李晓兵's avatar
李晓兵 committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
      {
        // 重新定位到当前位置
        relocation () {
          let vm = this
          var geolocation = new BMap.Geolocation()
          geolocation.getCurrentPosition(function (res) {
            //  debugger
            if (this.getStatus() === 0) {
              window.localStorage.setItem('province', res.address.province)
              window.localStorage.setItem('city', res.address.city)
              vm.places = window.localStorage.getItem('province') + '-' + window.localStorage.getItem('city')
              vm.province = '请选择省'
              vm.city = '请选择市'
              vm.flag = false
              vm.province_flag = true
            }
          }, {enableHighAccuracy: true})
        },
786817560's avatar
786817560 committed
112

李晓兵's avatar
李晓兵 committed
113 114 115 116 117
        // 省份查询
        selectLocation () {
          let vm = this
          let url = process.env.basePath + 'fnd_province_query'
          let param = {}
786817560's avatar
786817560 committed
118
          vm.hlsPopup.showLoading('请稍后')
李晓兵's avatar
李晓兵 committed
119
          vm.hlsHttp.post(url, param).then(function (res) {
786817560's avatar
786817560 committed
120
            vm.hlsPopup.hideLoading()
李晓兵's avatar
李晓兵 committed
121 122 123
            vm.lists = res.lists
            vm.$nextTick(() => {
              vm.scroll = new BScroll(vm.$refs.pro, {
李晓兵's avatar
李晓兵 committed
124
                click: true,
李晓兵's avatar
李晓兵 committed
125 126 127 128 129
              })
            })
          })
        },
        switchCity () {
786817560's avatar
786817560 committed
130

李晓兵's avatar
李晓兵 committed
131
        },
786817560's avatar
786817560 committed
132

李晓兵's avatar
李晓兵 committed
133 134 135 136 137 138 139 140 141
        // 省份与城市切换
        changeStyle (val) {
          if (val === 1) {
            this.flag = false
            this.province_flag = true
          } else {
            this.flag = true
          }
        },
786817560's avatar
786817560 committed
142

李晓兵's avatar
李晓兵 committed
143 144 145 146 147 148 149 150
        // 城市查询
        selectProvince (val) {
          this.province = val.province_name
          let url = process.env.basePath + 'fnd_city_query'
          let param = {
            province_id: val.province_id,
          }
          let vm = this
786817560's avatar
786817560 committed
151
          // vm.hlsPopus.showLoading('请稍后')
李晓兵's avatar
李晓兵 committed
152 153
          this.hlsHttp.post(url, param).then(function (res) {
            console.log(res)
786817560's avatar
786817560 committed
154
            // vm.hlsPopup.hideLoading()
李晓兵's avatar
李晓兵 committed
155
            vm.cityList = res.lists
李晓兵's avatar
李晓兵 committed
156 157 158 159 160
            vm.$nextTick(() => {
              vm.cityScroll = new BScroll(vm.$refs.city, {
                click: true,
              })
            })
李晓兵's avatar
李晓兵 committed
161 162 163 164 165 166 167 168 169 170
          })
          this.flag = !this.flag
          this.province_flag = false
        },
        selectCity (val) {
          this.hlsPopup.showConfirm({
            title: '提示',
            content: `是否切换到${val}?`,
            onConfirm: (data) => {
              if (data) {
linxin's avatar
linxin committed
171
                //  window.localStorage.setItem('bp_class', item.bp_class)
李晓兵's avatar
李晓兵 committed
172 173 174 175 176 177 178 179 180
                window.localStorage.setItem('province', this.province)
                window.localStorage.setItem('city', val)
                this.places = this.province + '-' + val
                this.city = val
              }
            },
          })
        },
      },
李晓兵's avatar
李晓兵 committed
181
}
786817560's avatar
786817560 committed
182 183
</script>
<style lang='less' scoped>
李晓兵's avatar
李晓兵 committed
184 185 186 187 188 189 190 191 192 193 194 195 196
  #location {
    .location-wrap{
      position: relative;
      overflow: hidden;
    }
    .pro-wrapper{
      position: absolute;
      top: 205px;
      bottom: 0;
      left: 0;
      width: 100%;
      overflow: hidden;
    }
786817560's avatar
786817560 committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    .h-header-btn {
      img {
        width: 16px;
        height: 16px;
        margin-left: 4px;
      }

      span {
        font-family: PingFangSC-Semibold;
        margin-left: 16px;
        font-size: 17px;
        letter-spacing: 0.61px;
        line-height: 24px;
      }
    }
    .current-location {
李晓兵's avatar
李晓兵 committed
213 214 215 216 217 218 219 220 221 222 223 224
      height: 34px;
      width: 100%;
      display: flex;
      align-items: center;
      background: rgba(0, 70, 156, 0.1);
      .img-box {
        width: 16px;
        height: 16px;
        margin-left: 17px;
        img {
          width: 100%;
          height: 100%;
786817560's avatar
786817560 committed
225
        }
李晓兵's avatar
李晓兵 committed
226 227 228 229 230 231 232 233 234

      }
      .select-location {
        margin-left: 17px
      }
      p {
        // width: 56px;
        font-family: PingFangSC-Semibold;
        font-size: 14px;
李晓兵's avatar
李晓兵 committed
235
        color: @headerColor;
李晓兵's avatar
李晓兵 committed
236 237 238 239
        letter-spacing: 0;
        margin-left: 6px;
        font-weight: 700
      }
786817560's avatar
786817560 committed
240 241
    }
    .place {
李晓兵's avatar
李晓兵 committed
242 243 244 245 246
      font-family: PingFangSC-Semibold;
      font-weight: 600;
      font-size: 14px;
      color: #383F45;
      letter-spacing: 0;
786817560's avatar
786817560 committed
247 248
    }
    .relocation {
李晓兵's avatar
李晓兵 committed
249 250
      font-family: PingFangSC-Regular;
      font-size: 13px;
李晓兵's avatar
李晓兵 committed
251
      color: @headerColor;
李晓兵's avatar
李晓兵 committed
252 253 254 255 256 257 258 259 260 261 262
      letter-spacing: 0;
      div {
        display: flex;
        flex-direction: row;
        align-items: center;
        img {
          width: 16px;
          height: 16px;
          margin-right: 6px
        }
      }
786817560's avatar
786817560 committed
263 264 265

    }
    .hls-list-item {
李晓兵's avatar
李晓兵 committed
266
      margin-bottom: 0
786817560's avatar
786817560 committed
267 268
    }
    .provinces {
李晓兵's avatar
李晓兵 committed
269 270 271 272 273 274 275
      background: #fff;
      width: 100%;
      height: 40px;
      display: flex;
      flex-direction: row;
      border-bottom: 1px solid #fafafa;
      p {
786817560's avatar
786817560 committed
276
        height: 40px;
李晓兵's avatar
李晓兵 committed
277 278 279 280 281 282
        line-height: 40px;
        margin-left: 15px;
        font-family: PingFangSC-Semibold;
        font-size: 14px;
        color: rgba(56,63,69,0.60);
        letter-spacing: 0.5px;
786817560's avatar
786817560 committed
283

李晓兵's avatar
李晓兵 committed
284 285 286 287 288 289 290
      }
      .styles {
        font-family: PingFangSC-Semibold;
        border-bottom: 2px solid blue;
        color: #383F45;
        font-weight: 600;
      }
786817560's avatar
786817560 committed
291
    }
李晓兵's avatar
李晓兵 committed
292
  }
786817560's avatar
786817560 committed
293
</style>