张延森 4 jaren geleden
bovenliggende
commit
6d9d0eb77a

+ 7
- 11
src/components/Picker/index.vue Bestand weergeven

@@ -1,11 +1,8 @@
1 1
 <template>
2 2
   <div>
3
-    <van-cell :title="title">
4
-      <div class="picker-item-body" @click="showPopup = true">{{value}}</div>
5
-    </van-cell>
3
+    <div class="picker-item-body" @click="showPopup = true">{{text}}</div>
6 4
     <van-popup v-model:show="showPopup" position="bottom">
7 5
       <van-picker
8
-        :title="title"
9 6
         :columns="columns"
10 7
         @confirm="onConfirm"
11 8
         @cancel="onCancel"
@@ -15,18 +12,17 @@
15 12
 </template>
16 13
 
17 14
 <script>
18
-import { Cell, Popup, Picker } from 'vant'
19
-import { computed, ref } from 'vue'
15
+import { Popup, Picker } from 'vant'
16
+import { computed, ref, toRaw, unref } from 'vue'
17
+import { isEmpty } from '@/utils'
20 18
 
21 19
 export default {
22 20
   components: {
23
-    [Cell.name]: Cell,
24 21
     [Popup.name]: Popup,
25 22
     [Picker.name]: Picker,
26 23
   },
27 24
   props: {
28 25
     options: Array,
29
-    title: String,
30 26
     placeholder: String,
31 27
     modelValue: undefined,
32 28
   },
@@ -34,8 +30,8 @@ export default {
34 30
   setup(props, { emit }) {
35 31
     const showPopup = ref(false)
36 32
 
37
-    const value = computed(() => {
38
-      if (props.modelValue === undefined || props.modelValue === null) {
33
+    const text = computed(() => {
34
+      if (isEmpty(props.modelValue) || isEmpty(toRaw(props.modelValue)) || isEmpty(unref(props.modelValue))) {
39 35
         return props.placeholder
40 36
       }
41 37
 
@@ -55,7 +51,7 @@ export default {
55 51
     const onCancel = () => showPopup.value = false;
56 52
 
57 53
     return {
58
-      value,
54
+      text,
59 55
       columns,
60 56
       showPopup,
61 57
       onConfirm,

+ 49
- 21
src/components/queryCompents/areaQuery/index.vue Bestand weergeven

@@ -2,22 +2,30 @@
2 2
   <div class="areaQuery">
3 3
     <van-row :gutter="12">
4 4
       <van-col span="12">
5
-        <Picker
6
-          title="区县"
7
-          :options="roomDistrictOptions"
8
-          v-model="val1"
9
-        />
5
+        <van-cell title="区县">
6
+          <Picker
7
+            placeholder="请选择区县"
8
+            :options="roomDistrictOptions"
9
+            v-model="val1"
10
+          />
11
+        </van-cell>
10 12
       </van-col>
11 13
       <van-col span="12">
12
-        
14
+        <van-cell title="商圈">
15
+          <Picker
16
+            placeholder="请选择商圈"
17
+            :options="roomBussinesOptions"
18
+            v-model="val2"
19
+          />
20
+        </van-cell>
13 21
       </van-col>
14 22
       </van-row>
15 23
     </div>
16 24
 </template>
17 25
 
18 26
 <script>
19
-import { computed, ref } from 'vue';
20
-import { Col, Row } from "vant";
27
+import { computed } from 'vue';
28
+import { Cell, Col, Row } from "vant";
21 29
 import { useModel } from '@zjxpcyc/vue-tiny-store'
22 30
 import Picker from '../../Picker'
23 31
 
@@ -26,35 +34,55 @@ export default {
26 34
   components: {
27 35
     [Row.name]: Row,
28 36
     [Col.name]: Col,
37
+    [Cell.name]: Cell,
29 38
     Picker,
30 39
   },
31 40
   props: {
32
-    name:String,
33
-    label:String,
34
-    other:Object,
35
-    // placeholder:'请选择',
41
+    modelValue: undefined,
36 42
   },
43
+  emits: ['update:modelValue'],
37 44
 
38
-  setup() {
39
-    const val1 = ref()
40
-    const val2 = ref()
45
+  setup(props, {emit}) {
46
+    const val1 = computed({
47
+      get: () => (props.modelValue || {}).roomDistrict,
48
+      set: val => emit('update:modelValue', { ...(props.modelValue || {}), roomDistrict: val })
49
+    })
50
+    const val2 = computed({
51
+      get: () => (props.modelValue || {}).roomBussines,
52
+      set: val => emit('update:modelValue', { ...(props.modelValue || {}), roomBussines: val })
53
+    })
41 54
 
42 55
     const { dicts, getBusinessCity } = useModel('dicts')
43
-    // 楼盘
44
-    // 区位
45
-    const roomDistrict = dicts.roomDistrict
46
-    if (!roomDistrict) {
47
-      getBusinessCity(1)
48
-    }
49 56
 
50 57
     const roomDistrictOptions = computed(() => {
58
+      // 楼盘
59
+      // 区县
60
+      const roomDistrict = dicts.roomDistrict
61
+      if (!roomDistrict) {
62
+        getBusinessCity(1)
63
+      }
51 64
       return (roomDistrict || []).map(x => ({...x, text: x.label}))
52 65
     })
66
+
67
+    // 商圈 - 依据区县联动
68
+    const roomBussinesOptions = computed(() => {
69
+      if (!val1.value) {
70
+        return []
71
+      }
72
+
73
+      const roomBussines = dicts.roomBussines
74
+      if (!roomBussines) {
75
+        getBusinessCity(2, val1.value)
76
+      }
77
+
78
+      return (roomBussines || []).map(x => ({...x, text: x.label}))
79
+    })
53 80
     
54 81
     return {
55 82
       val1,
56 83
       val2,
57 84
       roomDistrictOptions,
85
+      roomBussinesOptions,
58 86
     };
59 87
   },
60 88
 };

+ 1
- 1
src/store/models/dicts.js Bestand weergeven

@@ -145,7 +145,7 @@ export default () => {
145 145
         dicts['roomDistrict'] = res
146 146
       } else {
147 147
         // 商圈
148
-        dicts['roomDistrict'] = res
148
+        dicts['roomBussines'] = res
149 149
       }
150 150
     })
151 151
   }

+ 12
- 0
src/utils/index.js Bestand weergeven

@@ -0,0 +1,12 @@
1
+
2
+export function isEmpty (o) {
3
+  if (o === undefined || o === null || o === '') {
4
+    return true
5
+  }
6
+
7
+  if (Array.isArray(o) && o.length < 1) {
8
+    return true
9
+  }
10
+
11
+  return false
12
+}

+ 16
- 11
src/view/secondhand/components/secondhandmorescreen/index.vue Bestand weergeven

@@ -25,7 +25,7 @@
25 25
     <div>
26 26
       <van-form @submit="onSubmit">
27 27
         <van-cell-group title="区位">
28
-          <AreaQuery name="area.b" label=""></AreaQuery>
28
+          <AreaQuery v-model="roomArea"></AreaQuery>
29 29
         </van-cell-group>
30 30
         <van-cell-group title="房间要求">
31 31
           <van-field name="number">
@@ -98,7 +98,7 @@
98 98
 </template>
99 99
 
100 100
 <script>
101
-import { reactive, ref } from "vue";
101
+import { computed, reactive, ref } from "vue";
102 102
 import {
103 103
   Col,
104 104
   Row,
@@ -116,7 +116,7 @@ import {
116 116
   Icon,
117 117
   Popover,
118 118
 } from "vant";
119
-import { useModel } from '@zjxpcyc/vue-tiny-store'
119
+// import { useModel } from '@zjxpcyc/vue-tiny-store'
120 120
 
121 121
 import {
122 122
   AreaQuery,
@@ -157,14 +157,18 @@ export default {
157 157
   },
158 158
 emits:["onBack"],
159 159
   setup(props,{emit}) {
160
-    const { dicts, getBusinessCity } = useModel('dicts')
161
-    console.log(props)
162
-    // 楼盘
163
-    // 区位
164
-    const roomDistrict = dicts.roomDistrict
165
-    if (!roomDistrict) {
166
-      getBusinessCity(1)
167
-    }
160
+    // const { dicts, getBusinessCity } = useModel('dicts')
161
+    
162
+    const roomDistrict = ref()
163
+    const roomBussines = ref()
164
+    const roomArea = computed({
165
+      get: () => ({roomDistrict: roomDistrict.value, roomBussines: roomBussines.value}),
166
+      set: val => {
167
+        roomDistrict.value = val.roomDistrict
168
+        roomBussines.value = val.roomBussines
169
+      }
170
+    })
171
+
168 172
 
169 173
     const state = reactive({
170 174
       housetype: [],
@@ -225,6 +229,7 @@ emits:["onBack"],
225 229
     ];
226 230
 
227 231
     return {
232
+      roomArea,
228 233
       phoneShow,
229 234
       serchValue,
230 235
       searchType,