Your Name 4 年之前
父節點
當前提交
ca0e78c096

+ 15
- 1
src/store/models/dicts.js 查看文件

@@ -162,5 +162,19 @@ export default () => {
162 162
     })
163 163
   }
164 164
 
165
-  return { dicts, getDict, getBusinessCity }
165
+  const getBuilding = ({ buildingName, pageNo = 1, pageSize = 20 }) => {
166
+    return request({
167
+      url: "/comm/dict/building-list",
168
+      params: { buildingName, pageNo, pageSize },
169
+    }).then((res) => {
170
+      if (res.result && res.result.length && !buildingName && pageNo === 1) {
171
+        // 只缓存第一页的
172
+        dicts["building"] = res.result
173
+      }
174
+
175
+      return res
176
+    })
177
+  }
178
+
179
+  return { dicts, getDict, getBusinessCity, getBuilding }
166 180
 }

+ 180
- 0
src/view/addhouse/addsecondhand/components/BuildingPicker.vue 查看文件

@@ -0,0 +1,180 @@
1
+<template>
2
+  <van-popup
3
+    v-model:show="showPicker"
4
+    position="right"
5
+    get-container="#app"
6
+    style="width: 90vw; height: 100vh"
7
+  >
8
+    <div class="building-sider">
9
+      <div class="search-box">
10
+        <van-search
11
+          v-model="params.buildingName"
12
+          placeholder="请输入搜索关键词"
13
+          @search="handleSearch"
14
+          @cancel="handleCancel"
15
+        />
16
+      </div>
17
+      <div class="list-box">
18
+        <van-list
19
+          v-model="loading"
20
+          :finished="finished"
21
+          finished-text="没有更多了"
22
+          @load="handleLoad"
23
+        >
24
+          <van-cell
25
+            v-for="item in list"
26
+            :key="item.buildingId"
27
+            :title="item.buildingName"
28
+            @click="handleSelect(item)"
29
+          >
30
+            <template #right-icon v-if="item.id === selectedId">
31
+              <van-icon name="success" color="#07c160" />
32
+            </template>
33
+          </van-cell>
34
+        </van-list>
35
+      </div>
36
+      <div class="action-box">
37
+        <van-button size="small" type="warning" @click="handleSubmit">
38
+          确定
39
+        </van-button>
40
+        <van-button size="small" @click="showPicker = false">取消</van-button>
41
+      </div>
42
+    </div>
43
+  </van-popup>
44
+</template>
45
+
46
+<script>
47
+import { computed, onMounted, reactive, ref } from "vue"
48
+import { Button, Popup, Search, List, Cell, Icon } from "vant"
49
+import { useModel } from "@zjxpcyc/vue-tiny-store"
50
+
51
+export default {
52
+  components: {
53
+    [Button.name]: Button,
54
+    [Popup.name]: Popup,
55
+    [Search.name]: Search,
56
+    [List.name]: List,
57
+    [Cell.name]: Cell,
58
+    [Icon.name]: Icon,
59
+  },
60
+  emits: ["change", "update:show"],
61
+  props: {
62
+    show: Boolean,
63
+  },
64
+  setup(props, { emit }) {
65
+    const loading = ref(false)
66
+    const finished = ref(false)
67
+    const selectedId = ref()
68
+    const selectedItem = ref()
69
+
70
+    const params = reactive({
71
+      buildingName: undefined,
72
+      pageNo: 1,
73
+      pageSize: 20,
74
+    })
75
+
76
+    const { dicts, getBuilding } = useModel("dicts")
77
+    const list = ref(dicts.building || [])
78
+
79
+    const showPicker = computed({
80
+      get: () => props.show,
81
+      set: (val) => emit("update:show", val),
82
+    })
83
+
84
+    const handleSearch = () => {
85
+      params.pageNo = 1
86
+      finished.value = false
87
+      handleLoad()
88
+    }
89
+
90
+    const handleCancel = () => {
91
+      params.pageNo = 1
92
+      params.buildingName = undefined
93
+      finished.value = false
94
+      handleLoad()
95
+    }
96
+
97
+    const handleLoad = () => {
98
+      if (loading.value) {
99
+        return
100
+      }
101
+
102
+      loading.value = true
103
+      getBuilding(params)
104
+        .then((res) => {
105
+          params.pageNo += 1
106
+          loading.value = false
107
+          finished.value = res.currentPage >= res.totalPages
108
+          if (res.currentPage === 1) {
109
+            list.value = res.result || []
110
+          } else {
111
+            list.value = list.value.concat(res.result || [])
112
+          }
113
+        })
114
+        .catch((e) => {
115
+          console.error(e)
116
+          loading.value = false
117
+        })
118
+    }
119
+
120
+    const handleSelect = (item) => {
121
+      selectedId.value = item.id
122
+      selectedItem.value = item
123
+    }
124
+
125
+    const handleSubmit = () => {
126
+      showPicker.value = false
127
+      emit("change", { id: selectedId.value, item: selectedItem.value })
128
+    }
129
+
130
+    onMounted(() => {
131
+      // if (!list.value || !list.value.length) {
132
+      //   handleLoad()
133
+      // }
134
+    })
135
+
136
+    return {
137
+      showPicker,
138
+      loading,
139
+      params,
140
+      finished,
141
+      list,
142
+      selectedId,
143
+      handleSelect,
144
+      handleLoad,
145
+      handleSearch,
146
+      handleCancel,
147
+      handleSubmit,
148
+    }
149
+  },
150
+}
151
+</script>
152
+
153
+<style lang="less" scoped>
154
+.building-sider {
155
+  height: 100vh;
156
+  display: flex;
157
+  flex-direction: column;
158
+  overflow: hidden;
159
+
160
+  .search-box {
161
+    flex: none;
162
+  }
163
+
164
+  .action-box {
165
+    flex: none;
166
+    padding: 1em 0;
167
+    display: flex;
168
+    justify-content: space-around;
169
+
170
+    & > * {
171
+      padding: 0 2em;
172
+    }
173
+  }
174
+
175
+  .list-box {
176
+    flex: auto;
177
+    overflow-y: auto;
178
+  }
179
+}
180
+</style>

