张延森 4 years ago
parent
commit
6d9d0eb77a

+ 7
- 11
src/components/Picker/index.vue View File

1
 <template>
1
 <template>
2
   <div>
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
     <van-popup v-model:show="showPopup" position="bottom">
4
     <van-popup v-model:show="showPopup" position="bottom">
7
       <van-picker
5
       <van-picker
8
-        :title="title"
9
         :columns="columns"
6
         :columns="columns"
10
         @confirm="onConfirm"
7
         @confirm="onConfirm"
11
         @cancel="onCancel"
8
         @cancel="onCancel"
15
 </template>
12
 </template>
16
 
13
 
17
 <script>
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
 export default {
19
 export default {
22
   components: {
20
   components: {
23
-    [Cell.name]: Cell,
24
     [Popup.name]: Popup,
21
     [Popup.name]: Popup,
25
     [Picker.name]: Picker,
22
     [Picker.name]: Picker,
26
   },
23
   },
27
   props: {
24
   props: {
28
     options: Array,
25
     options: Array,
29
-    title: String,
30
     placeholder: String,
26
     placeholder: String,
31
     modelValue: undefined,
27
     modelValue: undefined,
32
   },
28
   },
34
   setup(props, { emit }) {
30
   setup(props, { emit }) {
35
     const showPopup = ref(false)
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
         return props.placeholder
35
         return props.placeholder
40
       }
36
       }
41
 
37
 
55
     const onCancel = () => showPopup.value = false;
51
     const onCancel = () => showPopup.value = false;
56
 
52
 
57
     return {
53
     return {
58
-      value,
54
+      text,
59
       columns,
55
       columns,
60
       showPopup,
56
       showPopup,
61
       onConfirm,
57
       onConfirm,

+ 49
- 21
src/components/queryCompents/areaQuery/index.vue View File

2
   <div class="areaQuery">
2
   <div class="areaQuery">
3
     <van-row :gutter="12">
3
     <van-row :gutter="12">
4
       <van-col span="12">
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
       </van-col>
12
       </van-col>
11
       <van-col span="12">
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
       </van-col>
21
       </van-col>
14
       </van-row>
22
       </van-row>
15
     </div>
23
     </div>
16
 </template>
24
 </template>
17
 
25
 
18
 <script>
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
 import { useModel } from '@zjxpcyc/vue-tiny-store'
29
 import { useModel } from '@zjxpcyc/vue-tiny-store'
22
 import Picker from '../../Picker'
30
 import Picker from '../../Picker'
23
 
31
 
26
   components: {
34
   components: {
27
     [Row.name]: Row,
35
     [Row.name]: Row,
28
     [Col.name]: Col,
36
     [Col.name]: Col,
37
+    [Cell.name]: Cell,
29
     Picker,
38
     Picker,
30
   },
39
   },
31
   props: {
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
     const { dicts, getBusinessCity } = useModel('dicts')
55
     const { dicts, getBusinessCity } = useModel('dicts')
43
-    // 楼盘
44
-    // 区位
45
-    const roomDistrict = dicts.roomDistrict
46
-    if (!roomDistrict) {
47
-      getBusinessCity(1)
48
-    }
49
 
56
 
50
     const roomDistrictOptions = computed(() => {
57
     const roomDistrictOptions = computed(() => {
58
+      // 楼盘
59
+      // 区县
60
+      const roomDistrict = dicts.roomDistrict
61
+      if (!roomDistrict) {
62
+        getBusinessCity(1)
63
+      }
51
       return (roomDistrict || []).map(x => ({...x, text: x.label}))
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
     return {
81
     return {
55
       val1,
82
       val1,
56
       val2,
83
       val2,
57
       roomDistrictOptions,
84
       roomDistrictOptions,
85
+      roomBussinesOptions,
58
     };
86
     };
59
   },
87
   },
60
 };
88
 };

+ 1
- 1
src/store/models/dicts.js View File

145
         dicts['roomDistrict'] = res
145
         dicts['roomDistrict'] = res
146
       } else {
146
       } else {
147
         // 商圈
147
         // 商圈
148
-        dicts['roomDistrict'] = res
148
+        dicts['roomBussines'] = res
149
       }
149
       }
150
     })
150
     })
151
   }
151
   }

+ 12
- 0
src/utils/index.js View File

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 View File

25
     <div>
25
     <div>
26
       <van-form @submit="onSubmit">
26
       <van-form @submit="onSubmit">
27
         <van-cell-group title="区位">
27
         <van-cell-group title="区位">
28
-          <AreaQuery name="area.b" label=""></AreaQuery>
28
+          <AreaQuery v-model="roomArea"></AreaQuery>
29
         </van-cell-group>
29
         </van-cell-group>
30
         <van-cell-group title="房间要求">
30
         <van-cell-group title="房间要求">
31
           <van-field name="number">
31
           <van-field name="number">
98
 </template>
98
 </template>
99
 
99
 
100
 <script>
100
 <script>
101
-import { reactive, ref } from "vue";
101
+import { computed, reactive, ref } from "vue";
102
 import {
102
 import {
103
   Col,
103
   Col,
104
   Row,
104
   Row,
116
   Icon,
116
   Icon,
117
   Popover,
117
   Popover,
118
 } from "vant";
118
 } from "vant";
119
-import { useModel } from '@zjxpcyc/vue-tiny-store'
119
+// import { useModel } from '@zjxpcyc/vue-tiny-store'
120
 
120
 
121
 import {
121
 import {
122
   AreaQuery,
122
   AreaQuery,
157
   },
157
   },
158
 emits:["onBack"],
158
 emits:["onBack"],
159
   setup(props,{emit}) {
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
     const state = reactive({
173
     const state = reactive({
170
       housetype: [],
174
       housetype: [],
225
     ];
229
     ];
226
 
230
 
227
     return {
231
     return {
232
+      roomArea,
228
       phoneShow,
233
       phoneShow,
229
       serchValue,
234
       serchValue,
230
       searchType,
235
       searchType,