李志伟 3 年前
父节点
当前提交
5cce81928a
共有 4 个文件被更改,包括 49 次插入22 次删除
  1. 15
    7
      src/components/AreaPicker/index.vue
  2. 6
    0
      src/main.js
  3. 19
    14
      src/pages/signup.vue
  4. 9
    1
      vue.config.js

+ 15
- 7
src/components/AreaPicker/index.vue 查看文件

1
 <template>
1
 <template>
2
-  <van-popup v-model="show">
3
-    <van-area title="地区" v-model="value" :area-list="areaList" :loading="loading" @confirm="$emit('change')" />
2
+  <van-popup v-model="visible" position="bottom">
3
+    <van-area title="地区" v-model="value" :area-list="areaList" :loading="loading" @confirm="handleConfirm" />
4
   </van-popup>
4
   </van-popup>
5
 </template>
5
 </template>
6
 
6
 
8
 export default {
8
 export default {
9
   name: 'AreaPicker',
9
   name: 'AreaPicker',
10
   props: {
10
   props: {
11
-    value: {
12
-      type: Array,
13
-      default: () => []
14
-    },
11
+    value: [String, Array],
15
     show: Boolean
12
     show: Boolean
16
   },
13
   },
17
   data() {
14
   data() {
21
     }
18
     }
22
   },
19
   },
23
   computed: {
20
   computed: {
21
+    visible: {
22
+      get() {
23
+        return this.show
24
+      },
25
+      set(val) {
26
+        this.$emit('update:show', val)
27
+      }
28
+    },
24
     areaList() {
29
     areaList() {
25
       return this.list.reduce((acc, x) => {
30
       return this.list.reduce((acc, x) => {
26
         const { province_list, city_list, county_list } = acc
31
         const { province_list, city_list, county_list } = acc
46
     this.getAreaData()
51
     this.getAreaData()
47
   },
52
   },
48
   methods: {
53
   methods: {
54
+    handleConfirm(v) {
55
+      this.$emit('change', v)
56
+    },
49
     getAreaData() {
57
     getAreaData() {
50
       const list = localStorage.getItem('areas')
58
       const list = localStorage.getItem('areas')
51
       if (list) {
59
       if (list) {
56
       this.loading = true
64
       this.loading = true
57
 
65
 
58
       // 如果不存在
66
       // 如果不存在
59
-      fetch('https://restapi.amap.com/v3/config/district?keywords=中国&subdistrict=3&key=194d2c8d01a9084e3b0bbb62d2d5fad0').then(res => res.JSON()).then(res => {
67
+      fetch('https://restapi.amap.com/v3/config/district?keywords=中国&subdistrict=3&key=194d2c8d01a9084e3b0bbb62d2d5fad0').then(res => res.json()).then(res => {
60
         this.list = res.districts[0].districts
68
         this.list = res.districts[0].districts
61
         localStorage.setItem('area', this.list)
69
         localStorage.setItem('area', this.list)
62
         this.loading = false
70
         this.loading = false

+ 6
- 0
src/main.js 查看文件

5
 import 'regenerator-runtime/runtime'
5
 import 'regenerator-runtime/runtime'
6
 import 'swiper/swiper-bundle.css'
6
 import 'swiper/swiper-bundle.css'
7
 
7
 
8
+
8
 import router from './router'
9
 import router from './router'
9
 import Swiper from './components/Swiper'
10
 import Swiper from './components/Swiper'
10
 import SwiperSlide from './components/SwiperSlide'
11
 import SwiperSlide from './components/SwiperSlide'
11
 
12
 
13
+import { Popup } from 'vant';
14
+import { Area } from 'vant';
15
+Vue.use(Popup);
16
+Vue.use(Area);
17
+
12
 Vue.config.productionTip = false
18
 Vue.config.productionTip = false
13
 Vue.component('swiper', Swiper)
19
 Vue.component('swiper', Swiper)
14
 Vue.component('swiper-slide', SwiperSlide)
20
 Vue.component('swiper-slide', SwiperSlide)

+ 19
- 14
src/pages/signup.vue 查看文件

36
       </div>
36
       </div>
37
       <div class="formItem addressdiv" @click="showArea = true">
37
       <div class="formItem addressdiv" @click="showArea = true">
38
         <label>所在地区</label>
38
         <label>所在地区</label>
39
-        <input class="address" type="text" placeholder="请选择" v-model="formData.address" />
39
+        <input class="address" type="text" placeholder="请选择" v-model="address" />
40
       </div>
40
       </div>
41
       <img @click="sumbit" class="submit" src="../../public/images/signup/submit.png" width="45%" />
41
       <img @click="sumbit" class="submit" src="../../public/images/signup/submit.png" width="45%" />
42
     </div>
42
     </div>
43
+    <area-picker :show.sync="showArea" @change="handleArea"></area-picker>
43
   </div>
44
   </div>
44
 </template>
45
 </template>
45
 <script>
46
 <script>
46
-// import checked from '../../public/images/signup/checked.png'
47
-// import Unchecked from '../../public/images/signup/Unchecked.png'
47
+
48
+
48
 export default {
49
 export default {
49
   components: {
50
   components: {
50
-    // AreaPicker: () => import('@/components/AreaPicker.vue')
51
+    AreaPicker: () => import('@/components/AreaPicker')
51
   },
52
   },
52
   data() {
53
   data() {
53
     return {
54
     return {
86
           }
87
           }
87
         ]
88
         ]
88
       ],
89
       ],
89
-      pickerVisibleProduct: false
90
+      pickerVisibleProduct: false,
91
+      address: undefined
92
+    }
93
+  },
94
+  watch: {
95
+    'this.formData.address'() {
96
+      this.address = formData.address[0].name+formData.address[1].name+formData.address[2].name
90
     }
97
     }
91
   },
98
   },
92
   methods: {
99
   methods: {
98
       this.ischecked = false
105
       this.ischecked = false
99
       this.formData.role = 'designer'
106
       this.formData.role = 'designer'
100
     },
107
     },
101
-    // showProduct() {
102
-    //   this.pickerVisibleProduct = true
103
-    // },
104
-    // cancelProduct() {
105
-    //   this.pickerVisibleProduct = false
106
-    // },
107
-    // confirmProduct(res) {
108
-    //   this.formData.intendedProduct = res[0].label
109
-    // },
108
+    handleArea(val) {
109
+      this.showArea = false
110
+      this.formData.address = val
111
+    },
110
     verification() {
112
     verification() {
111
       if (!this.formData.userName) {
113
       if (!this.formData.userName) {
112
         alert('请输入您的姓名')
114
         alert('请输入您的姓名')
135
 }
137
 }
136
 </script>
138
 </script>
137
 <style scoped>
139
 <style scoped>
140
+body #app{
141
+  background: none !important;
142
+}
138
 * {
143
 * {
139
   margin: 0;
144
   margin: 0;
140
   padding: 0;
145
   padding: 0;

+ 9
- 1
vue.config.js 查看文件

1
+
2
+const path = require('path')
3
+
1
 module.exports = {
4
 module.exports = {
2
-  publicPath: './'
5
+  publicPath: './',
6
+  chainWebpack(config) {
7
+    config.resolve.alias
8
+      .set('@/components', path.resolve(__dirname, 'src/components/'))
9
+      .set('@/utils', path.resolve(__dirname, 'src/utils/'))
10
+  }
3
 }
11
 }