+ 14
- 18
src/view/addhouse/addsecondhand/index.vue 查看文件

@@ -10,19 +10,15 @@
10 10
       <van-form @submit="onSubmit">
11 11
         <van-field
12 12
           v-model="state.username"
13
-          name="22222"
13
+          readonly
14 14
           label="选择楼盘"
15
+          placeholder="请选择"
15 16
           required
16
-          :rules="[{ required: true, message: '请选择楼盘' }]"
17
-        >
18
-          <template #input>
19
-            <van-search
20
-              v-model="state.username"
21
-              style="pdding: 0"
22
-              placeholder="请输入"
23
-            />
24
-          </template>
25
-        </van-field>
17
+          clickable
18
+          @click="showBuildingPicker = true"
19
+        />
20
+
21
+        <BuildingPicker v-model:show="showBuildingPicker" />
26 22
 
27 23
         <van-field
28 24
           v-model="state.username"
@@ -239,7 +235,7 @@
239 235
 </template>
240 236
 
241 237
 <script>
242
-import { reactive } from "vue"
238
+import { reactive, ref } from "vue"
243 239
 
244 240
 import {
245 241
   Icon,
@@ -257,13 +253,9 @@ import {
257 253
   Radio,
258 254
 } from "vant"
259 255
 
260
-import {
261
-  Pickerc,
262
-  Housetypec,
263
-  Ladderhousec,
264
-} from "../../../components/editCompents"
256
+import { Pickerc, Housetypec, Ladderhousec } from "@/components/editCompents"
265 257
 
266
-// import { router } from "../../../router";
258
+import BuildingPicker from "./components/BuildingPicker"
267 259
 
268 260
 export default {
269 261
   name: "addsecondhand",
@@ -283,12 +275,15 @@ export default {
283 275
     Housetypec: Housetypec,
284 276
     Pickerc: Pickerc,
285 277
     Ladderhousec: Ladderhousec,
278
+    BuildingPicker,
286 279
   },
287 280
   data() {
288 281
     return {}
289 282
   },
290 283
 
291 284
   setup() {
285
+    const showBuildingPicker = ref(false)
286
+
292 287
     const state = reactive({
293 288
       username: "",
294 289
       password: "",
@@ -304,6 +299,7 @@ export default {
304 299
 
305 300
     return {
306 301
       state,
302
+      showBuildingPicker,
307 303
       onSubmit,
308 304
     }
309 305
   },